summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/test/browser_inspector_search-sidebar.js
blob: d65a670ac40312bee85dac3de6a3e2243c29ec39 (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
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Test that depending where the user last clicked in the inspector, the right search
// field is focused when ctrl+F is pressed.

add_task(function* () {
  let {inspector} = yield openInspectorForURL("data:text/html;charset=utf-8,Search!");

  info("Check that by default, the inspector search field gets focused");
  pressCtrlF();
  isInInspectorSearchBox(inspector);

  info("Click somewhere in the rule-view");
  clickInRuleView(inspector);

  info("Check that the rule-view search field gets focused");
  pressCtrlF();
  isInRuleViewSearchBox(inspector);

  info("Click in the inspector again");
  yield clickContainer("head", inspector);

  info("Check that now we're back in the inspector, its search field gets focused");
  pressCtrlF();
  isInInspectorSearchBox(inspector);

  info("Switch to the computed view, and click somewhere inside it");
  selectComputedView(inspector);
  clickInComputedView(inspector);

  info("Check that the computed-view search field gets focused");
  pressCtrlF();
  isInComputedViewSearchBox(inspector);

  info("Click in the inspector yet again");
  yield clickContainer("body", inspector);

  info("We're back in the inspector again, check the inspector search field focuses");
  pressCtrlF();
  isInInspectorSearchBox(inspector);
});

function pressCtrlF() {
  EventUtils.synthesizeKey("f", {accelKey: true});
}

function clickInRuleView(inspector) {
  let el = inspector.panelDoc.querySelector("#sidebar-panel-ruleview");
  EventUtils.synthesizeMouseAtCenter(el, {}, inspector.panelDoc.defaultView);
}

function clickInComputedView(inspector) {
  let el = inspector.panelDoc.querySelector("#sidebar-panel-computedview");
  EventUtils.synthesizeMouseAtCenter(el, {}, inspector.panelDoc.defaultView);
}

function isInInspectorSearchBox(inspector) {
  // Focus ends up in an anonymous child of the XUL textbox.
  ok(inspector.panelDoc.activeElement.closest("#inspector-searchbox"),
     "The inspector search field is focused when ctrl+F is pressed");
}

function isInRuleViewSearchBox(inspector) {
  is(inspector.panelDoc.activeElement, inspector.ruleview.view.searchField,
     "The rule-view search field is focused when ctrl+F is pressed");
}

function isInComputedViewSearchBox(inspector) {
  is(inspector.panelDoc.activeElement, inspector.computedview.computedView.searchField,
     "The computed-view search field is focused when ctrl+F is pressed");
}