tor-browser

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

browser_dbg-preview.js (5225B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 // Test hovering on an object, which will show a popup and on a
      6 // simple value, which will show a tooltip.
      7 
      8 "use strict";
      9 
     10 // Showing/hiding the preview tooltip can be slow as we wait for CodeMirror scroll...
     11 requestLongerTimeout(2);
     12 
     13 add_task(async function () {
     14  const dbg = await initDebugger("doc-preview.html", "preview.js");
     15 
     16  await testPreviews(dbg, "testInline", [
     17    { line: 17, column: 16, expression: "prop", result: 2 },
     18  ]);
     19 
     20  await selectSource(dbg, "preview.js");
     21 
     22  await testPreviews(dbg, "empties", [
     23    { line: 6, column: 9, expression: "a", result: '""' },
     24    { line: 7, column: 9, expression: "b", result: "false" },
     25    { line: 8, column: 9, expression: "c", result: "undefined" },
     26    { line: 9, column: 9, expression: "d", result: "null" },
     27  ]);
     28 
     29  await testPreviews(dbg, "objects", [
     30    { line: 27, column: 10, expression: "empty", result: "Object" },
     31    { line: 28, column: 22, expression: "foo", result: 1 },
     32  ]);
     33 
     34  await testPreviews(dbg, "smalls", [
     35    { line: 14, column: 9, expression: "a", result: '"..."' },
     36    { line: 15, column: 9, expression: "b", result: "true" },
     37    { line: 16, column: 9, expression: "c", result: "1" },
     38    {
     39      line: 17,
     40      column: 9,
     41      expression: "d",
     42      fields: [["length", "0"]],
     43    },
     44  ]);
     45 
     46  await testPreviews(dbg, "classPreview", [
     47    { line: 50, column: 20, expression: "x", result: 1 },
     48    { line: 50, column: 29, expression: "#privateVar", result: 2 },
     49    {
     50      line: 50,
     51      column: 47,
     52      expression: "#privateStatic",
     53      fields: [
     54        ["first", `"a"`],
     55        ["second", `"b"`],
     56      ],
     57    },
     58    {
     59      line: 51,
     60      column: 26,
     61      expression: "this",
     62      fields: [
     63        ["x", "1"],
     64        ["#privateVar", "2"],
     65      ],
     66    },
     67    { line: 51, column: 39, expression: "#privateVar", result: 2 },
     68  ]);
     69 
     70  await testPreviews(dbg, "multipleTokens", [
     71    { line: 81, column: 4, expression: "foo", result: "Object" },
     72    { line: 81, column: 11, expression: "blip", result: "Object" },
     73    { line: 82, column: 8, expression: "bar", result: "Object" },
     74    { line: 84, column: 16, expression: "boom", result: `0` },
     75  ]);
     76 
     77  await testPreviews(dbg, "thisProperties", [
     78    { line: 96, column: 13, expression: "myProperty", result: "Object" },
     79    { line: 96, column: 23, expression: "x", result: "this-myProperty-x" },
     80    {
     81      line: 98,
     82      column: 13,
     83      expression: "propertyName",
     84      result: "myProperty",
     85    },
     86    {
     87      line: 98,
     88      column: 26,
     89      expression: "y",
     90      result: "this-myProperty-y",
     91    },
     92    {
     93      line: 99,
     94      column: 14,
     95      expression: "propertyName",
     96      result: "myProperty",
     97    },
     98    {
     99      line: 99,
    100      column: 28,
    101      expression: "z",
    102      result: "this-myProperty-z",
    103    },
    104  ]);
    105 
    106  await testPreviews(dbg, "valueOfExpression", [
    107    { line: 107, column: 6, expression: "value", result: "foo" },
    108  ]);
    109 
    110  await testPreviews(dbg, "spawnWorker", [
    111    { line: 126, column: 6, expression: "worker", result: "Worker" },
    112  ]);
    113 
    114  // javascript.options.experimental.explicit_resource_management is set to true, but it's
    115  // only supported on Nightly at the moment, so only check for SuppressedError if
    116  // they're supported.
    117  if (AppConstants.ENABLE_EXPLICIT_RESOURCE_MANAGEMENT) {
    118    info("Check that preview works in a script with `using` keyword");
    119 
    120    const onPaused = waitForPaused(dbg);
    121    dbg.commands.scriptCommand.execute(
    122      `
    123      {
    124        using erm = {
    125          [Symbol.dispose]() {},
    126          foo: 42
    127        };
    128        console.log(erm.foo);
    129        debugger;
    130      }`,
    131      {}
    132    );
    133 
    134    await onPaused;
    135    await assertPreviews(dbg, [
    136      // assignment
    137      { line: 3, column: 16, expression: "erm", result: "Object" },
    138      { line: 7, column: 26, expression: "foo", result: "42" },
    139    ]);
    140    await resume(dbg);
    141  }
    142 
    143  await selectSource(dbg, "preview.js");
    144  info(
    145    "Check that closing the preview tooltip doesn't release the underlying object actor"
    146  );
    147  invokeInTab("classPreview");
    148  await waitForPaused(dbg);
    149  info("Display popup a first time and hide it");
    150  await assertPreviews(dbg, [
    151    {
    152      line: 60,
    153      column: 7,
    154      expression: "y",
    155      fields: [["hello", "{…}"]],
    156    },
    157  ]);
    158 
    159  info("Display the popup again and try to expand a property");
    160  const { element: popupEl, tokenEl } = await tryHovering(
    161    dbg,
    162    60,
    163    7,
    164    "previewPopup"
    165  );
    166  const nodes = popupEl.querySelectorAll(".preview-popup .node");
    167  const initialNodesLength = nodes.length;
    168  nodes[1].querySelector(".theme-twisty").click();
    169  await waitFor(
    170    () =>
    171      popupEl.querySelectorAll(".preview-popup .node").length >
    172      initialNodesLength
    173  );
    174  ok(true, `"hello" was expanded`);
    175  await closePreviewForToken(dbg, tokenEl, "popup");
    176  await resume(dbg);
    177 });
    178 
    179 async function testPreviews(dbg, fnName, previews) {
    180  invokeInTab(fnName);
    181  await waitForPaused(dbg);
    182 
    183  await assertPreviews(dbg, previews);
    184  await resume(dbg);
    185 
    186  info(`Ran tests for ${fnName}`);
    187 }