Bug 1342142 Part 1 Toolkit test cleanups r=mossop
authorAndrew Swan <aswan@mozilla.com>
Wed, 22 Mar 2017 13:46:29 -0700
changeset 348985 fa49f7a3e67dc2d6f0a5163825b71b582b822b3b
parent 348984 f23ce5b464f89824fa836efc6cb93d33a2ae99e0
child 348986 9f93b4b4a7ca31e10ffe906e9a10658459dfe1d5
push id31541
push usercbook@mozilla.com
push dateThu, 23 Mar 2017 12:43:04 +0000
treeherdermozilla-central@89b93d310da5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1342142
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1342142 Part 1 Toolkit test cleanups r=mossop Fixed various issues related to webextension install prompts in tests: - Some existing tests install extensions from the about:addons search page, but when about:addons is run in its own top level window, these tests fail since there is no location bar to anchor notifications to. Given the mostly unsupported nature of running about:addons in its own top level window, this patch just takes the easy way out and skips running those tests in window mode. - Fix tests that might generate prompts to acknowledge them if they are enabled. - Update the test for mozAddonManager.permissionPromptsEnabled to properly handle the case where prompts are on by default. MozReview-Commit-ID: AdPmhGfB33o
toolkit/mozapps/extensions/test/browser/browser-common.ini
toolkit/mozapps/extensions/test/browser/browser.ini
toolkit/mozapps/extensions/test/browser/browser_eula.js
toolkit/mozapps/extensions/test/browser/browser_install.js
toolkit/mozapps/extensions/test/browser/browser_searching.js
toolkit/mozapps/extensions/test/browser/browser_webapi.js
toolkit/mozapps/extensions/test/browser/browser_webapi_install.js
toolkit/mozapps/extensions/test/browser/head.js
--- a/toolkit/mozapps/extensions/test/browser/browser-common.ini
+++ b/toolkit/mozapps/extensions/test/browser/browser-common.ini
@@ -33,27 +33,23 @@ skip-if = true # Bug 1093190 - Disabled 
 [browser_details.js]
 [browser_discovery.js]
 [browser_dragdrop.js]
 skip-if = buildapp == 'mulet'
 [browser_dragdrop_incompat.js]
 [browser_experiments.js]
 [browser_list.js]
 [browser_metadataTimeout.js]
-[browser_searching.js]
 [browser_sorting.js]
 [browser_sorting_plugins.js]
 [browser_plugin_enabled_state_locked.js]
 [browser_uninstalling.js]
-[browser_install.js]
 [browser_recentupdates.js]
 [browser_manualupdates.js]
 [browser_globalwarnings.js]
-[browser_eula.js]
-skip-if = buildapp == 'mulet'
 [browser_updateid.js]
 [browser_purchase.js]
 [browser_openDialog.js]
 tags = openwindow
 skip-if = os == 'win' # Disabled on Windows due to intermittent failures (bug 1135866)
 [browser_types.js]
 [browser_inlinesettings.js]
 [browser_inlinesettings_browser.js]
--- a/toolkit/mozapps/extensions/test/browser/browser.ini
+++ b/toolkit/mozapps/extensions/test/browser/browser.ini
@@ -49,28 +49,32 @@ support-files =
   !/toolkit/mozapps/extensions/test/xpinstall/unsigned.xpi
   !/toolkit/mozapps/extensions/test/xpinstall/amosigned.xpi
 
 [browser_addonrepository_performance.js]
 [browser_bug557956.js]
 [browser_bug616841.js]
 [browser_cancelCompatCheck.js]
 [browser_checkAddonCompatibility.js]
+[browser_discovery_install.js]
+[browser_eula.js]
+skip-if = buildapp == 'mulet'
 [browser_getmorethemes.js]
 [browser_gmpProvider.js]
 [browser_hotfix.js]
 # Verifies the old style of signing hotfixes
 skip-if = require_signing
+[browser_install.js]
 [browser_installssl.js]
 [browser_newaddon.js]
-[browser_updatessl.js]
+[browser_searching.js]
 [browser_system_addons_are_e10s.js]
 [browser_task_next_test.js]
-[browser_discovery_install.js]
 [browser_update.js]
+[browser_updatessl.js]
 [browser_webapi.js]
 [browser_webapi_access.js]
 [browser_webapi_addon_listener.js]
 [browser_webapi_enable.js]
 [browser_webapi_install.js]
 [browser_webapi_uninstall.js]
 
 [include:browser-common.ini]
--- a/toolkit/mozapps/extensions/test/browser/browser_eula.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_eula.js
@@ -11,17 +11,17 @@ var gSearchCount = 0;
 function test() {
   requestLongerTimeout(2);
   waitForExplicitFinish();
 
   // Turn on searching for this test
   Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15);
   Services.prefs.setCharPref("extensions.getAddons.search.url", TESTROOT + "browser_eula.xml");
 
