summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_search_bar_focus.js
blob: f5ef1b2bddce2a5eefc030bf2ac967a4b56a1304 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// Bug 570760 - Make ctrl-f and / focus the search box in the add-ons manager

async function testKeys(win, searchBox) {
  let doc = win.document;
  // If focus is on the search box move it away for the rest
  // of the test.
  if (doc.activeElement == searchBox) {
    let focus = BrowserTestUtils.waitForEvent(doc.firstElementChild, "focus");
    doc.firstElementChild.focus();
    await focus;
  }
  isnot(doc.activeElement, searchBox, "Search box is not focused");

  let focus = BrowserTestUtils.waitForEvent(searchBox, "focus");
  EventUtils.synthesizeKey("f", { accelKey: true }, win);
  await focus;
  is(
    searchBox.ownerDocument.activeElement,
    searchBox,
    "ctrl-f focuses search box"
  );

  let blur = BrowserTestUtils.waitForEvent(searchBox, "blur");
  searchBox.blur();

  doc.firstElementChild.focus();
  await blur;
  isnot(doc.activeElement, searchBox, "Search box is not focused");

  focus = BrowserTestUtils.waitForEvent(searchBox, "focus");
  EventUtils.synthesizeKey("/", {}, win);
  await focus;
  is(searchBox.ownerDocument.activeElement, searchBox, "/ focuses search box");

  searchBox.blur();
}

add_task(async function testSearchBarKeyboardAccess() {
  let win = await loadInitialView("extension");

  let doc = win.document;
  let searchBox = doc.querySelector("search-addons").input;

  await testKeys(win, searchBox);

  await closeView(win);
});