Bug 791670 - part 3 - fix newtab page tests; r=jaws
authorTim Taubert <ttaubert@mozilla.com>
Tue, 04 Jun 2013 22:20:44 +0200
changeset 133941 7f370b2b1317
parent 133940 bbac98ae1fea
child 133967 345e4c957e82
push id1708
push userttaubert@mozilla.com
push dateTue, 04 Jun 2013 20:21:21 +0000
treeherderfx-team@7f370b2b1317 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs791670
milestone24.0a1
Bug 791670 - part 3 - fix newtab page tests; r=jaws
browser/base/content/newtab/grid.js
browser/base/content/newtab/page.js
browser/base/content/test/browser_tabopen_reflows.js
browser/base/content/test/newtab/browser_newtab_bug723102.js
browser/base/content/test/newtab/browser_newtab_focus.js
browser/base/content/test/newtab/head.js
--- a/browser/base/content/newtab/grid.js
+++ b/browser/base/content/newtab/grid.js
@@ -25,16 +25,19 @@ let gGrid = {
   _cells: null,
   get cells() this._cells,
 
   /**
    * All sites contained in the grid's cells. Sites may be empty.
    */
   get sites() [cell.site for each (cell in this.cells)],
 
+  // Tells whether the grid has already been initialized.
+  get ready() !!this._node,
+
   /**
    * Initializes the grid.
    * @param aSelector The query selector of the grid.
    */
   init: function Grid_init() {
     this._node = document.getElementById("newtab-grid");
     this._createSiteFragment();
     this._render();
--- a/browser/base/content/newtab/page.js
+++ b/browser/base/content/newtab/page.js
@@ -45,17 +45,20 @@ let gPage = {
       gUndoDialog.hide();
     }
   },
 
   /**
    * Updates the whole page and the grid when the storage has changed.
    */
   update: function Page_update() {
-    gGrid.refresh();
+    // The grid might not be ready yet as we initialize it asynchronously.
+    if (gGrid.ready) {
+      gGrid.refresh();
+    }
   },
 
   /**
    * Internally initializes the page. This runs only when/if the feature
    * is/gets enabled.
    */
   _init: function Page_init() {
     if (this._initialized)
--- a/browser/base/content/test/browser_tabopen_reflows.js
+++ b/browser/base/content/test/browser_tabopen_reflows.js
@@ -28,23 +28,28 @@ const EXPECTED_REFLOWS = [
 
   // accessing element.scrollPosition in _fillTrailingGap() flushes layout
   "get_scrollPosition@chrome://global/content/bindings/scrollbox.xml|" +
     "_fillTrailingGap@chrome://browser/content/tabbrowser.xml|" +
     "_handleNewTab@chrome://browser/content/tabbrowser.xml|" +
     "onxbltransitionend@chrome://browser/content/tabbrowser.xml|"
 ];
 
+const PREF_PRELOAD = "browser.newtab.preload";
+
 /*
  * This test ensures that there are no unexpected
  * uninterruptible reflows when opening new tabs.
  */
 function test() {
   waitForExplicitFinish();
 
+  Services.prefs.setBoolPref(PREF_PRELOAD, false);
+  registerCleanupFunction(() => Services.prefs.clearUserPref(PREF_PRELOAD));
+
   // Add a reflow observer and open a new tab.
   docShell.addWeakReflowObserver(observer);
   BrowserOpenTab();
 
   // Wait until the tabopen animation has finished.
   waitForTransitionEnd(function () {
     // Remove reflow observer and clean up.
     docShell.removeWeakReflowObserver(observer);
--- a/browser/base/content/test/newtab/browser_newtab_bug723102.js
+++ b/browser/base/content/test/newtab/browser_newtab_bug723102.js
@@ -10,9 +10,10 @@ function runTests() {
   let firstTab = gBrowser.selectedTab;
 
   yield addNewTabPageTab();
   gBrowser.removeTab(firstTab);
 
   ok(NewTabUtils.allPages.enabled, "page is enabled");
   NewTabUtils.allPages.enabled = false;
   ok(getGrid().node.hasAttribute("page-disabled"), "page is disabled");
+  NewTabUtils.allPages.enabled = true;
 }
--- a/browser/base/content/test/newtab/browser_newtab_focus.js
+++ b/browser/base/content/test/newtab/browser_newtab_focus.js
@@ -23,16 +23,17 @@ function runTests() {
   // Count the focus with the enabled page.
   yield countFocus(FOCUS_COUNT);
 
   // Disable page and count the focus with the disabled page.
   NewTabUtils.allPages.enabled = false;
   yield countFocus(1);
 
   Services.prefs.clearUserPref("accessibility.tabfocus");
+  NewTabUtils.allPages.enabled = true;
 }
 
 /**
  * Focus the urlbar and count how many focus stops to return again to the urlbar.
  */
 function countFocus(aExpectedCount) {
   let focusCount = 0;
   let contentDoc = getContentDocument();
--- a/browser/base/content/test/newtab/head.js
+++ b/browser/base/content/test/newtab/head.js
@@ -222,17 +222,20 @@ function addNewTabPageTab() {
 
   function whenNewTabLoaded() {
     if (NewTabUtils.allPages.enabled) {
       // Continue when the link cache has been populated.
       NewTabUtils.links.populateCache(function () {
         executeSoon(TestRunner.next);
       });
     } else {
-      TestRunner.next();
+      // It's important that we call next() asynchronously.
+      // 'yield addNewTabPageTab()' would fail if next() is called
+      // synchronously because the iterator is already executing.
+      executeSoon(TestRunner.next);
     }
   }
 
   // The new tab page might have been preloaded in the background.
   if (browser.contentDocument.readyState == "complete") {
     whenNewTabLoaded();
     return;
   }