Bug 609803 - Intermittent timeout in browser/base/content/test/tabview/browser_tabview_launch.js followed by 'browser_tabview_privatebrowsing.js | Tab View is visible again' and finally a suite timeout in browser_tabview_undo_group.js [r=ian,a=test]
authorRaymond Lee <raymond@raysquare.com>
Tue, 08 Mar 2011 16:10:07 +0800
changeset 64512 86aa491210310000597b75ebeaa572769e55479b
parent 64511 e7038a9c371d8bbc3eb17464d82f6723db77b533
child 64513 565c588e3e5190ef2dd2680e1fc23e2f2f07d2de
push idunknown
push userunknown
push dateunknown
reviewersian, test
bugs609803
milestone2.2a1pre
Bug 609803 - Intermittent timeout in browser/base/content/test/tabview/browser_tabview_launch.js followed by 'browser_tabview_privatebrowsing.js | Tab View is visible again' and finally a suite timeout in browser_tabview_undo_group.js [r=ian,a=test]
browser/base/content/test/tabview/browser_tabview_launch.js
--- a/browser/base/content/test/tabview/browser_tabview_launch.js
+++ b/browser/base/content/test/tabview/browser_tabview_launch.js
@@ -1,52 +1,67 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 let tabViewShownCount = 0;
+let timerId;
 
 // ----------
 function test() {
   waitForExplicitFinish();
 
   // verify initial state
   ok(!TabView.isVisible(), "Tab View starts hidden");
 
   // launch tab view for the first time
   window.addEventListener("tabviewshown", onTabViewLoadedAndShown, false);
-  let tabViewCommand = document.getElementById("Browser:ToggleTabView");
-  tabViewCommand.doCommand();
+  TabView.toggle();
+
+  registerCleanupFunction(function () {
+    window.removeEventListener("tabviewshown", onTabViewLoadedAndShown, false);
+    if (timerId) 
+      clearTimeout(timerId);
+    TabView.hide()
+  });
 }
 
 // ----------
 function onTabViewLoadedAndShown() {
   window.removeEventListener("tabviewshown", onTabViewLoadedAndShown, false);
 
   // Evidently sometimes isVisible (which is based on the selectedIndex of the
   // tabview deck) isn't updated immediately when called from button.doCommand,
   // so we add a little timeout here to get outside of the doCommand call.
   // If the initial timeout isn't enough, we keep waiting in case it's taking
   // longer than expected.
   // See bug 594909.
   let deck = document.getElementById("tab-view-deck");
+  let iframe = document.getElementById("tab-view");
+  ok(iframe, "The tab view iframe exists");
+  
   function waitForSwitch() {
-    if (deck.selectedIndex == 1) {
+    if (deck.selectedPanel == iframe) {
       ok(TabView.isVisible(), "Tab View is visible. Count: " + tabViewShownCount);
       tabViewShownCount++;
 
       // kick off the series
       window.addEventListener("tabviewshown", onTabViewShown, false);
       window.addEventListener("tabviewhidden", onTabViewHidden, false);
+
+      registerCleanupFunction(function () {
+        window.removeEventListener("tabviewshown", onTabViewShown, false);
+        window.removeEventListener("tabviewhidden", onTabViewHidden, false);
+      });
       TabView.toggle();
     } else {
-      setTimeout(waitForSwitch, 10);
+      timerId = setTimeout(waitForSwitch, 10);
     }
   }
 
-  setTimeout(waitForSwitch, 1);
+  timerId = setTimeout(waitForSwitch, 1);
 }
 
 // ----------
 function onTabViewShown() {
   // add the count to the message so we can track things more easily.
   ok(TabView.isVisible(), "Tab View is visible. Count: " + tabViewShownCount);
   tabViewShownCount++;
   TabView.toggle();