michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const URL = "about:robots"; michael@0: michael@0: function test() { michael@0: let win; michael@0: michael@0: let listener = { michael@0: onLocationChange: (webProgress, request, uri, flags) => { michael@0: ok(webProgress.isTopLevel, "Received onLocationChange from top frame"); michael@0: is(uri.spec, URL, "Received onLocationChange for correct URL"); michael@0: finish(); michael@0: } michael@0: }; michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: // Remove the listener and window when we're done. michael@0: registerCleanupFunction(() => { michael@0: win.gBrowser.removeProgressListener(listener); michael@0: win.close(); michael@0: }); michael@0: michael@0: // Wait for the newly opened window. michael@0: whenNewWindowOpened(w => win = w); michael@0: michael@0: // Open a link in a new window. michael@0: openLinkIn(URL, "window", {}); michael@0: michael@0: // On the next tick, but before the window has finished loading, access the michael@0: // window's gBrowser property to force the tabbrowser constructor early. michael@0: (function tryAddProgressListener() { michael@0: executeSoon(() => { michael@0: try { michael@0: win.gBrowser.addProgressListener(listener); michael@0: } catch (e) { michael@0: // win.gBrowser wasn't ready, yet. Try again in a tick. michael@0: tryAddProgressListener(); michael@0: } michael@0: }); michael@0: })(); michael@0: } michael@0: michael@0: function whenNewWindowOpened(cb) { michael@0: Services.obs.addObserver(function obs(win) { michael@0: Services.obs.removeObserver(obs, "domwindowopened"); michael@0: cb(win); michael@0: }, "domwindowopened", false); michael@0: }