|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test that closing a window with the debugger in a paused state exits cleanly. |
|
6 */ |
|
7 |
|
8 let gDebuggee, gPanel, gDebugger, gWindow; |
|
9 |
|
10 const TAB_URL = EXAMPLE_URL + "doc_inline-debugger-statement.html"; |
|
11 |
|
12 function test() { |
|
13 addWindow(TAB_URL) |
|
14 .then(win => initDebugger(TAB_URL, win)) |
|
15 .then(([aTab, aDebuggee, aPanel, aWindow]) => { |
|
16 gDebuggee = aDebuggee; |
|
17 gPanel = aPanel; |
|
18 gDebugger = gPanel.panelWin; |
|
19 gWindow = aWindow; |
|
20 |
|
21 return testCleanExit(); |
|
22 }) |
|
23 .then(null, aError => { |
|
24 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
25 }); |
|
26 } |
|
27 |
|
28 function testCleanExit() { |
|
29 let deferred = promise.defer(); |
|
30 |
|
31 ok(!!gWindow, "Second window created."); |
|
32 |
|
33 gWindow.focus(); |
|
34 |
|
35 is(Services.wm.getMostRecentWindow("navigator:browser"), gWindow, |
|
36 "The second window is on top."); |
|
37 |
|
38 let isActive = promise.defer(); |
|
39 let isLoaded = promise.defer(); |
|
40 |
|
41 promise.all([isActive.promise, isLoaded.promise]).then(() => { |
|
42 gWindow.BrowserChromeTest.runWhenReady(() => { |
|
43 waitForSourceAndCaretAndScopes(gPanel, ".html", 16).then(() => { |
|
44 is(gDebugger.gThreadClient.paused, true, |
|
45 "Should be paused after the debugger statement."); |
|
46 gWindow.close(); |
|
47 deferred.resolve(); |
|
48 finish(); |
|
49 }); |
|
50 |
|
51 gDebuggee.runDebuggerStatement(); |
|
52 }); |
|
53 }); |
|
54 |
|
55 let focusManager = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager); |
|
56 if (focusManager.activeWindow != gWindow) { |
|
57 gWindow.addEventListener("activate", function onActivate(aEvent) { |
|
58 if (aEvent.target != gWindow) { |
|
59 return; |
|
60 } |
|
61 gWindow.removeEventListener("activate", onActivate, true); |
|
62 isActive.resolve(); |
|
63 }, true); |
|
64 } else { |
|
65 isActive.resolve(); |
|
66 } |
|
67 |
|
68 if (gWindow.content.location.href != TAB_URL) { |
|
69 gWindow.document.addEventListener("load", function onLoad(aEvent) { |
|
70 if (aEvent.target.documentURI != TAB_URL) { |
|
71 return; |
|
72 } |
|
73 gWindow.document.removeEventListener("load", onLoad, true); |
|
74 isLoaded.resolve(); |
|
75 }, true); |
|
76 } else { |
|
77 isLoaded.resolve(); |
|
78 } |
|
79 return deferred.promise; |
|
80 } |
|
81 |
|
82 registerCleanupFunction(function() { |
|
83 gWindow = null; |
|
84 gDebuggee = null; |
|
85 gPanel = null; |
|
86 gDebugger = null; |
|
87 }); |