summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_edit-selector-click-on-scrollbar.js
blob: 1846df60d826db3e4add612da9e595b8f9ec9bf5 (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
/* 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";

// Testing ruleview inplace-editor is not blurred when clicking on the ruleview
// container scrollbar.

const TEST_URI = `
  <style type="text/css">
    div.testclass {
      color: black;
    }
    .a {
      color: #aaa;
    }
    .b {
      color: #bbb;
    }
    .c {
      color: #ccc;
    }
    .d {
      color: #ddd;
    }
    .e {
      color: #eee;
    }
    .f {
      color: #fff;
    }
  </style>
  <div class="testclass a b c d e f">Styled Node</div>
`;

add_task(function* () {
  info("Toolbox height should be small enough to force scrollbars to appear");
  yield new Promise(done => {
    let options = {"set": [
      ["devtools.toolbox.footer.height", 200],
    ]};
    SpecialPowers.pushPrefEnv(options, done);
  });

  yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
  let {inspector, view} = yield openRuleView();
  yield selectNode(".testclass", inspector);

  info("Check we have an overflow on the ruleview container.");
  let container = view.element;
  let hasScrollbar = container.offsetHeight < container.scrollHeight;
  ok(hasScrollbar, "The rule view container should have a vertical scrollbar.");

  info("Focusing an existing selector name in the rule-view.");
  let ruleEditor = getRuleViewRuleEditor(view, 1);
  let editor = yield focusEditableField(view, ruleEditor.selectorText);
  is(inplaceEditor(ruleEditor.selectorText), editor,
    "The selector editor is focused.");

  info("Click on the scrollbar element.");
  yield clickOnRuleviewScrollbar(view);

  is(editor.input, view.styleDocument.activeElement,
    "The editor input should still be focused.");

  info("Check a new value can still be committed in the editable field");
  let newValue = ".testclass.a.b.c.d.e.f";
  let onRuleViewChanged = once(view, "ruleview-changed");

  info("Enter new value and commit.");
  editor.input.value = newValue;
  EventUtils.synthesizeKey("VK_RETURN", {});
  yield onRuleViewChanged;
  ok(getRuleViewRule(view, newValue), "Rule with '" + newValue + " 'exists.");
});

function* clickOnRuleviewScrollbar(view) {
  let container = view.element.parentNode;
  let onScroll = once(container, "scroll");
  let rect = container.getBoundingClientRect();
  // click 5 pixels before the bottom-right corner should hit the scrollbar
  EventUtils.synthesizeMouse(container, rect.width - 5, rect.height - 5,
    {}, view.styleWindow);
  yield onScroll;

  ok(true, "The rule view container scrolled after clicking on the scrollbar.");
}