From 0c02ae8e7662dc556ebe469d64825f187968e330 Mon Sep 17 00:00:00 2001 From: "gavin@gavinsharp.com" Date: Mon, 1 Dec 2008 01:35:57 -0800 Subject: [PATCH] Bug 463595: browser_Application.js uses timeouts and fails intermittently, patch by Dave Townsend , r=me (tests only) --- browser/fuel/test/browser_Application.js | 78 ++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 10 deletions(-) diff --git a/browser/fuel/test/browser_Application.js b/browser/fuel/test/browser_Application.js index 60bed94f0..25d5a8408 100644 --- a/browser/fuel/test/browser_Application.js +++ b/browser/fuel/test/browser_Application.js @@ -1,6 +1,65 @@ const Ci = Components.interfaces; const Cc = Components.classes; +// This listens for the next opened window and checks it is of the right url. +// opencallback is called when the new window is fully loaded +// closecallback is called when the window is closed +function WindowOpenListener(url, opencallback, closecallback) { + this.url = url; + this.opencallback = opencallback; + this.closecallback = closecallback; + + var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. + getService(Ci.nsIWindowMediator); + wm.addListener(this); +} + +WindowOpenListener.prototype = { + url: null, + opencallback: null, + closecallback: null, + window: null, + domwindow: null, + + handleEvent: function(event) { + is(this.domwindow.document.location.href, this.url, "Should have opened the correct window"); + + this.domwindow.removeEventListener("load", this, false); + // Allow any other load handlers to execute + var self = this; + executeSoon(function() { self.opencallback(self.domwindow); } ); + }, + + onWindowTitleChange: function(window, title) { + }, + + onOpenWindow: function(window) { + if (this.window) + return; + + this.window = window; + this.domwindow = window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowInternal); + this.domwindow.addEventListener("load", this, false); + }, + + onCloseWindow: function(window) { + if (this.window != window) + return; + + var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. + getService(Ci.nsIWindowMediator); + wm.removeListener(this); + this.opencallback = null; + this.window = null; + this.domwindow = null; + + // Let the window close complete + executeSoon(this.closecallback); + this.closecallback = null; + } +}; + function test() { ok(Application, "Check global access to Application"); @@ -12,17 +71,16 @@ function test() { var wMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); var console = wMediator.getMostRecentWindow("global:console"); waitForExplicitFinish(); - if (!console) { - Application.console.open(); - } - setTimeout(checkConsole, 500); + ok(!console, "Console should not already be open"); + + new WindowOpenListener("chrome://global/content/console.xul", consoleOpened, consoleClosed); + Application.console.open(); } -function checkConsole() { - var wMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); - var console = wMediator.getMostRecentWindow("global:console"); - ok(console, "Check to see if the console window opened"); - if (console) - console.close(); +function consoleOpened(win) { + win.close(); +} + +function consoleClosed() { finish(); } -- 2.11.4.GIT