Bug 753448 - Part 3 - Adapt tests for the new tab page; r=jaws
authorTim Taubert <tim.taubert@gmx.de>
Mon, 13 Aug 2012 09:34:10 -0700
changeset 102219 274f20ffcc5d
parent 102218 a5b58ae99ac9
child 102220 84324c323762
push id23271
push userttaubert@mozilla.com
push dateTue, 14 Aug 2012 04:18:45 +0000
treeherdermozilla-central@22288130fea2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs753448
milestone17.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 753448 - Part 3 - Adapt tests for the new tab page; r=jaws
browser/base/content/test/browser_bug724239.js
browser/base/content/test/browser_bug763468.js
browser/base/content/test/browser_bug767836.js
browser/base/content/test/newtab/head.js
--- a/browser/base/content/test/browser_bug724239.js
+++ b/browser/base/content/test/browser_bug724239.js
@@ -16,13 +16,18 @@ function test() {
     whenBrowserLoaded(browser, function () {
       ok(!gBrowser.canGoBack, "about:newtab wasn't added to the session history");
       finish();
     });
   });
 }
 
 function whenBrowserLoaded(aBrowser, aCallback) {
+  if (aBrowser.contentDocument.readyState == "complete") {
+    executeSoon(aCallback);
+    return;
+  }
+
   aBrowser.addEventListener("load", function onLoad() {
     aBrowser.removeEventListener("load", onLoad, true);
     executeSoon(aCallback);
   }, true);
 }
--- a/browser/base/content/test/browser_bug763468.js
+++ b/browser/base/content/test/browser_bug763468.js
@@ -62,15 +62,20 @@ function togglePrivateBrowsing(aCallback
   }, topic, false);
 
   pb.privateBrowsingEnabled = !pb.privateBrowsingEnabled;
 }
 
 function openNewTab(aCallback) {
   // Open a new tab
   BrowserOpenTab();
-  
+
   let browser = gBrowser.selectedBrowser;
+  if (browser.contentDocument.readyState == "complete") {
+    executeSoon(aCallback);
+    return;
+  }
+
   browser.addEventListener("load", function onLoad() {
     browser.removeEventListener("load", onLoad, true);
     executeSoon(aCallback);
   }, true);
 }
--- a/browser/base/content/test/browser_bug767836.js
+++ b/browser/base/content/test/browser_bug767836.js
@@ -79,15 +79,20 @@ function togglePrivateBrowsing(aCallback
   }, topic, false);
 
   pb.privateBrowsingEnabled = !pb.privateBrowsingEnabled;
 }
 
 function openNewTab(aCallback) {
   // Open a new tab
   BrowserOpenTab();
-  
+
   let browser = gBrowser.selectedBrowser;
+  if (browser.contentDocument.readyState == "complete") {
+    executeSoon(aCallback);
+    return;
+  }
+
   browser.addEventListener("load", function onLoad() {
     browser.removeEventListener("load", onLoad, true);
     executeSoon(aCallback);
   }, true);
 }
--- a/browser/base/content/test/newtab/head.js
+++ b/browser/base/content/test/newtab/head.js
@@ -198,28 +198,37 @@ function restore() {
 
 /**
  * Creates a new tab containing 'about:newtab'.
  */
 function addNewTabPageTab() {
   let tab = gBrowser.selectedTab = gBrowser.addTab("about:newtab");
   let browser = tab.linkedBrowser;
 
-  // Wait for the new tab page to be loaded.
-  browser.addEventListener("load", function onLoad() {
-    browser.removeEventListener("load", onLoad, true);
-
+  function whenNewTabLoaded() {
     if (NewTabUtils.allPages.enabled) {
       // Continue when the link cache has been populated.
       NewTabUtils.links.populateCache(function () {
         executeSoon(TestRunner.next);
       });
     } else {
       TestRunner.next();
     }
+  }
+
+  // The new tab page might have been preloaded in the background.
+  if (browser.contentDocument.readyState == "complete") {
+    whenNewTabLoaded();
+    return;
+  }
+
+  // Wait for the new tab page to be loaded.
+  browser.addEventListener("load", function onLoad() {
+    browser.removeEventListener("load", onLoad, true);
+    whenNewTabLoaded();
   }, true);
 }
 
 /**
  * Compares the current grid arrangement with the given pattern.
  * @param the pattern (see below)
  * @param the array of sites to compare with (optional)
  *