summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/the-label-element/proxy-modifier-click-to-associated-element.tentative.html
blob: fa50c080250699cf48d2661951ad73abc03655d4 (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
<!DOCTYPE HTML>
<title>clicks on label element with modifier keys should be proxied to its associated control</title>
<link rel="author" title="Mu-An Chiou" href="mailto:hi@muan.co">
<link rel="help" href="https://html.spec.whatwg.org/multipage/forms.html#the-label-element:the-label-element-10">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<div id="log"></div>
<div style="user-select: none;">
  <label id="click-label" for="click">foo</label><input id="click" type="checkbox" />
  <label id="shift-label" for="shift">foo</label><input id="shift" type="checkbox" />
  <label id="alt-label" for="alt">foo</label><input id="alt" type="checkbox" />
  <label id="meta-label" for="meta">foo</label><input id="meta" type="checkbox" />
</div>
<script>
  "use strict";

  function clickWithModifier(label, key) {
    new test_driver.Actions()
      .keyDown(key)
      .pointerMove(0, 0, { origin: label })
      .pointerDown()
      .pointerUp()
      .addTick()
      .keyUp(key)
      .send()
  }

  async_test(t => {
    const label = document.getElementById("click-label");
    const input = document.getElementById("click");

    input.addEventListener("click", t.step_func_done());
    new test_driver.click(label)

  }, "label with for attribute should proxy click events to the associated element on click");

  async_test(t => {
    const label = document.getElementById("shift-label");
    const input = document.getElementById("shift");

    input.addEventListener("click", t.step_func_done());
    clickWithModifier(label, "\uE008"); // ShiftLeft

  }, "label with for attribute should proxy click events to the associated element on shift click");

  async_test(t => {
    const label = document.getElementById("alt-label");
    const input = document.getElementById("alt");

    input.addEventListener("click", t.step_func_done());
    clickWithModifier(label, "\uE00A"); // AltLeft

  }, "label with for attribute should proxy click events to the associated element on alt click");

  async_test(t => {
    const label = document.getElementById("meta-label");
    const input = document.getElementById("meta");

    input.addEventListener("click", t.step_func_done());
    clickWithModifier(label, "\uE03D"); // OSLeft

  }, "label with for attribute should proxy click events to the associated element on meta click");

</script>