tor-browser

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

browser_jsterm_autocomplete_accept_no_scroll.js (1637B)


      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 the accepting an autocompletion does not scroll the input.
      7 
      8 const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>
      9  <script>
     10    /* Create a prototype-less object so popup does not contain native
     11     * Object prototype properties.
     12     */
     13    window.foobar = Object.create(null, Object.getOwnPropertyDescriptors({
     14      item0: "value0",
     15      item1: "value1",
     16    }));
     17  </script>`;
     18 
     19 add_task(async function () {
     20  const hud = await openNewTabAndConsole(TEST_URI);
     21  const { jsterm, ui } = hud;
     22  const { autocompletePopup: popup } = jsterm;
     23 
     24  info("Insert multiple new lines so the input overflows");
     25  const onPopUpOpen = popup.once("popup-opened");
     26  const lines = "\n".repeat(200);
     27  setInputValue(hud, lines);
     28 
     29  info("Fire the autocompletion popup");
     30  EventUtils.sendString("window.foobar.");
     31 
     32  await onPopUpOpen;
     33  const scrollableEl = ui.window.document.querySelector(".CodeMirror-scroll");
     34 
     35  Assert.greater(scrollableEl.scrollTop, 0, "The input overflows");
     36  const scrollTop = scrollableEl.scrollTop;
     37 
     38  info("Hit Enter to accept the autocompletion");
     39  const onPopupClose = popup.once("popup-closed");
     40  EventUtils.synthesizeKey("KEY_Enter");
     41  await onPopupClose;
     42 
     43  ok(!popup.isOpen, "popup is not open after KEY_Enter");
     44  is(
     45    getInputValue(hud),
     46    lines + "window.foobar.item0",
     47    "completion was successful after KEY_Enter"
     48  );
     49  is(
     50    scrollableEl.scrollTop,
     51    scrollTop,
     52    "The scrolling position stayed the same when accepting the completion"
     53  );
     54 });