summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/uievents/order-of-events/focus-events/focus-contained.html
blob: 8df612c1080a82ed4ffaae0c72287735af1e8cf0 (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
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Focus-related events should fire in the correct order</title>
  <link rel="help" href="https://w3c.github.io/uievents/#events-focusevent-event-order">
  <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>
  <script src="/uievents/resources/eventrecorder.js"></script>
</head>

<body>
  <ol>
    <li>Click into the text input.</li>
    <li>Click just below the text input.</li>
    <li>Click into the text input again.</li>
    <li>Click the "Done" button.</li>
  </ol>
  <div id="a" tabindex="1" style="width:400px; height:300px">
    <br /><br /><br />
    <input type="text", id="b"></div>
  </div>
  <button type="button" id="done">Done</button>
</body>

<script>
setup({explicit_timeout: true});
function stopPropagation(e) {
  e.stopPropagation();
}
var relevantEvents = [
  "focus",
  "blur",
  "focusin",
  "focusout"
];
window.onload = async function () {
  var a = document.getElementById("a");
  var b = document.getElementById("b");
  var button = document.getElementById("done");
  var inputs = [a, b];
  EventRecorder.configure({
      objectMap: {
         "a": a,
         "b": b,
      }
    });

  EventRecorder.addEventListenersForNodes(relevantEvents, inputs, stopPropagation);
  var expected = [
    {type: "focus", target: "b"},
    {type: "focusin", target: "b"},
    {type: "blur", target: "b"},
    {type: "focusout", target: "b"},
    {type: "focus", target: "a"},
    {type: "focusin", target: "a"},
    {type: "blur", target: "a"},
    {type: "focusout", target: "a"},
    {type: "focus", target: "b"},
    {type: "focusin", target: "b"},
    {type: "blur", target: "b"},
    {type: "focusout", target: "b"}
  ];

  async_test(function(t) {
    button.addEventListener("click", function () {
      t.step(function () {
        assert_true(EventRecorder.checkRecords(expected));
        t.done();
      });
    }, false);
  }, "Focus-related events should fire in the correct order");
  EventRecorder.start();

  await new test_driver.Actions()
    .pointerMove(0, 0, {origin: b})
    .pointerDown()
    .pointerUp()
    .pointerMove(0, 0, {origin: a})
    .pointerDown()
    .pointerUp()
    .pointerMove(0, 0, {origin: b})
    .pointerDown()
    .pointerUp()
    .pointerMove(0, 0, {origin: button})
    .pointerDown()
    .pointerUp()
    .send();
};
</script>
</html>