browser/devtools/debugger/test/browser_dbg_searchbox-help-popup-02.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:4bc7f366fe3b
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Make sure that the searchbox popup isn't displayed when there's some text
6 * already present.
7 */
8
9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
10
11 let gTab, gDebuggee, gPanel, gDebugger;
12 let gEditor, gSearchBox, gSearchBoxPanel;
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 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
22 gSearchBoxPanel = gDebugger.DebuggerView.Filtering._searchboxHelpPanel;
23
24 once(gSearchBoxPanel, "popupshown").then(() => {
25 ok(false, "Damn it, this shouldn't have happened.");
26 });
27
28 waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
29 .then(tryShowPopup)
30 .then(focusEditor)
31 .then(testFocusLost)
32 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
33 .then(null, aError => {
34 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
35 });
36
37 gDebuggee.firstCall();
38 });
39 }
40
41 function tryShowPopup() {
42 setText(gSearchBox, "#call()");
43 ok(isCaretPos(gPanel, 4, 22),
44 "The editor caret position appears to be correct.");
45 ok(isEditorSel(gPanel, [125, 131]),
46 "The editor selection appears to be correct.");
47 is(gEditor.getSelection(), "Call()",
48 "The editor selected text appears to be correct.");
49
50 is(gSearchBoxPanel.state, "closed",
51 "The search box panel shouldn't be visible yet.");
52
53 EventUtils.sendMouseEvent({ type: "click" }, gSearchBox, gDebugger);
54 }
55
56 function focusEditor() {
57 let deferred = promise.defer();
58
59 // Focusing the editor takes a tick to update the caret and selection.
60 gEditor.focus();
61 executeSoon(deferred.resolve);
62
63 return deferred.promise;
64 }
65
66 function testFocusLost() {
67 ok(isCaretPos(gPanel, 1, 1),
68 "The editor caret position appears to be correct after gaining focus.");
69 ok(isEditorSel(gPanel, [1, 1]),
70 "The editor selection appears to be correct after gaining focus.");
71 is(gEditor.getSelection(), "",
72 "The editor selected text appears to be correct after gaining focus.");
73
74 is(gSearchBoxPanel.state, "closed",
75 "The search box panel should still not be visible.");
76 }
77
78 registerCleanupFunction(function() {
79 gTab = null;
80 gDebuggee = null;
81 gPanel = null;
82 gDebugger = null;
83 gEditor = null;
84 gSearchBox = null;
85 gSearchBoxPanel = null;
86 });

mercurial