OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <title>Synthetic click event "magic"</title> | 2 <title>Synthetic click event "magic"</title> |
3 <script src="/resources/testharness.js"></script> | 3 <script src="/resources/testharness.js"></script> |
4 <script src="/resources/testharnessreport.js"></script> | 4 <script src="/resources/testharnessreport.js"></script> |
5 <div id=log></div> | 5 <div id=log></div> |
6 <div id=dump style=display:none></div> | 6 <div id=dump style=display:none></div> |
7 <script> | 7 <script> |
8 var dump = document.getElementById("dump") | 8 var dump = document.getElementById("dump") |
9 | 9 |
10 async_test(function(t) { | 10 async_test(function(t) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 assert_true(input.checked, "child pre-click must be triggered") | 71 assert_true(input.checked, "child pre-click must be triggered") |
72 }) | 72 }) |
73 child.dispatchEvent(new MouseEvent("click", {bubbles:true})) | 73 child.dispatchEvent(new MouseEvent("click", {bubbles:true})) |
74 t.done() | 74 t.done() |
75 }, "pick the first with activation behavior <input type=checkbox>") | 75 }, "pick the first with activation behavior <input type=checkbox>") |
76 | 76 |
77 var globalCounter = 0 // sorry | 77 var globalCounter = 0 // sorry |
78 async_test(function(t) { // as above with <a> | 78 async_test(function(t) { // as above with <a> |
79 var i = 0 | 79 var i = 0 |
80 var link = document.createElement("a") | 80 var link = document.createElement("a") |
81 link.href = "javascript:globalCounter--" // must not be triggered | 81 link.href = "javascript:(function(){globalCounter--})()" // must not be trigge
red |
82 dump.appendChild(link) | 82 dump.appendChild(link) |
83 var child = link.appendChild(document.createElement("a")) | 83 var child = link.appendChild(document.createElement("a")) |
84 child.href = "javascript:globalCounter++" | 84 child.href = "javascript:(function(){globalCounter++})()" |
85 child.dispatchEvent(new MouseEvent("click", {bubbles:true})) | 85 child.dispatchEvent(new MouseEvent("click", {bubbles:true})) |
86 assert_equals(globalCounter, 1) | 86 assert_equals(globalCounter, 1) |
87 t.done() | 87 t.done() |
88 }, "pick the first with activation behavior <a href>") | 88 }, "pick the first with activation behavior <a href>") |
89 | 89 |
90 async_test(function(t) { | 90 async_test(function(t) { |
91 var input = document.createElement("input") | 91 var input = document.createElement("input") |
92 input.type = "checkbox" | 92 input.type = "checkbox" |
93 dump.appendChild(input) | 93 dump.appendChild(input) |
94 var clickEvent = new MouseEvent("click") | 94 var clickEvent = new MouseEvent("click") |
(...skipping 14 matching lines...) Expand all Loading... |
109 var clickEvent = new MouseEvent("click") | 109 var clickEvent = new MouseEvent("click") |
110 var finalTarget = document.createElement("doesnotmatter") | 110 var finalTarget = document.createElement("doesnotmatter") |
111 finalTarget.onclick = t.step_func_done(function() { | 111 finalTarget.onclick = t.step_func_done(function() { |
112 assert_equals(clickEvent.target, finalTarget) | 112 assert_equals(clickEvent.target, finalTarget) |
113 }) | 113 }) |
114 input.onchange = t.step_func(function() { | 114 input.onchange = t.step_func(function() { |
115 finalTarget.dispatchEvent(clickEvent) | 115 finalTarget.dispatchEvent(clickEvent) |
116 }) | 116 }) |
117 input.dispatchEvent(clickEvent) | 117 input.dispatchEvent(clickEvent) |
118 }, "redispatch during post-click handling") | 118 }, "redispatch during post-click handling") |
| 119 |
| 120 async_test(function(t) { |
| 121 var input = document.createElement("input") |
| 122 input.type = "checkbox" |
| 123 dump.appendChild(input) |
| 124 var child = input.appendChild(document.createElement("input")) |
| 125 child.type = "checkbox" |
| 126 child.disabled = true |
| 127 child.click() |
| 128 assert_false(input.checked) |
| 129 assert_false(child.checked) |
| 130 t.done() |
| 131 }, "disabled checkbox still has activation behavior") |
| 132 |
| 133 async_test(function(t) { |
| 134 var state = "start" |
| 135 |
| 136 var form = document.createElement("form") |
| 137 form.onsubmit = t.step_func(() => { |
| 138 if(state == "start" || state == "checkbox") { |
| 139 state = "failure" |
| 140 } else if(state == "form") { |
| 141 state = "done" |
| 142 } |
| 143 return false |
| 144 }) |
| 145 dump.appendChild(form) |
| 146 var button = form.appendChild(document.createElement("button")) |
| 147 button.type = "submit" |
| 148 var checkbox = button.appendChild(document.createElement("input")) |
| 149 checkbox.type = "checkbox" |
| 150 checkbox.onclick = t.step_func(() => { |
| 151 if(state == "start") { |
| 152 assert_unreached() |
| 153 } else if(state == "checkbox") { |
| 154 assert_true(checkbox.checked) |
| 155 } |
| 156 }) |
| 157 checkbox.disabled = true |
| 158 checkbox.click() |
| 159 assert_equals(state, "start") |
| 160 |
| 161 state = "checkbox" |
| 162 checkbox.disabled = false |
| 163 checkbox.click() |
| 164 assert_equals(state, "checkbox") |
| 165 |
| 166 state = "form" |
| 167 button.click() |
| 168 assert_equals(state, "done") |
| 169 |
| 170 t.done() |
| 171 }, "disabled checkbox still has activation behavior, part 2") |
| 172 |
| 173 async_test(function(t) { |
| 174 var input = document.createElement("input") |
| 175 input.type = "checkbox" |
| 176 input.onclick = t.step_func_done(function() { |
| 177 assert_true(input.checked) |
| 178 }) |
| 179 input.click() |
| 180 }, "disconnected checkbox should be checked") |
| 181 |
| 182 async_test(function(t) { |
| 183 var input = document.createElement("input") |
| 184 input.type = "radio" |
| 185 input.onclick = t.step_func_done(function() { |
| 186 assert_true(input.checked) |
| 187 }) |
| 188 input.click() |
| 189 }, "disconnected radio should be checked") |
| 190 |
| 191 async_test(function(t) { |
| 192 var form = document.createElement("form") |
| 193 var didSubmit = false |
| 194 form.onsubmit = t.step_func(() => { |
| 195 didSubmit = true |
| 196 return false |
| 197 }) |
| 198 var input = form.appendChild(document.createElement("input")) |
| 199 input.type = "submit" |
| 200 input.click() |
| 201 assert_false(didSubmit) |
| 202 t.done() |
| 203 }, "disconnected form should not submit") |
119 </script> | 204 </script> |
OLD | NEW |