michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Bug 723069: Test the debugger breakpoint API and connection to the michael@0: * source editor. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; michael@0: michael@0: function test() { michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving; michael@0: michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gEditor = gDebugger.DebuggerView.editor; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gBreakpoints = gDebugger.DebuggerController.Breakpoints; michael@0: gBreakpointsAdded = gBreakpoints._added; michael@0: gBreakpointsRemoving = gBreakpoints._removing; michael@0: michael@0: waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(performTest); michael@0: gDebuggee.firstCall(); michael@0: }); michael@0: michael@0: function performTest() { michael@0: is(gDebugger.gThreadClient.state, "paused", michael@0: "Should only be getting stack frames while paused."); michael@0: is(gSources.itemCount, 2, michael@0: "Found the expected number of sources."); michael@0: is(gEditor.getText().indexOf("debugger"), 172, michael@0: "The correct source was loaded initially."); michael@0: is(gSources.selectedValue, gSources.values[1], michael@0: "The correct source is selected."); michael@0: michael@0: is(gBreakpointsAdded.size, 0, michael@0: "No breakpoints currently added."); michael@0: is(gBreakpointsRemoving.size, 0, michael@0: "No breakpoints currently being removed."); michael@0: is(gEditor.getBreakpoints().length, 0, michael@0: "No breakpoints currently shown in the editor."); michael@0: michael@0: ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }), michael@0: "_getAdded('foo', 3) returns falsey."); michael@0: ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }), michael@0: "_getRemoving('bar', 3) returns falsey."); michael@0: michael@0: is(gSources.values[1], gSources.selectedValue, michael@0: "The second source should be currently selected."); michael@0: michael@0: info("Add the first breakpoint."); michael@0: let location = { url: gSources.selectedValue, line: 6 }; michael@0: gEditor.once("breakpointAdded", onEditorBreakpointAddFirst); michael@0: gPanel.addBreakpoint(location).then(onBreakpointAddFirst); michael@0: } michael@0: michael@0: let breakpointsAdded = 0; michael@0: let breakpointsRemoved = 0; michael@0: let editorBreakpointChanges = 0; michael@0: michael@0: function onEditorBreakpointAddFirst(aEvent, aLine) { michael@0: editorBreakpointChanges++; michael@0: michael@0: ok(aEvent, michael@0: "breakpoint1 added to the editor."); michael@0: is(aLine, 5, michael@0: "Editor breakpoint line is correct."); michael@0: michael@0: is(gEditor.getBreakpoints().length, 1, michael@0: "editor.getBreakpoints().length is correct."); michael@0: } michael@0: michael@0: function onBreakpointAddFirst(aBreakpointClient) { michael@0: breakpointsAdded++; michael@0: michael@0: ok(aBreakpointClient, michael@0: "breakpoint1 added, client received."); michael@0: is(aBreakpointClient.location.url, gSources.selectedValue, michael@0: "breakpoint1 client url is correct."); michael@0: is(aBreakpointClient.location.line, 6, michael@0: "breakpoint1 client line is correct."); michael@0: michael@0: ok(gBreakpoints._getAdded(aBreakpointClient.location), michael@0: "breakpoint1 client found in the list of added breakpoints."); michael@0: ok(!gBreakpoints._getRemoving(aBreakpointClient.location), michael@0: "breakpoint1 client found in the list of removing breakpoints."); michael@0: michael@0: is(gBreakpointsAdded.size, 1, michael@0: "The list of added breakpoints holds only one breakpoint."); michael@0: is(gBreakpointsRemoving.size, 0, michael@0: "The list of removing breakpoints holds no breakpoint."); michael@0: michael@0: gBreakpoints._getAdded(aBreakpointClient.location).then(aClient => { michael@0: is(aClient, aBreakpointClient, michael@0: "_getAdded() returns the correct breakpoint."); michael@0: }); michael@0: michael@0: is(gSources.values[1], gSources.selectedValue, michael@0: "The second source should be currently selected."); michael@0: michael@0: info("Remove the first breakpoint."); michael@0: gEditor.once("breakpointRemoved", onEditorBreakpointRemoveFirst); michael@0: gPanel.removeBreakpoint(aBreakpointClient.location).then(onBreakpointRemoveFirst); michael@0: } michael@0: michael@0: function onEditorBreakpointRemoveFirst(aEvent, aLine) { michael@0: editorBreakpointChanges++; michael@0: michael@0: ok(aEvent, michael@0: "breakpoint1 removed from the editor."); michael@0: is(aLine, 5, michael@0: "Editor breakpoint line is correct."); michael@0: michael@0: is(gEditor.getBreakpoints().length, 0, michael@0: "editor.getBreakpoints().length is correct."); michael@0: } michael@0: michael@0: function onBreakpointRemoveFirst(aLocation) { michael@0: breakpointsRemoved++; michael@0: michael@0: ok(aLocation, michael@0: "breakpoint1 removed"); michael@0: is(aLocation.url, gSources.selectedValue, michael@0: "breakpoint1 removal url is correct."); michael@0: is(aLocation.line, 6, michael@0: "breakpoint1 removal line is correct."); michael@0: michael@0: testBreakpointAddBackground(); michael@0: } michael@0: michael@0: function testBreakpointAddBackground() { michael@0: is(gBreakpointsAdded.size, 0, michael@0: "No breakpoints currently added."); michael@0: is(gBreakpointsRemoving.size, 0, michael@0: "No breakpoints currently being removed."); michael@0: is(gEditor.getBreakpoints().length, 0, michael@0: "No breakpoints currently shown in the editor."); michael@0: michael@0: ok(!gBreakpoints._getAdded({ url: gSources.selectedValue, line: 6 }), michael@0: "_getAdded('gSources.selectedValue', 6) returns falsey."); michael@0: ok(!gBreakpoints._getRemoving({ url: gSources.selectedValue, line: 6 }), michael@0: "_getRemoving('gSources.selectedValue', 6) returns falsey."); michael@0: michael@0: is(gSources.values[1], gSources.selectedValue, michael@0: "The second source should be currently selected."); michael@0: michael@0: info("Add a breakpoint to the first source, which is not selected."); michael@0: let location = { url: gSources.values[0], line: 5 }; michael@0: let options = { noEditorUpdate: true }; michael@0: gEditor.on("breakpointAdded", onEditorBreakpointAddBackgroundTrap); michael@0: gPanel.addBreakpoint(location, options).then(onBreakpointAddBackground); michael@0: } michael@0: michael@0: function onEditorBreakpointAddBackgroundTrap() { michael@0: // Trap listener: no breakpoint must be added to the editor when a michael@0: // breakpoint is added to a source that is not currently selected. michael@0: editorBreakpointChanges++; michael@0: ok(false, "breakpoint2 must not be added to the editor."); michael@0: } michael@0: michael@0: function onBreakpointAddBackground(aBreakpointClient, aResponseError) { michael@0: breakpointsAdded++; michael@0: michael@0: ok(aBreakpointClient, michael@0: "breakpoint2 added, client received"); michael@0: is(aBreakpointClient.location.url, gSources.values[0], michael@0: "breakpoint2 client url is correct."); michael@0: is(aBreakpointClient.location.line, 5, michael@0: "breakpoint2 client line is correct."); michael@0: michael@0: ok(gBreakpoints._getAdded(aBreakpointClient.location), michael@0: "breakpoint2 client found in the list of added breakpoints."); michael@0: ok(!gBreakpoints._getRemoving(aBreakpointClient.location), michael@0: "breakpoint2 client found in the list of removing breakpoints."); michael@0: michael@0: is(gBreakpointsAdded.size, 1, michael@0: "The list of added breakpoints holds only one breakpoint."); michael@0: is(gBreakpointsRemoving.size, 0, michael@0: "The list of removing breakpoints holds no breakpoint."); michael@0: michael@0: gBreakpoints._getAdded(aBreakpointClient.location).then(aClient => { michael@0: is(aClient, aBreakpointClient, michael@0: "_getAdded() returns the correct breakpoint."); michael@0: }); michael@0: michael@0: is(gSources.values[1], gSources.selectedValue, michael@0: "The second source should be currently selected."); michael@0: michael@0: // Remove the trap listener. michael@0: gEditor.off("breakpointAdded", onEditorBreakpointAddBackgroundTrap); michael@0: michael@0: info("Switch to the first source, which is not yet selected"); michael@0: gEditor.once("breakpointAdded", onEditorBreakpointAddSwitch); michael@0: gEditor.once("change", onEditorTextChanged); michael@0: gSources.selectedIndex = 0; michael@0: } michael@0: michael@0: function onEditorBreakpointAddSwitch(aEvent, aLine) { michael@0: editorBreakpointChanges++; michael@0: michael@0: ok(aEvent, michael@0: "breakpoint2 added to the editor."); michael@0: is(aLine, 4, michael@0: "Editor breakpoint line is correct."); michael@0: michael@0: is(gEditor.getBreakpoints().length, 1, michael@0: "editor.getBreakpoints().length is correct"); michael@0: } michael@0: michael@0: function onEditorTextChanged() { michael@0: // Wait for the actual text to be shown. michael@0: if (gEditor.getText() == gDebugger.L10N.getStr("loadingText")) michael@0: return void gEditor.once("change", onEditorTextChanged); michael@0: michael@0: is(gEditor.getText().indexOf("debugger"), -1, michael@0: "The second source is no longer displayed."); michael@0: is(gEditor.getText().indexOf("firstCall"), 118, michael@0: "The first source is displayed."); michael@0: michael@0: is(gSources.values[0], gSources.selectedValue, michael@0: "The first source should be currently selected."); michael@0: michael@0: let window = gEditor.container.contentWindow; michael@0: executeSoon(() => window.mozRequestAnimationFrame(onReadyForClick)); michael@0: } michael@0: michael@0: function onReadyForClick() { michael@0: info("Remove the second breakpoint using the mouse."); michael@0: gEditor.once("breakpointRemoved", onEditorBreakpointRemoveSecond); michael@0: michael@0: let iframe = gEditor.container; michael@0: let testWin = iframe.ownerDocument.defaultView; michael@0: michael@0: // Flush the layout for the iframe. michael@0: info("rect " + iframe.contentDocument.documentElement.getBoundingClientRect()); michael@0: michael@0: let utils = testWin michael@0: .QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindowUtils); michael@0: michael@0: let coords = gEditor.getCoordsFromPosition({ line: 4, ch: 0 }); michael@0: let rect = iframe.getBoundingClientRect(); michael@0: let left = rect.left + 10; michael@0: let top = rect.top + coords.top + 4; michael@0: utils.sendMouseEventToWindow("mousedown", left, top, 0, 1, 0, false, 0, 0); michael@0: utils.sendMouseEventToWindow("mouseup", left, top, 0, 1, 0, false, 0, 0); michael@0: } michael@0: michael@0: function onEditorBreakpointRemoveSecond(aEvent, aLine) { michael@0: editorBreakpointChanges++; michael@0: michael@0: ok(aEvent, michael@0: "breakpoint2 removed from the editor."); michael@0: is(aLine, 4, michael@0: "Editor breakpoint line is correct."); michael@0: michael@0: is(gEditor.getBreakpoints().length, 0, michael@0: "editor.getBreakpoints().length is correct."); michael@0: michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => { michael@0: finalCheck(); michael@0: closeDebuggerAndFinish(gPanel); michael@0: }); michael@0: michael@0: gDebugger.gThreadClient.resume(); michael@0: } michael@0: michael@0: function finalCheck() { michael@0: is(gBreakpointsAdded.size, 0, michael@0: "No breakpoints currently added."); michael@0: is(gBreakpointsRemoving.size, 0, michael@0: "No breakpoints currently being removed."); michael@0: is(gEditor.getBreakpoints().length, 0, michael@0: "No breakpoints currently shown in the editor."); michael@0: michael@0: ok(!gBreakpoints._getAdded({ url: gSources.values[0], line: 5 }), michael@0: "_getAdded('gSources.values[0]', 5) returns falsey."); michael@0: ok(!gBreakpoints._getRemoving({ url: gSources.values[0], line: 5 }), michael@0: "_getRemoving('gSources.values[0]', 5) returns falsey."); michael@0: michael@0: ok(!gBreakpoints._getAdded({ url: gSources.values[1], line: 6 }), michael@0: "_getAdded('gSources.values[1]', 6) returns falsey."); michael@0: ok(!gBreakpoints._getRemoving({ url: gSources.values[1], line: 6 }), michael@0: "_getRemoving('gSources.values[1]', 6) returns falsey."); michael@0: michael@0: ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }), michael@0: "_getAdded('foo', 3) returns falsey."); michael@0: ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }), michael@0: "_getRemoving('bar', 3) returns falsey."); michael@0: michael@0: is(breakpointsAdded, 2, michael@0: "Correct number of breakpoints have been added."); michael@0: is(breakpointsRemoved, 1, michael@0: "Correct number of breakpoints have been removed."); michael@0: is(editorBreakpointChanges, 4, michael@0: "Correct number of editor breakpoint changes."); michael@0: } michael@0: }