Debian Codegraph @

testing/web-platform/mozilla/tests/html/semantics/forms/the-input-element/input-activation-behavior.html

raw
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <title>Activation behavior of input</title>
4 <link rel="help" href="https://dom.spec.whatwg.org/#eventtarget-activation-behavior">
5 <link rel="help" href="https://dom.spec.whatwg.org/#concept-event-dispatch">
6 <link rel="help" href="https://html.spec.whatwg.org/#the-input-element">
7 <link rel="help" href="https://github.com/whatwg/html/issues/1568">
8 <link rel="help" href="https://github.com/whatwg/html/issues/1576">
9 <link rel="help" href="https://github.com/whatwg/html/issues/10032">
10 <script src="/resources/testharness.js"></script>
11 <script src="/resources/testharnessreport.js"></script>
12 <div id=log></div>
13
14 <div id=test_container>
15 <a href="javascript:activated(document.querySelector('a'))" class="target"></a>
16 <area href="javascript:activated(document.querySelector('area'))" class="target">
17 </div>
18
19 <script>
20 let activations = [];
21 function activated(e) {
22 activations.push(e);
23 }
24
25 function testActivation(inputType, hasFormOwner, followTheParentLink) {
26 const elements = document.getElementsByClassName("target");
27 for (const anchor of elements) {
28 promise_test(async t => {
29 const input = document.createElement("input");
30 input.type = inputType;
31 input.oninput = function (e) {
32 activated(this);
33 };
34
35 if (hasFormOwner) {
36 const form = document.createElement("form");
37 form.onsubmit = function (e) {
38 activated(this.firstElementChild);
39 e.preventDefault();
40 return false;
41 };
42 form.onreset = function (e) {
43 activated(this.firstElementChild);
44 };
45 form.appendChild(input);
46 anchor.appendChild(form);
47 t.add_cleanup(function() {
48 form.remove();
49 activations = [];
50 });
51 } else {
52 anchor.appendChild(input);
53 t.add_cleanup(function() {
54 input.remove();
55 activations = [];
56 });
57 }
58
59 input.click();
60
61 // This is for a/area where JavaScript is executed in a queued task.
62 await new Promise(resolve => {
63 t.step_timeout(() => {
64 t.step_timeout(() => {
65 // All browser doesn't follow the spec for input button, see
66 // https://github.com/whatwg/html/issues/1576.
67 assert_array_equals(activations, [followTheParentLink ? anchor : input]);
68 if (inputType == "checkbox" || inputType == "radio") {
69 assert_equals(input.checked, true, "check input.checked");
70 }
71 resolve();
72 }, 0);
73 }, 0);
74 });
75 }, `Click child input ${inputType} ${hasFormOwner ? "with" : "without"} form owner ` +
76 `of parent ${anchor.tagName}, activation target should be ${followTheParentLink ? anchor.tagName : "input"}`);
77 }
78 }
79
80 // Click input types without form owner should not follow the parent link.
81 const TypesWithoutFormOwnerNotFollowParentLink = ["checkbox", "radio"];
82 for (const type of TypesWithoutFormOwnerNotFollowParentLink) {
83 testActivation(type, false /* hasFormOwner */, false /* followTheParentLink */);
84 }
85
86 // Click input types without form owner should follow the parent link.
87 const TypesWithoutFormOwnerFollowParentLink = ["button", "reset", "submit"];
88 for (const type of TypesWithoutFormOwnerFollowParentLink) {
89 testActivation(type, false /* hasFormOwner */, true /* followTheParentLink */);
90 }
91
92 // Click input types with form owner should not follow the parent link.
93 const TypesWithFormOwnerNotFollowParentLink = ["submit", "reset", "checkbox", "radio"];
94 for (const type of TypesWithFormOwnerNotFollowParentLink) {
95 testActivation(type, true /* hasFormOwner */, false /* followTheParentLink */);
96 }
97
98 // Click input types with form owner should follow the parent link.
99 const TypesWithFormOwnerFollowParentLink = ["button"];
100 for (const type of TypesWithFormOwnerFollowParentLink) {
101 testActivation(type, true /* hasFormOwner */, true /* followTheParentLink */);
102 }
103 </script>