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 more complex functionality of sources filtering (file search). |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_editor-mode.html"; |
michael@0 | 9 | |
michael@0 | 10 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 11 | let gSources, gSourceUtils, gSearchView, gSearchBox; |
michael@0 | 12 | |
michael@0 | 13 | function test() { |
michael@0 | 14 | // Debug test slaves are a bit slow at this test. |
michael@0 | 15 | requestLongerTimeout(3); |
michael@0 | 16 | |
michael@0 | 17 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 18 | gTab = aTab; |
michael@0 | 19 | gDebuggee = aDebuggee; |
michael@0 | 20 | gPanel = aPanel; |
michael@0 | 21 | gDebugger = gPanel.panelWin; |
michael@0 | 22 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 23 | gSourceUtils = gDebugger.SourceUtils; |
michael@0 | 24 | gSearchView = gDebugger.DebuggerView.FilteredSources; |
michael@0 | 25 | gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; |
michael@0 | 26 | |
michael@0 | 27 | waitForSourceShown(gPanel, "-01.js") |
michael@0 | 28 | .then(firstSearch) |
michael@0 | 29 | .then(secondSearch) |
michael@0 | 30 | .then(thirdSearch) |
michael@0 | 31 | .then(fourthSearch) |
michael@0 | 32 | .then(fifthSearch) |
michael@0 | 33 | .then(goDown) |
michael@0 | 34 | .then(goDownAndWrap) |
michael@0 | 35 | .then(goUpAndWrap) |
michael@0 | 36 | .then(goUp) |
michael@0 | 37 | .then(returnAndSwitch) |
michael@0 | 38 | .then(firstSearch) |
michael@0 | 39 | .then(clickAndSwitch) |
michael@0 | 40 | .then(() => closeDebuggerAndFinish(gPanel)) |
michael@0 | 41 | .then(null, aError => { |
michael@0 | 42 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 43 | }); |
michael@0 | 44 | }); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function firstSearch() { |
michael@0 | 48 | let finished = promise.all([ |
michael@0 | 49 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 50 | ensureCaretAt(gPanel, 1), |
michael@0 | 51 | once(gDebugger, "popupshown"), |
michael@0 | 52 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND) |
michael@0 | 53 | ]); |
michael@0 | 54 | |
michael@0 | 55 | setText(gSearchBox, "."); |
michael@0 | 56 | |
michael@0 | 57 | return finished.then(() => promise.all([ |
michael@0 | 58 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 59 | ensureCaretAt(gPanel, 1), |
michael@0 | 60 | verifyContents([ |
michael@0 | 61 | "code_script-switching-01.js?a=b", |
michael@0 | 62 | "code_test-editor-mode?c=d", |
michael@0 | 63 | "doc_editor-mode.html" |
michael@0 | 64 | ]) |
michael@0 | 65 | ])); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function secondSearch() { |
michael@0 | 69 | let finished = promise.all([ |
michael@0 | 70 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 71 | ensureCaretAt(gPanel, 1), |
michael@0 | 72 | once(gDebugger, "popupshown"), |
michael@0 | 73 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND) |
michael@0 | 74 | ]); |
michael@0 | 75 | |
michael@0 | 76 | typeText(gSearchBox, "-0"); |
michael@0 | 77 | |
michael@0 | 78 | return finished.then(() => promise.all([ |
michael@0 | 79 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 80 | ensureCaretAt(gPanel, 1), |
michael@0 | 81 | verifyContents(["code_script-switching-01.js?a=b"]) |
michael@0 | 82 | ])); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function thirdSearch() { |
michael@0 | 86 | let finished = promise.all([ |
michael@0 | 87 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 88 | ensureCaretAt(gPanel, 1), |
michael@0 | 89 | once(gDebugger, "popupshown"), |
michael@0 | 90 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND) |
michael@0 | 91 | ]); |
michael@0 | 92 | |
michael@0 | 93 | backspaceText(gSearchBox, 1); |
michael@0 | 94 | |
michael@0 | 95 | return finished.then(() => promise.all([ |
michael@0 | 96 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 97 | ensureCaretAt(gPanel, 1), |
michael@0 | 98 | verifyContents([ |
michael@0 | 99 | "code_script-switching-01.js?a=b", |
michael@0 | 100 | "code_test-editor-mode?c=d", |
michael@0 | 101 | "doc_editor-mode.html" |
michael@0 | 102 | ]) |
michael@0 | 103 | ])); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | function fourthSearch() { |
michael@0 | 107 | let finished = promise.all([ |
michael@0 | 108 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 109 | ensureCaretAt(gPanel, 1), |
michael@0 | 110 | once(gDebugger, "popupshown"), |
michael@0 | 111 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
michael@0 | 112 | waitForSourceShown(gPanel, "test-editor-mode") |
michael@0 | 113 | ]); |
michael@0 | 114 | |
michael@0 | 115 | setText(gSearchBox, "code_test"); |
michael@0 | 116 | |
michael@0 | 117 | return finished.then(() => promise.all([ |
michael@0 | 118 | ensureSourceIs(gPanel, "test-editor-mode"), |
michael@0 | 119 | ensureCaretAt(gPanel, 1), |
michael@0 | 120 | verifyContents(["code_test-editor-mode?c=d"]) |
michael@0 | 121 | ])); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function fifthSearch() { |
michael@0 | 125 | let finished = promise.all([ |
michael@0 | 126 | ensureSourceIs(gPanel, "test-editor-mode"), |
michael@0 | 127 | ensureCaretAt(gPanel, 1), |
michael@0 | 128 | once(gDebugger, "popupshown"), |
michael@0 | 129 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND), |
michael@0 | 130 | waitForSourceShown(gPanel, "-01.js") |
michael@0 | 131 | ]); |
michael@0 | 132 | |
michael@0 | 133 | backspaceText(gSearchBox, 4); |
michael@0 | 134 | |
michael@0 | 135 | return finished.then(() => promise.all([ |
michael@0 | 136 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 137 | ensureCaretAt(gPanel, 1), |
michael@0 | 138 | verifyContents([ |
michael@0 | 139 | "code_script-switching-01.js?a=b", |
michael@0 | 140 | "code_test-editor-mode?c=d" |
michael@0 | 141 | ]) |
michael@0 | 142 | ])); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | function goDown() { |
michael@0 | 146 | let finished = promise.all([ |
michael@0 | 147 | ensureSourceIs(gPanel, "-01.js"), |
michael@0 | 148 | ensureCaretAt(gPanel, 1), |
michael@0 | 149 | waitForSourceShown(gPanel, "test-editor-mode"), |
michael@0 | 150 | ]); |
michael@0 | 151 | |
michael@0 | 152 | EventUtils.sendKey("DOWN", gDebugger); |
michael@0 | 153 | |
michael@0 | 154 | return finished.then(() => promise.all([ |
michael@0 | 155 | ensureSourceIs(gPanel,"test-editor-mode"), |
michael@0 | 156 | ensureCaretAt(gPanel, 1), |
michael@0 | 157 | verifyContents([ |
michael@0 | 158 | "code_script-switching-01.js?a=b", |
michael@0 | 159 | "code_test-editor-mode?c=d" |
michael@0 | 160 | ]) |
michael@0 | 161 | ])); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | function goDownAndWrap() { |
michael@0 | 165 | let finished = promise.all([ |
michael@0 | 166 | ensureSourceIs(gPanel, "test-editor-mode"), |
michael@0 | 167 | ensureCaretAt(gPanel, 1), |
michael@0 | 168 | waitForSourceShown(gPanel, "-01.js") |
michael@0 | 169 | ]); |
michael@0 | 170 | |
michael@0 | 171 | EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger); |
michael@0 | 172 | |
michael@0 | 173 | return finished.then(() => promise.all([ |
michael@0 | 174 | ensureSourceIs(gPanel,"-01.js"), |
michael@0 | 175 | ensureCaretAt(gPanel, 1), |
michael@0 | 176 | verifyContents([ |
michael@0 | 177 | "code_script-switching-01.js?a=b", |
michael@0 | 178 | "code_test-editor-mode?c=d" |
michael@0 | 179 | ]) |
michael@0 | 180 | ])); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | function goUpAndWrap() { |
michael@0 | 184 | let finished = promise.all([ |
michael@0 | 185 | ensureSourceIs(gPanel,"-01.js"), |
michael@0 | 186 | ensureCaretAt(gPanel, 1), |
michael@0 | 187 | waitForSourceShown(gPanel, "test-editor-mode") |
michael@0 | 188 | ]); |
michael@0 | 189 | |
michael@0 | 190 | EventUtils.synthesizeKey("G", { metaKey: true }, gDebugger); |
michael@0 | 191 | |
michael@0 | 192 | return finished.then(() => promise.all([ |
michael@0 | 193 | ensureSourceIs(gPanel,"test-editor-mode"), |
michael@0 | 194 | ensureCaretAt(gPanel, 1), |
michael@0 | 195 | verifyContents([ |
michael@0 | 196 | "code_script-switching-01.js?a=b", |
michael@0 | 197 | "code_test-editor-mode?c=d" |
michael@0 | 198 | ]) |
michael@0 | 199 | ])); |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | function goUp() { |
michael@0 | 203 | let finished = promise.all([ |
michael@0 | 204 | ensureSourceIs(gPanel,"test-editor-mode"), |
michael@0 | 205 | ensureCaretAt(gPanel, 1), |
michael@0 | 206 | waitForSourceShown(gPanel, "-01.js"), |
michael@0 | 207 | ]); |
michael@0 | 208 | |
michael@0 | 209 | EventUtils.sendKey("UP", gDebugger); |
michael@0 | 210 | |
michael@0 | 211 | return finished.then(() => promise.all([ |
michael@0 | 212 | ensureSourceIs(gPanel,"-01.js"), |
michael@0 | 213 | ensureCaretAt(gPanel, 1), |
michael@0 | 214 | verifyContents([ |
michael@0 | 215 | "code_script-switching-01.js?a=b", |
michael@0 | 216 | "code_test-editor-mode?c=d" |
michael@0 | 217 | ]) |
michael@0 | 218 | ])); |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | function returnAndSwitch() { |
michael@0 | 222 | let finished = promise.all([ |
michael@0 | 223 | ensureSourceIs(gPanel,"-01.js"), |
michael@0 | 224 | ensureCaretAt(gPanel, 1), |
michael@0 | 225 | once(gDebugger, "popuphidden") |
michael@0 | 226 | ]); |
michael@0 | 227 | |
michael@0 | 228 | EventUtils.sendKey("RETURN", gDebugger); |
michael@0 | 229 | |
michael@0 | 230 | return finished.then(() => promise.all([ |
michael@0 | 231 | ensureSourceIs(gPanel,"-01.js"), |
michael@0 | 232 | ensureCaretAt(gPanel, 1) |
michael@0 | 233 | ])); |
michael@0 | 234 | } |
michael@0 | 235 | |
michael@0 | 236 | function clickAndSwitch() { |
michael@0 | 237 | let finished = promise.all([ |
michael@0 | 238 | ensureSourceIs(gPanel,"-01.js"), |
michael@0 | 239 | ensureCaretAt(gPanel, 1), |
michael@0 | 240 | once(gDebugger, "popuphidden"), |
michael@0 | 241 | waitForSourceShown(gPanel, "test-editor-mode") |
michael@0 | 242 | ]); |
michael@0 | 243 | |
michael@0 | 244 | EventUtils.sendMouseEvent({ type: "click" }, gSearchView.items[1].target, gDebugger); |
michael@0 | 245 | |
michael@0 | 246 | return finished.then(() => promise.all([ |
michael@0 | 247 | ensureSourceIs(gPanel,"test-editor-mode"), |
michael@0 | 248 | ensureCaretAt(gPanel, 1) |
michael@0 | 249 | ])); |
michael@0 | 250 | } |
michael@0 | 251 | |
michael@0 | 252 | function verifyContents(aMatches) { |
michael@0 | 253 | is(gSources.visibleItems.length, 3, |
michael@0 | 254 | "The unmatched sources in the widget should not be hidden."); |
michael@0 | 255 | is(gSearchView.itemCount, aMatches.length, |
michael@0 | 256 | "The filtered sources view should have the right items available."); |
michael@0 | 257 | |
michael@0 | 258 | for (let i = 0; i < gSearchView.itemCount; i++) { |
michael@0 | 259 | let trimmedLabel = gSourceUtils.trimUrlLength(gSourceUtils.trimUrlQuery(aMatches[i])); |
michael@0 | 260 | let trimmedLocation = gSourceUtils.trimUrlLength(EXAMPLE_URL + aMatches[i], 0, "start"); |
michael@0 | 261 | |
michael@0 | 262 | ok(gSearchView.widget._parent.querySelector(".results-panel-item-label[value=\"" + trimmedLabel + "\"]"), |
michael@0 | 263 | "The filtered sources view should have the correct source labels."); |
michael@0 | 264 | ok(gSearchView.widget._parent.querySelector(".results-panel-item-label-below[value=\"" + trimmedLocation + "\"]"), |
michael@0 | 265 | "The filtered sources view should have the correct source locations."); |
michael@0 | 266 | } |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | registerCleanupFunction(function() { |
michael@0 | 270 | gTab = null; |
michael@0 | 271 | gDebuggee = null; |
michael@0 | 272 | gPanel = null; |
michael@0 | 273 | gDebugger = null; |
michael@0 | 274 | gSources = null; |
michael@0 | 275 | gSourceUtils = null; |
michael@0 | 276 | gSearchView = null; |
michael@0 | 277 | gSearchBox = null; |
michael@0 | 278 | }); |