-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synthetic click events and event dispatch #3974
Merged
+119
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<!doctype html> | ||
<title>Synthetic click event "magic"</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id=log></div> | ||
<div id=dump style=display:none></div> | ||
<script> | ||
var dump = document.getElementById("dump") | ||
|
||
async_test(function(t) { | ||
var input = document.createElement("input") | ||
input.type = "checkbox" | ||
dump.appendChild(input) | ||
input.onclick = t.step_func_done(function() { | ||
assert_true(input.checked) | ||
}) | ||
input.click() | ||
}, "basic with click()") | ||
|
||
async_test(function(t) { | ||
var input = document.createElement("input") | ||
input.type = "checkbox" | ||
dump.appendChild(input) | ||
input.onclick = t.step_func_done(function() { | ||
assert_true(input.checked) | ||
}) | ||
input.dispatchEvent(new MouseEvent("click", {bubbles:true})) // equivalent to the above | ||
}, "basic with dispatchEvent()") | ||
|
||
async_test(function(t) { | ||
var input = document.createElement("input") | ||
input.type = "checkbox" | ||
dump.appendChild(input) | ||
input.onclick = t.step_func_done(function() { | ||
assert_false(input.checked) | ||
}) | ||
input.dispatchEvent(new Event("click", {bubbles:true})) // no MouseEvent | ||
}, "basic with wrong event class") | ||
|
||
async_test(function(t) { | ||
var input = document.createElement("input") | ||
input.type = "checkbox" | ||
dump.appendChild(input) | ||
var child = input.appendChild(new Text("does not matter")) | ||
child.dispatchEvent(new MouseEvent("click")) // does not bubble | ||
assert_false(input.checked) | ||
t.done() | ||
}, "look at parents only when event bubbles") | ||
|
||
async_test(function(t) { | ||
var input = document.createElement("input") | ||
input.type = "checkbox" | ||
dump.appendChild(input) | ||
input.onclick = t.step_func_done(function() { | ||
assert_true(input.checked) | ||
}) | ||
var child = input.appendChild(new Text("does not matter")) | ||
child.dispatchEvent(new MouseEvent("click", {bubbles:true})) | ||
}, "look at parents when event bubbles") | ||
|
||
async_test(function(t) { | ||
var input = document.createElement("input") | ||
input.type = "checkbox" | ||
dump.appendChild(input) | ||
input.onclick = t.step_func(function() { | ||
assert_false(input.checked, "input pre-click must not be triggered") | ||
}) | ||
var child = input.appendChild(document.createElement("input")) | ||
child.type = "checkbox" | ||
child.onclick = t.step_func(function() { | ||
assert_true(input.checked, "child pre-click must be triggered") | ||
}) | ||
child.dispatchEvent(new MouseEvent("click", {bubbles:true})) | ||
t.done() | ||
}, "pick the first with activation behavior <input type=checkbox>") | ||
|
||
var globalCounter = 0 // sorry | ||
async_test(function(t) { // as above with <a> | ||
var i = 0 | ||
var link = document.createElement("a") | ||
link.href = "javascript:globalCounter--" // must not be triggered | ||
dump.appendChild(link) | ||
var child = link.appendChild(document.createElement("a")) | ||
child.href = "javascript:globalCounter++" | ||
child.dispatchEvent(new MouseEvent("click", {bubbles:true})) | ||
assert_equals(globalCounter, 1) | ||
t.done() | ||
}, "pick the first with activation behavior <a href>") | ||
|
||
async_test(function(t) { | ||
var input = document.createElement("input") | ||
input.type = "checkbox" | ||
dump.appendChild(input) | ||
var clickEvent = new MouseEvent("click") | ||
input.onchange = t.step_func_done(function() { | ||
assert_false(clickEvent.defaultPrevented) | ||
assert_equals(clickEvent.eventPhase, 0) | ||
assert_equals(clickEvent.currentTarget, null) | ||
assert_equals(clickEvent.target, input) | ||
assert_equals(clickEvent.composedPath().length, 0) | ||
}) | ||
input.dispatchEvent(clickEvent) | ||
}, "event state during post-click handling") | ||
|
||
async_test(function(t) { | ||
var input = document.createElement("input") | ||
input.type = "checkbox" | ||
dump.appendChild(input) | ||
var clickEvent = new MouseEvent("click") | ||
var finalTarget = document.createElement("doesnotmatter") | ||
finalTarget.onclick = t.step_func_done(function() { | ||
assert_equals(clickEvent.target, finalTarget) | ||
}) | ||
input.onchange = t.step_func(function() { | ||
finalTarget.dispatchEvent(clickEvent) | ||
}) | ||
input.dispatchEvent(clickEvent) | ||
}, "redispatch during post-click handling") | ||
</script> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a blank line between tests