browser/devtools/debugger/test/browser_dbg_search-global-04.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:5814941aba2b
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 trigger MatchFound and NoMatchFound events
6 * properly, and triggers the expected UI behavior.
7 */
8
9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
10
11 let gTab, gDebuggee, gPanel, gDebugger;
12 let gEditor, gSources, gSearchView, gSearchBox;
13
14 function test() {
15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
16 gTab = aTab;
17 gDebuggee = aDebuggee;
18 gPanel = aPanel;
19 gDebugger = gPanel.panelWin;
20 gEditor = gDebugger.DebuggerView.editor;
21 gSources = gDebugger.DebuggerView.Sources;
22 gSearchView = gDebugger.DebuggerView.GlobalSearch;
23 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
24
25 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
26 .then(firstSearch)
27 .then(secondSearch)
28 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
29 .then(null, aError => {
30 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
31 });
32
33 gDebuggee.firstCall();
34 });
35 }
36
37 function firstSearch() {
38 let deferred = promise.defer();
39
40 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
41 // Some operations are synchronously dispatched on the main thread,
42 // to avoid blocking UI, thus giving the impression of faster searching.
43 executeSoon(() => {
44 info("Current source url:\n" + gSources.selectedValue);
45 info("Debugger editor text:\n" + gEditor.getText());
46
47 ok(isCaretPos(gPanel, 1),
48 "The editor shouldn't have jumped to a matching line yet.");
49 ok(gSources.selectedValue.contains("-02.js"),
50 "The current source shouldn't have changed after a global search.");
51 is(gSources.visibleItems.length, 2,
52 "Not all the sources are shown after the global search.");
53
54 deferred.resolve();
55 });
56 });
57
58 setText(gSearchBox, "!eval");
59
60 return deferred.promise;
61 }
62
63 function secondSearch() {
64 let deferred = promise.defer();
65
66 gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_NOT_FOUND, () => {
67 info("Current source url:\n" + gSources.selectedValue);
68 info("Debugger editor text:\n" + gEditor.getText());
69
70 ok(isCaretPos(gPanel, 1),
71 "The editor shouldn't have jumped to a matching line yet.");
72 ok(gSources.selectedValue.contains("-02.js"),
73 "The current source shouldn't have changed after a global search.");
74 is(gSources.visibleItems.length, 2,
75 "Not all the sources are shown after the global search.");
76
77 deferred.resolve();
78 });
79
80 typeText(gSearchBox, "/");
81
82 return deferred.promise;
83 }
84
85 registerCleanupFunction(function() {
86 gTab = null;
87 gDebuggee = null;
88 gPanel = null;
89 gDebugger = null;
90 gEditor = null;
91 gSources = null;
92 gSearchView = null;
93 gSearchBox = null;
94 });

mercurial