michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Tests that code completion works properly. michael@0: michael@0: const TEST_URI = "data:text/html;charset=utf8,

test code completion"; michael@0: michael@0: let testDriver; michael@0: michael@0: function test() { michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, function(hud) { michael@0: testDriver = testCompletion(hud); michael@0: testDriver.next(); michael@0: }); michael@0: }, true); michael@0: } michael@0: michael@0: function testNext() { michael@0: executeSoon(function() { michael@0: testDriver.next(); michael@0: }); michael@0: } michael@0: michael@0: function testCompletion(hud) { michael@0: let jsterm = hud.jsterm; michael@0: let input = jsterm.inputNode; michael@0: michael@0: // Test typing 'docu'. michael@0: input.value = "docu"; michael@0: input.setSelectionRange(4, 4); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: is(input.value, "docu", "'docu' completion (input.value)"); michael@0: is(jsterm.completeNode.value, " ment", "'docu' completion (completeNode)"); michael@0: michael@0: // Test typing 'docu' and press tab. michael@0: input.value = "docu"; michael@0: input.setSelectionRange(4, 4); michael@0: jsterm.complete(jsterm.COMPLETE_FORWARD, testNext); michael@0: yield undefined; michael@0: michael@0: is(input.value, "document", "'docu' tab completion"); michael@0: is(input.selectionStart, 8, "start selection is alright"); michael@0: is(input.selectionEnd, 8, "end selection is alright"); michael@0: is(jsterm.completeNode.value.replace(/ /g, ""), "", "'docu' completed"); michael@0: michael@0: // Test typing 'window.Ob' and press tab. Just 'window.O' is michael@0: // ambiguous: could be window.Object, window.Option, etc. michael@0: input.value = "window.Ob"; michael@0: input.setSelectionRange(9, 9); michael@0: jsterm.complete(jsterm.COMPLETE_FORWARD, testNext); michael@0: yield undefined; michael@0: michael@0: is(input.value, "window.Object", "'window.Ob' tab completion"); michael@0: michael@0: // Test typing 'document.getElem'. michael@0: input.value = "document.getElem"; michael@0: input.setSelectionRange(16, 16); michael@0: jsterm.complete(jsterm.COMPLETE_FORWARD, testNext); michael@0: yield undefined; michael@0: michael@0: is(input.value, "document.getElem", "'document.getElem' completion"); michael@0: is(jsterm.completeNode.value, " entsByTagNameNS", "'document.getElem' completion"); michael@0: michael@0: // Test pressing tab another time. michael@0: jsterm.complete(jsterm.COMPLETE_FORWARD, testNext); michael@0: yield undefined; michael@0: michael@0: is(input.value, "document.getElem", "'document.getElem' completion"); michael@0: is(jsterm.completeNode.value, " entsByTagName", "'document.getElem' another tab completion"); michael@0: michael@0: // Test pressing shift_tab. michael@0: jsterm.complete(jsterm.COMPLETE_BACKWARD, testNext); michael@0: yield undefined; michael@0: michael@0: is(input.value, "document.getElem", "'document.getElem' untab completion"); michael@0: is(jsterm.completeNode.value, " entsByTagNameNS", "'document.getElem' completion"); michael@0: michael@0: jsterm.clearOutput(); michael@0: michael@0: input.value = "docu"; michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: is(jsterm.completeNode.value, " ment", "'docu' completion"); michael@0: jsterm.execute(); michael@0: is(jsterm.completeNode.value, "", "clear completion on execute()"); michael@0: michael@0: // Test multi-line completion works michael@0: input.value = "console.log('one');\nconsol"; michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: is(jsterm.completeNode.value, " \n e", "multi-line completion"); michael@0: michael@0: // Test non-object autocompletion. michael@0: input.value = "Object.name.sl"; michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: is(jsterm.completeNode.value, " ice", "non-object completion"); michael@0: michael@0: // Test string literal autocompletion. michael@0: input.value = "'Asimov'.sl"; michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: is(jsterm.completeNode.value, " ice", "string literal completion"); michael@0: michael@0: testDriver = jsterm = input = null; michael@0: executeSoon(finishTest); michael@0: yield undefined; michael@0: } michael@0: