Bug 1254012 - [e10s] Fix browser_tabMatchesInAwesomebar_perwindowpb.js to run in e10s. r=gijs, a=ritu
authorJared Wein <jwein@mozilla.com>
Mon, 07 Mar 2016 05:37:00 -0500
changeset 323357 8893af0b7e816b74ba4be00f4b4a23f178d3b90f
parent 323356 9f020db3c130db6e2733b11ab35de4c3769ecfa9
child 323358 6b3a936c6587a1a35b8dc4fc96e4a01ab06443ef
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs, ritu
bugs1254012
milestone47.0a2
Bug 1254012 - [e10s] Fix browser_tabMatchesInAwesomebar_perwindowpb.js to run in e10s. r=gijs, a=ritu
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_tabMatchesInAwesomebar_perwindowpb.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -415,17 +415,17 @@ run-if = e10s
 [browser_subframe_favicons_not_used.js]
 [browser_syncui.js]
 [browser_tabDrop.js]
 skip-if = buildapp == 'mulet'
 [browser_tabReorder.js]
 skip-if = buildapp == 'mulet'
 [browser_tabMatchesInAwesomebar.js]
 [browser_tabMatchesInAwesomebar_perwindowpb.js]
-skip-if = e10s || os == 'linux' # Bug 1093373, bug 1104755
+skip-if = os == 'linux' # Bug 1104755
 [browser_tab_detach_restore.js]
 [browser_tab_drag_drop_perwindow.js]
 skip-if = buildapp == 'mulet'
 [browser_tab_dragdrop.js]
 skip-if = buildapp == 'mulet' || (e10s && debug) # Bug 1150036: In e10s, content process crashes, main process leaks!
 [browser_tab_dragdrop2.js]
 skip-if = buildapp == 'mulet'
 [browser_tabbar_big_widgets.js]
--- a/browser/base/content/test/general/browser_tabMatchesInAwesomebar_perwindowpb.js
+++ b/browser/base/content/test/general/browser_tabMatchesInAwesomebar_perwindowpb.js
@@ -1,106 +1,84 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html";
 
