|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const URL = "about:robots"; |
|
5 |
|
6 function test() { |
|
7 let win; |
|
8 |
|
9 let listener = { |
|
10 onLocationChange: (webProgress, request, uri, flags) => { |
|
11 ok(webProgress.isTopLevel, "Received onLocationChange from top frame"); |
|
12 is(uri.spec, URL, "Received onLocationChange for correct URL"); |
|
13 finish(); |
|
14 } |
|
15 }; |
|
16 |
|
17 waitForExplicitFinish(); |
|
18 |
|
19 // Remove the listener and window when we're done. |
|
20 registerCleanupFunction(() => { |
|
21 win.gBrowser.removeProgressListener(listener); |
|
22 win.close(); |
|
23 }); |
|
24 |
|
25 // Wait for the newly opened window. |
|
26 whenNewWindowOpened(w => win = w); |
|
27 |
|
28 // Open a link in a new window. |
|
29 openLinkIn(URL, "window", {}); |
|
30 |
|
31 // On the next tick, but before the window has finished loading, access the |
|
32 // window's gBrowser property to force the tabbrowser constructor early. |
|
33 (function tryAddProgressListener() { |
|
34 executeSoon(() => { |
|
35 try { |
|
36 win.gBrowser.addProgressListener(listener); |
|
37 } catch (e) { |
|
38 // win.gBrowser wasn't ready, yet. Try again in a tick. |
|
39 tryAddProgressListener(); |
|
40 } |
|
41 }); |
|
42 })(); |
|
43 } |
|
44 |
|
45 function whenNewWindowOpened(cb) { |
|
46 Services.obs.addObserver(function obs(win) { |
|
47 Services.obs.removeObserver(obs, "domwindowopened"); |
|
48 cb(win); |
|
49 }, "domwindowopened", false); |
|
50 } |