Bug 1121671 - See if using the TabSwitchDone event will work. a=test-only
💩💩 backed out by ffb13ef5ff0a 💩 💩
authorNeil Deakin <neil@mozilla.com>
Tue, 31 Mar 2015 10:00:00 -0400
changeset 258228 3f7826efc5de
parent 258227 09687ee1bf7e
child 258229 e98a992238e2
push id4623
push userryanvm@gmail.com
push date2015-04-03 01:49 +0000
treeherdermozilla-beta@9c755cdc241c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstest-only
bugs1121671
milestone38.0
Bug 1121671 - See if using the TabSwitchDone event will work. a=test-only
testing/mochitest/tests/browser/browser_waitForFocus.js
--- a/testing/mochitest/tests/browser/browser_waitForFocus.js
+++ b/testing/mochitest/tests/browser/browser_waitForFocus.js
@@ -18,21 +18,29 @@ function *promiseTabLoadEvent(tab, url)
     tab.linkedBrowser.addEventListener("load", handleLoadEvent, true, true);
     if (url)
       tab.linkedBrowser.loadURI(url);
   });
 }
 
 // Load a new blank tab
 add_task(function *() {
-  let tab = gBrowser.addTab();
-  gBrowser.selectedTab = tab;
+  let tab;
 
-  let browser = gBrowser.getBrowserForTab(tab);
+  yield new Promise(resolve => {
+    gBrowser.addEventListener("TabSwitchDone", function onSwitch() {
+      gBrowser.removeEventListener("TabSwitchDone", onSwitch);
+      executeSoon(resolve);
+    });
+    tab = gBrowser.selectedTab = gBrowser.addTab();
+  });
 
+  gURLBar.focus();
+
+  let browser = gBrowser.selectedBrowser;
   yield SimpleTest.promiseFocus(browser.contentWindowAsCPOW, true);
 
   is(document.activeElement, browser, "Browser is focused when about:blank is loaded");
 
   gBrowser.removeCurrentTab();
   gURLBar.focus();
 });