Bug 1262946 - Update browser_bug495058.js to account for initial browser focus changes. r?Gijs draft
authorMike Conley <mconley@mozilla.com>
Fri, 08 Apr 2016 13:58:57 -0400
changeset 348992 19718b967acfc4cb7da8c8e6f35d4d9397bf79b9
parent 348991 c9e3478db083fe20e1b2996bc05d09f6812ed309
child 518006 5d2a7fbd1285f16197bcf9e1634359a7f86752fa
push id14986
push usermconley@mozilla.com
push dateFri, 08 Apr 2016 19:29:06 +0000
reviewersGijs
bugs1262946, 495058
milestone48.0a1
Bug 1262946 - Update browser_bug495058.js to account for initial browser focus changes. r?Gijs MozReview-Commit-ID: BtjM4eYU0Rc
browser/base/content/test/general/browser_bug495058.js
--- a/browser/base/content/test/general/browser_bug495058.js
+++ b/browser/base/content/test/general/browser_bug495058.js
@@ -1,43 +1,50 @@
-function test() {
-  waitForExplicitFinish();
-  next();
-}
+/**
+ * Tests that the right elements of a tab are focused when it is
+ * torn out into its own window.
+ */
 
-var uris = [
+const URIS = [
   "about:blank",
   "about:sessionrestore",
   "about:privatebrowsing",
 ];
 
-function next() {
-  var tab = gBrowser.addTab();
-  var uri = uris.shift();
+add_task(function*() {
+  for (let uri of URIS) {
+    let tab = gBrowser.addTab();
+    yield BrowserTestUtils.loadURI(tab.linkedBrowser, uri);
+
+    let win = gBrowser.replaceTabWithWindow(tab);
+    yield BrowserTestUtils.waitForEvent(win, "load");
 
-  if (uri == "about:blank") {
-    detach();
-  } else {
-    let browser = tab.linkedBrowser;
-    browser.addEventListener("load", function () {
-      browser.removeEventListener("load", arguments.callee, true);
-      detach();
-    }, true);
-    browser.loadURI(uri);
-  }
+    tab = win.gBrowser.selectedTab;
+
+    // By default, we'll wait for MozAfterPaint to come up through the
+    // browser element. We'll handle the e10s case in the next block.
+    let contentPainted = BrowserTestUtils.waitForEvent(tab.linkedBrowser,
+                                                       "MozAfterPaint");
+
+    let delayedStartup =
+      TestUtils.topicObserved("browser-delayed-startup-finished",
+                              subject => subject == win);
 
-  function detach() {
-    var win = gBrowser.replaceTabWithWindow(tab);
-
-    whenDelayedStartupFinished(win, function () {
-      is(win.gBrowser.currentURI.spec, uri, uri + ": uri loaded in detached tab");
-      is(win.document.activeElement, win.gBrowser.selectedBrowser, uri + ": browser is focused");
-      is(win.gURLBar.value, "", uri + ": urlbar is empty");
-      ok(win.gURLBar.placeholder, uri + ": placeholder text is present");
+    if (gMultiProcessBrowser &&
+        E10SUtils.canLoadURIInProcess(uri, Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT)) {
+      // Until bug 1261842 is fixed, the initial browser is going to be
+      // non-remote. If we're transitioning to a URL that can be loaded
+      // remotely, we'll need to wait until that remoteness switch is done
+      // before we send any framescripts down to the browser.
+      yield BrowserTestUtils.waitForEvent(tab, "TabRemotenessChange");
+      contentPainted = BrowserTestUtils.contentPainted(tab.linkedBrowser);
+    }
 
-      win.close();
-      if (uris.length)
-        next();
-      else
-        executeSoon(finish);
-    });
+    yield Promise.all([delayedStartup, contentPainted]);
+
+    Assert.equal(win.gBrowser.currentURI.spec, uri, uri + ": uri loaded in detached tab");
+    Assert.equal(win.document.activeElement, win.gBrowser.selectedBrowser, uri + ": browser is focused");
+    Assert.equal(win.gURLBar.value, "", uri + ": urlbar is empty");
+    Assert.ok(win.gURLBar.placeholder, uri + ": placeholder text is present");
+
+    yield BrowserTestUtils.closeWindow(win);
   }
-}
+});