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