Skip to content
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

DOM: Test document.createEvent('touchevent') #33605

Merged
merged 3 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dom/nodes/Document-createEvent-touchevent.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
for (const variant of ['TouchEvent', 'touchevent', 'TOUCHEVENT']) {
test(() => {
if (!('ontouchstart' in document)) {
assert_throws_dom("NOT_SUPPORTED_ERR", () => {
document.createEvent(variant);
});
} else {
document.createEvent(variant);
zcorpan marked this conversation as resolved.
Show resolved Hide resolved
}
}, `document.createEvent('${variant}') should throw if 'expose legacy touch event APIs' is false`);
}
17 changes: 13 additions & 4 deletions dom/nodes/Document-createEvent.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
<script src="Document-createEvent.js"></script>
<div id="log"></div>
<script>
function testAlias(arg, iface) {
function supportsTouchEvents(isTouchEvent) {
if (isTouchEvent) {
assert_implements_optional('ontouchstart' in document, "'expose legacy touch event APIs' is false");
zcorpan marked this conversation as resolved.
Show resolved Hide resolved
}
}
function testAlias(arg, iface, isTouchEvent) {
var ev;
test(function() {
supportsTouchEvents(isTouchEvent);
ev = document.createEvent(arg);
assert_equals(Object.getPrototypeOf(ev), window[iface].prototype);
}, arg + " should be an alias for " + iface + ".");
test(function() {
supportsTouchEvents(isTouchEvent);
assert_equals(ev.type, "",
"type should be initialized to the empty string");
assert_equals(ev.target, null,
Expand All @@ -32,11 +39,13 @@
"isTrusted should be initialized to false");
}, "createEvent('" + arg + "') should be initialized correctly.");
}
aliases.TouchEvent = 'TouchEvent';
for (var alias in aliases) {
var isTouchEvent = alias === 'TouchEvent';
var iface = aliases[alias];
testAlias(alias, iface);
testAlias(alias.toLowerCase(), iface);
testAlias(alias.toUpperCase(), iface);
testAlias(alias, iface, isTouchEvent);
testAlias(alias.toLowerCase(), iface, isTouchEvent);
testAlias(alias.toUpperCase(), iface, isTouchEvent);

if (alias[alias.length - 1] != "s") {
var plural = alias + "s";
Expand Down