Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
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.
15 const TEST_URI = "data:text/html;charset=utf8,<p>dead objects!";
17 function test()
18 {
19 let hud = null;
21 registerCleanupFunction(() => {
22 Services.prefs.clearUserPref("devtools.chrome.enabled");
23 });
25 Task.spawn(runner).then(finishTest);
27 function* runner() {
28 Services.prefs.setBoolPref("devtools.chrome.enabled", true);
29 let {tab} = yield loadTab(TEST_URI);
31 info("open the browser console");
33 hud = yield HUDService.toggleBrowserConsole();
34 ok(hud, "browser console opened");
36 hud.jsterm.clearOutput();
38 // Add the reference to the content document.
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");
46 gBrowser.removeCurrentTab();
48 let msg = yield execute("foobarzTezt");
50 isnot(hud.outputNode.textContent.indexOf("[object DeadObject]"), -1,
51 "dead object found");
53 hud.jsterm.setInputValue("foobarzTezt");
55 for (let c of ".hello") {
56 EventUtils.synthesizeKey(c, {}, hud.iframeWindow);
57 }
59 yield execute();
61 isnot(hud.outputNode.textContent.indexOf("can't access dead object"), -1,
62 "'cannot access dead object' message found");
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");
70 msg.scrollIntoView();
72 executeSoon(() => {
73 EventUtils.synthesizeMouseAtCenter(clickable, {}, hud.iframeWindow);
74 });
76 yield hud.jsterm.once("variablesview-fetched");
77 ok(true, "variables view fetched");
79 msg = yield execute("delete window.foobarzTezt; 2013-26");
81 isnot(msg.textContent.indexOf("1987"), -1, "result message found");
82 }
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 }