tor-browser

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

browser_jsterm_autocomplete_native_getters.js (1609B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests that native getters (e.g. document.body) autocompletes in the web console.
      5 // See Bug 651501.
      6 
      7 "use strict";
      8 
      9 const TEST_URI =
     10  "data:text/html;charset=utf-8,<!DOCTYPE html>Test document.body autocompletion";
     11 
     12 add_task(async function () {
     13  const hud = await openNewTabAndConsole(TEST_URI);
     14  const { jsterm, ui } = hud;
     15 
     16  const { autocompletePopup: popup } = jsterm;
     17 
     18  ok(!popup.isOpen, "popup is not open");
     19  const onPopupOpen = popup.once("popup-opened");
     20 
     21  setInputValue(hud, "document.body");
     22  EventUtils.sendString(".");
     23 
     24  await onPopupOpen;
     25 
     26  ok(popup.isOpen, "popup is open");
     27  const cacheMatches = ui.wrapper.getStore().getState().autocomplete
     28    .cache.matches;
     29  is(popup.itemCount, cacheMatches.length, "popup.itemCount is correct");
     30  ok(
     31    cacheMatches.includes("addEventListener"),
     32    "addEventListener is in the list of suggestions"
     33  );
     34  ok(cacheMatches.includes("bgColor"), "bgColor is in the list of suggestions");
     35  ok(
     36    cacheMatches.includes("ATTRIBUTE_NODE"),
     37    "ATTRIBUTE_NODE is in the list of suggestions"
     38  );
     39 
     40  const onPopupClose = popup.once("popup-closed");
     41  EventUtils.synthesizeKey("KEY_Escape");
     42 
     43  await onPopupClose;
     44 
     45  ok(!popup.isOpen, "popup is not open");
     46  const onAutoCompleteUpdated = jsterm.once("autocomplete-updated");
     47  const inputStr = "document.b";
     48  setInputValue(hud, inputStr);
     49  EventUtils.sendString("o");
     50 
     51  await onAutoCompleteUpdated;
     52  checkInputCompletionValue(hud, "dy", "autocomplete shows document.body");
     53 });