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 the cached autocomplete results are used when the new michael@0: // user input is a subset of the existing completion results. michael@0: michael@0: const TEST_URI = "data:text/html;charset=utf8,
test cached autocompletion results"; michael@0: michael@0: let testDriver; michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); 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: let popup = jsterm.autocompletePopup; michael@0: michael@0: // Test if 'doc' gives 'document' michael@0: input.value = "doc"; michael@0: input.setSelectionRange(3, 3); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: is(input.value, "doc", "'docu' completion (input.value)"); michael@0: is(jsterm.completeNode.value, " ument", "'docu' completion (completeNode)"); michael@0: michael@0: // Test typing 'window.'. michael@0: input.value = "window."; michael@0: input.setSelectionRange(7, 7); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: ok(popup.getItems().length > 0, "'window.' gave a list of suggestions") michael@0: michael@0: content.wrappedJSObject.docfoobar = true; michael@0: michael@0: // Test typing 'window.doc'. michael@0: input.value = "window.doc"; michael@0: input.setSelectionRange(10, 10); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: let newItems = popup.getItems(); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "docfoobar"; michael@0: }), "autocomplete cached results do not contain docfoobar. list has not been updated"); michael@0: michael@0: // Test that backspace does not cause a request to the server michael@0: input.value = "window.do"; michael@0: input.setSelectionRange(9, 9); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "docfoobar"; michael@0: }), "autocomplete cached results do not contain docfoobar. list has not been updated"); michael@0: michael@0: delete content.wrappedJSObject.docfoobar; michael@0: michael@0: // Test if 'window.getC' gives 'getComputedStyle' michael@0: input.value = "window." michael@0: input.setSelectionRange(7, 7); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: input.value = "window.getC"; michael@0: input.setSelectionRange(11, 11); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: newItems = popup.getItems(); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "getComputedStyle"; michael@0: }), "autocomplete results do contain getComputedStyle"); michael@0: michael@0: // Test if 'dump(d' gives non-zero results michael@0: input.value = "dump(d"; michael@0: input.setSelectionRange(6, 6); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: ok(popup.getItems().length > 0, "'dump(d' gives non-zero results"); michael@0: michael@0: // Test that 'dump(window.)' works. michael@0: input.value = "dump(window.)"; michael@0: input.setSelectionRange(12, 12); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: content.wrappedJSObject.docfoobar = true; michael@0: michael@0: // Make sure 'dump(window.doc)' does not contain 'docfoobar'. michael@0: input.value = "dump(window.doc)"; michael@0: input.setSelectionRange(15, 15); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "docfoobar"; michael@0: }), "autocomplete cached results do not contain docfoobar. list has not been updated"); michael@0: michael@0: delete content.wrappedJSObject.docfoobar; michael@0: michael@0: testDriver = null; michael@0: executeSoon(finishTest); michael@0: yield undefined; michael@0: }