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); }