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 101984 274f20ffcc5d
parent 101983 a5b58ae99ac9
child 101985 84324c323762
push id999
push userttaubert@mozilla.com
push dateMon, 13 Aug 2012 16:38:01 +0000
treeherderfx-team@274f20ffcc5d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs753448
milestone17.0a1
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)
  *