/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; // See Bug 585991. const TEST_URI = `data:text/html;charset=utf-8, bug 585991 - autocomplete popup navigation and tab key usage test`; add_task(async function () { const hud = await openNewTabAndConsole(TEST_URI); const { jsterm } = hud; info("web console opened"); const { autocompletePopup: popup } = jsterm; ok(!popup.isOpen, "popup is not open"); const onPopUpOpen = popup.once("popup-opened"); setInputValue(hud, "window.foo"); // Shows the popup EventUtils.sendString("."); await onPopUpOpen; ok(popup.isOpen, "popup is open"); const expectedPopupItems = ["item00", "item1", "item2", "item3"]; ok( hasExactPopupLabels(popup, expectedPopupItems), "getItems returns the items we expect" ); is(popup.selectedIndex, 0, "Index of the first item is selected."); EventUtils.synthesizeKey("KEY_ArrowUp"); is(popup.selectedIndex, 3, "index 3 is selected"); is(popup.selectedItem.label, "item3", "item3 is selected"); checkInputCompletionValue(hud, "item3", "completeNode.value holds item3"); EventUtils.synthesizeKey("KEY_ArrowUp"); is(popup.selectedIndex, 2, "index 2 is selected"); is(popup.selectedItem.label, "item2", "item2 is selected"); checkInputCompletionValue(hud, "item2", "completeNode.value holds item2"); EventUtils.synthesizeKey("KEY_ArrowDown"); is(popup.selectedIndex, 3, "index 3 is selected"); is(popup.selectedItem.label, "item3", "item3 is selected"); checkInputCompletionValue(hud, "item3", "completeNode.value holds item3"); let currentSelectionIndex = popup.selectedIndex; EventUtils.synthesizeKey("KEY_PageUp"); ok( popup.selectedIndex < currentSelectionIndex, "Index is less after Page UP" ); currentSelectionIndex = popup.selectedIndex; EventUtils.synthesizeKey("KEY_PageDown"); ok( popup.selectedIndex > currentSelectionIndex, "Index is greater after PGDN" ); EventUtils.synthesizeKey("KEY_Home"); is(popup.selectedIndex, 0, "index is first after Home"); EventUtils.synthesizeKey("KEY_End"); is( popup.selectedIndex, expectedPopupItems.length - 1, "index is last after End" ); info("press Tab and wait for popup to hide"); const onPopupClose = popup.once("popup-closed"); EventUtils.synthesizeKey("KEY_Tab"); await onPopupClose; // At this point the completion suggestion should be accepted. ok(!popup.isOpen, "popup is not open"); is( getInputValue(hud), "window.foo.item3", "completion was successful after KEY_Tab" ); ok(!getInputCompletionValue(hud), "completeNode is empty"); info( "Check that hitting Home hides the completion text when the popup is hidden" ); await setInputValueForAutocompletion(hud, "window.foo.item0"); checkInputCompletionValue(hud, "0", "completeNode has expected value"); if (Services.appinfo.OS == "Darwin") { EventUtils.synthesizeKey("a", { ctrlKey: true }); } else { EventUtils.synthesizeKey("KEY_Home"); } checkInputCompletionValue( hud, "", "completeNode was cleared after hitting Home" ); info( "Check that hitting End hides the completion text when the popup is hidden" ); await setInputValueForAutocompletion(hud, "window.foo.item0"); checkInputCompletionValue(hud, "0", "completeNode has expected value"); EventUtils.synthesizeKey("KEY_End"); checkInputCompletionValue( hud, "", "completeNode was cleared after hitting End" ); });