summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_edit-selector-click-on-scrollbar.js
blob: 52e11097cc539232c4a79dfa355782fd6e7842bd (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
89
90
91
92
93
94
95
96
/* 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(async function () {
  info("Toolbox height should be small enough to force scrollbars to appear");
  await new Promise(done => {
    const options = { set: [["devtools.toolbox.footer.height", 200]] };
    SpecialPowers.pushPrefEnv(options, done);
  });

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

  info("Check we have an overflow on the ruleview container.");
  const container = view.element;
  const 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.");
  const ruleEditor = getRuleViewRuleEditor(view, 1);
  const editor = await focusEditableField(view, ruleEditor.selectorText);
  is(
    inplaceEditor(ruleEditor.selectorText),
    editor,
    "The selector editor is focused."
  );

  info("Click on the scrollbar element.");
  await 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");
  const newValue = ".testclass.a.b.c.d.e.f";
  const onRuleViewChanged = once(view, "ruleview-changed");

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

async function clickOnRuleviewScrollbar(view) {
  const container = view.element.parentNode;
  const onScroll = once(container, "scroll");
  const 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
  );
  await onScroll;

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