diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /devtools/client/shared/test/browser_autocomplete_popup_consecutive-show.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/shared/test/browser_autocomplete_popup_consecutive-show.js')
-rw-r--r-- | devtools/client/shared/test/browser_autocomplete_popup_consecutive-show.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/devtools/client/shared/test/browser_autocomplete_popup_consecutive-show.js b/devtools/client/shared/test/browser_autocomplete_popup_consecutive-show.js new file mode 100644 index 0000000000..667392f10b --- /dev/null +++ b/devtools/client/shared/test/browser_autocomplete_popup_consecutive-show.js @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that calling `showPopup` multiple time does not lead to invalid state. + +add_task(async function() { + const AutocompletePopup = require("resource://devtools/client/shared/autocomplete-popup.js"); + + info("Create an autocompletion popup"); + const { doc } = await createHost(); + const input = doc.createElement("input"); + doc.body.appendChild(input); + + const autocompleteOptions = { + position: "top", + autoSelect: true, + useXulWrapper: true, + }; + const popup = new AutocompletePopup(doc, autocompleteOptions); + const items = [{ label: "a" }, { label: "b" }, { label: "c" }]; + popup.setItems(items); + + input.focus(); + + let onAllEventsReceived = waitForNEvents(popup, "popup-opened", 3); + // Note that the lack of `await` on those function calls are wanted. + popup.openPopup(input, 0, 0, 0); + popup.openPopup(input, 0, 0, 1); + popup.openPopup(input, 0, 0, 2); + await onAllEventsReceived; + + ok(popup.isOpen, "popup is open"); + is( + popup.selectedIndex, + 2, + "Selected index matches the one that was set last when calling openPopup" + ); + + onAllEventsReceived = waitForNEvents(popup, "popup-opened", 2); + // Note that the lack of `await` on those function calls are wanted. + popup.openPopup(input, 0, 0, 1); + popup.openPopup(input); + await onAllEventsReceived; + + ok(popup.isOpen, "popup is open"); + is( + popup.selectedIndex, + 0, + "First item is selected, as last call to openPopup did not specify an index and autoSelect is true" + ); + + const onPopupClose = popup.once("popup-closed"); + popup.hidePopup(); + await onPopupClose; +}); |