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 | // Tests that code completion works properly. |
michael@0 | 7 | |
michael@0 | 8 | const TEST_URI = "data:text/html;charset=utf8,<p>test code completion"; |
michael@0 | 9 | |
michael@0 | 10 | let testDriver; |
michael@0 | 11 | |
michael@0 | 12 | function test() { |
michael@0 | 13 | addTab(TEST_URI); |
michael@0 | 14 | browser.addEventListener("load", function onLoad() { |
michael@0 | 15 | browser.removeEventListener("load", onLoad, true); |
michael@0 | 16 | openConsole(null, function(hud) { |
michael@0 | 17 | testDriver = testCompletion(hud); |
michael@0 | 18 | testDriver.next(); |
michael@0 | 19 | }); |
michael@0 | 20 | }, true); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function testNext() { |
michael@0 | 24 | executeSoon(function() { |
michael@0 | 25 | testDriver.next(); |
michael@0 | 26 | }); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function testCompletion(hud) { |
michael@0 | 30 | let jsterm = hud.jsterm; |
michael@0 | 31 | let input = jsterm.inputNode; |
michael@0 | 32 | |
michael@0 | 33 | // Test typing 'docu'. |
michael@0 | 34 | input.value = "docu"; |
michael@0 | 35 | input.setSelectionRange(4, 4); |
michael@0 | 36 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 37 | yield undefined; |
michael@0 | 38 | |
michael@0 | 39 | is(input.value, "docu", "'docu' completion (input.value)"); |
michael@0 | 40 | is(jsterm.completeNode.value, " ment", "'docu' completion (completeNode)"); |
michael@0 | 41 | |
michael@0 | 42 | // Test typing 'docu' and press tab. |
michael@0 | 43 | input.value = "docu"; |
michael@0 | 44 | input.setSelectionRange(4, 4); |
michael@0 | 45 | jsterm.complete(jsterm.COMPLETE_FORWARD, testNext); |
michael@0 | 46 | yield undefined; |
michael@0 | 47 | |
michael@0 | 48 | is(input.value, "document", "'docu' tab completion"); |
michael@0 | 49 | is(input.selectionStart, 8, "start selection is alright"); |
michael@0 | 50 | is(input.selectionEnd, 8, "end selection is alright"); |
michael@0 | 51 | is(jsterm.completeNode.value.replace(/ /g, ""), "", "'docu' completed"); |
michael@0 | 52 | |
michael@0 | 53 | // Test typing 'window.Ob' and press tab. Just 'window.O' is |
michael@0 | 54 | // ambiguous: could be window.Object, window.Option, etc. |
michael@0 | 55 | input.value = "window.Ob"; |
michael@0 | 56 | input.setSelectionRange(9, 9); |
michael@0 | 57 | jsterm.complete(jsterm.COMPLETE_FORWARD, testNext); |
michael@0 | 58 | yield undefined; |
michael@0 | 59 | |
michael@0 | 60 | is(input.value, "window.Object", "'window.Ob' tab completion"); |
michael@0 | 61 | |
michael@0 | 62 | // Test typing 'document.getElem'. |
michael@0 | 63 | input.value = "document.getElem"; |
michael@0 | 64 | input.setSelectionRange(16, 16); |
michael@0 | 65 | jsterm.complete(jsterm.COMPLETE_FORWARD, testNext); |
michael@0 | 66 | yield undefined; |
michael@0 | 67 | |
michael@0 | 68 | is(input.value, "document.getElem", "'document.getElem' completion"); |
michael@0 | 69 | is(jsterm.completeNode.value, " entsByTagNameNS", "'document.getElem' completion"); |
michael@0 | 70 | |
michael@0 | 71 | // Test pressing tab another time. |
michael@0 | 72 | jsterm.complete(jsterm.COMPLETE_FORWARD, testNext); |
michael@0 | 73 | yield undefined; |
michael@0 | 74 | |
michael@0 | 75 | is(input.value, "document.getElem", "'document.getElem' completion"); |
michael@0 | 76 | is(jsterm.completeNode.value, " entsByTagName", "'document.getElem' another tab completion"); |
michael@0 | 77 | |
michael@0 | 78 | // Test pressing shift_tab. |
michael@0 | 79 | jsterm.complete(jsterm.COMPLETE_BACKWARD, testNext); |
michael@0 | 80 | yield undefined; |
michael@0 | 81 | |
michael@0 | 82 | is(input.value, "document.getElem", "'document.getElem' untab completion"); |
michael@0 | 83 | is(jsterm.completeNode.value, " entsByTagNameNS", "'document.getElem' completion"); |
michael@0 | 84 | |
michael@0 | 85 | jsterm.clearOutput(); |
michael@0 | 86 | |
michael@0 | 87 | input.value = "docu"; |
michael@0 | 88 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 89 | yield undefined; |
michael@0 | 90 | |
michael@0 | 91 | is(jsterm.completeNode.value, " ment", "'docu' completion"); |
michael@0 | 92 | jsterm.execute(); |
michael@0 | 93 | is(jsterm.completeNode.value, "", "clear completion on execute()"); |
michael@0 | 94 | |
michael@0 | 95 | // Test multi-line completion works |
michael@0 | 96 | input.value = "console.log('one');\nconsol"; |
michael@0 | 97 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 98 | yield undefined; |
michael@0 | 99 | |
michael@0 | 100 | is(jsterm.completeNode.value, " \n e", "multi-line completion"); |
michael@0 | 101 | |
michael@0 | 102 | // Test non-object autocompletion. |
michael@0 | 103 | input.value = "Object.name.sl"; |
michael@0 | 104 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 105 | yield undefined; |
michael@0 | 106 | |
michael@0 | 107 | is(jsterm.completeNode.value, " ice", "non-object completion"); |
michael@0 | 108 | |
michael@0 | 109 | // Test string literal autocompletion. |
michael@0 | 110 | input.value = "'Asimov'.sl"; |
michael@0 | 111 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 112 | yield undefined; |
michael@0 | 113 | |
michael@0 | 114 | is(jsterm.completeNode.value, " ice", "string literal completion"); |
michael@0 | 115 | |
michael@0 | 116 | testDriver = jsterm = input = null; |
michael@0 | 117 | executeSoon(finishTest); |
michael@0 | 118 | yield undefined; |
michael@0 | 119 | } |
michael@0 | 120 |