Skip to content

Commit 75e0de2

Browse files
zcorpanannevk
andauthored
DOM: Test document.createEvent('touchevent')
See whatwg/dom#1071 Co-authored-by: Anne van Kesteren <[email protected]>
1 parent fbee830 commit 75e0de2

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
for (const variant of ['TouchEvent', 'touchevent', 'TOUCHEVENT']) {
2+
test(() => {
3+
if (!('ontouchstart' in document)) {
4+
assert_throws_dom("NOT_SUPPORTED_ERR", () => {
5+
document.createEvent(variant);
6+
});
7+
} else {
8+
document.createEvent(variant);
9+
// The interface and other details of the event is tested in Document-createEvent.https.html
10+
}
11+
}, `document.createEvent('${variant}') should throw if 'expose legacy touch event APIs' is false`);
12+
}

dom/nodes/Document-createEvent.https.html

+13-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
<script src="Document-createEvent.js"></script>
88
<div id="log"></div>
99
<script>
10-
function testAlias(arg, iface) {
10+
function supportsTouchEvents(isTouchEvent) {
11+
if (isTouchEvent) {
12+
assert_implements_optional('ontouchstart' in document, "'expose legacy touch event APIs'");
13+
}
14+
}
15+
function testAlias(arg, iface, isTouchEvent) {
1116
var ev;
1217
test(function() {
18+
supportsTouchEvents(isTouchEvent);
1319
ev = document.createEvent(arg);
1420
assert_equals(Object.getPrototypeOf(ev), window[iface].prototype);
1521
}, arg + " should be an alias for " + iface + ".");
1622
test(function() {
23+
supportsTouchEvents(isTouchEvent);
1724
assert_equals(ev.type, "",
1825
"type should be initialized to the empty string");
1926
assert_equals(ev.target, null,
@@ -32,11 +39,13 @@
3239
"isTrusted should be initialized to false");
3340
}, "createEvent('" + arg + "') should be initialized correctly.");
3441
}
42+
aliases.TouchEvent = 'TouchEvent';
3543
for (var alias in aliases) {
44+
var isTouchEvent = alias === 'TouchEvent';
3645
var iface = aliases[alias];
37-
testAlias(alias, iface);
38-
testAlias(alias.toLowerCase(), iface);
39-
testAlias(alias.toUpperCase(), iface);
46+
testAlias(alias, iface, isTouchEvent);
47+
testAlias(alias.toLowerCase(), iface, isTouchEvent);
48+
testAlias(alias.toUpperCase(), iface, isTouchEvent);
4049

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

0 commit comments

Comments
 (0)