summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_search-09.js
blob: f61d1c92130dc5ec49b25448d34b34020cadaf9c (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

requestLongerTimeout(2);

// Test that searching for XPaths via the search field actually selects the
// matching nodes.

const TEST_URL = URL_ROOT + "doc_inspector_search.html";

// The various states of the inspector: [key, id, isTextNode, isValid]
// [
//  what key to press,
//  what id should be selected after the keypress,
//  is the selected node a text node,
//  is the searched text valid selector
// ]
const KEY_STATES = [
  ["/", "b1", false, true], // /
  ["*", "b1", false, true], // /*
  ["VK_RETURN", "root", false, true], // /*
  ["VK_BACK_SPACE", "root", false, true], // /
  ["/", "root", false, true], // //
  ["d", "root", false, true], // //d
  ["i", "root", false, true], // //di
  ["v", "root", false, true], // //div
  ["VK_RETURN", "d1", false, true], // //div
  ["VK_RETURN", "d2", false, true], // //div
  ["VK_RETURN", "d1", false, true], // //div
  ["VK_BACK_SPACE", "d1", false, true], // //di
  ["VK_BACK_SPACE", "d1", false, true], // //d
  ["VK_BACK_SPACE", "d1", false, true], // //
  ["s", "d1", false, true], // //s
  ["p", "d1", false, true], // //sp
  ["a", "d1", false, true], // //spa
  ["n", "d1", false, true], // //span
  ["/", "d1", false, true], // //span/
  ["t", "d1", false, true], // //span/t
  ["e", "d1", false, true], // //span/te
  ["x", "d1", false, true], // //span/tex
  ["t", "d1", false, true], // //span/text
  ["(", "d1", false, true], // //span/text(
  [")", "d1", false, true], // //span/text()
  ["VK_RETURN", "s1", false, true], // //span/text()
  ["VK_RETURN", "s2", true, true], // //span/text()
];

add_task(async function () {
  const { inspector } = await openInspectorForURL(TEST_URL);
  const { searchBox } = inspector;

  await selectNode("#b1", inspector);
  await focusSearchBoxUsingShortcut(inspector.panelWin);

  let index = 0;
  for (const [key, id, isTextNode, isValid] of KEY_STATES) {
    info(index + ": Pressing key " + key + " to get id " + id + ".");
    const onSearchProcessingDone =
      inspector.searchSuggestions.once("processing-done");
    const onSearchResult = inspector.search.once("search-result");
    EventUtils.synthesizeKey(
      key,
      { shiftKey: key === "*" },
      inspector.panelWin
    );

    if (key === "VK_RETURN") {
      info("Waiting for " + (isValid ? "NO " : "") + "results");
      await onSearchResult;
    }

    info("Waiting for search query to complete");
    await onSearchProcessingDone;

    if (isTextNode) {
      info(
        "Text node of " +
          inspector.selection.nodeFront.parentNode.id +
          " is selected with text " +
          searchBox.value
      );

      is(
        inspector.selection.nodeFront.nodeType,
        Node.TEXT_NODE,
        "Correct node is selected for state " + index
      );
    } else {
      info(
        inspector.selection.nodeFront.id +
          " is selected with text " +
          searchBox.value
      );

      const nodeFront = await getNodeFront("#" + id, inspector);
      is(
        inspector.selection.nodeFront,
        nodeFront,
        "Correct node is selected for state " + index
      );
    }

    is(
      !searchBox.parentNode.classList.contains("devtools-searchbox-no-match"),
      isValid,
      "Correct searchbox result state for state " + index
    );

    index++;
  }
});