browser/devtools/webconsole/test/browser_webconsole_bug_585991_autocomplete_popup.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 test";
michael@0 7
michael@0 8 function test() {
michael@0 9 addTab(TEST_URI);
michael@0 10 browser.addEventListener("load", function onLoad() {
michael@0 11 browser.removeEventListener("load", onLoad, true);
michael@0 12 openConsole(null, consoleOpened);
michael@0 13 }, true);
michael@0 14 }
michael@0 15
michael@0 16 function consoleOpened(HUD) {
michael@0 17 let items = [
michael@0 18 {label: "item0", value: "value0"},
michael@0 19 {label: "item1", value: "value1"},
michael@0 20 {label: "item2", value: "value2"},
michael@0 21 ];
michael@0 22
michael@0 23 let popup = HUD.jsterm.autocompletePopup;
michael@0 24
michael@0 25 ok(!popup.isOpen, "popup is not open");
michael@0 26
michael@0 27 popup._panel.addEventListener("popupshown", function() {
michael@0 28 popup._panel.removeEventListener("popupshown", arguments.callee, false);
michael@0 29
michael@0 30 ok(popup.isOpen, "popup is open");
michael@0 31
michael@0 32 is(popup.itemCount, 0, "no items");
michael@0 33
michael@0 34 popup.setItems(items);
michael@0 35
michael@0 36 is(popup.itemCount, items.length, "items added");
michael@0 37
michael@0 38 let sameItems = popup.getItems();
michael@0 39 is(sameItems.every(function(aItem, aIndex) {
michael@0 40 return aItem === items[aIndex];
michael@0 41 }), true, "getItems returns back the same items");
michael@0 42
michael@0 43 is(popup.selectedIndex, 2,
michael@0 44 "Index of the first item from bottom is selected.");
michael@0 45 is(popup.selectedItem, items[2], "First item from bottom is selected");
michael@0 46
michael@0 47 popup.selectedIndex = 1;
michael@0 48
michael@0 49 is(popup.selectedIndex, 1, "index 1 is selected");
michael@0 50 is(popup.selectedItem, items[1], "item1 is selected");
michael@0 51
michael@0 52 popup.selectedItem = items[2];
michael@0 53
michael@0 54 is(popup.selectedIndex, 2, "index 2 is selected");
michael@0 55 is(popup.selectedItem, items[2], "item2 is selected");
michael@0 56
michael@0 57 is(popup.selectPreviousItem(), items[1], "selectPreviousItem() works");
michael@0 58
michael@0 59 is(popup.selectedIndex, 1, "index 1 is selected");
michael@0 60 is(popup.selectedItem, items[1], "item1 is selected");
michael@0 61
michael@0 62 is(popup.selectNextItem(), items[2], "selectPreviousItem() works");
michael@0 63
michael@0 64 is(popup.selectedIndex, 2, "index 2 is selected");
michael@0 65 is(popup.selectedItem, items[2], "item2 is selected");
michael@0 66
michael@0 67 ok(popup.selectNextItem(), "selectPreviousItem() works");
michael@0 68
michael@0 69 is(popup.selectedIndex, 0, "index 0 is selected");
michael@0 70 is(popup.selectedItem, items[0], "item0 is selected");
michael@0 71
michael@0 72 items.push({label: "label3", value: "value3"});
michael@0 73 popup.appendItem(items[3]);
michael@0 74
michael@0 75 is(popup.itemCount, items.length, "item3 appended");
michael@0 76
michael@0 77 popup.selectedIndex = 3;
michael@0 78 is(popup.selectedItem, items[3], "item3 is selected");
michael@0 79
michael@0 80 popup.removeItem(items[2]);
michael@0 81
michael@0 82 is(popup.selectedIndex, 2, "index2 is selected");
michael@0 83 is(popup.selectedItem, items[3], "item3 is still selected");
michael@0 84 is(popup.itemCount, items.length - 1, "item2 removed");
michael@0 85
michael@0 86 popup.clearItems();
michael@0 87 is(popup.itemCount, 0, "items cleared");
michael@0 88
michael@0 89 popup.hidePopup();
michael@0 90 finishTest();
michael@0 91 }, false);
michael@0 92
michael@0 93 popup.openPopup();
michael@0 94 }
michael@0 95

mercurial