summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/webextensions/browser_update_interactive_noprompt.js
blob: 016eb22667ccac2ecb980acd1d908e9bc6d97815 (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
66
67
68
69
70
71
72
73
74
75
76
77
// Set some prefs that apply to all the tests in this file
add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      // We don't have pre-pinned certificates for the local mochitest server
      ["extensions.install.requireBuiltInCerts", false],
      ["extensions.update.requireBuiltInCerts", false],

      // Don't require the extensions to be signed
      ["xpinstall.signatures.required", false],

      // Point updates to the local mochitest server
      ["extensions.update.url", `${BASE}/browser_webext_update.json`],
    ],
  });
});

// Helper to test that an update of a given extension does not
// generate any permission prompts.
async function testUpdateNoPrompt(
  filename,
  id,
  initialVersion = "1.0",
  updateVersion = "2.0"
) {
  // Navigate away to ensure that BrowserOpenAddonMgr() opens a new tab
  BrowserTestUtils.loadURIString(gBrowser.selectedBrowser, "about:mozilla");
  await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);

  // Install initial version of the test extension
  let addon = await promiseInstallAddon(`${BASE}/${filename}`);
  ok(addon, "Addon was installed");
  is(addon.version, initialVersion, "Version 1 of the addon is installed");

  // Go to Extensions in about:addons
  let win = await BrowserOpenAddonsMgr("addons://list/extension");

  await waitAboutAddonsViewLoaded(win.document);

  let sawPopup = false;
  function popupListener() {
    sawPopup = true;
  }
  PopupNotifications.panel.addEventListener("popupshown", popupListener);

  // Trigger an update check, we should see the update get applied
  let updatePromise = waitForUpdate(addon);
  triggerPageOptionsAction(win, "check-for-updates");
  await updatePromise;

  addon = await AddonManager.getAddonByID(id);
  is(addon.version, updateVersion, "Should have upgraded");

  ok(!sawPopup, "Should not have seen a permission notification");
  PopupNotifications.panel.removeEventListener("popupshown", popupListener);

  BrowserTestUtils.removeTab(gBrowser.selectedTab);
  await addon.uninstall();
}

// Test that we don't see a prompt when no new promptable permissions
// are added.
add_task(() =>
  testUpdateNoPrompt(
    "browser_webext_update_perms1.xpi",
    "update_perms@tests.mozilla.org"
  )
);

// Test that an update that narrows origin permissions is just applied without
// showing a notification promt
add_task(() =>
  testUpdateNoPrompt(
    "browser_webext_update_origins1.xpi",
    "update_origins@tests.mozilla.org"
  )
);