tor-browser

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

browser_inspector_highlighter-autohide.js (2713B)


      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 "use strict";
      6 
      7 // Test that clicking on a node in the markup view or picking a node with the node picker
      8 // shows a highlighter which is automatically hidden after a delay.
      9 add_task(async function () {
     10  info("Loading the test document and opening the inspector");
     11  const { inspector, toolbox, highlighterTestFront } =
     12    await openInspectorForURL(
     13      "data:text/html;charset=utf-8,<p id='one'>TEST 1</p><p id='two'>TEST 2</p>"
     14    );
     15  const { waitForHighlighterTypeShown, waitForHighlighterTypeHidden } =
     16    getHighlighterTestHelpers(inspector);
     17 
     18  // While in test mode, the configuration to automatically hide Box Model Highlighters
     19  // after a delay is ignored to prevent intermittent test failures from race conditions.
     20  // Restore this behavior just for this test because it is explicitly checked.
     21  const HIGHLIGHTER_AUTOHIDE_TIMER = inspector.HIGHLIGHTER_AUTOHIDE_TIMER;
     22  inspector.HIGHLIGHTER_AUTOHIDE_TIMER = 1000;
     23 
     24  registerCleanupFunction(() => {
     25    // Restore the value to avoid impacting other tests.
     26    inspector.HIGHLIGHTER_AUTOHIDE_TIMER = HIGHLIGHTER_AUTOHIDE_TIMER;
     27  });
     28 
     29  info(
     30    "Check that selecting an element in the markup-view shows the highlighter and auto-hides it"
     31  );
     32  let onHighlighterShown = waitForHighlighterTypeShown(
     33    inspector.highlighters.TYPES.BOXMODEL
     34  );
     35  const onHighlighterHidden = waitForHighlighterTypeHidden(
     36    inspector.highlighters.TYPES.BOXMODEL
     37  );
     38 
     39  let delay;
     40  const start = Date.now();
     41  onHighlighterHidden.then(() => {
     42    delay = Date.now() - start;
     43  });
     44 
     45  await clickContainer("#one", inspector);
     46 
     47  info("Wait for Box Model Highlighter shown");
     48  await onHighlighterShown;
     49  info("Wait for Box Model Highlighter hidden");
     50  await onHighlighterHidden;
     51 
     52  ok(true, "Highlighter was shown and hidden");
     53  Assert.greaterOrEqual(
     54    delay,
     55    inspector.HIGHLIGHTER_AUTOHIDE_TIMER,
     56    `Highlighter was hidden after expected delay (${delay}ms)`
     57  );
     58 
     59  info("Check that picking a node hides the highlighter right away");
     60  onHighlighterShown = waitForHighlighterTypeShown(
     61    inspector.highlighters.TYPES.BOXMODEL
     62  );
     63  await startPicker(toolbox);
     64  await hoverElement(inspector, "#two", 0, 0);
     65  await onHighlighterShown;
     66  ok(
     67    await highlighterTestFront.isHighlighting(),
     68    "Highlighter was shown when hovering the node"
     69  );
     70 
     71  await pickElement(inspector, "#two", 0, 0);
     72  is(
     73    await highlighterTestFront.isHighlighting(),
     74    false,
     75    "Highlighter gets hidden without delay after picking a node"
     76  );
     77 });