browser/devtools/debugger/test/browser_dbg_breakpoints-highlight.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Test if breakpoints are highlighted when they should.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
michael@0 9
michael@0 10 function test() {
michael@0 11 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 12 let gEditor, gSources;
michael@0 13
michael@0 14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 15 gTab = aTab;
michael@0 16 gDebuggee = aDebuggee;
michael@0 17 gPanel = aPanel;
michael@0 18 gDebugger = gPanel.panelWin;
michael@0 19 gEditor = gDebugger.DebuggerView.editor;
michael@0 20 gSources = gDebugger.DebuggerView.Sources;
michael@0 21
michael@0 22 waitForSourceShown(gPanel, "-01.js")
michael@0 23 .then(addBreakpoints)
michael@0 24 .then(() => clickBreakpointAndCheck(0, 0, 5))
michael@0 25 .then(() => clickBreakpointAndCheck(1, 1, 6))
michael@0 26 .then(() => clickBreakpointAndCheck(2, 1, 7))
michael@0 27 .then(() => clickBreakpointAndCheck(3, 1, 8))
michael@0 28 .then(() => clickBreakpointAndCheck(4, 1, 9))
michael@0 29 .then(() => ensureThreadClientState(gPanel, "resumed"))
michael@0 30 .then(() => closeDebuggerAndFinish(gPanel))
michael@0 31 .then(null, aError => {
michael@0 32 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 33 });
michael@0 34 });
michael@0 35
michael@0 36 function addBreakpoints() {
michael@0 37 return promise.resolve(null)
michael@0 38 .then(() => initialChecks(0, 1))
michael@0 39 .then(() => gPanel.addBreakpoint({ url: gSources.values[0], line: 5 }))
michael@0 40 .then(() => initialChecks(0, 5))
michael@0 41 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 6 }))
michael@0 42 .then(() => waitForSourceShown(gPanel, "-02.js"))
michael@0 43 .then(() => waitForCaretUpdated(gPanel, 6))
michael@0 44 .then(() => initialChecks(1, 6))
michael@0 45 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 7 }))
michael@0 46 .then(() => initialChecks(1, 7))
michael@0 47 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 8 }))
michael@0 48 .then(() => initialChecks(1, 8))
michael@0 49 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 9 }))
michael@0 50 .then(() => initialChecks(1, 9));
michael@0 51 }
michael@0 52
michael@0 53 function initialChecks(aSourceIndex, aCaretLine) {
michael@0 54 checkEditorContents(aSourceIndex);
michael@0 55
michael@0 56 is(gSources.selectedLabel, gSources.items[aSourceIndex].label,
michael@0 57 "The currently selected source label is incorrect (0).");
michael@0 58 is(gSources.selectedValue, gSources.items[aSourceIndex].value,
michael@0 59 "The currently selected source value is incorrect (0).");
michael@0 60 ok(isCaretPos(gPanel, aCaretLine),
michael@0 61 "The editor caret line and column were incorrect (0).");
michael@0 62 }
michael@0 63
michael@0 64 function clickBreakpointAndCheck(aBreakpointIndex, aSourceIndex, aCaretLine) {
michael@0 65 let finished = waitForCaretUpdated(gPanel, aCaretLine).then(() => {
michael@0 66 checkHighlight(gSources.values[aSourceIndex], aCaretLine);
michael@0 67 checkEditorContents(aSourceIndex);
michael@0 68
michael@0 69 is(gSources.selectedLabel, gSources.items[aSourceIndex].label,
michael@0 70 "The currently selected source label is incorrect (1).");
michael@0 71 is(gSources.selectedValue, gSources.items[aSourceIndex].value,
michael@0 72 "The currently selected source value is incorrect (1).");
michael@0 73 ok(isCaretPos(gPanel, aCaretLine),
michael@0 74 "The editor caret line and column were incorrect (1).");
michael@0 75 });
michael@0 76
michael@0 77 EventUtils.sendMouseEvent({ type: "click" },
michael@0 78 gDebugger.document.querySelectorAll(".dbg-breakpoint")[aBreakpointIndex],
michael@0 79 gDebugger);
michael@0 80
michael@0 81 return finished;
michael@0 82 }
michael@0 83
michael@0 84 function checkHighlight(aUrl, aLine) {
michael@0 85 is(gSources._selectedBreakpointItem, gSources.getBreakpoint({ url: aUrl, line: aLine }),
michael@0 86 "The currently selected breakpoint item is incorrect.");
michael@0 87 is(gSources._selectedBreakpointItem.attachment.url, aUrl,
michael@0 88 "The selected breakpoint item's source location attachment is incorrect.");
michael@0 89 is(gSources._selectedBreakpointItem.attachment.line, aLine,
michael@0 90 "The selected breakpoint item's source line number is incorrect.");
michael@0 91 ok(gSources._selectedBreakpointItem.target.classList.contains("selected"),
michael@0 92 "The selected breakpoint item's target should have a selected class.");
michael@0 93 }
michael@0 94
michael@0 95 function checkEditorContents(aSourceIndex) {
michael@0 96 if (aSourceIndex == 0) {
michael@0 97 is(gEditor.getText().indexOf("firstCall"), 118,
michael@0 98 "The first source is correctly displayed.");
michael@0 99 } else {
michael@0 100 is(gEditor.getText().indexOf("debugger"), 172,
michael@0 101 "The second source is correctly displayed.");
michael@0 102 }
michael@0 103 }
michael@0 104 }

mercurial