Bug 1602318 - Change search engine tests to listen for, and block loads in the parent. r=kmag
authorMatt Woodrow <mwoodrow@mozilla.com>
Sun, 26 Apr 2020 00:49:49 +0000
changeset 526099 e571f05c40db1bff5520327762c58a48df10391f
parent 526098 ebba2085a6b5675e23e5eebf05555f9d92530f27
child 526100 d4dd2b03884ddaa1c1ac57c37a74d5c1e21d7369
push id37350
push usernbeleuzu@mozilla.com
push dateSun, 26 Apr 2020 09:43:12 +0000
treeherdermozilla-central@21659f178a12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1602318
milestone77.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 1602318 - Change search engine tests to listen for, and block loads in the parent. r=kmag Differential Revision: https://phabricator.services.mozilla.com/D67098
browser/components/search/test/browser/browser_google_behavior.js
browser/components/search/test/browser/browser_searchEngine_behaviors.js
browser/components/search/test/browser/head.js
--- a/browser/components/search/test/browser/browser_google_behavior.js
+++ b/browser/components/search/test/browser/browser_google_behavior.js
@@ -180,25 +180,27 @@ async function testSearchEngine(engineDe
 
   for (let test of engineTests) {
     info(`Running: ${test.name}`);
 
     if (test.preTest) {
       await test.preTest(tab);
     }
 
-    let stateChangePromise = promiseStateChangeURI();
+    let promises = [
+      BrowserTestUtils.waitForDocLoadAndStopIt(
+        "https://www.google.com/search?client=" + test.code + "&q=foo",
+        tab
+      ),
+      BrowserTestUtils.browserStopped(tab.linkedBrowser, null, true),
+    ];
 
     await test.run(tab);
 
-    let receivedURI = await stateChangePromise;
-
-    let receivedURLParams = new URLSearchParams(receivedURI.split("?")[1]);
-
-    Assert.equal(receivedURLParams.get("client"), test.code);
+    await Promise.all(promises);
 
     if (test.postTest) {
       await test.postTest(tab);
     }
   }
 
   engine.alias = undefined;
   BrowserTestUtils.removeTab(tab);
--- a/browser/components/search/test/browser/browser_searchEngine_behaviors.js
+++ b/browser/components/search/test/browser/browser_searchEngine_behaviors.js
@@ -184,21 +184,22 @@ async function testSearchEngine(engineDe
 
   for (let test of engineTests) {
     info(`Running: ${test.name}`);
 
     if (test.preTest) {
       await test.preTest(tab);
     }
 
-    let stateChangePromise = promiseStateChangeURI();
+    let promises = [
+      BrowserTestUtils.waitForDocLoadAndStopIt(test.searchURL, tab),
+      BrowserTestUtils.browserStopped(tab.linkedBrowser, null, true),
+    ];
 
     await test.run(tab);
 
-    let receivedURI = await stateChangePromise;
-
-    Assert.equal(receivedURI, test.searchURL);
+    await Promise.all(promises);
   }
 
   engine.alias = undefined;
   sb.value = "";
   BrowserTestUtils.removeTab(tab);
 }
--- a/browser/components/search/test/browser/head.js
+++ b/browser/components/search/test/browser/head.js
@@ -104,83 +104,16 @@ async function promiseNewEngine(basename
       await Services.search.setDefaultPrivate(currentPrivate);
     }
     await Services.search.removeEngine(engine);
     info("Search engine removed: " + basename);
   });
   return engine;
 }
 
-let promiseStateChangeFrameScript =
-  "data:," +
-  encodeURIComponent(
-    `(${() => {
-      /* globals docShell, sendAsyncMessage */
-
-      const global = this;
-      const LISTENER = Symbol("listener");
-      let listener = {
-        QueryInterface: ChromeUtils.generateQI([
-          "nsISupportsWeakReference",
-          "nsIWebProgressListener",
-        ]),
-
-        onStateChange: function onStateChange(webProgress, req, flags, status) {
-          // Only care about top-level document starts
-          if (
-            !webProgress.isTopLevel ||
-            !(flags & Ci.nsIWebProgressListener.STATE_START)
-          ) {
-            return;
-          }
-
-          req.QueryInterface(Ci.nsIChannel);
-          let spec = req.originalURI.spec;
-          if (spec == "about:blank") {
-            return;
-          }
-
-          delete global[LISTENER];
-          docShell.removeProgressListener(listener);
-
-          req.cancel(Cr.NS_ERROR_FAILURE);
-
-          sendAsyncMessage("PromiseStateChange::StateChanged", spec);
-        },
-      };
-
-      // Make sure the weak reference stays alive.
-      global[LISTENER] = listener;
-
-      docShell.QueryInterface(Ci.nsIWebProgress);
-      docShell.addProgressListener(
-        listener,
-        Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT
-      );
-    }})()`
-  );
-
-function promiseStateChangeURI() {
-  const MSG = "PromiseStateChange::StateChanged";
-
-  return new Promise(resolve => {
-    let mm = window.getGroupMessageManager("browsers");
-    mm.loadFrameScript(promiseStateChangeFrameScript, true);
-
-    let listener = msg => {
-      mm.removeMessageListener(MSG, listener);
-      mm.removeDelayedFrameScript(promiseStateChangeFrameScript);
-
-      resolve(msg.data);
-    };
-
-    mm.addMessageListener(MSG, listener);
-  });
-}
-
 // Get an array of the one-off buttons.
 function getOneOffs() {
   let oneOffs = [];
   let searchPopup = document.getElementById("PopupSearchAutoComplete");
   let oneOffsContainer = searchPopup.searchOneOffsContainer;
   let oneOff = oneOffsContainer.querySelector(".search-panel-one-offs");
   for (oneOff = oneOff.firstChild; oneOff; oneOff = oneOff.nextSibling) {
     if (oneOff.nodeType == Node.ELEMENT_NODE) {