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

"use strict";

// Test that the inspector search shortcut works from the inner iframes of the
// inspector panel (eg markup-view iframe) and that shortcuts triggered by other
// panels are not consumed by the inspector.
// See Bug 1589617.
add_task(async function () {
  const { inspector, toolbox } = await openInspectorForURL(
    "data:text/html;charset=utf-8,<span>Test search shortcut conflicts</span>"
  );
  const { searchBox } = inspector;
  const doc = inspector.panelDoc;

  info("Check that the shortcut works when opening the inspector");
  await focusSearchBoxUsingShortcut(inspector.panelWin);
  ok(containsFocus(doc, searchBox), "Focus is in a searchbox");

  info("Focus the markup view");
  inspector.markup._frame.focus();
  ok(!containsFocus(doc, searchBox), "Focus is no longer in the searchbox");

  info("Check that the shortcut works from the markup view");
  const focused = once(searchBox, "focus");
  synthesizeKeyShortcut(INSPECTOR_L10N.getStr("inspector.searchHTML.key"));
  await focused;
  ok(containsFocus(doc, searchBox), "Focus is in the searchbox again");

  // We focus the markup view again to check if using the shortcut from the
  // webconsole will focus the inspector searchbox unintentionally.
  inspector.markup._frame.focus();
  ok(!containsFocus(doc, searchBox), "Focus is no longer in the searchbox");

  info("Switch to webconsole");
  await toolbox.selectTool("webconsole");
  const hud = toolbox.getCurrentPanel().hud;
  const consoleSearchBox = hud.ui.outputNode.querySelector(
    ".devtools-searchbox input"
  );

  info("Check that the console search shortcut works");
  const consoleSearchFocused = once(consoleSearchBox, "focus");

  // Note: we expect the console and inspector to share the same shortcut.
  // If they diverge, the test will need to be updated.
  synthesizeKeyShortcut(INSPECTOR_L10N.getStr("inspector.searchHTML.key"));
  await consoleSearchFocused;
  const consoleDoc = hud.ui.outputNode.ownerDocument;
  ok(
    containsFocus(consoleDoc, consoleSearchBox),
    "Focus is in the console searchbox"
  );

  info("Switch back to the inspector");
  await toolbox.selectTool("inspector");
  ok(!containsFocus(doc, searchBox), "Focus is not in the inspector searchbox");
});