Bug 967873 - Start TabView when starting tests that might lazily load it (r=Gijs)
authorBill McCloskey <billm@mozilla.com>
Thu, 24 Sep 2015 13:00:53 -0700
changeset 298313 108be35e74968325606c263ff840a17a5f454224
parent 298312 d55fde51f4b09e143d2b902410cba9647ee7fb03
child 298314 22b61a49ad45959daa47a1769d173374cfa0e0a4
push id6068
push userkcambridge@mozilla.com
push dateFri, 02 Oct 2015 20:37:20 +0000
reviewersGijs
bugs967873
milestone44.0a1
Bug 967873 - Start TabView when starting tests that might lazily load it (r=Gijs)
browser/base/content/test/general/browser_bug585558.js
browser/base/content/test/general/browser_bug597218.js
browser/base/content/test/general/browser_hide_removing.js
browser/base/content/test/general/browser_visibleTabs.js
browser/base/content/test/general/browser_visibleTabs_bookmarkAllPages.js
browser/base/content/test/general/browser_visibleTabs_bookmarkAllTabs.js
browser/base/content/test/general/browser_visibleTabs_contextMenu.js
browser/base/content/test/general/browser_visibleTabs_tabPreview.js
browser/components/sessionstore/test/browser_607016.js
browser/components/sessionstore/test/browser_635418.js
--- a/browser/base/content/test/general/browser_bug585558.js
+++ b/browser/base/content/test/general/browser_bug585558.js
@@ -9,16 +9,23 @@ function addTab(aURL) {
 }
 
 function testAttrib(elem, attrib, attribValue, msg) {
   is(elem.hasAttribute(attrib), attribValue, msg);
 }
 
 function test() {
   waitForExplicitFinish();
+
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  TabView._initFrame(runTest);
+}
+
+function runTest() {
   is(gBrowser.tabs.length, 1, "one tab is open initially");
 
   // Add several new tabs in sequence, hiding some, to ensure that the
   // correct attributes get set
 
   addTab("http://mochi.test:8888/#0");
   addTab("http://mochi.test:8888/#1");
   addTab("http://mochi.test:8888/#2");
--- a/browser/base/content/test/general/browser_bug597218.js
+++ b/browser/base/content/test/general/browser_bug597218.js
@@ -1,15 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function test() {
   waitForExplicitFinish();
 
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  TabView._initFrame(runTest);
+}
+
+function runTest() {
   // establish initial state
   is(gBrowser.tabs.length, 1, "we start with one tab");
   
   // create a tab
   let tab = gBrowser.loadOneTab("about:blank");
   ok(!tab.hidden, "tab starts out not hidden");
   is(gBrowser.tabs.length, 2, "we now have two tabs");
 
--- a/browser/base/content/test/general/browser_hide_removing.js
+++ b/browser/base/content/test/general/browser_hide_removing.js
@@ -2,16 +2,22 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Bug 587922: tabs don't get removed if they're hidden
 
 function test() {
   waitForExplicitFinish();
 
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  TabView._initFrame(runTest);
+}
+
+function runTest() {
   // Add a tab that will get removed and hidden
   let testTab = gBrowser.addTab("about:blank", {skipAnimation: true});
   is(gBrowser.visibleTabs.length, 2, "just added a tab, so 2 tabs");
   gBrowser.selectedTab = testTab;
 
   let numVisBeforeHide, numVisAfterHide;
   gBrowser.tabContainer.addEventListener("TabSelect", function() {
     gBrowser.tabContainer.removeEventListener("TabSelect", arguments.callee, false);
--- a/browser/base/content/test/general/browser_visibleTabs.js
+++ b/browser/base/content/test/general/browser_visibleTabs.js
@@ -1,13 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-function test() {
+add_task(function* () {
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  yield new Promise(resolve => TabView._initFrame(resolve));
+
   // There should be one tab when we start the test
   let [origTab] = gBrowser.visibleTabs;
 
   // Add a tab that will get pinned
   let pinned = gBrowser.addTab();
   gBrowser.pinTab(pinned);
 
   let testTab = gBrowser.addTab();
@@ -95,9 +99,10 @@ function test() {
   gBrowser.removeTab(testTab);
   is(gBrowser.visibleTabs.length, 1, "only orig is left and visible");
   is(gBrowser.tabs.length, 1, "sanity check that it matches");
   is(gBrowser.selectedTab, origTab, "got the orig tab");
   is(origTab.hidden, false, "and it's not hidden -- visible!");
 
   if (tabViewWindow)
     tabViewWindow.GroupItems.groupItems[0].close();
-}
+});
+
--- a/browser/base/content/test/general/browser_visibleTabs_bookmarkAllPages.js
+++ b/browser/base/content/test/general/browser_visibleTabs_bookmarkAllPages.js
@@ -1,15 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function test() {
   waitForExplicitFinish();
 
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  TabView._initFrame(runTest);
+}
+
+function runTest() {
   let tabOne = gBrowser.addTab("about:blank");
   let tabTwo = gBrowser.addTab("http://mochi.test:8888/");
   gBrowser.selectedTab = tabTwo;
 
   let browser = gBrowser.getBrowserForTab(tabTwo);
   let onLoad = function() {
     browser.removeEventListener("load", onLoad, true);
 
--- a/browser/base/content/test/general/browser_visibleTabs_bookmarkAllTabs.js
+++ b/browser/base/content/test/general/browser_visibleTabs_bookmarkAllTabs.js
@@ -1,15 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function test() {
   waitForExplicitFinish();
 
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  TabView._initFrame(runTest);
+}
+
+function runTest() {
   // There should be one tab when we start the test
   let [origTab] = gBrowser.visibleTabs;
   is(gBrowser.visibleTabs.length, 1, "1 tab should be open");  
   is(Disabled(), true, "Bookmark All Tabs should be disabled");
 
   // Add a tab
   let testTab1 = gBrowser.addTab();
   is(gBrowser.visibleTabs.length, 2, "2 tabs should be open");
--- a/browser/base/content/test/general/browser_visibleTabs_contextMenu.js
+++ b/browser/base/content/test/general/browser_visibleTabs_contextMenu.js
@@ -1,13 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-function test() {
+add_task(function* test() {
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  yield new Promise(resolve => TabView._initFrame(resolve));
+
   // There should be one tab when we start the test
   let [origTab] = gBrowser.visibleTabs;
   is(gBrowser.visibleTabs.length, 1, "there is one visible tab");
   let testTab = gBrowser.addTab();
   is(gBrowser.visibleTabs.length, 2, "there are now two visible tabs");
 
   // Check the context menu with two tabs
   updateTabContextMenu(origTab);
@@ -46,9 +50,10 @@ function test() {
   
   // Check the context menu of the original tab
   // Close Tabs To The End should now be enabled
   updateTabContextMenu(origTab);
   is(document.getElementById("context_closeTabsToTheEnd").disabled, false, "Close Tabs To The End is enabled");
 
   gBrowser.removeTab(testTab);
   gBrowser.removeTab(pinned);
-}
+});
+
--- a/browser/base/content/test/general/browser_visibleTabs_tabPreview.js
+++ b/browser/base/content/test/general/browser_visibleTabs_tabPreview.js
@@ -1,13 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-function test() {
+add_task(function* test() {
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  yield new Promise(resolve => TabView._initFrame(resolve));
+
   gPrefService.setBoolPref("browser.ctrlTab.previews", true);
 
   let [origTab] = gBrowser.visibleTabs;
   let tabOne = gBrowser.addTab();
   let tabTwo = gBrowser.addTab();
 
   // test the ctrlTab.tabList
   pressCtrlTab();
@@ -25,17 +29,17 @@ function test() {
   releaseCtrl();
 
   // cleanup
   gBrowser.removeTab(tabOne);
   gBrowser.removeTab(tabTwo);
 
   if (gPrefService.prefHasUserValue("browser.ctrlTab.previews"))
     gPrefService.clearUserPref("browser.ctrlTab.previews");
-}
+});
 
 function pressCtrlTab(aShiftKey) {
   EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true, shiftKey: !!aShiftKey });
 }
 
 function releaseCtrl() {
   EventUtils.synthesizeKey("VK_CONTROL", { type: "keyup" });
 }
--- a/browser/components/sessionstore/test/browser_607016.js
+++ b/browser/components/sessionstore/test/browser_607016.js
@@ -1,16 +1,20 @@
 "use strict";
 
 var stateBackup = ss.getBrowserState();
 
 add_task(function* () {
   /** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly **/
   ignoreAllUncaughtExceptions();
 
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  yield new Promise(resolve => TabView._initFrame(resolve));
+
   // Set the pref to true so we know exactly how many tabs should be restoring at
   // any given time. This guarantees that a finishing load won't start another.
   Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
 
   let state = { windows: [{ tabs: [
     { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } },
     { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } }, // overwriting
     { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } }, // hiding
--- a/browser/components/sessionstore/test/browser_635418.js
+++ b/browser/components/sessionstore/test/browser_635418.js
@@ -2,16 +2,22 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This tests that hiding/showing a tab, on its own, eventually triggers a
 // session store.
 
 function test() {
   waitForExplicitFinish();
+  // Ensure TabView has been initialized already. Otherwise it could
+  // activate at an unexpected time and show/hide tabs.
+  TabView._initFrame(runTest);
+}
+
+function runTest() {
   // We speed up the interval between session saves to ensure that the test
   // runs quickly.
   Services.prefs.setIntPref("browser.sessionstore.interval", 2000);
 
   // Loading a tab causes a save state and this is meant to catch that event.
   waitForSaveState(testBug635418_1);
 
   // Assumption: Only one window is open and it has one tab open.