Wed, 31 Dec 2014 06:09:35 +0100
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 | * Tests if the global search results switch back and forth, and wrap around |
michael@0 | 6 | * when switching between them. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
michael@0 | 10 | |
michael@0 | 11 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 12 | let gEditor, gSources, gSearchView, gSearchBox; |
michael@0 | 13 | |
michael@0 | 14 | function test() { |
michael@0 | 15 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 16 | gTab = aTab; |
michael@0 | 17 | gDebuggee = aDebuggee; |
michael@0 | 18 | gPanel = aPanel; |
michael@0 | 19 | gDebugger = gPanel.panelWin; |
michael@0 | 20 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 21 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 22 | gSearchView = gDebugger.DebuggerView.GlobalSearch; |
michael@0 | 23 | gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; |
michael@0 | 24 | |
michael@0 | 25 | waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) |
michael@0 | 26 | .then(firstSearch) |
michael@0 | 27 | .then(doFirstJump) |
michael@0 | 28 | .then(doSecondJump) |
michael@0 | 29 | .then(doWrapAroundJump) |
michael@0 | 30 | .then(doBackwardsWrapAroundJump) |
michael@0 | 31 | .then(testSearchTokenEmpty) |
michael@0 | 32 | .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
michael@0 | 33 | .then(null, aError => { |
michael@0 | 34 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 35 | }); |
michael@0 | 36 | |
michael@0 | 37 | gDebuggee.firstCall(); |
michael@0 | 38 | }); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function firstSearch() { |
michael@0 | 42 | let deferred = promise.defer(); |
michael@0 | 43 | |
michael@0 | 44 | is(gSearchView.itemCount, 0, |
michael@0 | 45 | "The global search pane shouldn't have any entries yet."); |
michael@0 | 46 | is(gSearchView.widget._parent.hidden, true, |
michael@0 | 47 | "The global search pane shouldn't be visible yet."); |
michael@0 | 48 | is(gSearchView._splitter.hidden, true, |
michael@0 | 49 | "The global search pane splitter shouldn't be visible yet."); |
michael@0 | 50 | |
michael@0 | 51 | gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { |
michael@0 | 52 | // Some operations are synchronously dispatched on the main thread, |
michael@0 | 53 | // to avoid blocking UI, thus giving the impression of faster searching. |
michael@0 | 54 | executeSoon(() => { |
michael@0 | 55 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 56 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 57 | |
michael@0 | 58 | ok(isCaretPos(gPanel, 1), |
michael@0 | 59 | "The editor shouldn't have jumped to a matching line yet."); |
michael@0 | 60 | ok(gSources.selectedValue.contains("-02.js"), |
michael@0 | 61 | "The current source shouldn't have changed after a global search."); |
michael@0 | 62 | is(gSources.visibleItems.length, 2, |
michael@0 | 63 | "Not all the sources are shown after the global search."); |
michael@0 | 64 | |
michael@0 | 65 | deferred.resolve(); |
michael@0 | 66 | }); |
michael@0 | 67 | }); |
michael@0 | 68 | |
michael@0 | 69 | setText(gSearchBox, "!eval"); |
michael@0 | 70 | |
michael@0 | 71 | return deferred.promise; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function doFirstJump() { |
michael@0 | 75 | let deferred = promise.defer(); |
michael@0 | 76 | |
michael@0 | 77 | waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => { |
michael@0 | 78 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 79 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 80 | |
michael@0 | 81 | ok(gSources.selectedValue.contains("-01.js"), |
michael@0 | 82 | "The currently shown source is incorrect (1)."); |
michael@0 | 83 | is(gSources.visibleItems.length, 2, |
michael@0 | 84 | "Not all the sources are shown after the global search (1)."); |
michael@0 | 85 | |
michael@0 | 86 | // The editor's selected text takes a tick to update. |
michael@0 | 87 | executeSoon(() => { |
michael@0 | 88 | ok(isCaretPos(gPanel, 5, 7), |
michael@0 | 89 | "The editor didn't jump to the correct line (1)."); |
michael@0 | 90 | is(gEditor.getSelection(), "eval", |
michael@0 | 91 | "The editor didn't select the correct text (1)."); |
michael@0 | 92 | |
michael@0 | 93 | deferred.resolve(); |
michael@0 | 94 | }); |
michael@0 | 95 | }); |
michael@0 | 96 | |
michael@0 | 97 | EventUtils.sendKey("DOWN", gDebugger); |
michael@0 | 98 | |
michael@0 | 99 | return deferred.promise; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function doSecondJump() { |
michael@0 | 103 | let deferred = promise.defer(); |
michael@0 | 104 | |
michael@0 | 105 | waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => { |
michael@0 | 106 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 107 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 108 | |
michael@0 | 109 | ok(gSources.selectedValue.contains("-02.js"), |
michael@0 | 110 | "The currently shown source is incorrect (2)."); |
michael@0 | 111 | is(gSources.visibleItems.length, 2, |
michael@0 | 112 | "Not all the sources are shown after the global search (2)."); |
michael@0 | 113 | |
michael@0 | 114 | // The editor's selected text takes a tick to update. |
michael@0 | 115 | executeSoon(() => { |
michael@0 | 116 | ok(isCaretPos(gPanel, 6, 7), |
michael@0 | 117 | "The editor didn't jump to the correct line (2)."); |
michael@0 | 118 | is(gEditor.getSelection(), "eval", |
michael@0 | 119 | "The editor didn't select the correct text (2)."); |
michael@0 | 120 | |
michael@0 | 121 | deferred.resolve(); |
michael@0 | 122 | }); |
michael@0 | 123 | }); |
michael@0 | 124 | |
michael@0 | 125 | EventUtils.sendKey("DOWN", gDebugger); |
michael@0 | 126 | |
michael@0 | 127 | return deferred.promise; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | function doWrapAroundJump() { |
michael@0 | 131 | let deferred = promise.defer(); |
michael@0 | 132 | |
michael@0 | 133 | waitForSourceAndCaret(gPanel, "-01.js", 1).then(() => { |
michael@0 | 134 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 135 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 136 | |
michael@0 | 137 | ok(gSources.selectedValue.contains("-01.js"), |
michael@0 | 138 | "The currently shown source is incorrect (3)."); |
michael@0 | 139 | is(gSources.visibleItems.length, 2, |
michael@0 | 140 | "Not all the sources are shown after the global search (3)."); |
michael@0 | 141 | |
michael@0 | 142 | // The editor's selected text takes a tick to update. |
michael@0 | 143 | executeSoon(() => { |
michael@0 | 144 | ok(isCaretPos(gPanel, 5, 7), |
michael@0 | 145 | "The editor didn't jump to the correct line (3)."); |
michael@0 | 146 | is(gEditor.getSelection(), "eval", |
michael@0 | 147 | "The editor didn't select the correct text (3)."); |
michael@0 | 148 | |
michael@0 | 149 | deferred.resolve(); |
michael@0 | 150 | }); |
michael@0 | 151 | }); |
michael@0 | 152 | |
michael@0 | 153 | EventUtils.sendKey("DOWN", gDebugger); |
michael@0 | 154 | |
michael@0 | 155 | return deferred.promise; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | function doBackwardsWrapAroundJump() { |
michael@0 | 159 | let deferred = promise.defer(); |
michael@0 | 160 | |
michael@0 | 161 | waitForSourceAndCaret(gPanel, "-02.js", 1).then(() => { |
michael@0 | 162 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 163 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 164 | |
michael@0 | 165 | ok(gSources.selectedValue.contains("-02.js"), |
michael@0 | 166 | "The currently shown source is incorrect (4)."); |
michael@0 | 167 | is(gSources.visibleItems.length, 2, |
michael@0 | 168 | "Not all the sources are shown after the global search (4)."); |
michael@0 | 169 | |
michael@0 | 170 | // The editor's selected text takes a tick to update. |
michael@0 | 171 | executeSoon(() => { |
michael@0 | 172 | ok(isCaretPos(gPanel, 6, 7), |
michael@0 | 173 | "The editor didn't jump to the correct line (4)."); |
michael@0 | 174 | is(gEditor.getSelection(), "eval", |
michael@0 | 175 | "The editor didn't select the correct text (4)."); |
michael@0 | 176 | |
michael@0 | 177 | deferred.resolve(); |
michael@0 | 178 | }); |
michael@0 | 179 | }); |
michael@0 | 180 | |
michael@0 | 181 | EventUtils.sendKey("UP", gDebugger); |
michael@0 | 182 | |
michael@0 | 183 | return deferred.promise; |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | function testSearchTokenEmpty() { |
michael@0 | 187 | backspaceText(gSearchBox, 4); |
michael@0 | 188 | |
michael@0 | 189 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 190 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 191 | |
michael@0 | 192 | ok(gSources.selectedValue.contains("-02.js"), |
michael@0 | 193 | "The currently shown source is incorrect (4)."); |
michael@0 | 194 | is(gSources.visibleItems.length, 2, |
michael@0 | 195 | "Not all the sources are shown after the global search (4)."); |
michael@0 | 196 | ok(isCaretPos(gPanel, 6, 7), |
michael@0 | 197 | "The editor didn't remain at the correct line (4)."); |
michael@0 | 198 | is(gEditor.getSelection(), "", |
michael@0 | 199 | "The editor shouldn't keep the previous text selected (4)."); |
michael@0 | 200 | |
michael@0 | 201 | is(gSearchView.itemCount, 0, |
michael@0 | 202 | "The global search pane shouldn't have any child nodes after clearing."); |
michael@0 | 203 | is(gSearchView.widget._parent.hidden, true, |
michael@0 | 204 | "The global search pane shouldn't be visible after clearing."); |
michael@0 | 205 | is(gSearchView._splitter.hidden, true, |
michael@0 | 206 | "The global search pane splitter shouldn't be visible after clearing."); |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | registerCleanupFunction(function() { |
michael@0 | 210 | gTab = null; |
michael@0 | 211 | gDebuggee = null; |
michael@0 | 212 | gPanel = null; |
michael@0 | 213 | gDebugger = null; |
michael@0 | 214 | gEditor = null; |
michael@0 | 215 | gSources = null; |
michael@0 | 216 | gSearchView = null; |
michael@0 | 217 | gSearchBox = null; |
michael@0 | 218 | }); |