Add a console test for inspection of optimized out variables (bug 1004562). r=vporof

--HG--
extra : rebase_source : e86a2000d30e58b3ec17ab64bfcd0ac7fed29e5b
This commit is contained in:
Panos Astithas 2014-05-13 16:16:44 +03:00
parent be06238ed6
commit ab9abfb79a
4 changed files with 118 additions and 0 deletions

2
browser/devtools/webconsole/test/browser.ini Executable file → Normal file
View File

@ -61,6 +61,7 @@ support-files =
test-bug-859170-longstring-hang.html
test-bug-869003-iframe.html
test-bug-869003-top-window.html
test-closure-optimized-out.html
test-closures.html
test-console-assert.html
test-console-count.html
@ -137,6 +138,7 @@ support-files =
[browser_console_native_getters.js]
[browser_console_navigation_marker.js]
[browser_console_nsiconsolemessage.js]
[browser_console_optimized_out_vars.js]
[browser_console_private_browsing.js]
[browser_console_variables_view.js]
[browser_console_variables_view_while_debugging.js]

View File

@ -0,0 +1,82 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Check that inspecting an optimized out variable works when execution is
// paused.
function test() {
Task.spawn(function* () {
const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-closure-optimized-out.html";
let {tab} = yield loadTab(TEST_URI);
let hud = yield openConsole(tab);
let { toolbox, panel, panelWin } = yield openDebugger();
yield waitForThreadEvents(panel, "resumed");
ok(true, "Debugger resumed");
let sources = panelWin.DebuggerView.Sources;
yield panel.addBreakpoint({ url: sources.values[0], line: 18 });
yield ensureThreadClientState(panel, "resumed");
let fetchedScopes = panelWin.once(panelWin.EVENTS.FETCHED_SCOPES);
let button = content.document.querySelector("button");
ok(button, "Button element found");
// Spin the event loop before causing the debuggee to pause, to allow
// this function to return first.
executeSoon(() => button.click());
let packet = yield fetchedScopes;
ok(true, "Scopes were fetched");
yield toolbox.selectTool("webconsole");
// This is the meat of the test: evaluate the optimized out variable.
hud.jsterm.execute("upvar");
yield waitForMessages({
webconsole: hud,
messages: [{
text: "optimized out",
category: CATEGORY_OUTPUT,
}]
});
finishTest();
}).then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
}
// Debugger helper functions stolen from browser/devtools/debugger/test/head.js.
function ensureThreadClientState(aPanel, aState) {
let thread = aPanel.panelWin.gThreadClient;
let state = thread.state;
info("Thread is: '" + state + "'.");
if (state == aState) {
return promise.resolve(null);
} else {
return waitForThreadEvents(aPanel, aState);
}
}
function waitForThreadEvents(aPanel, aEventName, aEventRepeat = 1) {
info("Waiting for thread event: '" + aEventName + "' to fire: " + aEventRepeat + " time(s).");
let deferred = promise.defer();
let thread = aPanel.panelWin.gThreadClient;
let count = 0;
thread.addListener(aEventName, function onEvent(aEventName, ...aArgs) {
info("Thread event '" + aEventName + "' fired: " + (++count) + " time(s).");
if (count == aEventRepeat) {
ok(true, "Enough '" + aEventName + "' thread events have been fired.");
thread.removeListener(aEventName, onEvent);
deferred.resolve.apply(deferred, aArgs);
}
});
return deferred.promise;
}

View File

@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'/>
<title>Debugger Test for Inspecting Optimized-Out Variables</title>
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
<script type="text/javascript">
window.addEventListener("load", function onload() {
window.removeEventListener("load", onload);
function clickHandler(event) {
button.removeEventListener("click", clickHandler, false);
function outer(arg) {
var upvar = arg * 2;
// The inner lambda only aliases arg, so the frontend alias analysis decides
// that upvar is not aliased and is not in the CallObject.
return function () {
arg += 2;
};
}
var f = outer(42);
f();
}
var button = document.querySelector("button");
button.addEventListener("click", clickHandler, false);
});
</script>
</head>
<body>
<button>Click me!</button>
</body>
</html>