1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_console_dead_objects.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +// Check that Dead Objects do not break the Web/Browser Consoles. See bug 883649. 1.10 +// This test does: 1.11 +// - opens a new tab, 1.12 +// - opens the Browser Console, 1.13 +// - stores a reference to the content document of the tab on the chrome window object, 1.14 +// - closes the tab, 1.15 +// - tries to use the object that was pointing to the now-defunct content 1.16 +// document. This is the dead object. 1.17 + 1.18 +const TEST_URI = "data:text/html;charset=utf8,<p>dead objects!"; 1.19 + 1.20 +function test() 1.21 +{ 1.22 + let hud = null; 1.23 + 1.24 + registerCleanupFunction(() => { 1.25 + Services.prefs.clearUserPref("devtools.chrome.enabled"); 1.26 + }); 1.27 + 1.28 + Task.spawn(runner).then(finishTest); 1.29 + 1.30 + function* runner() { 1.31 + Services.prefs.setBoolPref("devtools.chrome.enabled", true); 1.32 + let {tab} = yield loadTab(TEST_URI); 1.33 + 1.34 + info("open the browser console"); 1.35 + 1.36 + hud = yield HUDService.toggleBrowserConsole(); 1.37 + ok(hud, "browser console opened"); 1.38 + 1.39 + hud.jsterm.clearOutput(); 1.40 + 1.41 + // Add the reference to the content document. 1.42 + 1.43 + yield execute("Cu = Components.utils;" + 1.44 + "Cu.import('resource://gre/modules/Services.jsm');" + 1.45 + "chromeWindow = Services.wm.getMostRecentWindow('navigator:browser');" + 1.46 + "foobarzTezt = chromeWindow.content.document;" + 1.47 + "delete chromeWindow"); 1.48 + 1.49 + gBrowser.removeCurrentTab(); 1.50 + 1.51 + let msg = yield execute("foobarzTezt"); 1.52 + 1.53 + isnot(hud.outputNode.textContent.indexOf("[object DeadObject]"), -1, 1.54 + "dead object found"); 1.55 + 1.56 + hud.jsterm.setInputValue("foobarzTezt"); 1.57 + 1.58 + for (let c of ".hello") { 1.59 + EventUtils.synthesizeKey(c, {}, hud.iframeWindow); 1.60 + } 1.61 + 1.62 + yield execute(); 1.63 + 1.64 + isnot(hud.outputNode.textContent.indexOf("can't access dead object"), -1, 1.65 + "'cannot access dead object' message found"); 1.66 + 1.67 + // Click the second execute output. 1.68 + let clickable = msg.querySelector("a"); 1.69 + ok(clickable, "clickable object found"); 1.70 + isnot(clickable.textContent.indexOf("[object DeadObject]"), -1, 1.71 + "message text check"); 1.72 + 1.73 + msg.scrollIntoView(); 1.74 + 1.75 + executeSoon(() => { 1.76 + EventUtils.synthesizeMouseAtCenter(clickable, {}, hud.iframeWindow); 1.77 + }); 1.78 + 1.79 + yield hud.jsterm.once("variablesview-fetched"); 1.80 + ok(true, "variables view fetched"); 1.81 + 1.82 + msg = yield execute("delete window.foobarzTezt; 2013-26"); 1.83 + 1.84 + isnot(msg.textContent.indexOf("1987"), -1, "result message found"); 1.85 + } 1.86 + 1.87 + function execute(str) { 1.88 + let deferred = promise.defer(); 1.89 + hud.jsterm.execute(str, (msg) => { 1.90 + deferred.resolve(msg); 1.91 + }); 1.92 + return deferred.promise; 1.93 + } 1.94 +}