browser/devtools/webconsole/test/browser_console_dead_objects.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial