tor-browser

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

browser_jsterm_autocomplete_control_space.js (1951B)


      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 Ctrl+Space displays the autocompletion popup when it's hidden.
      7 
      8 const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>
      9 <head>
     10  <script>
     11    /* Create a prototype-less object so popup does not contain native
     12     * Object prototype properties.
     13     */
     14    var foo = Object.create(null, Object.getOwnPropertyDescriptors({
     15      item0: "value0",
     16      item1: "value1",
     17    }));
     18  </script>
     19 </head>
     20 <body>bug 585991 - autocomplete popup ctrl+space usage test</body>`;
     21 
     22 add_task(async function () {
     23  const hud = await openNewTabAndConsole(TEST_URI);
     24  info("web console opened");
     25 
     26  const { autocompletePopup: popup } = hud.jsterm;
     27 
     28  info("wait for completion: foo.");
     29  await setInputValueForAutocompletion(hud, "foo.");
     30 
     31  const { itemCount } = popup;
     32  ok(popup.isOpen, "popup is open");
     33  Assert.greater(itemCount, 0, "popup has items");
     34 
     35  info("Check that Ctrl+Space when the popup is opened has no effect");
     36  EventUtils.synthesizeKey(" ", { ctrlKey: true });
     37  ok(popup.isOpen, "The popup wasn't closed on Ctrl+Space");
     38  is(popup.itemCount, itemCount, "The popup wasn't modified on Ctrl+Space");
     39 
     40  info("press Escape to close the popup");
     41  let onPopupClose = popup.once("popup-closed");
     42  EventUtils.synthesizeKey("KEY_Escape");
     43  await onPopupClose;
     44  ok(!popup.isOpen, "popup is not open after VK_ESCAPE");
     45 
     46  info("Check that Ctrl+Space opens the popup when it was closed");
     47  const onAutocompleteUpdated = hud.jsterm.once("autocomplete-updated");
     48  EventUtils.synthesizeKey(" ", { ctrlKey: true });
     49  await onAutocompleteUpdated;
     50 
     51  ok(popup.isOpen, "popup opens on Ctrl+Space");
     52  is(popup.itemCount, itemCount, "popup has the expected items");
     53 
     54  info("Close the popup again");
     55  onPopupClose = popup.once("popup-closed");
     56  EventUtils.synthesizeKey("KEY_Escape");
     57  await onPopupClose;
     58 });