Bug 1341337 Break up browser_update_background.js
MozReview-Commit-ID: GUoghOXKUiS
--- a/browser/base/content/test/webextensions/browser.ini
+++ b/browser/base/content/test/webextensions/browser.ini
@@ -19,10 +19,11 @@ support-files =
[browser_extension_sideloading.js]
[browser_extension_update_background.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_interactive.js]
+[browser_update_checkForUpdates.js]
+[browser_update_findUpdates.js]
[browser_update_interactive_noprompt.js]
rename from browser/base/content/test/webextensions/browser_update_interactive.js
rename to browser/base/content/test/webextensions/browser_update_checkForUpdates.js
--- a/browser/base/content/test/webextensions/browser_update_interactive.js
+++ b/browser/base/content/test/webextensions/browser_update_checkForUpdates.js
@@ -1,113 +1,8 @@
-const {AddonManagerPrivate} = Cu.import("resource://gre/modules/AddonManager.jsm", {});
-
-const ID = "update2@tests.mozilla.org";
-
-// 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],
- ]});
-});
-
-// Helper function to test a specific scenario for interactive updates.
-// `checkFn` is a callable that triggers a check for updates.
-// `autoUpdate` specifies whether the test should be run with
-// updates applied automatically or not.
-function* interactiveUpdateTest(autoUpdate, checkFn) {
- yield SpecialPowers.pushPrefEnv({set: [
- ["extensions.update.autoUpdateDefault", autoUpdate],
-
- // Point updates to the local mochitest server
- ["extensions.update.url", `${BASE}/browser_webext_update.json`],
- ]});
-
- // Trigger an update check, manually applying the update if we're testing
- // without auto-update.
- async function triggerUpdate(win, addon) {
- let manualUpdatePromise;
- if (!autoUpdate) {
- manualUpdatePromise = new Promise(resolve => {
- let listener = {
- onNewInstall() {
- AddonManager.removeInstallListener(listener);
- resolve();
- },
- };
- AddonManager.addInstallListener(listener);
- });
- }
-
- let promise = checkFn(win, addon);
-
- if (manualUpdatePromise) {
- await manualUpdatePromise;
-
- let list = win.document.getElementById("addon-list");
-
- // Make sure we have XBL bindings
- list.clientHeight;
-
- let item = list.children.find(_item => _item.value == ID);
- EventUtils.synthesizeMouseAtCenter(item._updateBtn, {}, win);
- }
-
- return {promise};
- }
-
- // Navigate away from the starting page to force about:addons to load
- // in a new tab during the tests below.
- gBrowser.selectedBrowser.loadURI("about:robots");
- yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
-
- // Install version 1.0 of the test extension
- let addon = yield promiseInstallAddon(`${BASE}/browser_webext_update1.xpi`);
- ok(addon, "Addon was installed");
- is(addon.version, "1.0", "Version 1 of the addon is installed");
-
- let win = yield BrowserOpenAddonsMgr("addons://list/extension");
-
- // Trigger an update check
- let popupPromise = promisePopupNotificationShown("addon-webext-permissions");
- let {promise: checkPromise} = yield triggerUpdate(win, addon);
- let panel = yield popupPromise;
-
- // Click the cancel button, wait to see the cancel event
- let cancelPromise = promiseInstallEvent(addon, "onInstallCancelled");
- panel.secondaryButton.click();
- yield cancelPromise;
-
- addon = yield AddonManager.getAddonByID(ID);
- is(addon.version, "1.0", "Should still be running the old version");
-
- // Make sure the update check is completely finished.
- yield checkPromise;
-
- // Trigger a new update check
- popupPromise = promisePopupNotificationShown("addon-webext-permissions");
- checkPromise = (yield triggerUpdate(win, addon)).promise;
-
- // This time, accept the upgrade
- let updatePromise = promiseInstallEvent(addon, "onInstallEnded");
- panel = yield popupPromise;
- panel.button.click();
-
- addon = yield updatePromise;
- is(addon.version, "2.0", "Should have upgraded");
-
- yield checkPromise;
-
- yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
- addon.uninstall();
- yield SpecialPowers.popPrefEnv();
-}
-
// Invoke the "Check for Updates" menu item
function checkAll(win) {
win.gViewController.doCommand("cmd_findAllUpdates");
return new Promise(resolve => {
let observer = {
observe(subject, topic, data) {
Services.obs.removeObserver(observer, "EM-update-check-finished");
resolve();
@@ -115,18 +10,8 @@ function checkAll(win) {
};
Services.obs.addObserver(observer, "EM-update-check-finished", false);
});
}
// Test "Check for Updates" with both auto-update settings
add_task(() => interactiveUpdateTest(true, checkAll));
add_task(() => interactiveUpdateTest(false, checkAll));
-
-
-// Invoke an invidual extension's "Find Updates" menu item
-function checkOne(win, addon) {
- win.gViewController.doCommand("cmd_findItemUpdates", addon);
-}
-
-// Test "Find Updates" with both auto-update settings
-add_task(() => interactiveUpdateTest(true, checkOne));
-add_task(() => interactiveUpdateTest(false, checkOne));
copy from browser/base/content/test/webextensions/browser_update_interactive.js
copy to browser/base/content/test/webextensions/browser_update_findUpdates.js
--- a/browser/base/content/test/webextensions/browser_update_interactive.js
+++ b/browser/base/content/test/webextensions/browser_update_findUpdates.js
@@ -1,132 +1,8 @@
-const {AddonManagerPrivate} = Cu.import("resource://gre/modules/AddonManager.jsm", {});
-
-const ID = "update2@tests.mozilla.org";
-
-// 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],
- ]});
-});
-
-// Helper function to test a specific scenario for interactive updates.
-// `checkFn` is a callable that triggers a check for updates.
-// `autoUpdate` specifies whether the test should be run with
-// updates applied automatically or not.
-function* interactiveUpdateTest(autoUpdate, checkFn) {
- yield SpecialPowers.pushPrefEnv({set: [
- ["extensions.update.autoUpdateDefault", autoUpdate],
-
- // Point updates to the local mochitest server
- ["extensions.update.url", `${BASE}/browser_webext_update.json`],
- ]});
-
- // Trigger an update check, manually applying the update if we're testing
- // without auto-update.
- async function triggerUpdate(win, addon) {
- let manualUpdatePromise;
- if (!autoUpdate) {
- manualUpdatePromise = new Promise(resolve => {
- let listener = {
- onNewInstall() {
- AddonManager.removeInstallListener(listener);
- resolve();
- },
- };
- AddonManager.addInstallListener(listener);
- });
- }
-
- let promise = checkFn(win, addon);
-
- if (manualUpdatePromise) {
- await manualUpdatePromise;
-
- let list = win.document.getElementById("addon-list");
-
- // Make sure we have XBL bindings
- list.clientHeight;
-
- let item = list.children.find(_item => _item.value == ID);
- EventUtils.synthesizeMouseAtCenter(item._updateBtn, {}, win);
- }
-
- return {promise};
- }
-
- // Navigate away from the starting page to force about:addons to load
- // in a new tab during the tests below.
- gBrowser.selectedBrowser.loadURI("about:robots");
- yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
-
- // Install version 1.0 of the test extension
- let addon = yield promiseInstallAddon(`${BASE}/browser_webext_update1.xpi`);
- ok(addon, "Addon was installed");
- is(addon.version, "1.0", "Version 1 of the addon is installed");
-
- let win = yield BrowserOpenAddonsMgr("addons://list/extension");
-
- // Trigger an update check
- let popupPromise = promisePopupNotificationShown("addon-webext-permissions");
- let {promise: checkPromise} = yield triggerUpdate(win, addon);
- let panel = yield popupPromise;
-
- // Click the cancel button, wait to see the cancel event
- let cancelPromise = promiseInstallEvent(addon, "onInstallCancelled");
- panel.secondaryButton.click();
- yield cancelPromise;
-
- addon = yield AddonManager.getAddonByID(ID);
- is(addon.version, "1.0", "Should still be running the old version");
-
- // Make sure the update check is completely finished.
- yield checkPromise;
-
- // Trigger a new update check
- popupPromise = promisePopupNotificationShown("addon-webext-permissions");
- checkPromise = (yield triggerUpdate(win, addon)).promise;
-
- // This time, accept the upgrade
- let updatePromise = promiseInstallEvent(addon, "onInstallEnded");
- panel = yield popupPromise;
- panel.button.click();
-
- addon = yield updatePromise;
- is(addon.version, "2.0", "Should have upgraded");
-
- yield checkPromise;
-
- yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
- addon.uninstall();
- yield SpecialPowers.popPrefEnv();
-}
-
-// Invoke the "Check for Updates" menu item
-function checkAll(win) {
- win.gViewController.doCommand("cmd_findAllUpdates");
- return new Promise(resolve => {
- let observer = {
- observe(subject, topic, data) {
- Services.obs.removeObserver(observer, "EM-update-check-finished");
- resolve();
- },
- };
- Services.obs.addObserver(observer, "EM-update-check-finished", false);
- });
-}
-
-// Test "Check for Updates" with both auto-update settings
-add_task(() => interactiveUpdateTest(true, checkAll));
-add_task(() => interactiveUpdateTest(false, checkAll));
-
-
// Invoke an invidual extension's "Find Updates" menu item
function checkOne(win, addon) {
win.gViewController.doCommand("cmd_findItemUpdates", addon);
}
// Test "Find Updates" with both auto-update settings
add_task(() => interactiveUpdateTest(true, checkOne));
add_task(() => interactiveUpdateTest(false, checkOne));
--- a/browser/base/content/test/webextensions/head.js
+++ b/browser/base/content/test/webextensions/head.js
@@ -370,16 +370,114 @@ async function testInstallMethod(install
// Should see 2 canceled installs followed by 1 successful install
// for this method.
expectTelemetry([`${telemetryBase}Rejected`, `${telemetryBase}Rejected`, `${telemetryBase}Accepted`]);
}
await SpecialPowers.popPrefEnv();
}
+// Helper function to test a specific scenario for interactive updates.
+// `checkFn` is a callable that triggers a check for updates.
+// `autoUpdate` specifies whether the test should be run with
+// updates applied automatically or not.
+async function interactiveUpdateTest(autoUpdate, checkFn) {
+ const ID = "update2@tests.mozilla.org";
+
+ await SpecialPowers.pushPrefEnv({set: [
+ // We don't have pre-pinned certificates for the local mochitest server
+ ["extensions.install.requireBuiltInCerts", false],
+ ["extensions.update.requireBuiltInCerts", false],
+
+ ["extensions.update.autoUpdateDefault", autoUpdate],
+
+ // Point updates to the local mochitest server
+ ["extensions.update.url", `${BASE}/browser_webext_update.json`],
+ ]});
+
+ // Trigger an update check, manually applying the update if we're testing
+ // without auto-update.
+ async function triggerUpdate(win, addon) {
+ let manualUpdatePromise;
+ if (!autoUpdate) {
+ manualUpdatePromise = new Promise(resolve => {
+ let listener = {
+ onNewInstall() {
+ AddonManager.removeInstallListener(listener);
+ resolve();
+ },
+ };
+ AddonManager.addInstallListener(listener);
+ });
+ }
+
+ let promise = checkFn(win, addon);
+
+ if (manualUpdatePromise) {
+ await manualUpdatePromise;
+
+ let list = win.document.getElementById("addon-list");
+
+ // Make sure we have XBL bindings
+ list.clientHeight;
+
+ let item = list.children.find(_item => _item.value == ID);
+ EventUtils.synthesizeMouseAtCenter(item._updateBtn, {}, win);
+ }
+
+ return {promise};
+ }
+
+ // Navigate away from the starting page to force about:addons to load
+ // in a new tab during the tests below.
+ gBrowser.selectedBrowser.loadURI("about:robots");
+ await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
+
+ // Install version 1.0 of the test extension
+ let addon = await promiseInstallAddon(`${BASE}/browser_webext_update1.xpi`);
+ ok(addon, "Addon was installed");
+ is(addon.version, "1.0", "Version 1 of the addon is installed");
+
+ let win = await BrowserOpenAddonsMgr("addons://list/extension");
+
+ // Trigger an update check
+ let popupPromise = promisePopupNotificationShown("addon-webext-permissions");
+ let {promise: checkPromise} = await triggerUpdate(win, addon);
+ let panel = await popupPromise;
+
+ // Click the cancel button, wait to see the cancel event
+ let cancelPromise = promiseInstallEvent(addon, "onInstallCancelled");
+ panel.secondaryButton.click();
+ await cancelPromise;
+
+ addon = await AddonManager.getAddonByID(ID);
+ is(addon.version, "1.0", "Should still be running the old version");
+
+ // Make sure the update check is completely finished.
+ await checkPromise;
+
+ // Trigger a new update check
+ popupPromise = promisePopupNotificationShown("addon-webext-permissions");
+ checkPromise = (await triggerUpdate(win, addon)).promise;
+
+ // This time, accept the upgrade
+ let updatePromise = waitForUpdate(addon);
+ panel = await popupPromise;
+ panel.button.click();
+
+ addon = await updatePromise;
+ is(addon.version, "2.0", "Should have upgraded");
+
+ await checkPromise;
+
+ await BrowserTestUtils.removeTab(gBrowser.selectedTab);
+ addon.uninstall();
+ await SpecialPowers.popPrefEnv();
+}
+
// The tests in this directory install a bunch of extensions but they
// need to uninstall them before exiting, as a stray leftover extension
// after one test can foul up subsequent tests.
// So, add a task to run before any tests that grabs a list of all the
// add-ons that are pre-installed in the test environment and then checks
// the list of installed add-ons at the end of the test to make sure no
// new add-ons have been added.
// Individual tests can store a cleanup function in the testCleanup global