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 basic functionality of global search (lowercase + upper case, expected |
michael@0 | 6 | * UI behavior, number of results found etc.) |
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(secondSearch) |
michael@0 | 28 | .then(clearSearch) |
michael@0 | 29 | .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
michael@0 | 30 | .then(null, aError => { |
michael@0 | 31 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 32 | }); |
michael@0 | 33 | |
michael@0 | 34 | gDebuggee.firstCall(); |
michael@0 | 35 | }); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function firstSearch() { |
michael@0 | 39 | let deferred = promise.defer(); |
michael@0 | 40 | |
michael@0 | 41 | is(gSearchView.itemCount, 0, |
michael@0 | 42 | "The global search pane shouldn't have any entries yet."); |
michael@0 | 43 | is(gSearchView.widget._parent.hidden, true, |
michael@0 | 44 | "The global search pane shouldn't be visible yet."); |
michael@0 | 45 | is(gSearchView._splitter.hidden, true, |
michael@0 | 46 | "The global search pane splitter shouldn't be visible yet."); |
michael@0 | 47 | |
michael@0 | 48 | gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { |
michael@0 | 49 | // Some operations are synchronously dispatched on the main thread, |
michael@0 | 50 | // to avoid blocking UI, thus giving the impression of faster searching. |
michael@0 | 51 | executeSoon(() => { |
michael@0 | 52 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 53 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 54 | |
michael@0 | 55 | ok(isCaretPos(gPanel, 1), |
michael@0 | 56 | "The editor shouldn't have jumped to a matching line yet."); |
michael@0 | 57 | ok(gSources.selectedValue.contains("-02.js"), |
michael@0 | 58 | "The current source shouldn't have changed after a global search."); |
michael@0 | 59 | is(gSources.visibleItems.length, 2, |
michael@0 | 60 | "Not all the sources are shown after the global search."); |
michael@0 | 61 | |
michael@0 | 62 | let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
michael@0 | 63 | is(sourceResults.length, 2, |
michael@0 | 64 | "There should be matches found in two sources."); |
michael@0 | 65 | |
michael@0 | 66 | let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]); |
michael@0 | 67 | let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]); |
michael@0 | 68 | is(item0.instance.expanded, true, |
michael@0 | 69 | "The first source results should automatically be expanded.") |
michael@0 | 70 | is(item1.instance.expanded, true, |
michael@0 | 71 | "The second source results should automatically be expanded.") |
michael@0 | 72 | |
michael@0 | 73 | let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result"); |
michael@0 | 74 | let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result"); |
michael@0 | 75 | is(searchResult0.length, 1, |
michael@0 | 76 | "There should be one line result for the first url."); |
michael@0 | 77 | is(searchResult1.length, 2, |
michael@0 | 78 | "There should be two line results for the second url."); |
michael@0 | 79 | |
michael@0 | 80 | let firstLine0 = searchResult0[0]; |
michael@0 | 81 | is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1", |
michael@0 | 82 | "The first result for the first source doesn't have the correct line attached."); |
michael@0 | 83 | |
michael@0 | 84 | is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1, |
michael@0 | 85 | "The first result for the first source doesn't have the correct number of nodes for a line."); |
michael@0 | 86 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 3, |
michael@0 | 87 | "The first result for the first source doesn't have the correct number of strings in a line."); |
michael@0 | 88 | |
michael@0 | 89 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1, |
michael@0 | 90 | "The first result for the first source doesn't have the correct number of matches in a line."); |
michael@0 | 91 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de", |
michael@0 | 92 | "The first result for the first source doesn't have the correct match in a line."); |
michael@0 | 93 | |
michael@0 | 94 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2, |
michael@0 | 95 | "The first result for the first source doesn't have the correct number of non-matches in a line."); |
michael@0 | 96 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ", |
michael@0 | 97 | "The first result for the first source doesn't have the correct non-matches in a line."); |
michael@0 | 98 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.", |
michael@0 | 99 | "The first result for the first source doesn't have the correct non-matches in a line."); |
michael@0 | 100 | |
michael@0 | 101 | let firstLine1 = searchResult1[0]; |
michael@0 | 102 | is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1", |
michael@0 | 103 | "The first result for the second source doesn't have the correct line attached."); |
michael@0 | 104 | |
michael@0 | 105 | is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1, |
michael@0 | 106 | "The first result for the second source doesn't have the correct number of nodes for a line."); |
michael@0 | 107 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3, |
michael@0 | 108 | "The first result for the second source doesn't have the correct number of strings in a line."); |
michael@0 | 109 | |
michael@0 | 110 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1, |
michael@0 | 111 | "The first result for the second source doesn't have the correct number of matches in a line."); |
michael@0 | 112 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de", |
michael@0 | 113 | "The first result for the second source doesn't have the correct match in a line."); |
michael@0 | 114 | |
michael@0 | 115 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2, |
michael@0 | 116 | "The first result for the second source doesn't have the correct number of non-matches in a line."); |
michael@0 | 117 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ", |
michael@0 | 118 | "The first result for the second source doesn't have the correct non-matches in a line."); |
michael@0 | 119 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.", |
michael@0 | 120 | "The first result for the second source doesn't have the correct non-matches in a line."); |
michael@0 | 121 | |
michael@0 | 122 | let secondLine1 = searchResult1[1]; |
michael@0 | 123 | is(secondLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "6", |
michael@0 | 124 | "The second result for the second source doesn't have the correct line attached."); |
michael@0 | 125 | |
michael@0 | 126 | is(secondLine1.querySelectorAll(".dbg-results-line-contents").length, 1, |
michael@0 | 127 | "The second result for the second source doesn't have the correct number of nodes for a line."); |
michael@0 | 128 | is(secondLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3, |
michael@0 | 129 | "The second result for the second source doesn't have the correct number of strings in a line."); |
michael@0 | 130 | |
michael@0 | 131 | is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1, |
michael@0 | 132 | "The second result for the second source doesn't have the correct number of matches in a line."); |
michael@0 | 133 | is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de", |
michael@0 | 134 | "The second result for the second source doesn't have the correct match in a line."); |
michael@0 | 135 | |
michael@0 | 136 | is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2, |
michael@0 | 137 | "The second result for the second source doesn't have the correct number of non-matches in a line."); |
michael@0 | 138 | is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), ' eval("', |
michael@0 | 139 | "The second result for the second source doesn't have the correct non-matches in a line."); |
michael@0 | 140 | is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), 'bugger;");', |
michael@0 | 141 | "The second result for the second source doesn't have the correct non-matches in a line."); |
michael@0 | 142 | |
michael@0 | 143 | deferred.resolve(); |
michael@0 | 144 | }); |
michael@0 | 145 | }); |
michael@0 | 146 | |
michael@0 | 147 | setText(gSearchBox, "!de"); |
michael@0 | 148 | |
michael@0 | 149 | return deferred.promise; |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | function secondSearch() { |
michael@0 | 153 | let deferred = promise.defer(); |
michael@0 | 154 | |
michael@0 | 155 | is(gSearchView.itemCount, 2, |
michael@0 | 156 | "The global search pane should have some child nodes from the previous search."); |
michael@0 | 157 | is(gSearchView.widget._parent.hidden, false, |
michael@0 | 158 | "The global search pane should be visible from the previous search."); |
michael@0 | 159 | is(gSearchView._splitter.hidden, false, |
michael@0 | 160 | "The global search pane splitter should be visible from the previous search."); |
michael@0 | 161 | |
michael@0 | 162 | gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { |
michael@0 | 163 | // Some operations are synchronously dispatched on the main thread, |
michael@0 | 164 | // to avoid blocking UI, thus giving the impression of faster searching. |
michael@0 | 165 | executeSoon(() => { |
michael@0 | 166 | info("Current source url:\n" + gSources.selectedValue); |
michael@0 | 167 | info("Debugger editor text:\n" + gEditor.getText()); |
michael@0 | 168 | |
michael@0 | 169 | ok(isCaretPos(gPanel, 1), |
michael@0 | 170 | "The editor shouldn't have jumped to a matching line yet."); |
michael@0 | 171 | ok(gSources.selectedValue.contains("-02.js"), |
michael@0 | 172 | "The current source shouldn't have changed after a global search."); |
michael@0 | 173 | is(gSources.visibleItems.length, 2, |
michael@0 | 174 | "Not all the sources are shown after the global search."); |
michael@0 | 175 | |
michael@0 | 176 | let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); |
michael@0 | 177 | is(sourceResults.length, 2, |
michael@0 | 178 | "There should be matches found in two sources."); |
michael@0 | 179 | |
michael@0 | 180 | let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]); |
michael@0 | 181 | let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]); |
michael@0 | 182 | is(item0.instance.expanded, true, |
michael@0 | 183 | "The first source results should automatically be expanded.") |
michael@0 | 184 | is(item1.instance.expanded, true, |
michael@0 | 185 | "The second source results should automatically be expanded.") |
michael@0 | 186 | |
michael@0 | 187 | let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result"); |
michael@0 | 188 | let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result"); |
michael@0 | 189 | is(searchResult0.length, 1, |
michael@0 | 190 | "There should be one line result for the first url."); |
michael@0 | 191 | is(searchResult1.length, 1, |
michael@0 | 192 | "There should be one line result for the second url."); |
michael@0 | 193 | |
michael@0 | 194 | let firstLine0 = searchResult0[0]; |
michael@0 | 195 | is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1", |
michael@0 | 196 | "The first result for the first source doesn't have the correct line attached."); |
michael@0 | 197 | |
michael@0 | 198 | is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1, |
michael@0 | 199 | "The first result for the first source doesn't have the correct number of nodes for a line."); |
michael@0 | 200 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 5, |
michael@0 | 201 | "The first result for the first source doesn't have the correct number of strings in a line."); |
michael@0 | 202 | |
michael@0 | 203 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2, |
michael@0 | 204 | "The first result for the first source doesn't have the correct number of matches in a line."); |
michael@0 | 205 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed", |
michael@0 | 206 | "The first result for the first source doesn't have the correct matches in a line."); |
michael@0 | 207 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed", |
michael@0 | 208 | "The first result for the first source doesn't have the correct matches in a line."); |
michael@0 | 209 | |
michael@0 | 210 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3, |
michael@0 | 211 | "The first result for the first source doesn't have the correct number of non-matches in a line."); |
michael@0 | 212 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d", |
michael@0 | 213 | "The first result for the first source doesn't have the correct non-matches in a line."); |
michael@0 | 214 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat", |
michael@0 | 215 | "The first result for the first source doesn't have the correct non-matches in a line."); |
michael@0 | 216 | is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.", |
michael@0 | 217 | "The first result for the first source doesn't have the correct non-matches in a line."); |
michael@0 | 218 | |
michael@0 | 219 | let firstLine1 = searchResult1[0]; |
michael@0 | 220 | is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1", |
michael@0 | 221 | "The first result for the second source doesn't have the correct line attached."); |
michael@0 | 222 | |
michael@0 | 223 | is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1, |
michael@0 | 224 | "The first result for the second source doesn't have the correct number of nodes for a line."); |
michael@0 | 225 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 5, |
michael@0 | 226 | "The first result for the second source doesn't have the correct number of strings in a line."); |
michael@0 | 227 | |
michael@0 | 228 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2, |
michael@0 | 229 | "The first result for the second source doesn't have the correct number of matches in a line."); |
michael@0 | 230 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed", |
michael@0 | 231 | "The first result for the second source doesn't have the correct matches in a line."); |
michael@0 | 232 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed", |
michael@0 | 233 | "The first result for the second source doesn't have the correct matches in a line."); |
michael@0 | 234 | |
michael@0 | 235 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3, |
michael@0 | 236 | "The first result for the second source doesn't have the correct number of non-matches in a line."); |
michael@0 | 237 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d", |
michael@0 | 238 | "The first result for the second source doesn't have the correct non-matches in a line."); |
michael@0 | 239 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat", |
michael@0 | 240 | "The first result for the second source doesn't have the correct non-matches in a line."); |
michael@0 | 241 | is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.", |
michael@0 | 242 | "The first result for the second source doesn't have the correct non-matches in a line."); |
michael@0 | 243 | |
michael@0 | 244 | deferred.resolve(); |
michael@0 | 245 | }); |
michael@0 | 246 | }); |
michael@0 | 247 | |
michael@0 | 248 | backspaceText(gSearchBox, 2); |
michael@0 | 249 | typeText(gSearchBox, "ED"); |
michael@0 | 250 | |
michael@0 | 251 | return deferred.promise; |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | function clearSearch() { |
michael@0 | 255 | gSearchView.clearView(); |
michael@0 | 256 | |
michael@0 | 257 | is(gSearchView.itemCount, 0, |
michael@0 | 258 | "The global search pane shouldn't have any child nodes after clearing."); |
michael@0 | 259 | is(gSearchView.widget._parent.hidden, true, |
michael@0 | 260 | "The global search pane shouldn't be visible after clearing."); |
michael@0 | 261 | is(gSearchView._splitter.hidden, true, |
michael@0 | 262 | "The global search pane splitter shouldn't be visible after clearing."); |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | registerCleanupFunction(function() { |
michael@0 | 266 | gTab = null; |
michael@0 | 267 | gDebuggee = null; |
michael@0 | 268 | gPanel = null; |
michael@0 | 269 | gDebugger = null; |
michael@0 | 270 | gEditor = null; |
michael@0 | 271 | gSources = null; |
michael@0 | 272 | gSearchView = null; |
michael@0 | 273 | gSearchBox = null; |
michael@0 | 274 | }); |