summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_eager_evaluation_element_highlight.js
blob: 94f7c92920d1c60e33c720c79cbb20a2324cafce (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
70
71
72
73
74
75
/* 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";

const TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html>
<h1 class="title">hello</h1>
<div id="mydiv">mydivtext</div>
<script>
  x = Object.create(null, Object.getOwnPropertyDescriptors({
    a: document.querySelector("h1"),
    b: document.querySelector("div"),
    c: document.createElement("hr")
  }));
</script>`;

// Test that when the eager evaluation result is an element, it gets highlighted.
add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);
  const { jsterm, toolbox } = hud;
  const { autocompletePopup } = jsterm;

  const highlighterTestFront = await getHighlighterTestFront(toolbox);
  const highlighter = toolbox.getHighlighter();
  let onHighlighterShown;
  let onHighlighterHidden;
  let data;

  ok(!autocompletePopup.isOpen, "popup is not open");
  const onPopupOpen = autocompletePopup.once("popup-opened");
  onHighlighterShown = highlighter.waitForHighlighterShown();
  EventUtils.sendString("x.");
  await onPopupOpen;

  await waitForEagerEvaluationResult(hud, `<h1 class="title">`);
  data = await onHighlighterShown;
  is(data.nodeFront.displayName, "h1", "The correct node was highlighted");
  isVisible = await highlighterTestFront.isHighlighting();
  is(isVisible, true, "Highlighter is displayed");

  onHighlighterShown = highlighter.waitForHighlighterShown();
  EventUtils.synthesizeKey("KEY_ArrowDown");
  await waitForEagerEvaluationResult(hud, `<div id="mydiv">`);
  data = await onHighlighterShown;
  is(data.nodeFront.displayName, "div", "The correct node was highlighted");
  isVisible = await highlighterTestFront.isHighlighting();
  is(isVisible, true, "Highlighter is displayed");

  onHighlighterHidden = highlighter.waitForHighlighterHidden();
  EventUtils.synthesizeKey("KEY_ArrowDown");
  await waitForEagerEvaluationResult(hud, `<hr>`);
  await onHighlighterHidden;
  ok(true, "The highlighter isn't displayed on a non-connected element");

  info("Test that text nodes are highlighted");
  onHighlighterShown = highlighter.waitForHighlighterShown();
  EventUtils.sendString("b.firstChild");
  await waitForEagerEvaluationResult(hud, `#text "mydivtext"`);
  data = await onHighlighterShown;
  is(
    data.nodeFront.displayName,
    "#text",
    "The correct text node was highlighted"
  );
  isVisible = await highlighterTestFront.isHighlighting();
  is(isVisible, true, "Highlighter is displayed");

  onHighlighterHidden = highlighter.waitForHighlighterHidden();
  EventUtils.synthesizeKey("KEY_Enter");
  await waitFor(() => findEvaluationResultMessage(hud, `#text "mydivtext"`));
  await waitForNoEagerEvaluationResult(hud);
  isVisible = await highlighterTestFront.isHighlighting();
  is(isVisible, false, "Highlighter is closed after evaluating the expression");
});