Bug 1485660 - Special test fixes. r=jdescottes
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 15 Oct 2018 08:36:15 +0000
changeset 489604 4ac958d94290160ed534261ec799b8a86f302029
parent 489603 09ff21b58c0bb6f9bf69c67823c45de790b40f9e
child 489605 278e3ec5091b61d04a78637ca35dfcfff30dbca2
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjdescottes
bugs1485660
milestone64.0a1
Bug 1485660 - Special test fixes. r=jdescottes * browser_addons_debug_webextension_popup: It looks like frame-update events are now fired earlier. I had to move the listener to an earlier step in order to make it work. * helper_disable_cache + toolbox.js: this test wasn't correctly listening for reconfigure request's end. Not clear how this test was passing before without high rate of intermittent... * test_webextension-addon-debugging-connect.html: We can no longer listen for frame-update *before* the target object is created. (because we now need a TabTarget object or the TargetFront and not just the DebuggerClient) * Fix reload request in shadereditor which may still be pending after test ends. MozReview-Commit-ID: 49qvWSCn6nq Depends on D8066 Differential Revision: https://phabricator.services.mozilla.com/D7460
devtools/client/aboutdebugging/test/browser_addons_debug_webextension_popup.js
devtools/client/framework/test/helper_disable_cache.js
devtools/client/framework/toolbox.js
devtools/client/shadereditor/test/head.js
devtools/server/tests/mochitest/test_webextension-addon-debugging-connect.html
--- a/devtools/client/aboutdebugging/test/browser_addons_debug_webextension_popup.js
+++ b/devtools/client/aboutdebugging/test/browser_addons_debug_webextension_popup.js
@@ -86,17 +86,27 @@ add_task(async function testWebExtension
   // Be careful, this JS function is going to be executed in the addon toolbox,
   // which lives in another process. So do not try to use any scope variable!
   const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
 
   const testScript = function() {
     /* eslint-disable no-undef */
 
     let jsterm;
-    let popupFramePromise;
+    const popupFramePromise = new Promise(resolve => {
+      const listener = data => {
+        if (data.frames.some(({url}) => url && url.endsWith("popup.html"))) {
+          toolbox.target.off("frame-update", listener);
+          resolve();
+        }
+      };
+      toolbox.target.on("frame-update", listener);
+    });
+
+    const waitForFrameListUpdate = toolbox.target.once("frame-update");
 
     toolbox.selectTool("webconsole")
       .then(async (console) => {
         const clickNoAutoHideMenu = () => {
           return new Promise(resolve => {
             toolbox.doc.getElementById("toolbox-meatball-menu-button").click();
             toolbox.doc.addEventListener("popupshown", () => {
               const menuItem =
@@ -106,28 +116,16 @@ add_task(async function testWebExtension
             }, { once: true });
           });
         };
 
         dump(`Clicking the menu button\n`);
         await clickNoAutoHideMenu();
         dump(`Clicked the menu button\n`);
 
-        popupFramePromise = new Promise(resolve => {
-          const listener = data => {
-            if (data.frames.some(({url}) => url && url.endsWith("popup.html"))) {
-              toolbox.target.off("frame-update", listener);
-              resolve();
-            }
-          };
-          toolbox.target.on("frame-update", listener);
-        });
-
-        const waitForFrameListUpdate = toolbox.target.once("frame-update");
-
         jsterm = console.hud.jsterm;
         jsterm.execute("myWebExtensionShowPopup()");
 
         await Promise.all([
           // Wait the initial frame update (which list the background page).
           waitForFrameListUpdate,
           // Wait the new frame update (once the extension popup has been opened).
           popupFramePromise,
--- a/devtools/client/framework/test/helper_disable_cache.js
+++ b/devtools/client/framework/test/helper_disable_cache.js
@@ -80,21 +80,22 @@ async function checkCacheEnabled(tabX, e
 async function setDisableCacheCheckboxChecked(tabX, state) {
   gBrowser.selectedTab = tabX.tab;
 
   const panel = tabX.toolbox.getCurrentPanel();
   const cbx = panel.panelDoc.getElementById("devtools-disable-cache");
 
   if (cbx.checked !== state) {
     info("Setting disable cache checkbox to " + state + " for " + tabX.title);
+    const onReconfigured = tabX.toolbox.once("cache-reconfigured");
     cbx.click();
 
-    // We need to wait for all checkboxes to be updated and the docshells to
-    // apply the new cache settings.
-    await waitForTick();
+    // We have to wait for the reconfigure request to be finished before reloading
+    // the page.
+    await onReconfigured;
   }
 }
 
 function reloadTab(tabX) {
   const browser = gBrowser.selectedBrowser;
 
   const reloadTabPromise = BrowserTestUtils.browserLoaded(browser).then(function() {
     info("Reloaded tab " + tabX.title);
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -1334,26 +1334,31 @@ Toolbox.prototype = {
 
     return this.pickerButton;
   },
 
   /**
    * Apply the current cache setting from devtools.cache.disabled to this
    * toolbox's tab.
    */
-  _applyCacheSettings: function() {
+  _applyCacheSettings: async function() {
     const pref = "devtools.cache.disabled";
     const cacheDisabled = Services.prefs.getBoolPref(pref);
 
     if (this.target.activeTab) {
-      this.target.activeTab.reconfigure({
+      await this.target.activeTab.reconfigure({
         options: {
           "cacheDisabled": cacheDisabled
         }
       });
+
+      // This event is only emitted for tests in order to know when to reload
+      if (flags.testing) {
+        this.emit("cache-reconfigured");
+      }
     }
   },
 
   /**
    * Apply the current service workers testing setting from
    * devtools.serviceWorkers.testing.enabled to this toolbox's tab.
    */
   _applyServiceWorkersTestingSettings: function() {
--- a/devtools/client/shadereditor/test/head.js
+++ b/devtools/client/shadereditor/test/head.js
@@ -130,19 +130,20 @@ function navigateInHistory(aTarget, aDir
   return once(aTarget, aWaitForTargetEvent);
 }
 
 function navigate(aTarget, aUrl, aWaitForTargetEvent = "navigate") {
   executeSoon(() => aTarget.activeTab.navigateTo({ url: aUrl }));
   return once(aTarget, aWaitForTargetEvent);
 }
 
-function reload(aTarget, aWaitForTargetEvent = "navigate") {
-  executeSoon(() => aTarget.activeTab.reload());
-  return once(aTarget, aWaitForTargetEvent);
+async function reload(aTarget, aWaitForTargetEvent = "navigate") {
+  const onTargetEvent = once(aTarget, aWaitForTargetEvent);
+  await aTarget.activeTab.reload();
+  return onTargetEvent;
 }
 
 function initBackend(aUrl) {
   info("Initializing a shader editor front.");
 
   DebuggerServer.init();
   DebuggerServer.registerAllActors();
 
--- a/devtools/server/tests/mochitest/test_webextension-addon-debugging-connect.html
+++ b/devtools/server/tests/mochitest/test_webextension-addon-debugging-connect.html
@@ -37,25 +37,24 @@ async function test_connect_addon(oopMod
   await client.connect();
 
   // List addons and assertions on the expected addon actor.
   const {addons} = await client.mainRoot.listAddons();
   const addonTargetActor = addons.filter(actor => actor.id === extension.id).pop();
   ok(addonTargetActor, "The expected webextension addon actor has been found");
 
   // Connect to the target addon actor and wait for the updated list of frames.
-  const waitFramesUpdated = waitForFramesUpdated({client});
   const addonTarget = await TargetFactory.forRemoteTab({
     form: addonTargetActor,
     client,
     chrome: true,
   });
   is(addonTarget.form.isOOP, oopMode,
      "Got the expected oop mode in the webextension actor form");
-  const frames = await waitFramesUpdated;
+  const frames = await waitForFramesUpdated(addonTarget);
   const backgroundPageFrame = frames.filter((frame) => {
     return frame.url && frame.url.endsWith("/_generated_background_page.html");
   }).pop();
   is(backgroundPageFrame.addonID, extension.id, "Got an extension frame");
   ok(addonTarget.activeTab, "The addon target has an activeTab");
 
   // When running in oop mode we can explicitly attach the thread without locking
   // the main process.