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: const TEST_URI = "data:text/html;charset=utf-8,

bug 585991 - autocomplete popup test"; 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, consoleOpened); michael@0: }, true); michael@0: } michael@0: michael@0: function consoleOpened(HUD) { michael@0: let items = [ michael@0: {label: "item0", value: "value0"}, michael@0: {label: "item1", value: "value1"}, michael@0: {label: "item2", value: "value2"}, michael@0: ]; michael@0: michael@0: let popup = HUD.jsterm.autocompletePopup; michael@0: michael@0: ok(!popup.isOpen, "popup is not open"); michael@0: michael@0: popup._panel.addEventListener("popupshown", function() { michael@0: popup._panel.removeEventListener("popupshown", arguments.callee, false); michael@0: michael@0: ok(popup.isOpen, "popup is open"); michael@0: michael@0: is(popup.itemCount, 0, "no items"); michael@0: michael@0: popup.setItems(items); michael@0: michael@0: is(popup.itemCount, items.length, "items added"); michael@0: michael@0: let sameItems = popup.getItems(); michael@0: is(sameItems.every(function(aItem, aIndex) { michael@0: return aItem === items[aIndex]; michael@0: }), true, "getItems returns back the same items"); michael@0: michael@0: is(popup.selectedIndex, 2, michael@0: "Index of the first item from bottom is selected."); michael@0: is(popup.selectedItem, items[2], "First item from bottom is selected"); michael@0: michael@0: popup.selectedIndex = 1; michael@0: michael@0: is(popup.selectedIndex, 1, "index 1 is selected"); michael@0: is(popup.selectedItem, items[1], "item1 is selected"); michael@0: michael@0: popup.selectedItem = items[2]; michael@0: michael@0: is(popup.selectedIndex, 2, "index 2 is selected"); michael@0: is(popup.selectedItem, items[2], "item2 is selected"); michael@0: michael@0: is(popup.selectPreviousItem(), items[1], "selectPreviousItem() works"); michael@0: michael@0: is(popup.selectedIndex, 1, "index 1 is selected"); michael@0: is(popup.selectedItem, items[1], "item1 is selected"); michael@0: michael@0: is(popup.selectNextItem(), items[2], "selectPreviousItem() works"); michael@0: michael@0: is(popup.selectedIndex, 2, "index 2 is selected"); michael@0: is(popup.selectedItem, items[2], "item2 is selected"); michael@0: michael@0: ok(popup.selectNextItem(), "selectPreviousItem() works"); michael@0: michael@0: is(popup.selectedIndex, 0, "index 0 is selected"); michael@0: is(popup.selectedItem, items[0], "item0 is selected"); michael@0: michael@0: items.push({label: "label3", value: "value3"}); michael@0: popup.appendItem(items[3]); michael@0: michael@0: is(popup.itemCount, items.length, "item3 appended"); michael@0: michael@0: popup.selectedIndex = 3; michael@0: is(popup.selectedItem, items[3], "item3 is selected"); michael@0: michael@0: popup.removeItem(items[2]); michael@0: michael@0: is(popup.selectedIndex, 2, "index2 is selected"); michael@0: is(popup.selectedItem, items[3], "item3 is still selected"); michael@0: is(popup.itemCount, items.length - 1, "item2 removed"); michael@0: michael@0: popup.clearItems(); michael@0: is(popup.itemCount, 0, "items cleared"); michael@0: michael@0: popup.hidePopup(); michael@0: finishTest(); michael@0: }, false); michael@0: michael@0: popup.openPopup(); michael@0: } michael@0: