Bug 1341337 - Split test browser_extension_update_background.js; r=kmag
authorGeoff Brown <gbrown@mozilla.com>
Mon, 03 Apr 2017 16:50:13 -0600
changeset 555406 284cf846989b496bb3b8b711f5648dbb9f4ef2f9
parent 555405 2a47268c3fdd5cd5b27ff92d2efaf44af628ee6a
child 555407 edfb3b0fc079dd1bf4346dba9f94d2b8964a82d7
push id52236
push usercykesiopka.bmo@gmail.com
push dateTue, 04 Apr 2017 09:12:57 +0000
reviewerskmag
bugs1341337
milestone55.0a1
Bug 1341337 - Split test browser_extension_update_background.js; r=kmag
browser/base/content/test/webextensions/browser.ini
browser/base/content/test/webextensions/browser_extension_update_background.js
browser/base/content/test/webextensions/browser_extension_update_background_noprompt.js
--- a/browser/base/content/test/webextensions/browser.ini
+++ b/browser/base/content/test/webextensions/browser.ini
@@ -13,16 +13,17 @@ support-files =
   browser_webext_update_icon2.xpi
   browser_webext_update_perms1.xpi
   browser_webext_update_perms2.xpi
   browser_webext_update.json
   browser_webext_search.xml
 
 [browser_extension_sideloading.js]
 [browser_extension_update_background.js]
+[browser_extension_update_background_noprompt.js]
 [browser_permissions_addons_search.js]
 [browser_permissions_installTrigger.js]
 [browser_permissions_local_file.js]
 [browser_permissions_mozAddonManager.js]
 [browser_permissions_unsigned.js]
 skip-if = require_signing
 [browser_update_checkForUpdates.js]
 [browser_update_findUpdates.js]
--- a/browser/base/content/test/webextensions/browser_extension_update_background.js
+++ b/browser/base/content/test/webextensions/browser_extension_update_background.js
@@ -181,60 +181,8 @@ function checkNonDefaultIcon(icon) {
   // path, just make sure we've got a jar url pointing to the right path
   // inside the jar.
   ok(icon.startsWith("jar:file://"), "Icon is a jar url");
   ok(icon.endsWith("/icon.png"), "Icon is icon.png inside a jar");
 }
 
 add_task(() => backgroundUpdateTest(`${BASE}/browser_webext_update_icon1.xpi`,
                                     ID_ICON, checkNonDefaultIcon));
-
-// Helper function to test an upgrade that should not show a prompt
-async function testNoPrompt(origUrl, id) {
-  await SpecialPowers.pushPrefEnv({set: [
-    // Turn on background updates
-    ["extensions.update.enabled", true],
-
-    // Point updates to the local mochitest server
-    ["extensions.update.background.url", `${BASE}/browser_webext_update.json`],
-  ]});
-
-  // Install version 1.0 of the test extension
-  let addon = await promiseInstallAddon(origUrl);
-
-  ok(addon, "Addon was installed");
-
-  let sawPopup = false;
-  PopupNotifications.panel.addEventListener("popupshown",
-                                            () => sawPopup = true,
-                                            {once: true});
-
-  // Trigger an update check and wait for the update to be applied.
-  let updatePromise = waitForUpdate(addon);
-  AddonManagerPrivate.backgroundUpdateCheck();
-  await updatePromise;
-
-  // There should be no notifications about the update
-  is(getBadgeStatus(), "", "Should not have addon alert badge");
-
-  await PanelUI.show();
-  let addons = document.getElementById("PanelUI-footer-addons");
-  is(addons.children.length, 0, "Have 0 updates in the PanelUI menu");
-  await PanelUI.hide();
-
-  ok(!sawPopup, "Should not have seen permissions notification");
-
-  addon = await AddonManager.getAddonByID(id);
-  is(addon.version, "2.0", "Update should have applied");
-
-  addon.uninstall();
-  await SpecialPowers.popPrefEnv();
-}
-
-// Test that an update that adds new non-promptable permissions is just
-// applied without showing a notification dialog.
-add_task(() => testNoPrompt(`${BASE}/browser_webext_update_perms1.xpi`,
-                            ID_PERMS));
-
-// Test that an update from a legacy extension to a webextension
-// doesn't show a prompt even when the webextension uses
-// promptable required permissions.
-add_task(() => testNoPrompt(`${BASE}/browser_legacy.xpi`, ID_LEGACY));
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/webextensions/browser_extension_update_background_noprompt.js
@@ -0,0 +1,83 @@
+const {AddonManagerPrivate} = Cu.import("resource://gre/modules/AddonManager.jsm", {});
+
+const ID_PERMS = "update_perms@tests.mozilla.org";
+const ID_LEGACY = "legacy_update@tests.mozilla.org";
+
+function getBadgeStatus() {
+  let menuButton = document.getElementById("PanelUI-menu-button");
+  return menuButton.getAttribute("badge-status");
+}
+
+// Set some prefs that apply to all the tests in this file
+add_task(function* setup() {
+  yield SpecialPowers.pushPrefEnv({set: [
+    // We don't have pre-pinned certificates for the local mochitest server
+    ["extensions.install.requireBuiltInCerts", false],
+    ["extensions.update.requireBuiltInCerts", false],
+  ]});
+
+  // Navigate away from the initial page so that about:addons always
+  // opens in a new tab during tests
+  gBrowser.selectedBrowser.loadURI("about:robots");
+  yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
+
+  registerCleanupFunction(function*() {
+    // Return to about:blank when we're done
+    gBrowser.selectedBrowser.loadURI("about:blank");
+    yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
+  });
+});
+
+hookExtensionsTelemetry();
+
+// Helper function to test an upgrade that should not show a prompt
+async function testNoPrompt(origUrl, id) {
+  await SpecialPowers.pushPrefEnv({set: [
+    // Turn on background updates
+    ["extensions.update.enabled", true],
+
+    // Point updates to the local mochitest server
+    ["extensions.update.background.url", `${BASE}/browser_webext_update.json`],
+  ]});
+
+  // Install version 1.0 of the test extension
+  let addon = await promiseInstallAddon(origUrl);
+
+  ok(addon, "Addon was installed");
+
+  let sawPopup = false;
+  PopupNotifications.panel.addEventListener("popupshown",
+                                            () => sawPopup = true,
+                                            {once: true});
+
+  // Trigger an update check and wait for the update to be applied.
+  let updatePromise = waitForUpdate(addon);
+  AddonManagerPrivate.backgroundUpdateCheck();
+  await updatePromise;
+
+  // There should be no notifications about the update
+  is(getBadgeStatus(), "", "Should not have addon alert badge");
+
+  await PanelUI.show();
+  let addons = document.getElementById("PanelUI-footer-addons");
+  is(addons.children.length, 0, "Have 0 updates in the PanelUI menu");
+  await PanelUI.hide();
+
+  ok(!sawPopup, "Should not have seen permissions notification");
+
+  addon = await AddonManager.getAddonByID(id);
+  is(addon.version, "2.0", "Update should have applied");
+
+  addon.uninstall();
+  await SpecialPowers.popPrefEnv();
+}
+
+// Test that an update that adds new non-promptable permissions is just
+// applied without showing a notification dialog.
+add_task(() => testNoPrompt(`${BASE}/browser_webext_update_perms1.xpi`,
+                            ID_PERMS));
+
+// Test that an update from a legacy extension to a webextension
+// doesn't show a prompt even when the webextension uses
+// promptable required permissions.
+add_task(() => testNoPrompt(`${BASE}/browser_legacy.xpi`, ID_LEGACY));