tor-browser

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

browser_dbg-preview-invalid-tokens.js (4111B)


      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 add_task(async function () {
     11  const dbg = await initDebugger("doc-preview.html", "preview.js");
     12 
     13  await selectSource(dbg, "preview.js");
     14 
     15  // Test hovering tokens for which we shouldn't have a preview popup displayed
     16  invokeInTab("invalidTargets");
     17  await waitForPaused(dbg);
     18  // CodeMirror refreshes after inline previews are displayed, so wait until they're rendered.
     19  await waitForInlinePreviews(dbg);
     20 
     21  await assertNoPreviews(dbg, `"a"`, 69, 4);
     22  await assertNoPreviews(dbg, `false`, 70, 4);
     23  await assertNoPreviews(dbg, `undefined`, 71, 4);
     24  await assertNoPreviews(dbg, `null`, 72, 4);
     25  await assertNoPreviews(dbg, `42`, 73, 4);
     26  await assertNoPreviews(dbg, `const`, 74, 4);
     27 
     28  // checking inline preview widget
     29  // Move the cursor to the top left corner to have a clean state
     30  resetCursorPositionToTopLeftCorner(dbg);
     31 
     32  // Wait for all the updates to the document to complete to make all
     33  // token elements have been rendered
     34  await waitForDocumentLoadComplete(dbg);
     35  const inlinePreviewEl = findElement(dbg, "inlinePreviewsOnLine", 74);
     36  is(inlinePreviewEl.innerText, `myVar:"foo"`, "got expected inline preview");
     37 
     38  const racePromise = Promise.any([
     39    waitForElement(dbg, "previewPopup"),
     40    wait(500).then(() => "TIMEOUT"),
     41  ]);
     42  // Hover over the inline preview element
     43  hoverToken(inlinePreviewEl);
     44  const raceResult = await racePromise;
     45  is(raceResult, "TIMEOUT", "No popup was displayed over the inline preview");
     46 
     47  await resume(dbg);
     48 
     49  info("Test hovering element not in a line");
     50  await getDebuggerSplitConsole(dbg);
     51  const { hud } = dbg.toolbox.getPanel("webconsole");
     52  evaluateExpressionInConsole(
     53    hud,
     54    `
     55      a = 1;
     56      debugger;
     57      b = 2;`
     58  );
     59  await waitForPaused(dbg);
     60  await dbg.toolbox.toggleSplitConsole();
     61 
     62  resetCursorPositionToTopLeftCorner(dbg);
     63 
     64  const racePromiseLines = Promise.any([
     65    waitForElement(dbg, "previewPopup"),
     66    wait(500).then(() => "TIMEOUT_LINES"),
     67  ]);
     68  // We don't want to use hoverToken, as it synthesize the event at the center of the element,
     69  // which wouldn't reproduce the original issue we want to check
     70  EventUtils.synthesizeMouse(
     71    findElement(dbg, "CodeMirrorLines"),
     72    0,
     73    0,
     74    {
     75      type: "mousemove",
     76    },
     77    dbg.win
     78  );
     79  is(
     80    await racePromiseLines,
     81    "TIMEOUT_LINES",
     82    "No popup was displayed over the content container element"
     83  );
     84 
     85  // Trigger a preview popup on an element which actually will show a popup
     86  // to avoid test document leaks linked to the earlier mousemove events which
     87  // did not trigger any popup.
     88  const aTokenEl = await getTokenElAtLine(dbg, "a", 2, 8);
     89  await tryHoverToken(dbg, aTokenEl, "previewPopup");
     90 
     91  // Resume
     92  await resume(dbg);
     93  await selectSource(dbg, "preview.js");
     94 });
     95 
     96 async function assertNoPreviews(dbg, expression, line, column) {
     97  // Move the cursor to the top left corner to have a clean state
     98  resetCursorPositionToTopLeftCorner(dbg);
     99 
    100  // Wait for all the updates to the document to complete to make all
    101  // token elements have been rendered
    102  await waitForDocumentLoadComplete(dbg);
    103 
    104  const tokenElement = await getTokenFromPosition(dbg, { line, column });
    105  is(
    106    tokenElement.textContent,
    107    expression,
    108    `The token at ${line} and ${column} has the expected content`
    109  );
    110 
    111  hoverToken(tokenElement);
    112 
    113  // Hover the token
    114  const result = await Promise.race([
    115    waitForElement(dbg, "previewPopup"),
    116    wait(500).then(() => "NO POPUP AFTER TIMEOUT"),
    117  ]);
    118  is(
    119    result,
    120    "NO POPUP AFTER TIMEOUT",
    121    `No popup was displayed when hovering "${expression}"`
    122  );
    123 }
    124 
    125 function resetCursorPositionToTopLeftCorner(dbg) {
    126  EventUtils.synthesizeMouse(
    127    findElement(dbg, "codeMirror"),
    128    0,
    129    0,
    130    {
    131      type: "mousemove",
    132    },
    133    dbg.win
    134  );
    135 }