summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_search-01.js
blob: 3d56252f25cda60a53207072b42421d2546db037 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

requestLongerTimeout(2);

// Test that searching for nodes in the search field actually selects those
// nodes.

const TEST_URL = URL_ROOT + "doc_inspector_search.html";

// The various states of the inspector: [key, id, isValid]
// [
//  what key to press,
//  what id should be selected after the keypress,
//  is the searched text valid selector
// ]
const KEY_STATES = [
  ["#", "b1", true], // #
  ["d", "b1", true], // #d
  ["1", "b1", true], // #d1
  ["VK_RETURN", "d1", true], // #d1
  ["VK_BACK_SPACE", "d1", true], // #d
  ["2", "d1", true], // #d2
  ["VK_RETURN", "d2", true], // #d2
  ["2", "d2", true], // #d22
  ["VK_RETURN", "d2", false], // #d22
  ["VK_BACK_SPACE", "d2", false], // #d2
  ["VK_RETURN", "d2", true], // #d2
  ["VK_BACK_SPACE", "d2", true], // #d
  ["1", "d2", true], // #d1
  ["VK_RETURN", "d1", true], // #d1
  ["VK_BACK_SPACE", "d1", true], // #d
  ["VK_BACK_SPACE", "d1", true], // #
  ["VK_BACK_SPACE", "d1", true], //
  ["d", "d1", true], // d
  ["i", "d1", true], // di
  ["v", "d1", true], // div
  [".", "d1", true], // div.
  ["c", "d1", true], // div.c
  ["VK_UP", "d1", true], // div.c1
  ["VK_TAB", "d1", true], // div.c1
  ["VK_RETURN", "d2", true], // div.c1
  ["VK_BACK_SPACE", "d2", true], // div.c
  ["VK_BACK_SPACE", "d2", true], // div.
  ["VK_BACK_SPACE", "d2", true], // div
  ["VK_BACK_SPACE", "d2", true], // di
  ["VK_BACK_SPACE", "d2", true], // d
  ["VK_BACK_SPACE", "d2", true], //
  [".", "d2", true], // .
  ["c", "d2", true], // .c
  ["1", "d2", true], // .c1
  ["VK_RETURN", "d2", true], // .c1
  ["VK_RETURN", "s2", true], // .c1
  ["VK_RETURN", "p1", true], // .c1
  ["P", "p1", true], // .c1P
  ["VK_RETURN", "p1", false], // .c1P
];

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, isValid] of KEY_STATES) {
    const promises = [];
    info(index + ": Pressing key " + key + " to get id " + id + ".");

    info("Waiting for current key press processing to complete");
    promises.push(inspector.searchSuggestions.once("processing-done"));

    if (key === "VK_RETURN") {
      info("Waiting for " + (isValid ? "NO " : "") + "results");
      promises.push(inspector.search.once("search-result"));
    }

    info("Waiting for search query to complete");
    promises.push(inspector.searchSuggestions.once("processing-done"));

    EventUtils.synthesizeKey(key, {}, inspector.panelWin);

    await Promise.all(promises);
    info(
      "The keypress press process, any possible search results and the search query are complete."
    );

    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++;
  }
});