tor-browser

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

browser_inspector_picker-reset-reference.js (2389B)


      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 the node picker reset its reference for the last hovered node when the user
      8 // stops picking (See Bug 1736183).
      9 
     10 const TEST_URL =
     11  "data:text/html;charset=utf8,<h1 id=target>Pick target</h1><h2>ignore me</h2>";
     12 
     13 add_task(async () => {
     14  const { inspector, toolbox, highlighterTestFront } =
     15    await openInspectorForURL(TEST_URL);
     16 
     17  const { waitForHighlighterTypeHidden } = getHighlighterTestHelpers(inspector);
     18 
     19  info(
     20    "Start the picker and hover an element to populate the picker hovered node reference"
     21  );
     22  await startPicker(toolbox);
     23  await hoverElement(inspector, "#target");
     24  ok(
     25    await highlighterTestFront.assertHighlightedNode("#target"),
     26    "The highlighter is shown on the expected node"
     27  );
     28 
     29  info("Hit Escape to cancel picking");
     30  let onHighlighterHidden = waitForHighlighterTypeHidden(
     31    inspector.highlighters.TYPES.BOXMODEL
     32  );
     33  await stopPickerWithEscapeKey(toolbox);
     34  await onHighlighterHidden;
     35 
     36  info("And start it again, and hover the same node again");
     37  await startPicker(toolbox);
     38  await hoverElement(inspector, "#target");
     39  ok(
     40    await highlighterTestFront.assertHighlightedNode("#target"),
     41    "The highlighter is shown on the expected node again"
     42  );
     43 
     44  info("Pick the element to stop the picker");
     45  onHighlighterHidden = waitForHighlighterTypeHidden(
     46    inspector.highlighters.TYPES.BOXMODEL
     47  );
     48  // nodePicker isPicking property is set to false _after_ picker-node-picked event, so
     49  // we need to wait for picker-stopped here.
     50  const onPickerStopped = toolbox.nodePicker.once("picker-stopped");
     51  await pickElement(inspector, "#target", 5, 5);
     52  await onHighlighterHidden;
     53  await onPickerStopped;
     54 
     55  info("And start it and hover the same node, again");
     56  await startPicker(toolbox);
     57  await hoverElement(inspector, "#target");
     58  ok(
     59    await highlighterTestFront.assertHighlightedNode("#target"),
     60    "The highlighter is shown on the expected node again"
     61  );
     62 
     63  info("Stop the picker to avoid pending Promise");
     64  onHighlighterHidden = waitForHighlighterTypeHidden(
     65    inspector.highlighters.TYPES.BOXMODEL
     66  );
     67  await stopPickerWithEscapeKey(toolbox);
     68  await onHighlighterHidden;
     69 });