Trial fix for bug 620789 - Intermittent browser_bug581253.js | Test timed out followed by Found a tab after previous test timed out; r=mak a=tests
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Tue, 08 Feb 2011 14:16:37 -0500
changeset 62152 25fd6de1de0de88b884e6248f3f2ff0db045160f
parent 62151 c8a7ff3b95437336abc9e0e412cf3fd1a3454667
child 62153 b1be334b5f1c544e38e1f7be41b310b7bf45720a
push idunknown
push userunknown
push dateunknown
reviewersmak, tests
bugs620789, 581253
milestone2.0b12pre
Trial fix for bug 620789 - Intermittent browser_bug581253.js | Test timed out followed by Found a tab after previous test timed out; r=mak a=tests
browser/base/content/test/browser_bug581253.js
--- a/browser/base/content/test/browser_bug581253.js
+++ b/browser/base/content/test/browser_bug581253.js
@@ -1,19 +1,23 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 let testURL = "data:text/plain,nothing but plain text";
 let testTag = "581253_tag";
 let starButton = document.getElementById("star-button");
+let timerID = -1;
 
 function test() {
   registerCleanupFunction(function() {
     PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
+    if (timerID > 0) {
+      clearTimeout(timerID);
+    }
   });
   waitForExplicitFinish();
 
   let tab = gBrowser.selectedTab = gBrowser.addTab();
   tab.linkedBrowser.addEventListener("load", (function(event) {
     tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
 
     let uri = makeURI(testURL);
@@ -26,22 +30,22 @@ function test() {
     ok(PlacesUtils.bookmarks.isBookmarked(uri), "the test url is bookmarked");
     waitForStarChange(true, onStarred);
   }), true);
 
   content.location = testURL;
 }
 
 function waitForStarChange(aValue, aCallback) {
-  let starButton = document.getElementById("star-button");
   if (PlacesStarButton._ignoreClicks || starButton.hasAttribute("starred") != aValue) {
     info("Waiting for star button change.");
-    setTimeout(arguments.callee, 50, aValue, aCallback);
+    timerID = setTimeout(arguments.callee, 50, aValue, aCallback);
     return;
   }
+  timerID = -1;
   aCallback();
 }
 
 function onStarred() {
   ok(starButton.getAttribute("starred") == "true",
      "star button indicates that the page is bookmarked");
 
   let uri = makeURI(testURL);