Skip to content

Commit 5792208

Browse files
joyeecheungaddaleax
authored andcommitted
test: pull html/webappapis/timers WPT
Using ``` git node wpt html/webappapis/timers ``` PR-URL: #25618 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 25c19eb commit 5792208

8 files changed

+108
-0
lines changed

test/fixtures/wpt/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Last update:
1616
- resources: https://github.com/web-platform-tests/wpt/tree/679a364421/resources
1717
- interfaces: https://github.com/web-platform-tests/wpt/tree/712c9f275e/interfaces
1818
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/0c3bed38df/html/webappapis/microtask-queuing
19+
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/ddfe9c089b/html/webappapis/timers
1920

2021
[Web Platform Tests]: https://github.com/web-platform-tests/wpt
2122
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!doctype html>
2+
<title>Interaction of setTimeout and WebIDL</title>
3+
<link rel="author" title="Ian Hickson" href="mailto:ian@hixie.ch">
4+
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
5+
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout">
6+
<link rel="help" href="https://heycam.github.io/webidl/#es-operations">
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
<div id="log"></div>
10+
<script>
11+
var t = async_test()
12+
function finishTest() {
13+
assert_equals(log, "ONE TWO ")
14+
t.done()
15+
}
16+
var log = '';
17+
function logger(s) { log += s + ' '; }
18+
19+
setTimeout({ toString: function () {
20+
setTimeout("logger('ONE')", 100);
21+
return "logger('TWO'); t.step(finishTest)";
22+
} }, 100);
23+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function timeout_trampoline(t, timeout, message) {
2+
t.step_timeout(function() {
3+
// Yield in case we managed to be called before the second interval callback.
4+
t.step_timeout(function() {
5+
assert_unreached(message);
6+
}, timeout);
7+
}, timeout);
8+
}
9+
10+
async_test(function(t) {
11+
let ctr = 0;
12+
let h = setInterval(t.step_func(function() {
13+
if (++ctr == 2) {
14+
clearInterval(h);
15+
t.done();
16+
return;
17+
}
18+
}) /* no interval */);
19+
20+
timeout_trampoline(t, 100, "Expected setInterval callback to be called two times");
21+
}, "Calling setInterval with no interval should be the same as if called with 0 interval");
22+
23+
async_test(function(t) {
24+
let ctr = 0;
25+
let h = setInterval(t.step_func(function() {
26+
if (++ctr == 2) {
27+
clearInterval(h);
28+
t.done();
29+
return;
30+
}
31+
}), undefined);
32+
33+
timeout_trampoline(t, 100, "Expected setInterval callback to be called two times");
34+
}, "Calling setInterval with undefined interval should be the same as if called with 0 interval");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<title>Negative timeout in setInterval</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script>
6+
var i = 0;
7+
var interval;
8+
function next() {
9+
i++;
10+
if (i === 20) {
11+
clearInterval(interval);
12+
done();
13+
}
14+
}
15+
setTimeout(assert_unreached, 1000);
16+
interval = setInterval(next, -100);
17+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!doctype html>
2+
<title>Negative timeout in setTimeout</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script>
6+
setTimeout(done, -100);
7+
setTimeout(assert_unreached, 10);
8+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<title>Type long timeout for setInterval</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script>
6+
var interval;
7+
function next() {
8+
clearInterval(interval);
9+
done();
10+
}
11+
interval = setInterval(next, Math.pow(2, 32));
12+
setTimeout(assert_unreached, 100);
13+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!doctype html>
2+
<title>Type long timeout for setTimeout</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script>
6+
setTimeout(done, Math.pow(2, 32));
7+
setTimeout(assert_unreached, 100);
8+
</script>

test/fixtures/wpt/versions.json

+4
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@
2222
"html/webappapis/microtask-queuing": {
2323
"commit": "0c3bed38df6d9dcd1441873728fb5c1bb59c92df",
2424
"path": "html/webappapis/microtask-queuing"
25+
},
26+
"html/webappapis/timers": {
27+
"commit": "ddfe9c089bab565a9d3aa37bdef63d8012c1a94c",
28+
"path": "html/webappapis/timers"
2529
}
2630
}

0 commit comments

Comments
 (0)