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 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | const TEST_URI = "data:text/html;charset=utf-8,<p>bug 585991 - autocomplete popup keyboard usage test"; |
michael@0 | 7 | let HUD, popup, jsterm, inputNode, completeNode; |
michael@0 | 8 | |
michael@0 | 9 | function test() { |
michael@0 | 10 | addTab(TEST_URI); |
michael@0 | 11 | browser.addEventListener("load", function onLoad() { |
michael@0 | 12 | browser.removeEventListener("load", onLoad, true); |
michael@0 | 13 | openConsole(null, consoleOpened); |
michael@0 | 14 | }, true); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function consoleOpened(aHud) { |
michael@0 | 18 | HUD = aHud; |
michael@0 | 19 | info("web console opened"); |
michael@0 | 20 | |
michael@0 | 21 | jsterm = HUD.jsterm; |
michael@0 | 22 | |
michael@0 | 23 | jsterm.execute("window.foobarBug585991={" + |
michael@0 | 24 | "'item0': 'value0'," + |
michael@0 | 25 | "'item1': 'value1'," + |
michael@0 | 26 | "'item2': 'value2'," + |
michael@0 | 27 | "'item3': 'value3'" + |
michael@0 | 28 | "}"); |
michael@0 | 29 | popup = jsterm.autocompletePopup; |
michael@0 | 30 | completeNode = jsterm.completeNode; |
michael@0 | 31 | inputNode = jsterm.inputNode; |
michael@0 | 32 | |
michael@0 | 33 | ok(!popup.isOpen, "popup is not open"); |
michael@0 | 34 | |
michael@0 | 35 | popup._panel.addEventListener("popupshown", function onShown() { |
michael@0 | 36 | popup._panel.removeEventListener("popupshown", onShown, false); |
michael@0 | 37 | |
michael@0 | 38 | ok(popup.isOpen, "popup is open"); |
michael@0 | 39 | |
michael@0 | 40 | // 4 values, and the following properties: |
michael@0 | 41 | // __defineGetter__ __defineSetter__ __lookupGetter__ __lookupSetter__ |
michael@0 | 42 | // hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString |
michael@0 | 43 | // toSource unwatch valueOf watch constructor. |
michael@0 | 44 | is(popup.itemCount, 18, "popup.itemCount is correct"); |
michael@0 | 45 | |
michael@0 | 46 | let sameItems = popup.getItems().reverse().map(function(e) {return e.label;}); |
michael@0 | 47 | ok(sameItems.every(function(prop, index) { |
michael@0 | 48 | return [ |
michael@0 | 49 | "__defineGetter__", |
michael@0 | 50 | "__defineSetter__", |
michael@0 | 51 | "__lookupGetter__", |
michael@0 | 52 | "__lookupSetter__", |
michael@0 | 53 | "constructor", |
michael@0 | 54 | "hasOwnProperty", |
michael@0 | 55 | "isPrototypeOf", |
michael@0 | 56 | "item0", |
michael@0 | 57 | "item1", |
michael@0 | 58 | "item2", |
michael@0 | 59 | "item3", |
michael@0 | 60 | "propertyIsEnumerable", |
michael@0 | 61 | "toLocaleString", |
michael@0 | 62 | "toSource", |
michael@0 | 63 | "toString", |
michael@0 | 64 | "unwatch", |
michael@0 | 65 | "valueOf", |
michael@0 | 66 | "watch", |
michael@0 | 67 | ][index] === prop}), "getItems returns the items we expect"); |
michael@0 | 68 | |
michael@0 | 69 | is(popup.selectedIndex, 17, |
michael@0 | 70 | "Index of the first item from bottom is selected."); |
michael@0 | 71 | EventUtils.synthesizeKey("VK_DOWN", {}); |
michael@0 | 72 | |
michael@0 | 73 | let prefix = jsterm.inputNode.value.replace(/[\S]/g, " "); |
michael@0 | 74 | |
michael@0 | 75 | is(popup.selectedIndex, 0, "index 0 is selected"); |
michael@0 | 76 | is(popup.selectedItem.label, "watch", "watch is selected"); |
michael@0 | 77 | is(completeNode.value, prefix + "watch", |
michael@0 | 78 | "completeNode.value holds watch"); |
michael@0 | 79 | |
michael@0 | 80 | EventUtils.synthesizeKey("VK_DOWN", {}); |
michael@0 | 81 | |
michael@0 | 82 | is(popup.selectedIndex, 1, "index 1 is selected"); |
michael@0 | 83 | is(popup.selectedItem.label, "valueOf", "valueOf is selected"); |
michael@0 | 84 | is(completeNode.value, prefix + "valueOf", |
michael@0 | 85 | "completeNode.value holds valueOf"); |
michael@0 | 86 | |
michael@0 | 87 | EventUtils.synthesizeKey("VK_UP", {}); |
michael@0 | 88 | |
michael@0 | 89 | is(popup.selectedIndex, 0, "index 0 is selected"); |
michael@0 | 90 | is(popup.selectedItem.label, "watch", "watch is selected"); |
michael@0 | 91 | is(completeNode.value, prefix + "watch", |
michael@0 | 92 | "completeNode.value holds watch"); |
michael@0 | 93 | |
michael@0 | 94 | let currentSelectionIndex = popup.selectedIndex; |
michael@0 | 95 | |
michael@0 | 96 | EventUtils.synthesizeKey("VK_PAGE_DOWN", {}); |
michael@0 | 97 | |
michael@0 | 98 | ok(popup.selectedIndex > currentSelectionIndex, |
michael@0 | 99 | "Index is greater after PGDN"); |
michael@0 | 100 | |
michael@0 | 101 | currentSelectionIndex = popup.selectedIndex; |
michael@0 | 102 | EventUtils.synthesizeKey("VK_PAGE_UP", {}); |
michael@0 | 103 | |
michael@0 | 104 | ok(popup.selectedIndex < currentSelectionIndex, "Index is less after Page UP"); |
michael@0 | 105 | |
michael@0 | 106 | info("press Tab and wait for popup to hide"); |
michael@0 | 107 | popup._panel.addEventListener("popuphidden", popupHideAfterTab, false); |
michael@0 | 108 | EventUtils.synthesizeKey("VK_TAB", {}); |
michael@0 | 109 | }, false); |
michael@0 | 110 | |
michael@0 | 111 | info("wait for completion: window.foobarBug585991."); |
michael@0 | 112 | jsterm.setInputValue("window.foobarBug585991"); |
michael@0 | 113 | EventUtils.synthesizeKey(".", {}); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function popupHideAfterTab() |
michael@0 | 117 | { |
michael@0 | 118 | // At this point the completion suggestion should be accepted. |
michael@0 | 119 | popup._panel.removeEventListener("popuphidden", popupHideAfterTab, false); |
michael@0 | 120 | |
michael@0 | 121 | ok(!popup.isOpen, "popup is not open"); |
michael@0 | 122 | |
michael@0 | 123 | is(inputNode.value, "window.foobarBug585991.watch", |
michael@0 | 124 | "completion was successful after VK_TAB"); |
michael@0 | 125 | |
michael@0 | 126 | ok(!completeNode.value, "completeNode is empty"); |
michael@0 | 127 | |
michael@0 | 128 | popup._panel.addEventListener("popupshown", function onShown() { |
michael@0 | 129 | popup._panel.removeEventListener("popupshown", onShown, false); |
michael@0 | 130 | |
michael@0 | 131 | ok(popup.isOpen, "popup is open"); |
michael@0 | 132 | |
michael@0 | 133 | is(popup.itemCount, 18, "popup.itemCount is correct"); |
michael@0 | 134 | |
michael@0 | 135 | is(popup.selectedIndex, 17, "First index from bottom is selected"); |
michael@0 | 136 | EventUtils.synthesizeKey("VK_DOWN", {}); |
michael@0 | 137 | |
michael@0 | 138 | let prefix = jsterm.inputNode.value.replace(/[\S]/g, " "); |
michael@0 | 139 | |
michael@0 | 140 | is(popup.selectedIndex, 0, "index 0 is selected"); |
michael@0 | 141 | is(popup.selectedItem.label, "watch", "watch is selected"); |
michael@0 | 142 | is(completeNode.value, prefix + "watch", |
michael@0 | 143 | "completeNode.value holds watch"); |
michael@0 | 144 | |
michael@0 | 145 | popup._panel.addEventListener("popuphidden", function onHidden() { |
michael@0 | 146 | popup._panel.removeEventListener("popuphidden", onHidden, false); |
michael@0 | 147 | |
michael@0 | 148 | ok(!popup.isOpen, "popup is not open after VK_ESCAPE"); |
michael@0 | 149 | |
michael@0 | 150 | is(inputNode.value, "window.foobarBug585991.", |
michael@0 | 151 | "completion was cancelled"); |
michael@0 | 152 | |
michael@0 | 153 | ok(!completeNode.value, "completeNode is empty"); |
michael@0 | 154 | |
michael@0 | 155 | executeSoon(testReturnKey); |
michael@0 | 156 | }, false); |
michael@0 | 157 | |
michael@0 | 158 | info("press Escape to close the popup"); |
michael@0 | 159 | executeSoon(function() { |
michael@0 | 160 | EventUtils.synthesizeKey("VK_ESCAPE", {}); |
michael@0 | 161 | }); |
michael@0 | 162 | }, false); |
michael@0 | 163 | |
michael@0 | 164 | info("wait for completion: window.foobarBug585991."); |
michael@0 | 165 | executeSoon(function() { |
michael@0 | 166 | jsterm.setInputValue("window.foobarBug585991"); |
michael@0 | 167 | EventUtils.synthesizeKey(".", {}); |
michael@0 | 168 | }); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | function testReturnKey() |
michael@0 | 172 | { |
michael@0 | 173 | popup._panel.addEventListener("popupshown", function onShown() { |
michael@0 | 174 | popup._panel.removeEventListener("popupshown", onShown, false); |
michael@0 | 175 | |
michael@0 | 176 | ok(popup.isOpen, "popup is open"); |
michael@0 | 177 | |
michael@0 | 178 | is(popup.itemCount, 18, "popup.itemCount is correct"); |
michael@0 | 179 | |
michael@0 | 180 | is(popup.selectedIndex, 17, "First index from bottom is selected"); |
michael@0 | 181 | EventUtils.synthesizeKey("VK_DOWN", {}); |
michael@0 | 182 | |
michael@0 | 183 | let prefix = jsterm.inputNode.value.replace(/[\S]/g, " "); |
michael@0 | 184 | |
michael@0 | 185 | is(popup.selectedIndex, 0, "index 0 is selected"); |
michael@0 | 186 | is(popup.selectedItem.label, "watch", "watch is selected"); |
michael@0 | 187 | is(completeNode.value, prefix + "watch", |
michael@0 | 188 | "completeNode.value holds watch"); |
michael@0 | 189 | |
michael@0 | 190 | EventUtils.synthesizeKey("VK_DOWN", {}); |
michael@0 | 191 | |
michael@0 | 192 | is(popup.selectedIndex, 1, "index 1 is selected"); |
michael@0 | 193 | is(popup.selectedItem.label, "valueOf", "valueOf is selected"); |
michael@0 | 194 | is(completeNode.value, prefix + "valueOf", |
michael@0 | 195 | "completeNode.value holds valueOf"); |
michael@0 | 196 | |
michael@0 | 197 | popup._panel.addEventListener("popuphidden", function onHidden() { |
michael@0 | 198 | popup._panel.removeEventListener("popuphidden", onHidden, false); |
michael@0 | 199 | |
michael@0 | 200 | ok(!popup.isOpen, "popup is not open after VK_RETURN"); |
michael@0 | 201 | |
michael@0 | 202 | is(inputNode.value, "window.foobarBug585991.valueOf", |
michael@0 | 203 | "completion was successful after VK_RETURN"); |
michael@0 | 204 | |
michael@0 | 205 | ok(!completeNode.value, "completeNode is empty"); |
michael@0 | 206 | |
michael@0 | 207 | dontShowArrayNumbers(); |
michael@0 | 208 | }, false); |
michael@0 | 209 | |
michael@0 | 210 | info("press Return to accept suggestion. wait for popup to hide"); |
michael@0 | 211 | |
michael@0 | 212 | executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {})); |
michael@0 | 213 | }, false); |
michael@0 | 214 | |
michael@0 | 215 | info("wait for completion suggestions: window.foobarBug585991."); |
michael@0 | 216 | |
michael@0 | 217 | executeSoon(function() { |
michael@0 | 218 | jsterm.setInputValue("window.foobarBug58599"); |
michael@0 | 219 | EventUtils.synthesizeKey("1", {}); |
michael@0 | 220 | EventUtils.synthesizeKey(".", {}); |
michael@0 | 221 | }); |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | function dontShowArrayNumbers() |
michael@0 | 225 | { |
michael@0 | 226 | info("dontShowArrayNumbers"); |
michael@0 | 227 | content.wrappedJSObject.foobarBug585991 = ["Sherlock Holmes"]; |
michael@0 | 228 | |
michael@0 | 229 | let jsterm = HUD.jsterm; |
michael@0 | 230 | let popup = jsterm.autocompletePopup; |
michael@0 | 231 | let completeNode = jsterm.completeNode; |
michael@0 | 232 | |
michael@0 | 233 | popup._panel.addEventListener("popupshown", function onShown() { |
michael@0 | 234 | popup._panel.removeEventListener("popupshown", onShown, false); |
michael@0 | 235 | |
michael@0 | 236 | let sameItems = popup.getItems().map(function(e) {return e.label;}); |
michael@0 | 237 | ok(!sameItems.some(function(prop, index) { prop === "0"; }), |
michael@0 | 238 | "Completing on an array doesn't show numbers."); |
michael@0 | 239 | |
michael@0 | 240 | popup._panel.addEventListener("popuphidden", testReturnWithNoSelection, false); |
michael@0 | 241 | |
michael@0 | 242 | info("wait for popup to hide"); |
michael@0 | 243 | executeSoon(() => EventUtils.synthesizeKey("VK_ESCAPE", {})); |
michael@0 | 244 | }, false); |
michael@0 | 245 | |
michael@0 | 246 | info("wait for popup to show"); |
michael@0 | 247 | executeSoon(() => { |
michael@0 | 248 | jsterm.setInputValue("window.foobarBug585991"); |
michael@0 | 249 | EventUtils.synthesizeKey(".", {}); |
michael@0 | 250 | }); |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | function testReturnWithNoSelection() |
michael@0 | 254 | { |
michael@0 | 255 | popup._panel.removeEventListener("popuphidden", testReturnWithNoSelection, false); |
michael@0 | 256 | |
michael@0 | 257 | info("test pressing return with open popup, but no selection, see bug 873250"); |
michael@0 | 258 | content.wrappedJSObject.testBug873250a = "hello world"; |
michael@0 | 259 | content.wrappedJSObject.testBug873250b = "hello world 2"; |
michael@0 | 260 | |
michael@0 | 261 | popup._panel.addEventListener("popupshown", function onShown() { |
michael@0 | 262 | popup._panel.removeEventListener("popupshown", onShown); |
michael@0 | 263 | |
michael@0 | 264 | ok(popup.isOpen, "popup is open"); |
michael@0 | 265 | is(popup.itemCount, 2, "popup.itemCount is correct"); |
michael@0 | 266 | isnot(popup.selectedIndex, -1, "popup.selectedIndex is correct"); |
michael@0 | 267 | |
michael@0 | 268 | info("press Return and wait for popup to hide"); |
michael@0 | 269 | popup._panel.addEventListener("popuphidden", popupHideAfterReturnWithNoSelection); |
michael@0 | 270 | executeSoon(() => EventUtils.synthesizeKey("VK_RETURN", {})); |
michael@0 | 271 | }); |
michael@0 | 272 | |
michael@0 | 273 | executeSoon(() => { |
michael@0 | 274 | info("wait for popup to show"); |
michael@0 | 275 | jsterm.setInputValue("window.testBu"); |
michael@0 | 276 | EventUtils.synthesizeKey("g", {}); |
michael@0 | 277 | }); |
michael@0 | 278 | } |
michael@0 | 279 | |
michael@0 | 280 | function popupHideAfterReturnWithNoSelection() |
michael@0 | 281 | { |
michael@0 | 282 | popup._panel.removeEventListener("popuphidden", popupHideAfterReturnWithNoSelection); |
michael@0 | 283 | |
michael@0 | 284 | ok(!popup.isOpen, "popup is not open after VK_RETURN"); |
michael@0 | 285 | |
michael@0 | 286 | is(inputNode.value, "", "inputNode is empty after VK_RETURN"); |
michael@0 | 287 | is(completeNode.value, "", "completeNode is empty"); |
michael@0 | 288 | is(jsterm.history[jsterm.history.length-1], "window.testBug", |
michael@0 | 289 | "jsterm history is correct"); |
michael@0 | 290 | |
michael@0 | 291 | executeSoon(testCompletionInText); |
michael@0 | 292 | } |
michael@0 | 293 | |
michael@0 | 294 | function testCompletionInText() |
michael@0 | 295 | { |
michael@0 | 296 | info("test that completion works inside text, see bug 812618"); |
michael@0 | 297 | |
michael@0 | 298 | popup._panel.addEventListener("popupshown", function onShown() { |
michael@0 | 299 | popup._panel.removeEventListener("popupshown", onShown); |
michael@0 | 300 | |
michael@0 | 301 | ok(popup.isOpen, "popup is open"); |
michael@0 | 302 | is(popup.itemCount, 2, "popup.itemCount is correct"); |
michael@0 | 303 | |
michael@0 | 304 | EventUtils.synthesizeKey("VK_DOWN", {}); |
michael@0 | 305 | is(popup.selectedIndex, 0, "popup.selectedIndex is correct"); |
michael@0 | 306 | ok(!completeNode.value, "completeNode.value is empty"); |
michael@0 | 307 | |
michael@0 | 308 | let items = popup.getItems().reverse().map(e => e.label); |
michael@0 | 309 | let sameItems = items.every((prop, index) => |
michael@0 | 310 | ["testBug873250a", "testBug873250b"][index] === prop); |
michael@0 | 311 | ok(sameItems, "getItems returns the items we expect"); |
michael@0 | 312 | |
michael@0 | 313 | info("press Tab and wait for popup to hide"); |
michael@0 | 314 | popup._panel.addEventListener("popuphidden", popupHideAfterCompletionInText); |
michael@0 | 315 | EventUtils.synthesizeKey("VK_TAB", {}); |
michael@0 | 316 | }); |
michael@0 | 317 | |
michael@0 | 318 | jsterm.setInputValue("dump(window.testBu)"); |
michael@0 | 319 | inputNode.selectionStart = inputNode.selectionEnd = 18; |
michael@0 | 320 | EventUtils.synthesizeKey("g", {}); |
michael@0 | 321 | } |
michael@0 | 322 | |
michael@0 | 323 | function popupHideAfterCompletionInText() |
michael@0 | 324 | { |
michael@0 | 325 | // At this point the completion suggestion should be accepted. |
michael@0 | 326 | popup._panel.removeEventListener("popuphidden", popupHideAfterCompletionInText); |
michael@0 | 327 | |
michael@0 | 328 | ok(!popup.isOpen, "popup is not open"); |
michael@0 | 329 | is(inputNode.value, "dump(window.testBug873250b)", |
michael@0 | 330 | "completion was successful after VK_TAB"); |
michael@0 | 331 | is(inputNode.selectionStart, 26, "cursor location is correct"); |
michael@0 | 332 | is(inputNode.selectionStart, inputNode.selectionEnd, "cursor location (confirmed)"); |
michael@0 | 333 | ok(!completeNode.value, "completeNode is empty"); |
michael@0 | 334 | |
michael@0 | 335 | finishUp(); |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | function finishUp() { |
michael@0 | 339 | HUD = popup = jsterm = inputNode = completeNode = null; |
michael@0 | 340 | finishTest(); |
michael@0 | 341 | } |