tor-browser

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

browser_jsterm_content_defined_helpers.js (1383B)


      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 using helper functions in jsterm call the global content functions
      7 // if they are defined.
      8 
      9 const PREFIX = "content-";
     10 const HELPERS = [
     11  "$_",
     12  "$",
     13  "$$",
     14  "$0",
     15  "$x",
     16  "clear",
     17  "clearHistory",
     18  "copy",
     19  "help",
     20  "inspect",
     21  "keys",
     22  "screenshot",
     23  "values",
     24 ];
     25 
     26 // The page script sets a global function for each known helper (except print).
     27 const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8>
     28  <script>
     29    const helpers = ${JSON.stringify(HELPERS)};
     30    for (const helper of helpers) {
     31      window[helper] = () => "${PREFIX}" + helper;
     32    }
     33  </script>`;
     34 
     35 add_task(async function () {
     36  const hud = await openNewTabAndConsole(TEST_URI);
     37  const { jsterm } = hud;
     38  const { autocompletePopup } = jsterm;
     39 
     40  for (const helper of HELPERS) {
     41    await setInputValueForAutocompletion(hud, helper);
     42    const autocompleteItems = getAutocompletePopupLabels(
     43      autocompletePopup
     44    ).filter(l => l === helper);
     45    is(
     46      autocompleteItems.length,
     47      1,
     48      `There's no duplicated "${helper}" item in the autocomplete popup`
     49    );
     50 
     51    await executeAndWaitForResultMessage(
     52      hud,
     53      `${helper}()`,
     54      `"${PREFIX + helper}"`
     55    );
     56    ok(true, `output is correct for ${helper}()`);
     57  }
     58 });