michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Check that Dead Objects do not break the Web/Browser Consoles. See bug 883649. michael@0: // This test does: michael@0: // - opens a new tab, michael@0: // - opens the Browser Console, michael@0: // - stores a reference to the content document of the tab on the chrome window object, michael@0: // - closes the tab, michael@0: // - tries to use the object that was pointing to the now-defunct content michael@0: // document. This is the dead object. michael@0: michael@0: const TEST_URI = "data:text/html;charset=utf8,
dead objects!"; michael@0: michael@0: function test() michael@0: { michael@0: let hud = null; michael@0: michael@0: registerCleanupFunction(() => { michael@0: Services.prefs.clearUserPref("devtools.chrome.enabled"); michael@0: }); michael@0: michael@0: Task.spawn(runner).then(finishTest); michael@0: michael@0: function* runner() { michael@0: Services.prefs.setBoolPref("devtools.chrome.enabled", true); michael@0: let {tab} = yield loadTab(TEST_URI); michael@0: michael@0: info("open the browser console"); michael@0: michael@0: hud = yield HUDService.toggleBrowserConsole(); michael@0: ok(hud, "browser console opened"); michael@0: michael@0: hud.jsterm.clearOutput(); michael@0: michael@0: // Add the reference to the content document. michael@0: michael@0: yield execute("Cu = Components.utils;" + michael@0: "Cu.import('resource://gre/modules/Services.jsm');" + michael@0: "chromeWindow = Services.wm.getMostRecentWindow('navigator:browser');" + michael@0: "foobarzTezt = chromeWindow.content.document;" + michael@0: "delete chromeWindow"); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: let msg = yield execute("foobarzTezt"); michael@0: michael@0: isnot(hud.outputNode.textContent.indexOf("[object DeadObject]"), -1, michael@0: "dead object found"); michael@0: michael@0: hud.jsterm.setInputValue("foobarzTezt"); michael@0: michael@0: for (let c of ".hello") { michael@0: EventUtils.synthesizeKey(c, {}, hud.iframeWindow); michael@0: } michael@0: michael@0: yield execute(); michael@0: michael@0: isnot(hud.outputNode.textContent.indexOf("can't access dead object"), -1, michael@0: "'cannot access dead object' message found"); michael@0: michael@0: // Click the second execute output. michael@0: let clickable = msg.querySelector("a"); michael@0: ok(clickable, "clickable object found"); michael@0: isnot(clickable.textContent.indexOf("[object DeadObject]"), -1, michael@0: "message text check"); michael@0: michael@0: msg.scrollIntoView(); michael@0: michael@0: executeSoon(() => { michael@0: EventUtils.synthesizeMouseAtCenter(clickable, {}, hud.iframeWindow); michael@0: }); michael@0: michael@0: yield hud.jsterm.once("variablesview-fetched"); michael@0: ok(true, "variables view fetched"); michael@0: michael@0: msg = yield execute("delete window.foobarzTezt; 2013-26"); michael@0: michael@0: isnot(msg.textContent.indexOf("1987"), -1, "result message found"); michael@0: } michael@0: michael@0: function execute(str) { michael@0: let deferred = promise.defer(); michael@0: hud.jsterm.execute(str, (msg) => { michael@0: deferred.resolve(msg); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: }