Skip to content

Commit

Permalink
Bug 1764306 [wpt PR 33605] - DOM: Test document.createEvent('toucheve…
Browse files Browse the repository at this point in the history
…nt'), a=testonly

Automatic update from web-platform-tests
DOM: Test document.createEvent('touchevent')

See whatwg/dom#1071

Co-authored-by: Anne van Kesteren <[email protected]>
--

wpt-commits: 75e0de2aa153aea2e31860cd6ec4628b7b673011
wpt-pr: 33605
  • Loading branch information
zcorpan authored and moz-wptsync-bot committed May 15, 2022
1 parent 17e9151 commit fbf27c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
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`);
}
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 fbf27c7

Please sign in to comment.