Bug 1094510 - make browser_canonizeURL.js not hit the network in e10s mode, r=mconley
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 29 Feb 2016 14:11:04 +0000
changeset 324663 5bfead86cc6c7cdfe68fb584789b83c87b2c3bf2
parent 324662 f601b789e1e1cb118a9b4186011a6c208aeae1df
child 324664 970aa793c5e2778172cd8e527f9dc04848400d40
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1094510
milestone47.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 1094510 - make browser_canonizeURL.js not hit the network in e10s mode, r=mconley MozReview-Commit-ID: JlEYeir749V
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_canonizeURL.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -285,17 +285,16 @@ tags = mcb
 tags = mcb
 [browser_bug970746.js]
 [browser_bug1015721.js]
 skip-if = os == 'win' || e10s # Bug 1159268 - Need a content-process safe version of synthesizeWheel
 [browser_bug1064280_changeUrlInPinnedTab.js]
 [browser_bug1070778.js]
 [browser_accesskeys.js]
 [browser_canonizeURL.js]
-skip-if = e10s # Bug 1094510 - test hits the network in e10s mode only
 [browser_clipboard.js]
 [browser_contentAreaClick.js]
 [browser_contextmenu.js]
 skip-if = toolkit == "gtk2" || toolkit == "gtk3" # disabled on Linux due to bug 513558
 [browser_ctrlTab.js]
 [browser_datachoices_notification.js]
 skip-if = !datareporting
 [browser_devedition.js]
--- a/browser/base/content/test/general/browser_canonizeURL.js
+++ b/browser/base/content/test/general/browser_canonizeURL.js
@@ -1,13 +1,8 @@
-function test() {
-  waitForExplicitFinish();
-  testNext();
-}
-
 var pairs = [
   ["example", "http://www.example.net/"],
   ["ex-ample", "http://www.ex-ample.net/"],
   ["  example ", "http://www.example.net/"],
   [" example/foo ", "http://www.example.net/foo"],
   [" example/foo bar ", "http://www.example.net/foo%20bar"],
   ["example.net", "http://example.net/"],
   ["http://example", "http://example/"],
@@ -15,42 +10,61 @@ var pairs = [
   ["ex-ample.foo", "http://ex-ample.foo/"],
   ["example.foo/bar ", "http://example.foo/bar"],
   ["1.1.1.1", "http://1.1.1.1/"],
   ["ftp://example", "ftp://example/"],
   ["ftp.example.bar", "ftp://ftp.example.bar/"],
   ["ex ample", Services.search.defaultEngine.getSubmission("ex ample", null, "keyword").uri.spec],
 ];
 
-function testNext() {
-  if (!pairs.length) {
-    finish();
-    return;
-  }
+add_task(function*() {
+  for (let [inputValue, expectedURL] of pairs) {
+    let focusEventPromise = BrowserTestUtils.waitForEvent(gURLBar, "focus");
+    let messagePromise = BrowserTestUtils.waitForMessage(gBrowser.selectedBrowser.messageManager,
+                                                         "browser_canonizeURL:start");
 
-  let [inputValue, expectedURL] = pairs.shift();
+    let stoppedLoadPromise = ContentTask.spawn(gBrowser.selectedBrowser, [inputValue, expectedURL],
+      function([inputValue, expectedURL]) {
+        return new Promise(resolve => {
+          let wpl = {
+            onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
+              if (aStateFlags & Ci.nsIWebProgressListener.STATE_START &&
+                  aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
+                if (!aRequest || !(aRequest instanceof Ci.nsIChannel)) {
+                  return;
+                }
+                aRequest.QueryInterface(Ci.nsIChannel);
+                is(aRequest.originalURI.spec, expectedURL,
+                   "entering '" + inputValue + "' loads expected URL");
 
-  gBrowser.addProgressListener({
-    onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
-      if (aStateFlags & Ci.nsIWebProgressListener.STATE_START &&
-          aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
-        is(aRequest.originalURI.spec, expectedURL,
-           "entering '" + inputValue + "' loads expected URL");
+                webProgress.removeProgressListener(filter);
+                filter.removeProgressListener(wpl);
+                docShell.QueryInterface(Ci.nsIWebNavigation);
+                docShell.stop(docShell.STOP_ALL);
+                resolve();
+              }
+            },
+          };
+          let filter = Cc["@mozilla.org/appshell/component/browser-status-filter;1"]
+                           .createInstance(Ci.nsIWebProgress);
+          filter.addProgressListener(wpl, Ci.nsIWebProgress.NOTIFY_ALL);
 
-        gBrowser.removeProgressListener(this);
-        gBrowser.stop();
-
-        executeSoon(testNext);
+          let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                    .getInterface(Ci.nsIWebProgress);
+          webProgress.addProgressListener(filter, Ci.nsIWebProgress.NOTIFY_ALL);
+          // We're sending this off to trigger the start of the this test, when all the
+          // listeners are in place:
+          sendAsyncMessage("browser_canonizeURL:start");
+        });
       }
-    }
-  });
+    );
 
-  gURLBar.addEventListener("focus", function onFocus() {
-    gURLBar.removeEventListener("focus", onFocus);
+    gBrowser.selectedBrowser.focus();
+    gURLBar.focus();
+
+    yield Promise.all([focusEventPromise, messagePromise]);
+
     gURLBar.inputField.value = inputValue.slice(0, -1);
     EventUtils.synthesizeKey(inputValue.slice(-1) , {});
     EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true });
-  });
-
-  gBrowser.selectedBrowser.focus();
-  gURLBar.focus();
-
-}
+    yield stoppedLoadPromise;
+  }
+});
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -587,16 +587,37 @@ this.BrowserTestUtils = {
 
       mm.sendAsyncMessage("Test:SynthesizeMouse",
                           {target, targetFn, x: offsetX, y: offsetY, event: event},
                           {object: cpowObject});
     });
   },
 
   /**
+   * Wait for a message to be fired from a particular message manager
+   *
+   * @param {nsIMessageManager} messageManager
+   *                            The message manager that should be used.
+   * @param {String}            message
+   *                            The message we're waiting for.
+   * @param {Function}          checkFn (optional)
+   *                            Optional function to invoke to check the message.
+   */
+  waitForMessage(messageManager, message, checkFn) {
+    return new Promise(resolve => {
+      messageManager.addMessageListener(message, function onMessage(msg) {
+        if (!checkFn || checkFn(msg)) {
+          messageManager.removeMessageListener(message, onMessage);
+          resolve();
+        }
+      });
+    });
+  },
+
+  /**
    *  Version of synthesizeMouse that uses the center of the target as the mouse
    *  location. Arguments and the return value are the same.
    */
   synthesizeMouseAtCenter(target, event, browser)
   {
     // Use a flag to indicate to center rather than having a separate message.
     event.centered = true;
     return BrowserTestUtils.synthesizeMouse(target, 0, 0, event, browser);