Skip to content

Commit

Permalink
DOM: Test document.createEvent('touchevent')
Browse files Browse the repository at this point in the history
  • Loading branch information
zcorpan committed Apr 12, 2022
1 parent e82768c commit a1c8073
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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);
}
}, `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");
}
}
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

0 comments on commit a1c8073

Please sign in to comment.