Bug 1333713 Ensure last update check finished before starting a new one r=mossop
authorAndrew Swan <aswan@mozilla.com>
Wed, 01 Mar 2017 16:44:48 -0800
changeset 374743 eb6b0553d0797d7b8a88006080add8992d5dfa97
parent 374742 06074f7e890125261d08c88a7769e24acba7ab76
child 374744 28f283aaca24903d61a966fe1e80aa56ad8e9656
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1333713
milestone54.0a1
Bug 1333713 Ensure last update check finished before starting a new one r=mossop MozReview-Commit-ID: 61kLJMXQ56m
browser/base/content/test/webextensions/browser_extension_update_interactive.js
toolkit/mozapps/extensions/content/extensions.js
--- a/browser/base/content/test/webextensions/browser_extension_update_interactive.js
+++ b/browser/base/content/test/webextensions/browser_extension_update_interactive.js
@@ -24,90 +24,106 @@ function* interactiveUpdateTest(autoUpda
     ["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.
-  function* triggerUpdate(win, addon) {
+  async function triggerUpdate(win, addon) {
     let manualUpdatePromise;
     if (!autoUpdate) {
       manualUpdatePromise = new Promise(resolve => {
         let listener = {
           onNewInstall() {
             AddonManager.removeInstallListener(listener);
             resolve();
           },
         };
         AddonManager.addInstallListener(listener);
       });
     }
 
-    checkFn(win, addon);
+    let promise = checkFn(win, addon);
 
     if (manualUpdatePromise) {
-      yield 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");
-  yield triggerUpdate(win, addon);
+  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");
-  yield triggerUpdate(win, addon);
+  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
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -1097,16 +1097,18 @@ var gViewController = {
           if (pendingChecks > 0)
             return;
 
           this.inProgress = false;
           gViewController.updateCommand("cmd_findAllUpdates");
           document.getElementById("updates-progress").hidden = true;
           gUpdatesView.maybeRefresh();
 
+          Services.obs.notifyObservers(null, "EM-update-check-finished", null);
+
           if (numManualUpdates > 0 && numUpdated == 0) {
             document.getElementById("updates-manualUpdatesFound-btn").hidden = false;
             return;
           }
 
           if (numUpdated == 0) {
             document.getElementById("updates-noneFound").hidden = false;
             return;