Bug 1094510 - make browser_canonizeURL.js not hit the network in e10s mode, r?mconley draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 29 Feb 2016 14:11:04 +0000
changeset 335450 0b56c6af9e9ecd1b4de10744de82c066e1ff2bee
parent 335447 2fa086d51b6a8d94566493b34cbce00a37af5024
child 515126 b4cbbc23e806872e84b6f440bbc623d41c3600d5
push id11779
push usergijskruitbosch@gmail.com
push dateMon, 29 Feb 2016 14:43:22 +0000
reviewersmconley
bugs1094510
milestone47.0a1
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,59 @@ 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);
+          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);