Bug 704918 - GCLI 'console clear' doesn't clear everything in the console; r=dcamp

This commit is contained in:
Joe Walker 2012-01-27 18:24:52 +00:00
parent 5d9cd634cb
commit 45a9ddfcec
4 changed files with 100 additions and 7 deletions

View File

@ -77,9 +77,18 @@ gcli.addCommand({
gcli.addCommand({
name: "console clear",
description: gcli.lookup("consoleclearDesc"),
exec: function(args, context) {
exec: function Command_consoleClear(args, context) {
let window = context.environment.chromeDocument.defaultView;
let hud = HUDService.getHudReferenceById(context.environment.hudId);
hud.gcliterm.clearOutput();
// Use a timeout so we also clear the reporting of the clear command
let threadManager = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager);
threadManager.mainThread.dispatch({
run: function() {
hud.gcliterm.clearOutput();
}
}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
}
});
@ -90,7 +99,7 @@ gcli.addCommand({
gcli.addCommand({
name: "console close",
description: gcli.lookup("consolecloseDesc"),
exec: function(args, context) {
exec: function Command_consoleClose(args, context) {
let tab = HUDService.getHudReferenceById(context.environment.hudId).tab;
HUDService.deactivateHUDForContext(tab);
}
@ -112,8 +121,7 @@ gcli.addCommand({
}
],
exec: function Command_inspect(args, context) {
let hud = HUDService.getHudReferenceById(context.environment.hudId);
let InspectorUI = hud.gcliterm.document.defaultView.InspectorUI;
InspectorUI.openInspectorUI(args.node);
let document = context.environment.chromeDocument;
document.defaultView.InspectorUI.openInspectorUI(args.node);
}
});

View File

@ -6850,7 +6850,11 @@ function GcliTerm(aContentWindow, aHudId, aDocument, aConsole, aHintNode, aConso
};
this.opts = {
environment: { hudId: this.hudId },
environment: {
hudId: this.hudId,
chromeDocument: this.document,
contentDocument: aContentWindow.document
},
chromeDocument: this.document,
contentDocument: aContentWindow.document,
jsEnvironment: {

View File

@ -143,6 +143,7 @@ _BROWSER_TEST_FILES = \
browser_webconsole_bug_678816.js \
browser_webconsole_bug_664131_console_group.js \
browser_webconsole_bug_704295.js \
browser_gcli_commands.js \
browser_gcli_inspect.js \
browser_gcli_integrate.js \
browser_gcli_require.js \

View File

@ -0,0 +1,80 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// For more information on GCLI see:
// - https://github.com/mozilla/gcli/blob/master/docs/index.md
// - https://wiki.mozilla.org/DevTools/Features/GCLI
// Tests that the inspect command works as it should
Components.utils.import("resource:///modules/gcli.jsm");
let hud;
let gcliterm;
registerCleanupFunction(function() {
gcliterm = undefined;
hud = undefined;
Services.prefs.clearUserPref("devtools.gcli.enable");
});
function test() {
Services.prefs.setBoolPref("devtools.gcli.enable", true);
addTab("http://example.com/browser/browser/devtools/webconsole/test/browser_gcli_inspect.html");
browser.addEventListener("DOMContentLoaded", onLoad, false);
}
function onLoad() {
browser.removeEventListener("DOMContentLoaded", onLoad, false);
openConsole();
hud = HUDService.getHudByWindow(content);
gcliterm = hud.gcliterm;
testEcho();
// gcli._internal.console.error("Command Tests Completed");
}
function testEcho() {
let nodes = exec("echo message");
is(nodes.length, 2, "after echo");
is(nodes[0].textContent, "echo message", "output 0");
is(nodes[1].textContent.trim(), "message", "output 1");
testConsoleClear();
}
function testConsoleClear() {
let nodes = exec("console clear");
is(nodes.length, 1, "after console clear 1");
executeSoon(function() {
let nodes = hud.outputNode.querySelectorAll("richlistitem");
is(nodes.length, 0, "after console clear 2");
testConsoleClose();
});
}
function testConsoleClose() {
ok(hud.hudId in HUDService.hudReferences, "console open");
exec("console close");
ok(!(hud.hudId in HUDService.hudReferences), "console closed");
finishTest();
}
function exec(command) {
gcliterm.clearOutput();
let nodes = hud.outputNode.querySelectorAll("richlistitem");
is(nodes.length, 0, "setup - " + command);
gcliterm.opts.console.inputter.setInput(command);
gcliterm.opts.requisition.exec();
return hud.outputNode.querySelectorAll("richlistitem");
}