summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_search_keyboard_trap.js
blob: b3f4fcdb3d441e07ce0884c4f9b61b160444ecc7 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test ability to tab to and away from inspector search using keyboard.

const TEST_URL = URL_ROOT + "doc_inspector_search.html";

/**
 * Test data has the format of:
 * {
 *   desc         {String}    description for better logging
 *   focused      {Boolean}   flag, indicating if search box contains focus
 *   keys:        {Array}     list of keys that include key code and optional
 *                            event data (shiftKey, etc)
 * }
 *
 */
const TEST_DATA = [
  {
    desc: "Move focus to a next focusable element",
    focused: false,
    keys: [
      {
        key: "VK_TAB",
        options: {},
      },
    ],
  },
  {
    desc: "Move focus back to searchbox",
    focused: true,
    keys: [
      {
        key: "VK_TAB",
        options: { shiftKey: true },
      },
    ],
  },
  {
    desc:
      "Open popup and then tab away (2 times) to the a next focusable " +
      "element",
    focused: false,
    keys: [
      {
        key: "d",
        options: {},
      },
      {
        key: "VK_TAB",
        options: {},
      },
      {
        key: "VK_TAB",
        options: {},
      },
    ],
  },
  {
    desc: "Move focus back to searchbox",
    focused: true,
    keys: [
      {
        key: "VK_TAB",
        options: { shiftKey: true },
      },
    ],
  },
];

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

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

  // Ensure a searchbox is focused.
  ok(containsFocus(doc, searchBox), "Focus is in a searchbox");

  for (const { desc, focused, keys } of TEST_DATA) {
    info(desc);
    for (const { key, options } of keys) {
      const done = !focused
        ? inspector.searchSuggestions.once("processing-done")
        : Promise.resolve();
      EventUtils.synthesizeKey(key, options);
      await done;
    }
    is(containsFocus(doc, searchBox), focused, "Focus is set correctly");
  }
});