summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_picker-reset-reference.js
blob: 2a9bc39ca6050218e0a3e2f3c7e9a7df2a356065 (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
59
60
61
62
63
64
65
66
67
68
69
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

// Test that the node picker reset its reference for the last hovered node when the user
// stops picking (See Bug 1736183).

const TEST_URL =
  "data:text/html;charset=utf8,<h1 id=target>Pick target</h1><h2>ignore me</h2>";

add_task(async () => {
  const { inspector, toolbox, highlighterTestFront } =
    await openInspectorForURL(TEST_URL);

  const { waitForHighlighterTypeHidden } = getHighlighterTestHelpers(inspector);

  info(
    "Start the picker and hover an element to populate the picker hovered node reference"
  );
  await startPicker(toolbox);
  await hoverElement(inspector, "#target");
  ok(
    await highlighterTestFront.assertHighlightedNode("#target"),
    "The highlighter is shown on the expected node"
  );

  info("Hit Escape to cancel picking");
  let onHighlighterHidden = waitForHighlighterTypeHidden(
    inspector.highlighters.TYPES.BOXMODEL
  );
  await stopPickerWithEscapeKey(toolbox);
  await onHighlighterHidden;

  info("And start it again, and hover the same node again");
  await startPicker(toolbox);
  await hoverElement(inspector, "#target");
  ok(
    await highlighterTestFront.assertHighlightedNode("#target"),
    "The highlighter is shown on the expected node again"
  );

  info("Pick the element to stop the picker");
  onHighlighterHidden = waitForHighlighterTypeHidden(
    inspector.highlighters.TYPES.BOXMODEL
  );
  // nodePicker isPicking property is set to false _after_ picker-node-picked event, so
  // we need to wait for picker-stopped here.
  const onPickerStopped = toolbox.nodePicker.once("picker-stopped");
  await pickElement(inspector, "#target", 5, 5);
  await onHighlighterHidden;
  await onPickerStopped;

  info("And start it and hover the same node, again");
  await startPicker(toolbox);
  await hoverElement(inspector, "#target");
  ok(
    await highlighterTestFront.assertHighlightedNode("#target"),
    "The highlighter is shown on the expected node again"
  );

  info("Stop the picker to avoid pending Promise");
  onHighlighterHidden = waitForHighlighterTypeHidden(
    inspector.highlighters.TYPES.BOXMODEL
  );
  await stopPickerWithEscapeKey(toolbox);
  await onHighlighterHidden;
});