summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_content_defined_helpers.js
blob: b4c4504c84a55b301f0900cb9848d31ed4648ed8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that using helper functions in jsterm call the global content functions
// if they are defined.

const PREFIX = "content-";
const HELPERS = [
  "$_",
  "$",
  "$$",
  "$0",
  "$x",
  "clear",
  "clearHistory",
  "copy",
  "help",
  "inspect",
  "keys",
  "screenshot",
  "values",
];

// The page script sets a global function for each known helper (except print).
const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8>
  <script>
    const helpers = ${JSON.stringify(HELPERS)};
    for (const helper of helpers) {
      window[helper] = () => "${PREFIX}" + helper;
    }
  </script>`;

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);
  const { jsterm } = hud;
  const { autocompletePopup } = jsterm;

  for (const helper of HELPERS) {
    await setInputValueForAutocompletion(hud, helper);
    const autocompleteItems = getAutocompletePopupLabels(
      autocompletePopup
    ).filter(l => l === helper);
    is(
      autocompleteItems.length,
      1,
      `There's no duplicated "${helper}" item in the autocomplete popup`
    );

    await executeAndWaitForResultMessage(
      hud,
      `${helper}()`,
      `"${PREFIX + helper}"`
    );
    ok(true, `output is correct for ${helper}()`);
  }
});