Bug 766001 - In the webconsole, when you click on the filename/line-number of a js-error or message, the debugger should open instead of view source. r=past,msucan,vporof f=rcampbell

This commit is contained in:
Girish Sharma 2012-12-17 04:40:44 +05:30
parent 603b27eabb
commit 195edb524a
7 changed files with 211 additions and 0 deletions

View File

@ -343,6 +343,67 @@ WebConsole.prototype = {
this.viewSource(aSourceURL, aSourceLine);
},
/**
* Tries to open a JavaScript file related to the web page for the web console
* instance in the Script Debugger. If the file is not found, it is opened in
* source view instead.
*
* @param string aSourceURL
* The URL of the file.
* @param integer aSourceLine
* The line number which you want to place the caret.
*/
viewSourceInDebugger:
function WC_viewSourceInDebugger(aSourceURL, aSourceLine)
{
let self = this;
let panelWin = null;
let debuggerWasOpen = true;
let toolbox = gDevTools.getToolbox(this.target);
if (!toolbox.getPanel("jsdebugger")) {
debuggerWasOpen = false;
let toolboxWin = toolbox.doc.defaultView;
toolboxWin.addEventListener("Debugger:AfterSourcesAdded",
function afterSourcesAdded() {
toolboxWin.removeEventListener("Debugger:AfterSourcesAdded",
afterSourcesAdded);
loadScript();
});
}
toolbox.selectTool("jsdebugger").then(function onDebuggerOpen(dbg) {
panelWin = dbg.panelWin;
if (debuggerWasOpen) {
loadScript();
}
});
function loadScript() {
let debuggerView = panelWin.DebuggerView;
if (!debuggerView.Sources.containsValue(aSourceURL)) {
toolbox.selectTool("webconsole");
self.viewSource(aSourceURL, aSourceLine);
return;
}
if (debuggerWasOpen && debuggerView.Sources.selectedValue == aSourceURL) {
debuggerView.editor.setCaretPosition(aSourceLine - 1);
return;
}
panelWin.addEventListener("Debugger:SourceShown", onSource, false);
debuggerView.Sources.preferredSource = aSourceURL;
}
function onSource(aEvent) {
if (aEvent.detail.url != aSourceURL) {
return;
}
panelWin.removeEventListener("Debugger:SourceShown", onSource, false);
panelWin.DebuggerView.editor.setCaretPosition(aSourceLine - 1);
}
},
/**
* Destroy the object. Call this method to avoid memory leaks when the Web
* Console is closed.

View File

@ -104,6 +104,7 @@ MOCHITEST_BROWSER_FILES = \
browser_webconsole_bug_622303_persistent_filters.js \
browser_webconsole_bug_770099_bad_policyuri.js \
browser_webconsole_bug_770099_violation.js \
browser_webconsole_bug_766001_JS_Console_in_Debugger.js \
browser_webconsole_bug_782653_CSS_links_in_Style_Editor.js \
browser_cached_messages.js \
browser_bug664688_sandbox_update_after_navigation.js \
@ -210,6 +211,9 @@ MOCHITEST_BROWSER_FILES += \
test-result-format-as-string.html \
test-bug-737873-mixedcontent.html \
test-repeated-messages.html \
test-bug-766001-console-log.js \
test-bug-766001-js-console-links.html \
test-bug-766001-js-errors.js \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,113 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
* ***** END LICENSE BLOCK ***** */
const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test" +
"/test-bug-766001-js-console-links.html";
let nodes, dbg, toolbox, target, index = 0, src, line;
function test()
{
expectUncaughtException();
requestLongerTimeout(2);
addTab(TEST_URI);
browser.addEventListener("load", function onLoad() {
browser.removeEventListener("load", onLoad, true);
openConsole(null, testViewSource);
}, true);
}
function testViewSource(aHud)
{
registerCleanupFunction(function() {
nodes = dbg = toolbox = target = index = src = line = null;
});
let JSSelector = ".webconsole-msg-exception .webconsole-location";
let consoleSelector = ".webconsole-msg-console .webconsole-location";
waitForSuccess({
name: "find the location node",
validatorFn: function()
{
return aHud.outputNode.querySelector(JSSelector) &&
aHud.outputNode.querySelector(consoleSelector);
},
successFn: function()
{
nodes = [aHud.outputNode.querySelector(JSSelector),
aHud.outputNode.querySelector(consoleSelector)];
target = TargetFactory.forTab(gBrowser.selectedTab);
toolbox = gDevTools.getToolbox(target);
toolbox.once("jsdebugger-selected", checkLineAndClickNext);
EventUtils.sendMouseEvent({ type: "click" }, nodes[index%2]);
},
failureFn: finishTest,
});
}
function checkLineAndClickNext(aEvent, aPanel)
{
if (index == 3) {
finishTest();
return;
}
info(aEvent + " event fired for index " + index);
dbg = aPanel;
src = nodes[index%2].getAttribute("title");
ok(src, "source url found for index " + index);
line = nodes[index%2].sourceLine;
ok(line, "found source line for index " + index);
info("Waiting for the correct script to be selected for index " + index);
dbg.panelWin.addEventListener("Debugger:SourceShown", onSource, false);
}
function onSource(aEvent) {
if (aEvent.detail.url != src) {
return;
}
dbg.panelWin.removeEventListener("Debugger:SourceShown", onSource, false);
ok(true, "Correct script is selected for index " + index);
checkCorrectLine(function() {
gDevTools.showToolbox(target, "webconsole").then(function() {
index++;
info("webconsole selected for index " + index);
toolbox.once("jsdebugger-selected", checkLineAndClickNext);
EventUtils.sendMouseEvent({ type: "click" }, nodes[index%2]);
});
});
}
function checkCorrectLine(aCallback)
{
waitForSuccess({
name: "correct source and line test for debugger for index " + index,
validatorFn: function()
{
let debuggerView = dbg.panelWin.DebuggerView;
if (debuggerView.editor &&
debuggerView.editor.getCaretPosition().line == line - 1) {
return true;
}
return false;
},
successFn: function()
{
aCallback && executeSoon(aCallback);
},
failureFn: finishTest,
timeout: 10000,
});
}

View File

@ -0,0 +1,8 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
window.addEventListener("load", function() {
console.log("Blah Blah");
}, false);

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Web Console test for bug 766001 : Open JS/Console call Links in Debugger</title>
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
<script type="text/javascript" src="test-bug-766001-js-errors.js"></script>
<script type="text/javascript" src="test-bug-766001-console-log.js"></script>
</head>
<body>
<p>Web Console test for bug 766001 : Open JS/Console call Links in Debugger.</p>
</body>
</html>

View File

@ -0,0 +1,7 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
window.addEventListener("load", function() {
document.bar();
}, false);

View File

@ -2410,6 +2410,10 @@ WebConsoleFrame.prototype = {
else if (locationNode.parentNode.category == CATEGORY_CSS) {
this.owner.viewSourceInStyleEditor(aSourceURL, aSourceLine);
}
else if (locationNode.parentNode.category == CATEGORY_JS ||
locationNode.parentNode.category == CATEGORY_WEBDEV) {
this.owner.viewSourceInDebugger(aSourceURL, aSourceLine);
}
else {
this.owner.viewSource(aSourceURL, aSourceLine);
}