summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_highlighter-08.js
blob: 49b544a3258fe1b0d2f67ea9c73154c5b9317521 (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
/* 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 performing multiple requests to highlight nodes or to hide the highlighter,
// without waiting for the former ones to complete, still works well.
add_task(async function () {
  info("Loading the test document and opening the inspector");
  const { inspector, highlighterTestFront } = await openInspectorForURL(
    "data:text/html,"
  );
  const html = await getNodeFront("html", inspector);
  const body = await getNodeFront("body", inspector);
  const type = inspector.highlighters.TYPES.BOXMODEL;
  const getActiveHighlighter = () => {
    return inspector.highlighters.getActiveHighlighter(type);
  };
  is(getActiveHighlighter(), null, "The highlighter is hidden by default");

  info("Highlight <body>, and hide the highlighter immediately after");
  await Promise.all([
    inspector.highlighters.showHighlighterTypeForNode(type, body),
    inspector.highlighters.hideHighlighterType(type),
  ]);
  is(getActiveHighlighter(), null, "The highlighter is hidden");

  info("Highlight <body>, then <html>, then <body> again, synchronously");
  await Promise.all([
    inspector.highlighters.showHighlighterTypeForNode(type, body),
    inspector.highlighters.showHighlighterTypeForNode(type, html),
    inspector.highlighters.showHighlighterTypeForNode(type, body),
  ]);
  ok(
    await highlighterTestFront.assertHighlightedNode("body"),
    "The highlighter highlights <body>"
  );

  info("Highlight <html>, then <body>, then <html> again, synchronously");
  await Promise.all([
    inspector.highlighters.showHighlighterTypeForNode(type, html),
    inspector.highlighters.showHighlighterTypeForNode(type, body),
    inspector.highlighters.showHighlighterTypeForNode(type, html),
  ]);
  ok(
    await highlighterTestFront.assertHighlightedNode("html"),
    "The highlighter highlights <html>"
  );

  info("Hide the highlighter, and highlight <html> immediately after");
  await Promise.all([
    inspector.highlighters.hideHighlighterType(type),
    inspector.highlighters.showHighlighterTypeForNode(type, body),
  ]);
  ok(
    await highlighterTestFront.assertHighlightedNode("body"),
    "The highlighter highlights <body>"
  );

  info("Highlight <html>, and hide the highlighter immediately after");
  await Promise.all([
    inspector.highlighters.showHighlighterTypeForNode(type, html),
    inspector.highlighters.hideHighlighterType(type),
  ]);
  is(getActiveHighlighter(), null, "The highlighter is hidden");
});