From 91971fd03129e3ba2ac916a62b5b7b2b0b2d005f Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 9 Oct 2009 23:13:53 +0200 Subject: [PATCH] Bug 513420 - random failure in browser_privatebrowsing_windowtitle.js, r=mconnor. Further modified by me, r=ehsan --- .../browser_privatebrowsing_windowtitle.js | 59 +++++++++++-------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle.js index 558502f1bf1..ce25fd97959 100644 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle.js +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle.js @@ -80,35 +80,44 @@ function test() { let tab = gBrowser.selectedTab = gBrowser.addTab(); let browser = gBrowser.selectedBrowser; - browser.addEventListener("load", function() { - browser.removeEventListener("load", arguments.callee, true); + // ensure that the test is run after the titlebar has been updated + let timer = null; + let _updateTitlebar = gBrowser.updateTitlebar; + gBrowser.updateTitlebar = function() { + if (timer) { + timer.cancel(); + timer = null; + } + timer = Cc["@mozilla.org/timer;1"]. + createInstance(Ci.nsITimer); + timer.initWithCallback(function () { + _updateTitlebar.apply(gBrowser, arguments); + gBrowser.updateTitlebar = _updateTitlebar; + is(document.title, expected_title, "The window title for " + url + + " is correct (" + (insidePB ? "inside" : "outside") + + " private browsing mode)"); - // ensure that the test is run after the page onload event - setTimeout(function() { - setTimeout(function() { - is(document.title, expected_title, "The window title for " + url + - " is correct (" + (insidePB ? "inside" : "outside") + - " private browsing mode)"); + let win = gBrowser.replaceTabWithWindow(tab); + win.addEventListener("load", function() { + win.removeEventListener("load", arguments.callee, false); - let win = gBrowser.replaceTabWithWindow(tab); - win.addEventListener("load", function() { - win.removeEventListener("load", arguments.callee, false); + // ensure that the test is run after delayedStartup + let _delayedStartup = win.delayedStartup; + win.delayedStartup = function() { + _delayedStartup.apply(win, arguments); + win.delayedStartup = _delayedStartup; - // ensure that the test is run after delayedStartup - setTimeout(function() { - setTimeout(function() { - is(win.document.title, expected_title, "The window title for " + url + - " detahced tab is correct (" + (insidePB ? "inside" : "outside") + - " private browsing mode)"); - win.close(); + is(win.document.title, expected_title, "The window title for " + url + + " detached tab is correct (" + (insidePB ? "inside" : "outside") + + " private browsing mode)"); + win.close(); + + setTimeout(funcNext, 0); + }; + }, false); + }, 300, Ci.nsITimer.TYPE_ONE_SHOT); + }; - funcNext(); - }, 0); - }, 0); - }, false); - }, 0); - }, 0); - }, true); browser.loadURI(url); }