-  open_manager(null, function(aWindow) {
+  open_manager("addons://list/extension", function(aWindow) {
     gManagerWindow = aWindow;
     run_next_test();
   });
 }
 
 function end_test() {
   close_manager(gManagerWindow, finish);
 }
@@ -44,21 +44,22 @@ function installSearchResult(aCallback) 
     EventUtils.synthesizeMouseAtCenter(remote, { }, gManagerWindow);
 
     let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
     ok(!!item, "Should see the search result in the list");
 
     let status = get_node(item, "install-status");
     EventUtils.synthesizeMouseAtCenter(get_node(status, "install-remote-btn"), {}, gManagerWindow);
 
-    item.mInstall.addListener({
-      onInstallEnded() {
-        executeSoon(aCallback);
-      }
+    let promptPromise = promiseNotification();
+    let installPromise = new Promise(resolve => {
+      item.mInstall.addListener({onInstallEnded: resolve});
     });
+
+    promptPromise.then(() => installPromise).then(aCallback);
   });
 }
 
 // Install an add-on through the search page, accept the EULA and then undo it
 add_test(function() {
   // Accept the EULA when it appears
   let sawEULA = false;
   wait_for_window_open(function(aWindow) {
--- a/toolkit/mozapps/extensions/test/browser/browser_install.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_install.js
@@ -104,21 +104,22 @@ function installSearchResult(aCallback) 
     EventUtils.synthesizeMouseAtCenter(remote, { }, gManagerWindow);
 
     let item = get_addon_element(gManagerWindow, "install1@tests.mozilla.org");
     ok(!!item, "Should see the search result in the list");
 
     let status = get_node(item, "install-status");
     EventUtils.synthesizeMouseAtCenter(get_node(status, "install-remote-btn"), {}, gManagerWindow);
 
-    item.mInstall.addListener({
-      onInstallEnded() {
-        executeSoon(aCallback);
-      }
+    let promptPromise = promiseNotification();
+    let installPromise = new Promise(resolve => {
+      item.mInstall.addListener({onInstallEnded: resolve});
     });
+
+    promptPromise.then(() => installPromise).then(aCallback);
   });
 }
 
 function get_list_item_count() {
   return get_test_items_in_list(gManagerWindow).length;
 }
 
 function check_undo_install() {
--- a/toolkit/mozapps/extensions/test/browser/browser_searching.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_searching.js
@@ -547,16 +547,18 @@ add_test(function() {
   search(QUERY, false, function() {
     var list = gManagerWindow.document.getElementById("search-list");
     var remoteItem = get_addon_item(REMOTE_TO_INSTALL);
     list.ensureElementIsVisible(remoteItem);
 
     installBtn = get_install_button(remoteItem);
     is(installBtn.hidden, false, "Install button should be showing before install");
     remoteItem.mAddon.install.addListener(listener);
+    // If prompts are enabled, accept the install prompt.
+    promiseNotification();
     EventUtils.synthesizeMouseAtCenter(installBtn, { }, gManagerWindow);
   });
 });
 
 // Tests that re-searching for query results in correct results
 add_test(function() {
   // Select a different category
   gCategoryUtilities.openType("extension", function() {
--- a/toolkit/mozapps/extensions/test/browser/browser_webapi.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webapi.js
@@ -109,14 +109,16 @@ add_task(testWithAPI(function*(browser) 
   function* check(value, message) {
     let enabled = yield ContentTask.spawn(browser, null, function*() {
       return content.navigator.mozAddonManager.permissionPromptsEnabled;
     });
     is(enabled, value, message);
   }
 
   const PERM = "extensions.webextPermissionPrompts";
-  yield SpecialPowers.pushPrefEnv({clear: [[PERM]]});
-  yield check(false, `mozAddonManager.permissionPromptsEnabled is false when ${PERM} is unset`);
+  if (Services.prefs.getBoolPref(PERM, false) == false) {
+    yield SpecialPowers.pushPrefEnv({clear: [[PERM]]});
+    yield check(false, `mozAddonManager.permissionPromptsEnabled is false when ${PERM} is unset`);
+  }
 
   yield SpecialPowers.pushPrefEnv({set: [[PERM, true]]});
   yield check(true, `mozAddonManager.permissionPromptsEnabled is true when ${PERM} is set`);
 }));
--- a/toolkit/mozapps/extensions/test/browser/browser_webapi_install.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_install.js
@@ -192,18 +192,22 @@ function makeRegularTest(options, what) 
         props: {state: "STATE_INSTALLING"},
       },
       {
         event: "onInstallEnded",
         props: {state: "STATE_INSTALLED"},
       },
     ];
 
+    let promptPromise = promiseNotification("addon-installed");
+
     yield testInstall(browser, options, steps, what);
 
+    yield promptPromise;
+
     let version = Services.prefs.getIntPref("webapitest.active_version");
     is(version, 1, "the install really did work");
 
     // Sanity check to ensure that the test in makeInstallTest() that
     // installs.size == 0 means we actually did clean up.
     ok(AddonManager.webAPI.installs.size > 0, "webAPI is tracking the AddonInstall");
 
     let addons = yield promiseAddonsByIDs([ID]);
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -1448,8 +1448,28 @@ function getTestPluginTag() {
   // Find the test plugin
   for (let i = 0; i < tags.length; i++) {
     if (tags[i].name == "Test Plug-in")
       return tags[i];
   }
   ok(false, "Unable to find plugin");
   return null;
 }
+
+// Wait for and then acknowledge (by pressing the primary button) the
+// given notification.
+function promiseNotification(id = "addon-webext-permissions") {
+  if (!Services.prefs.getBoolPref("extensions.webextPermissionPrompts", false)) {
+    return Promise.resolve();
+  }
+
+  return new Promise(resolve => {
+    function popupshown() {
+      let notification = PopupNotifications.getNotification(id);
+      if (notification) {
+        PopupNotifications.panel.removeEventListener("popupshown", popupshown);
+        PopupNotifications.panel.firstChild.button.click();
+        resolve();
+      }
+    }
+    PopupNotifications.panel.addEventListener("popupshown", popupshown);
+  });
+}