tor-browser

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

browser_jsterm_autocomplete_eager_evaluation.js (1154B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests that the main expression is eagerly evaluated and its results are used in the autocomple popup
      5 
      6 "use strict";
      7 
      8 const TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html>Test autocompletion for expression variables<script>
      9    var testObj = {
     10      fun: () => ({ yay: "yay", yo: "yo", boo: "boo" })
     11    };
     12  </script>`;
     13 
     14 add_task(async function () {
     15  const hud = await openNewTabAndConsole(TEST_URI);
     16  const { jsterm } = hud;
     17  const { autocompletePopup } = jsterm;
     18 
     19  const cases = [
     20    { input: "testObj.fun().y", results: ["yay", "yo"] },
     21    {
     22      input: `Array.of(1,2,3).reduce((i, agg) => agg + i).toS`,
     23      results: ["toString"],
     24    },
     25    { input: `1..toE`, results: ["toExponential"] },
     26  ];
     27 
     28  for (const test of cases) {
     29    info(`Test: ${test.input}`);
     30    await setInputValueForAutocompletion(hud, test.input);
     31    ok(
     32      hasExactPopupLabels(autocompletePopup, test.results),
     33      "Autocomplete popup shows expected results: " +
     34        getAutocompletePopupLabels(autocompletePopup).join("\n")
     35    );
     36  }
     37 });