tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_autocomplete_popup_consecutive-show.js (1712B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that calling `showPopup` multiple time does not lead to invalid state.
      7 
      8 add_task(async function () {
      9  const AutocompletePopup = require("resource://devtools/client/shared/autocomplete-popup.js");
     10 
     11  info("Create an autocompletion popup");
     12  const { doc } = await createHost();
     13  const input = doc.createElement("input");
     14  doc.body.appendChild(input);
     15 
     16  const autocompleteOptions = {
     17    position: "top",
     18    autoSelect: true,
     19    useXulWrapper: true,
     20  };
     21  const popup = new AutocompletePopup(doc, autocompleteOptions);
     22  const items = [{ label: "a" }, { label: "b" }, { label: "c" }];
     23  popup.setItems(items);
     24 
     25  input.focus();
     26 
     27  let onAllEventsReceived = waitForNEvents(popup, "popup-opened", 3);
     28  // Note that the lack of `await` on those function calls are wanted.
     29  popup.openPopup(input, 0, 0, 0);
     30  popup.openPopup(input, 0, 0, 1);
     31  popup.openPopup(input, 0, 0, 2);
     32  await onAllEventsReceived;
     33 
     34  ok(popup.isOpen, "popup is open");
     35  is(
     36    popup.selectedIndex,
     37    2,
     38    "Selected index matches the one that was set last when calling openPopup"
     39  );
     40 
     41  onAllEventsReceived = waitForNEvents(popup, "popup-opened", 2);
     42  // Note that the lack of `await` on those function calls are wanted.
     43  popup.openPopup(input, 0, 0, 1);
     44  popup.openPopup(input);
     45  await onAllEventsReceived;
     46 
     47  ok(popup.isOpen, "popup is open");
     48  is(
     49    popup.selectedIndex,
     50    0,
     51    "First item is selected, as last call to openPopup did not specify an index and autoSelect is true"
     52  );
     53 
     54  const onPopupClose = popup.once("popup-closed");
     55  popup.hidePopup();
     56  await onPopupClose;
     57 });