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: * Test if breakpoints are highlighted when they should. 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; 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: michael@0: waitForSourceShown(gPanel, "-01.js") michael@0: .then(addBreakpoints) michael@0: .then(() => clickBreakpointAndCheck(0, 0, 5)) michael@0: .then(() => clickBreakpointAndCheck(1, 1, 6)) michael@0: .then(() => clickBreakpointAndCheck(2, 1, 7)) michael@0: .then(() => clickBreakpointAndCheck(3, 1, 8)) michael@0: .then(() => clickBreakpointAndCheck(4, 1, 9)) michael@0: .then(() => ensureThreadClientState(gPanel, "resumed")) michael@0: .then(() => closeDebuggerAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: }); michael@0: michael@0: function addBreakpoints() { michael@0: return promise.resolve(null) michael@0: .then(() => initialChecks(0, 1)) michael@0: .then(() => gPanel.addBreakpoint({ url: gSources.values[0], line: 5 })) michael@0: .then(() => initialChecks(0, 5)) michael@0: .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 6 })) michael@0: .then(() => waitForSourceShown(gPanel, "-02.js")) michael@0: .then(() => waitForCaretUpdated(gPanel, 6)) michael@0: .then(() => initialChecks(1, 6)) michael@0: .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 7 })) michael@0: .then(() => initialChecks(1, 7)) michael@0: .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 8 })) michael@0: .then(() => initialChecks(1, 8)) michael@0: .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 9 })) michael@0: .then(() => initialChecks(1, 9)); michael@0: } michael@0: michael@0: function initialChecks(aSourceIndex, aCaretLine) { michael@0: checkEditorContents(aSourceIndex); michael@0: michael@0: is(gSources.selectedLabel, gSources.items[aSourceIndex].label, michael@0: "The currently selected source label is incorrect (0)."); michael@0: is(gSources.selectedValue, gSources.items[aSourceIndex].value, michael@0: "The currently selected source value is incorrect (0)."); michael@0: ok(isCaretPos(gPanel, aCaretLine), michael@0: "The editor caret line and column were incorrect (0)."); michael@0: } michael@0: michael@0: function clickBreakpointAndCheck(aBreakpointIndex, aSourceIndex, aCaretLine) { michael@0: let finished = waitForCaretUpdated(gPanel, aCaretLine).then(() => { michael@0: checkHighlight(gSources.values[aSourceIndex], aCaretLine); michael@0: checkEditorContents(aSourceIndex); michael@0: michael@0: is(gSources.selectedLabel, gSources.items[aSourceIndex].label, michael@0: "The currently selected source label is incorrect (1)."); michael@0: is(gSources.selectedValue, gSources.items[aSourceIndex].value, michael@0: "The currently selected source value is incorrect (1)."); michael@0: ok(isCaretPos(gPanel, aCaretLine), michael@0: "The editor caret line and column were incorrect (1)."); michael@0: }); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "click" }, michael@0: gDebugger.document.querySelectorAll(".dbg-breakpoint")[aBreakpointIndex], michael@0: gDebugger); michael@0: michael@0: return finished; michael@0: } michael@0: michael@0: function checkHighlight(aUrl, aLine) { michael@0: is(gSources._selectedBreakpointItem, gSources.getBreakpoint({ url: aUrl, line: aLine }), michael@0: "The currently selected breakpoint item is incorrect."); michael@0: is(gSources._selectedBreakpointItem.attachment.url, aUrl, michael@0: "The selected breakpoint item's source location attachment is incorrect."); michael@0: is(gSources._selectedBreakpointItem.attachment.line, aLine, michael@0: "The selected breakpoint item's source line number is incorrect."); michael@0: ok(gSources._selectedBreakpointItem.target.classList.contains("selected"), michael@0: "The selected breakpoint item's target should have a selected class."); michael@0: } michael@0: michael@0: function checkEditorContents(aSourceIndex) { michael@0: if (aSourceIndex == 0) { michael@0: is(gEditor.getText().indexOf("firstCall"), 118, michael@0: "The first source is correctly displayed."); michael@0: } else { michael@0: is(gEditor.getText().indexOf("debugger"), 172, michael@0: "The second source is correctly displayed."); michael@0: } michael@0: } michael@0: }