Bug 1235372, re-enable browser_private_search_perwindowpb.js in e10s, r=florian
authorNeil Deakin <neil@mozilla.com>
Wed, 20 Jan 2016 08:42:15 -0500
changeset 323573 fcec1ad52046f9639750a67ff6b3776dd8bc0a6d
parent 323572 08806bb2137468b87ee60486983b5876f733f97f
child 323574 a3c338f0bb7c71c4f0122557a17ea9beafab3547
push id9750
push userdtownsend@mozilla.com
push dateWed, 20 Jan 2016 18:02:09 +0000
reviewersflorian
bugs1235372
milestone46.0a1
Bug 1235372, re-enable browser_private_search_perwindowpb.js in e10s, r=florian
browser/components/search/test/browser.ini
browser/components/search/test/browser_private_search_perwindowpb.js
browser/components/search/test/head.js
--- a/browser/components/search/test/browser.ini
+++ b/browser/components/search/test/browser.ini
@@ -31,17 +31,16 @@ skip-if = e10s # Bug ?????? - some issue
 [browser_google_behavior.js]
 skip-if = e10s # Bug ?????? - some issue with progress listeners [JavaScript Error: "req.originalURI is null" {file: "chrome://mochitests/content/browser/browser/components/search/test/browser_bing_behavior.js" line: 127}]
 [browser_healthreport.js]
 [browser_hiddenOneOffs_cleanup.js]
 [browser_hiddenOneOffs_diacritics.js]
 [browser_oneOffHeader.js]
 skip-if = e10s # bug ?????? - Test alters the searchbar textbox value which causes issues with other tests in e10s.
 [browser_private_search_perwindowpb.js]
-skip-if = e10s # Bug ?????? - Test uses load event and checks event.target.
 [browser_yahoo.js]
 [browser_yahoo_behavior.js]
 skip-if = e10s # Bug ?????? - some issue with progress listeners [JavaScript Error: "req.originalURI is null" {file: "chrome://mochitests/content/browser/browser/components/search/test/browser_bing_behavior.js" line: 127}]
 [browser_abouthome_behavior.js]
 skip-if = e10s || true # Bug ??????, Bug 1100301 - leaks windows until shutdown when --run-by-dir
 [browser_searchbar_openpopup.js]
 skip-if = os == "linux" || e10s # Linux has different focus behaviours and e10s seems to have timing issues.
 [browser_searchbar_keyboard_navigation.js]
--- a/browser/components/search/test/browser_private_search_perwindowpb.js
+++ b/browser/components/search/test/browser_private_search_perwindowpb.js
@@ -1,109 +1,73 @@
 // This test performs a search in a public window, then a different
 // search in a private window, and then checks in the public window
 // whether there is an autocomplete entry for the private search.
 
