summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_path.js
blob: da2596ef53910bd8c14f6d8882aeedfae5e06677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/* import-globals-from helper-addons.js */
Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);

/**
 * Test the the path used to install a temporary addon is saved in a preference and reused
 * next time the feature is used.
 */

const EXTENSION_PATH = "resources/test-temporary-extension/manifest.json";
const EXTENSION_NAME = "test-temporary-extension";
const LAST_DIR_PREF = "devtools.aboutdebugging.tmpExtDirPath";

// Check that the preference is updated when trying to install a temporary extension.
add_task(async function testPreferenceUpdatedAfterInstallingExtension() {
  registerCleanupFunction(() => {
    Services.prefs.clearUserPref(LAST_DIR_PREF);
  });
  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  await installTemporaryExtension(EXTENSION_PATH, EXTENSION_NAME, document);

  info("Check whether the selected dir sets into the pref");
  const lastDirPath = Services.prefs.getCharPref(LAST_DIR_PREF, "");
  const expectedPath = getTestFilePath("resources/test-temporary-extension");
  is(lastDirPath, expectedPath, "The selected dir should set into the pref");

  await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, document));
  await removeTemporaryExtension(EXTENSION_NAME, document);
  await removeTab(tab);
});

// Check that the preference is updated when trying to install a temporary extension.
add_task(async function testPreferenceRetrievedWhenInstallingExtension() {
  const selectedDir = getTestFilePath("resources/packaged-extension");

  await pushPref(LAST_DIR_PREF, selectedDir);

  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  const MockFilePicker = SpecialPowers.MockFilePicker;
  MockFilePicker.init(window.browsingContext);
  const onFilePickerShown = new Promise(resolve => {
    MockFilePicker.showCallback = fp => {
      resolve(fp);
    };
  });
  document.querySelector(".qa-temporary-extension-install-button").click();

  info("Check whether the shown dir is same as the pref");
  const fp = await onFilePickerShown;
  is(
    fp.displayDirectory.path,
    selectedDir,
    "Shown directory sets as same as the pref"
  );

  await removeTab(tab);
});