-function test() {
-  waitForExplicitFinish();
-
-  let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html";
+add_task(function*() {
+  let normalWindow = yield BrowserTestUtils.openNewBrowserWindow();
+  let privateWindow = yield BrowserTestUtils.openNewBrowserWindow({private: true});
+  yield runTest(normalWindow, privateWindow, false);
+  yield BrowserTestUtils.closeWindow(normalWindow);
+  yield BrowserTestUtils.closeWindow(privateWindow);
 
-  function testOnWindow(aOptions, aCallback) {
-    whenNewWindowLoaded(aOptions, function(aWin) {
-      // execute should only be called when need, like when you are opening
-      // web pages on the test. If calling executeSoon() is not necesary, then
-      // call whenNewWindowLoaded() instead of testOnWindow() on your test.
-      executeSoon(() => aCallback(aWin));
-    });
-  };
+  normalWindow = yield BrowserTestUtils.openNewBrowserWindow();
+  privateWindow = yield BrowserTestUtils.openNewBrowserWindow({private: true});
+  yield runTest(privateWindow, normalWindow, false);
+  yield BrowserTestUtils.closeWindow(normalWindow);
+  yield BrowserTestUtils.closeWindow(privateWindow);
+
+  privateWindow = yield BrowserTestUtils.openNewBrowserWindow({private: true});
+  yield runTest(privateWindow, privateWindow, false);
+  yield BrowserTestUtils.closeWindow(privateWindow);
 
-  testOnWindow({}, function(aNormalWindow) {
-    testOnWindow({private: true}, function(aPrivateWindow) {
-      runTest(aNormalWindow, aPrivateWindow, false, function() {
-        aNormalWindow.close();
-        aPrivateWindow.close();
-        testOnWindow({}, function(aNormalWindow) {
-          testOnWindow({private: true}, function(aPrivateWindow) {
-            runTest(aPrivateWindow, aNormalWindow, false, function() {
-              aNormalWindow.close();
-              aPrivateWindow.close();
-              testOnWindow({private: true}, function(aPrivateWindow) {
-                runTest(aPrivateWindow, aPrivateWindow, false, function() {
-                  aPrivateWindow.close();
-                  testOnWindow({}, function(aNormalWindow) {
-                    runTest(aNormalWindow, aNormalWindow, true, function() {
-                      aNormalWindow.close();
-                      finish();
-                    });
-                  });
-                });
-              });
-            });
-          });
-        });
-      });
+  normalWindow = yield BrowserTestUtils.openNewBrowserWindow();
+  yield runTest(normalWindow, normalWindow, true);
+  yield BrowserTestUtils.closeWindow(normalWindow);
+});
+
+function* runTest(aSourceWindow, aDestWindow, aExpectSwitch, aCallback) {
+  let baseTab = yield BrowserTestUtils.openNewForegroundTab(aSourceWindow.gBrowser, testURL);
+  let testTab = yield BrowserTestUtils.openNewForegroundTab(aDestWindow.gBrowser);
+
+  info("waiting for focus on the window");
+  yield promiseWaitForFocus(aDestWindow);
+  info("got focus on the window");
+
+  // Select the testTab
+  aDestWindow.gBrowser.selectedTab = testTab;
+
+  // Ensure that this tab has no history entries
+  let sessionHistoryCount = yield new Promise(resolve => {
+    SessionStore.getSessionHistory(gBrowser.selectedTab, function(sessionHistory) {
+      resolve(sessionHistory.entries.length);
     });
   });
 
-  function runTest(aSourceWindow, aDestWindow, aExpectSwitch, aCallback) {
-    // Open the base tab
-    let baseTab = aSourceWindow.gBrowser.addTab(testURL);
-    baseTab.linkedBrowser.addEventListener("load", function() {
-      // Wait for the tab to be fully loaded so matching happens correctly
-      if (baseTab.linkedBrowser.currentURI.spec == "about:blank")
-        return;
-      baseTab.linkedBrowser.removeEventListener("load", arguments.callee, true);
-
-      let testTab = aDestWindow.gBrowser.addTab();
+  ok(sessionHistoryCount < 2,
+     `The test tab has 1 or fewer history entries. sessionHistoryCount=${sessionHistoryCount}`);
+  // Ensure that this tab is on about:blank
+  is(testTab.linkedBrowser.currentURI.spec, "about:blank",
+     "The test tab is on about:blank");
+  // Ensure that this tab's document has no child nodes
+  yield ContentTask.spawn(testTab.linkedBrowser, null, function*() {
+    ok(!content.document.body.hasChildNodes(),
+       "The test tab has no child nodes");
+  });
+  ok(!testTab.hasAttribute("busy"),
+     "The test tab doesn't have the busy attribute");
 
-      waitForFocus(function() {
-        // Select the testTab
-        aDestWindow.gBrowser.selectedTab = testTab;
-
-        // Ensure that this tab has no history entries
-        ok(testTab.linkedBrowser.sessionHistory.count < 2,
-           "The test tab has 1 or less history entries");
-        // Ensure that this tab is on about:blank
-        is(testTab.linkedBrowser.currentURI.spec, "about:blank",
-           "The test tab is on about:blank");
-        // Ensure that this tab's document has no child nodes
-        ok(!testTab.linkedBrowser.contentDocument.body.hasChildNodes(),
-           "The test tab has no child nodes");
-        ok(!testTab.hasAttribute("busy"),
-           "The test tab doesn't have the busy attribute");
+  // Wait for the Awesomebar popup to appear.
+  yield promiseAutocompleteResultPopup(testURL, aDestWindow);
 
-        // Wait for the Awesomebar popup to appear.
-        promiseAutocompleteResultPopup(testURL, aDestWindow).then(() => {
-          if (aExpectSwitch) {
-            // If we expect a tab switch then the current tab
-            // will be closed and we switch to the other tab.
-            let tabContainer = aDestWindow.gBrowser.tabContainer;
-            tabContainer.addEventListener("TabClose", function onClose(event) {
-              if (event.target == testTab) {
-                tabContainer.removeEventListener("TabClose", onClose);
-                executeSoon(aCallback);
-              }
-            });
-          } else {
-            // If we don't expect a tab switch then wait for the tab to load.
-            testTab.addEventListener("load", function onLoad() {
-              testTab.removeEventListener("load", onLoad, true);
-              executeSoon(aCallback);
-            }, true);
-          }
+  info(`awesomebar popup appeared. aExpectSwitch: ${aExpectSwitch}`);
+  // Make sure the last match is selected.
+  let {controller, popup} = aDestWindow.gURLBar;
+  while (popup.selectedIndex < controller.matchCount - 1) {
+    info("handling key navigation for DOM_VK_DOWN key");
+    controller.handleKeyNavigation(KeyEvent.DOM_VK_DOWN);
+  }
 
-          // Make sure the last match is selected.
-          let {controller, popup} = aDestWindow.gURLBar;
-          while (popup.selectedIndex < controller.matchCount - 1) {
-            controller.handleKeyNavigation(KeyEvent.DOM_VK_DOWN);
-          }
+  let awaitTabSwitch;
+  if (aExpectSwitch) {
+    awaitTabSwitch = BrowserTestUtils.removeTab(testTab, {dontRemove: true})
+  }
 
-          // Execute the selected action.
-          controller.handleEnter(true);
-        });
-      }, aDestWindow);
-    }, true);
+  // Execute the selected action.
+  controller.handleEnter(true);
+  info("sent Enter command to the controller");
+
+  if (aExpectSwitch) {
+    // If we expect a tab switch then the current tab
+    // will be closed and we switch to the other tab.
+    yield awaitTabSwitch;
+  } else {
+    // If we don't expect a tab switch then wait for the tab to load.
+    yield BrowserTestUtils.browserLoaded(testTab.linkedBrowser);
   }
 }