1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug880101.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,50 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +const URL = "about:robots"; 1.8 + 1.9 +function test() { 1.10 + let win; 1.11 + 1.12 + let listener = { 1.13 + onLocationChange: (webProgress, request, uri, flags) => { 1.14 + ok(webProgress.isTopLevel, "Received onLocationChange from top frame"); 1.15 + is(uri.spec, URL, "Received onLocationChange for correct URL"); 1.16 + finish(); 1.17 + } 1.18 + }; 1.19 + 1.20 + waitForExplicitFinish(); 1.21 + 1.22 + // Remove the listener and window when we're done. 1.23 + registerCleanupFunction(() => { 1.24 + win.gBrowser.removeProgressListener(listener); 1.25 + win.close(); 1.26 + }); 1.27 + 1.28 + // Wait for the newly opened window. 1.29 + whenNewWindowOpened(w => win = w); 1.30 + 1.31 + // Open a link in a new window. 1.32 + openLinkIn(URL, "window", {}); 1.33 + 1.34 + // On the next tick, but before the window has finished loading, access the 1.35 + // window's gBrowser property to force the tabbrowser constructor early. 1.36 + (function tryAddProgressListener() { 1.37 + executeSoon(() => { 1.38 + try { 1.39 + win.gBrowser.addProgressListener(listener); 1.40 + } catch (e) { 1.41 + // win.gBrowser wasn't ready, yet. Try again in a tick. 1.42 + tryAddProgressListener(); 1.43 + } 1.44 + }); 1.45 + })(); 1.46 +} 1.47 + 1.48 +function whenNewWindowOpened(cb) { 1.49 + Services.obs.addObserver(function obs(win) { 1.50 + Services.obs.removeObserver(obs, "domwindowopened"); 1.51 + cb(win); 1.52 + }, "domwindowopened", false); 1.53 +}