Bug 737803 - Setting a breakpoint in a line without code should move the icon to the actual location; r=past

This commit is contained in:
Anton Kovalyov 2012-10-08 10:08:12 -07:00
parent d87cad64a8
commit 00838baa99
6 changed files with 154 additions and 5 deletions

View File

@ -1463,7 +1463,18 @@ Breakpoints.prototype = {
let line = aBreakpoint.line + 1;
this.addBreakpoint({ url: url, line: line }, null, true);
this.addBreakpoint({ url: url, line: line }, function (aBp) {
if (aBp.requestedLocation) {
this.editor.removeBreakpoint(aBp.requestedLocation.line - 1);
let breakpoints = this.getBreakpoints(url, aBp.location.line);
if (breakpoints.length > 1) {
this.removeBreakpoint(breakpoints[0], null, true, true);
} else {
this.updateEditorBreakpoints();
}
}
}.bind(this), true);
},
/**
@ -1555,6 +1566,18 @@ Breakpoints.prototype = {
}
this.activeThread.setBreakpoint(aLocation, function(aResponse, aBpClient) {
let loc = aResponse.actualLocation;
if (loc) {
aBpClient.requestedLocation = {
line: aBpClient.location.line,
url: aBpClient.location.url
};
aBpClient.location.line = loc.line;
aBpClient.location.url = loc.url;
}
this.store[aBpClient.actor] = aBpClient;
this.displayBreakpoint(aBpClient, aNoEditorUpdate, aNoPaneUpdate);
aCallback && aCallback(aBpClient, aResponse.error);
@ -1655,6 +1678,18 @@ Breakpoints.prototype = {
}
}
return null;
},
getBreakpoints: function BP_getBreakpoints(aUrl, aLine) {
let breakpoints = [];
for each (let breakpoint in this.store) {
if (breakpoint.location.url == aUrl && breakpoint.location.line == aLine) {
breakpoints.push(breakpoint);
}
}
return breakpoints;
}
};

View File

@ -2107,7 +2107,7 @@ BreakpointsView.prototype = {
enableBreakpoint:
function DVB_enableBreakpoint(aTarget, aCallback, aNoCheckboxUpdate) {
let { breakpointUrl: url, breakpointLine: line } = aTarget;
let breakpoint = DebuggerController.Breakpoints.getBreakpoint(url, line)
let breakpoint = DebuggerController.Breakpoints.getBreakpoint(url, line);
if (!breakpoint) {
if (!aNoCheckboxUpdate) {

View File

@ -70,6 +70,7 @@ MOCHITEST_BROWSER_TESTS = \
browser_dbg_menustatus.js \
browser_dbg_bfcache.js \
browser_dbg_breakpoint-new-script.js \
browser_dbg_bug737803_editor_actual_location.js \
head.js \
$(NULL)

View File

@ -160,17 +160,17 @@ function test()
executeSoon(function()
{
line = 4;
line = 6;
gPane.addBreakpoint({url: gScripts.selected, line: line},
function(cl, err) {
onBreakpointAdd.call({ increment: increment, line: line }, cl, err);
line = 5;
line = 7;
gPane.addBreakpoint({url: gScripts.selected, line: line},
function(cl, err) {
onBreakpointAdd.call({ increment: increment, line: line }, cl, err);
line = 6;
line = 8;
gPane.addBreakpoint({url: gScripts.selected, line: line},
function(cl, err) {
onBreakpointAdd.call({ increment: increment, line: line }, cl, err);

View File

@ -0,0 +1,109 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Bug 737803: Setting a breakpoint in a line without code should move
* the icon to the actual location.
*/
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
let gPane = null;
let gTab = null;
let gDebuggee = null;
let gDebugger = null;
let gScripts = null;
let gEditor = null;
let gBreakpoints = null;
function test() {
let tempScope = {};
Cu.import("resource:///modules/source-editor.jsm", tempScope);
let SourceEditor = tempScope.SourceEditor;
let scriptShown = false;
let framesAdded = false;
let testStarted = false;
let resumed = false;
debug_tab_pane(TAB_URL, function (aTab, aDebuggee, aPane) {
gTab = aTab;
gPane = aPane;
gDebuggee = aDebuggee;
gDebugger = gPane.contentWindow;
resumed = true;
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function () {
framesAdded = true;
executeSoon(startTest);
});
executeSoon(function () {
gDebuggee.firstCall();
});
});
function onScriptShown(aEvent) {
scriptShown = aEvent.detail.url.indexOf("-02.js") != -1;
executeSoon(startTest);
}
window.addEventListener("Debugger:ScriptShown", onScriptShown);
function startTest() {
if (scriptShown && framesAdded && resumed && !testStarted) {
window.removeEventListener("Debugger:ScriptShown", onScriptShown);
testStarted = true;
Services.tm.currentThread.dispatch({ run: performTest }, 0);
}
}
function performTest() {
gScripts = gDebugger.DebuggerView.Scripts;
gEditor = gDebugger.editor;
gBreakpoints = gPane.breakpoints;
is(Object.keys(gBreakpoints), 0, "There are no breakpoints");
gEditor.addEventListener(SourceEditor.EVENTS.BREAKPOINT_CHANGE,
onEditorBreakpointAdd);
let location = { url: gScripts.selected, line: 4 };
executeSoon(function () {
gPane.addBreakpoint(location, onBreakpointAdd);
});
}
function onBreakpointAdd(aBpClient) {
is(aBpClient.location.url, gScripts.selected, "URL is the same");
is(aBpClient.location.line, 6, "Line number is new");
is(aBpClient.requestedLocation.line, 4, "Requested location is correct");
}
function onEditorBreakpointAdd(aEvent) {
gEditor.removeEventListener(SourceEditor.EVENTS.BREAKPOINT_CHANGE,
onEditorBreakpointAdd);
is(gEditor.getBreakpoints().length, 1,
"There is only one breakpoint in the editor");
ok(!gPane.getBreakpoint(gScripts.selected, 4),
"There are no breakpoints on an invalid line");
let br = gPane.getBreakpoint(gScripts.selected, 6);
is(br.location.url, gScripts.selected, "URL is correct");
is(br.location.line, 6, "Line number is correct");
closeDebuggerAndFinish();
}
registerCleanupFunction(function () {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gScripts = null;
gEditor = null;
gBreakpoints = null;
});
}

View File

@ -4,4 +4,8 @@
function secondCall() {
// This comment is useful for browser_dbg_select-line.js. ☺
eval("debugger;");
function foo() {}
if (true) {
foo();
}
}