summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsive/test/browser/browser_typeahead_find.js
blob: 7bc22de1ef9976e020fcbf2970d2af21d2f42583 (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
/* 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";

/**
 * This test attempts to exercise automatic triggering of typeaheadfind
 * within RDM content. It does this by simulating keystrokes while
 * various elements in the RDM content are focused.

 * The test currently does not work due to hitting the assert in
 * Bug 516128.
 */

const TEST_URL =
  "data:text/html;charset=utf-8," +
  '<body id="body"><input id="input" type="text"/><p>text</body>';

addRDMTask(TEST_URL, async function ({ ui, manager }) {
  // Turn on the pref that allows meta viewport support.
  await pushPref("accessibility.typeaheadfind", true);

  const browser = ui.getViewportBrowser();

  info("--- Starting test output ---");

  const expected = [
    {
      id: "body",
      findTriggered: true,
    },
    {
      id: "input",
      findTriggered: false,
    },
  ];

  for (const e of expected) {
    await SpecialPowers.spawn(browser, [{ e }], async function (args) {
      const { e: values } = args;
      const element = content.document.getElementById(values.id);

      // Set focus on the desired element.
      element.focus();
    });

    // Press the 'T' key and see if find is triggered.
    await BrowserTestUtils.synthesizeKey("t", {}, browser);

    const findBar = await gBrowser.getFindBar();

    const findIsTriggered = findBar._findField.value == "t";
    is(
      findIsTriggered,
      e.findTriggered,
      "Text input with focused element " +
        e.id +
        " should " +
        (e.findTriggered ? "" : "not ") +
        "trigger find."
    );
    findBar._findField.value = "";

    await SpecialPowers.spawn(browser, [], async function () {
      // Clear focus.
      content.document.activeElement.blur();
    });
  }
});