-function test() {
+add_task(function* () {
   // Don't use about:home as the homepage for new windows
   Services.prefs.setIntPref("browser.startup.page", 0);
   registerCleanupFunction(() => Services.prefs.clearUserPref("browser.startup.page"));
 
-  waitForExplicitFinish();
-
   let engineURL =
     "http://mochi.test:8888/browser/browser/components/search/test/";
   let windowsToClose = [];
-  registerCleanupFunction(function() {
-    let engine = Services.search.getEngineByName("Bug 426329");
-    Services.search.removeEngine(engine);
-    windowsToClose.forEach(function(win) {
-      win.close();
-    });
-  });
 
-  function onPageLoad(aWin, aCallback) {
-    aWin.gBrowser.addEventListener("DOMContentLoaded", function load(aEvent) {
-      let doc = aEvent.originalTarget;
-      info(doc.location.href);
-      if (doc.location.href.indexOf(engineURL) != -1) {
-        aWin.gBrowser.removeEventListener("DOMContentLoaded", load, false);
-        aCallback();
-      }
-    }, false);
-  }
-
-  function performSearch(aWin, aIsPrivate, aCallback) {
+  function performSearch(aWin, aIsPrivate) {
     let searchBar = aWin.BrowserSearch.searchBar;
     ok(searchBar, "got search bar");
-    onPageLoad(aWin, aCallback);
+
+    let loadPromise = BrowserTestUtils.browserLoaded(aWin.gBrowser.selectedBrowser);
 
     searchBar.value = aIsPrivate ? "private test" : "public test";
     searchBar.focus();
     EventUtils.synthesizeKey("VK_RETURN", {}, aWin);
+
+    return loadPromise;
   }
 
-  function addEngine(aCallback) {
-    let installCallback = {
-      onSuccess: function (engine) {
-        Services.search.currentEngine = engine;
-        aCallback();
-      },
-      onError: function (errorCode) {
-        ok(false, "failed to install engine: " + errorCode);
-      }
-    };
-    Services.search.addEngine(engineURL + "426329.xml", null,
-                              "data:image/x-icon,%00", false, installCallback);
+  function* testOnWindow(aIsPrivate) {
+    let win = yield BrowserTestUtils.openNewBrowserWindow({ private: aIsPrivate });
+    yield SimpleTest.promiseFocus(win);
+    windowsToClose.push(win);
+    return win;
   }
 
-  function testOnWindow(aIsPrivate, aCallback) {
-    let win = whenNewWindowLoaded({ private: aIsPrivate }, function() {
-      waitForFocus(aCallback, win);
-    });
-    windowsToClose.push(win);
-  }
+  yield promiseNewEngine("426329.xml", { iconURL: "data:image/x-icon,%00" });
+
+  let newWindow = yield* testOnWindow(false);
+  yield performSearch(newWindow, false);
 
-  addEngine(function() {
-    testOnWindow(false, function(win) {
-      performSearch(win, false, function() {
-        testOnWindow(true, function(win) {
-          performSearch(win, true, function() {
-            testOnWindow(false, function(win) {
-              checkSearchPopup(win, finish);
-            });
-          });
-        });
-      });
-    });
-  });
-}
+  newWindow = yield* testOnWindow(true);
+  yield performSearch(newWindow, true);
 
-function checkSearchPopup(aWin, aCallback) {
-  let searchBar = aWin.BrowserSearch.searchBar;
+  newWindow = yield* testOnWindow(false);
+
+  let searchBar = newWindow.BrowserSearch.searchBar;
   searchBar.value = "p";
   searchBar.focus();
 
   let popup = searchBar.textbox.popup;
-  popup.addEventListener("popupshowing", function showing() {
-    popup.removeEventListener("popupshowing", showing, false);
+  let popupPromise = BrowserTestUtils.waitForEvent(popup, "popupshown");
+  searchBar.textbox.showHistoryPopup();
+  yield popupPromise;
 
-    let entries = getMenuEntries(searchBar);
-    for (let i = 0; i < entries.length; i++) {
-      isnot(entries[i], "private test",
-            "shouldn't see private autocomplete entries");
-    }
+  let entries = getMenuEntries(searchBar);
+  for (let i = 0; i < entries.length; i++) {
+    isnot(entries[i], "private test",
+          "shouldn't see private autocomplete entries");
+  }
 
-    searchBar.textbox.toggleHistoryPopup();
-    searchBar.value = "";
-    aCallback();
-  }, false);
+  searchBar.textbox.toggleHistoryPopup();
+  searchBar.value = "";
 
-  searchBar.textbox.showHistoryPopup();
-}
+  windowsToClose.forEach(function(win) {
+    win.close();
+  });
+});
 
 function getMenuEntries(searchBar) {
   let entries = [];
   let autocompleteMenu = searchBar.textbox.popup;
   // Could perhaps pull values directly from the controller, but it seems
   // more reliable to test the values that are actually in the tree?
   let column = autocompleteMenu.tree.columns[0];
   let numRows = autocompleteMenu.tree.view.rowCount;
--- a/browser/components/search/test/head.js
+++ b/browser/components/search/test/head.js
@@ -1,25 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
   "resource://gre/modules/Promise.jsm");
 
-function whenNewWindowLoaded(aOptions, aCallback) {
-  let win = OpenBrowserWindow(aOptions);
-  let focused = SimpleTest.promiseFocus(win);
-  let startupFinished = TestUtils.topicObserved("browser-delayed-startup-finished",
-                                                subject => subject == win).then(() => win);
-  Promise.all([focused, startupFinished])
-    .then(results => executeSoon(() => aCallback(results[1])));
-
-  return win;
-}
-
 /**
  * Recursively compare two objects and check that every property of expectedObj has the same value
  * on actualObj.
  */
 function isSubObjectOf(expectedObj, actualObj, name) {
   for (let prop in expectedObj) {
     if (typeof expectedObj[prop] == 'function')
       continue;
@@ -118,17 +107,17 @@ function promiseNewEngine(basename, opti
     //Default the setAsCurrent option to true.
     let setAsCurrent =
       options.setAsCurrent == undefined ? true : options.setAsCurrent;
     info("Waiting for engine to be added: " + basename);
     Services.search.init({
       onInitComplete: function() {
         let url = getRootDirectory(gTestPath) + basename;
         let current = Services.search.currentEngine;
-        Services.search.addEngine(url, null, "", false, {
+        Services.search.addEngine(url, null, options.iconURL || "", false, {
           onSuccess: function (engine) {
             info("Search engine added: " + basename);
             if (setAsCurrent) {
               Services.search.currentEngine = engine;
             }
             registerCleanupFunction(() => {
               if (setAsCurrent) {
                 Services.search.currentEngine = current;