|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 // Check that Dead Objects do not break the Web/Browser Consoles. See bug 883649. |
|
7 // This test does: |
|
8 // - opens a new tab, |
|
9 // - opens the Browser Console, |
|
10 // - stores a reference to the content document of the tab on the chrome window object, |
|
11 // - closes the tab, |
|
12 // - tries to use the object that was pointing to the now-defunct content |
|
13 // document. This is the dead object. |
|
14 |
|
15 const TEST_URI = "data:text/html;charset=utf8,<p>dead objects!"; |
|
16 |
|
17 function test() |
|
18 { |
|
19 let hud = null; |
|
20 |
|
21 registerCleanupFunction(() => { |
|
22 Services.prefs.clearUserPref("devtools.chrome.enabled"); |
|
23 }); |
|
24 |
|
25 Task.spawn(runner).then(finishTest); |
|
26 |
|
27 function* runner() { |
|
28 Services.prefs.setBoolPref("devtools.chrome.enabled", true); |
|
29 let {tab} = yield loadTab(TEST_URI); |
|
30 |
|
31 info("open the browser console"); |
|
32 |
|
33 hud = yield HUDService.toggleBrowserConsole(); |
|
34 ok(hud, "browser console opened"); |
|
35 |
|
36 hud.jsterm.clearOutput(); |
|
37 |
|
38 // Add the reference to the content document. |
|
39 |
|
40 yield execute("Cu = Components.utils;" + |
|
41 "Cu.import('resource://gre/modules/Services.jsm');" + |
|
42 "chromeWindow = Services.wm.getMostRecentWindow('navigator:browser');" + |
|
43 "foobarzTezt = chromeWindow.content.document;" + |
|
44 "delete chromeWindow"); |
|
45 |
|
46 gBrowser.removeCurrentTab(); |
|
47 |
|
48 let msg = yield execute("foobarzTezt"); |
|
49 |
|
50 isnot(hud.outputNode.textContent.indexOf("[object DeadObject]"), -1, |
|
51 "dead object found"); |
|
52 |
|
53 hud.jsterm.setInputValue("foobarzTezt"); |
|
54 |
|
55 for (let c of ".hello") { |
|
56 EventUtils.synthesizeKey(c, {}, hud.iframeWindow); |
|
57 } |
|
58 |
|
59 yield execute(); |
|
60 |
|
61 isnot(hud.outputNode.textContent.indexOf("can't access dead object"), -1, |
|
62 "'cannot access dead object' message found"); |
|
63 |
|
64 // Click the second execute output. |
|
65 let clickable = msg.querySelector("a"); |
|
66 ok(clickable, "clickable object found"); |
|
67 isnot(clickable.textContent.indexOf("[object DeadObject]"), -1, |
|
68 "message text check"); |
|
69 |
|
70 msg.scrollIntoView(); |
|
71 |
|
72 executeSoon(() => { |
|
73 EventUtils.synthesizeMouseAtCenter(clickable, {}, hud.iframeWindow); |
|
74 }); |
|
75 |
|
76 yield hud.jsterm.once("variablesview-fetched"); |
|
77 ok(true, "variables view fetched"); |
|
78 |
|
79 msg = yield execute("delete window.foobarzTezt; 2013-26"); |
|
80 |
|
81 isnot(msg.textContent.indexOf("1987"), -1, "result message found"); |
|
82 } |
|
83 |
|
84 function execute(str) { |
|
85 let deferred = promise.defer(); |
|
86 hud.jsterm.execute(str, (msg) => { |
|
87 deferred.resolve(msg); |
|
88 }); |
|
89 return deferred.promise; |
|
90 } |
|
91 } |