Skip to content

Commit

Permalink
DOM: Test document.createEvent('touchevent')
Browse files Browse the repository at this point in the history
See whatwg/dom#1071

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
  • Loading branch information
2 people authored and DanielRyanSmith committed Apr 27, 2022
1 parent bd96e09 commit 016db52
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
12 changes: 12 additions & 0 deletions dom/nodes/Document-createEvent-touchevent.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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);
// The interface and other details of the event is tested in Document-createEvent.https.html
}
}, `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'");
}
}
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 016db52

Please sign in to comment.