Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/dom/events/Event-dispatch-click.html

Issue 2446483002: Import wpt@c5a14f553cba5f197743b9af605a84eddd8692a2 (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <title>Synthetic click event "magic"</title>
3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <div id=log></div>
6 <div id=dump style=display:none></div>
7 <script>
8 var dump = document.getElementById("dump")
9
10 async_test(function(t) {
11 var input = document.createElement("input")
12 input.type = "checkbox"
13 dump.appendChild(input)
14 input.onclick = t.step_func_done(function() {
15 assert_true(input.checked)
16 })
17 input.click()
18 }, "basic with click()")
19
20 async_test(function(t) {
21 var input = document.createElement("input")
22 input.type = "checkbox"
23 dump.appendChild(input)
24 input.onclick = t.step_func_done(function() {
25 assert_true(input.checked)
26 })
27 input.dispatchEvent(new MouseEvent("click", {bubbles:true})) // equivalent to the above
28 }, "basic with dispatchEvent()")
29
30 async_test(function(t) {
31 var input = document.createElement("input")
32 input.type = "checkbox"
33 dump.appendChild(input)
34 input.onclick = t.step_func_done(function() {
35 assert_false(input.checked)
36 })
37 input.dispatchEvent(new Event("click", {bubbles:true})) // no MouseEvent
38 }, "basic with wrong event class")
39
40 async_test(function(t) {
41 var input = document.createElement("input")
42 input.type = "checkbox"
43 dump.appendChild(input)
44 var child = input.appendChild(new Text("does not matter"))
45 child.dispatchEvent(new MouseEvent("click")) // does not bubble
46 assert_false(input.checked)
47 t.done()
48 }, "look at parents only when event bubbles")
49
50 async_test(function(t) {
51 var input = document.createElement("input")
52 input.type = "checkbox"
53 dump.appendChild(input)
54 input.onclick = t.step_func_done(function() {
55 assert_true(input.checked)
56 })
57 var child = input.appendChild(new Text("does not matter"))
58 child.dispatchEvent(new MouseEvent("click", {bubbles:true}))
59 }, "look at parents when event bubbles")
60
61 async_test(function(t) {
62 var input = document.createElement("input")
63 input.type = "checkbox"
64 dump.appendChild(input)
65 input.onclick = t.step_func(function() {
66 assert_false(input.checked, "input pre-click must not be triggered")
67 })
68 var child = input.appendChild(document.createElement("input"))
69 child.type = "checkbox"
70 child.onclick = t.step_func(function() {
71 assert_true(input.checked, "child pre-click must be triggered")
72 })
73 child.dispatchEvent(new MouseEvent("click", {bubbles:true}))
74 t.done()
75 }, "pick the first with activation behavior <input type=checkbox>")
76
77 var globalCounter = 0 // sorry
78 async_test(function(t) { // as above with <a>
79 var i = 0
80 var link = document.createElement("a")
81 link.href = "javascript:globalCounter--" // must not be triggered
82 dump.appendChild(link)
83 var child = link.appendChild(document.createElement("a"))
84 child.href = "javascript:globalCounter++"
85 child.dispatchEvent(new MouseEvent("click", {bubbles:true}))
86 assert_equals(globalCounter, 1)
87 t.done()
88 }, "pick the first with activation behavior <a href>")
89
90 async_test(function(t) {
91 var input = document.createElement("input")
92 input.type = "checkbox"
93 dump.appendChild(input)
94 var clickEvent = new MouseEvent("click")
95 input.onchange = t.step_func_done(function() {
96 assert_false(clickEvent.defaultPrevented)
97 assert_equals(clickEvent.eventPhase, 0)
98 assert_equals(clickEvent.currentTarget, null)
99 assert_equals(clickEvent.target, input)
100 assert_equals(clickEvent.composedPath().length, 0)
101 })
102 input.dispatchEvent(clickEvent)
103 }, "event state during post-click handling")
104
105 async_test(function(t) {
106 var input = document.createElement("input")
107 input.type = "checkbox"
108 dump.appendChild(input)
109 var clickEvent = new MouseEvent("click")
110 var finalTarget = document.createElement("doesnotmatter")
111 finalTarget.onclick = t.step_func_done(function() {
112 assert_equals(clickEvent.target, finalTarget)
113 })
114 input.onchange = t.step_func(function() {
115 finalTarget.dispatchEvent(clickEvent)
116 })
117 input.dispatchEvent(clickEvent)
118 }, "redispatch during post-click handling")
119 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698