|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if the global search results are expanded/collapsed on click, and |
|
6 * clicking matches makes the source editor shows the correct source and |
|
7 * makes a selection based on the match. |
|
8 */ |
|
9 |
|
10 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
|
11 |
|
12 let gTab, gDebuggee, gPanel, gDebugger; |
|
13 let gEditor, gSources, gSearchView, gSearchBox; |
|
14 |
|
15 function test() { |
|
16 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
17 gTab = aTab; |
|
18 gDebuggee = aDebuggee; |
|
19 gPanel = aPanel; |
|
20 gDebugger = gPanel.panelWin; |
|
21 gEditor = gDebugger.DebuggerView.editor; |
|
22 gSources = gDebugger.DebuggerView.Sources; |
|
23 gSearchView = gDebugger.DebuggerView.GlobalSearch; |
|
24 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; |
|
25 |
|
26 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) |
|
27 .then(doSearch) |
|
28 .then(testExpandCollapse) |
|
29 .then(testClickLineToJump) |
|
30 .then(testClickMatchToJump) |
|
31 .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
|
32 .then(null, aError => { |
|
33 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
34 }); |
|
35 |
|
36 gDebuggee.firstCall(); |
|
37 }); |
|
38 } |
|
39 |
|
40 function doSearch() { |
|
41 let deferred = promise.defer(); |
|
42 |
|
43 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { |
|
44 // Some operations are synchronously dispatched on the main thread, |
|
45 // to avoid blocking UI, thus giving the impression of faster searching. |
|
46 executeSoon(() => { |
|
47 info("Current source url:\n" + gSources.selectedValue); |
|
48 info("Debugger editor text:\n" + gEditor.getText()); |
|
49 |
|
50 ok(isCaretPos(gPanel, 1), |
|
51 "The editor shouldn't have jumped to a matching line yet."); |
|
52 ok(gSources.selectedValue.contains("-02.js"), |
|
53 "The current source shouldn't have changed after a global search."); |
|
54 is(gSources.visibleItems.length, 2, |
|
55 "Not all the sources are shown after the global search."); |
|
56 |
|
57 deferred.resolve(); |
|
58 }); |
|
59 }); |
|
60 |
|
61 setText(gSearchBox, "!a"); |
|
62 |
|
63 return deferred.promise; |
|
64 } |
|
65 |
|
66 function testExpandCollapse() { |
|
67 let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
|
68 let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]); |
|
69 let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]); |
|
70 let firstHeader = sourceResults[0].querySelector(".dbg-results-header"); |
|
71 let secondHeader = sourceResults[1].querySelector(".dbg-results-header"); |
|
72 |
|
73 EventUtils.sendMouseEvent({ type: "click" }, firstHeader); |
|
74 EventUtils.sendMouseEvent({ type: "click" }, secondHeader); |
|
75 |
|
76 is(item0.instance.expanded, false, |
|
77 "The first source results should be collapsed on click.") |
|
78 is(item1.instance.expanded, false, |
|
79 "The second source results should be collapsed on click.") |
|
80 |
|
81 EventUtils.sendMouseEvent({ type: "click" }, firstHeader); |
|
82 EventUtils.sendMouseEvent({ type: "click" }, secondHeader); |
|
83 |
|
84 is(item0.instance.expanded, true, |
|
85 "The first source results should be expanded on an additional click."); |
|
86 is(item1.instance.expanded, true, |
|
87 "The second source results should be expanded on an additional click."); |
|
88 } |
|
89 |
|
90 function testClickLineToJump() { |
|
91 let deferred = promise.defer(); |
|
92 |
|
93 let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
|
94 let firstHeader = sourceResults[0].querySelector(".dbg-results-header"); |
|
95 let firstLine = sourceResults[0].querySelector(".dbg-results-line-contents"); |
|
96 |
|
97 waitForSourceAndCaret(gPanel, "-01.js", 1, 1).then(() => { |
|
98 info("Current source url:\n" + gSources.selectedValue); |
|
99 info("Debugger editor text:\n" + gEditor.getText()); |
|
100 |
|
101 ok(isCaretPos(gPanel, 1, 1), |
|
102 "The editor didn't jump to the correct line (1)."); |
|
103 is(gEditor.getSelection(), "", |
|
104 "The editor didn't select the correct text (1)."); |
|
105 ok(gSources.selectedValue.contains("-01.js"), |
|
106 "The currently shown source is incorrect (1)."); |
|
107 is(gSources.visibleItems.length, 2, |
|
108 "Not all the sources are shown after the global search (1)."); |
|
109 |
|
110 deferred.resolve(); |
|
111 }); |
|
112 |
|
113 EventUtils.sendMouseEvent({ type: "click" }, firstLine); |
|
114 |
|
115 return deferred.promise; |
|
116 } |
|
117 |
|
118 function testClickMatchToJump() { |
|
119 let deferred = promise.defer(); |
|
120 |
|
121 let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
|
122 let secondHeader = sourceResults[1].querySelector(".dbg-results-header"); |
|
123 let secondMatches = sourceResults[1].querySelectorAll(".dbg-results-line-contents-string[match=true]"); |
|
124 let lastMatch = Array.slice(secondMatches).pop(); |
|
125 |
|
126 waitForSourceAndCaret(gPanel, "-02.js", 1, 1).then(() => { |
|
127 info("Current source url:\n" + gSources.selectedValue); |
|
128 info("Debugger editor text:\n" + gEditor.getText()); |
|
129 |
|
130 ok(isCaretPos(gPanel, 1, 1), |
|
131 "The editor didn't jump to the correct line (2)."); |
|
132 is(gEditor.getSelection(), "", |
|
133 "The editor didn't select the correct text (2)."); |
|
134 ok(gSources.selectedValue.contains("-02.js"), |
|
135 "The currently shown source is incorrect (2)."); |
|
136 is(gSources.visibleItems.length, 2, |
|
137 "Not all the sources are shown after the global search (2)."); |
|
138 |
|
139 deferred.resolve(); |
|
140 }); |
|
141 |
|
142 EventUtils.sendMouseEvent({ type: "click" }, lastMatch); |
|
143 |
|
144 return deferred.promise; |
|
145 } |
|
146 |
|
147 registerCleanupFunction(function() { |
|
148 gTab = null; |
|
149 gDebuggee = null; |
|
150 gPanel = null; |
|
151 gDebugger = null; |
|
152 gEditor = null; |
|
153 gSources = null; |
|
154 gSearchView = null; |
|
155 gSearchBox = null; |
|
156 }); |