Skip to content

Commit

Permalink
test: pull html/webappapis/timers WPT
Browse files Browse the repository at this point in the history
Using

```
git node wpt html/webappapis/timers
```

PR-URL: #25618
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung authored and addaleax committed Feb 1, 2019
1 parent 25c19eb commit 5792208
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Last update:
- resources: https://github.com/web-platform-tests/wpt/tree/679a364421/resources
- interfaces: https://github.com/web-platform-tests/wpt/tree/712c9f275e/interfaces
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/0c3bed38df/html/webappapis/microtask-queuing
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/ddfe9c089b/html/webappapis/timers

[Web Platform Tests]: https://github.com/web-platform-tests/wpt
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt
23 changes: 23 additions & 0 deletions test/fixtures/wpt/html/webappapis/timers/evil-spec-example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!doctype html>
<title>Interaction of setTimeout and WebIDL</title>
<link rel="author" title="Ian Hickson" href="mailto:ian@hixie.ch">
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout">
<link rel="help" href="https://heycam.github.io/webidl/#es-operations">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test()
function finishTest() {
assert_equals(log, "ONE TWO ")
t.done()
}
var log = '';
function logger(s) { log += s + ' '; }

setTimeout({ toString: function () {
setTimeout("logger('ONE')", 100);
return "logger('TWO'); t.step(finishTest)";
} }, 100);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function timeout_trampoline(t, timeout, message) {
t.step_timeout(function() {
// Yield in case we managed to be called before the second interval callback.
t.step_timeout(function() {
assert_unreached(message);
}, timeout);
}, timeout);
}

async_test(function(t) {
let ctr = 0;
let h = setInterval(t.step_func(function() {
if (++ctr == 2) {
clearInterval(h);
t.done();
return;
}
}) /* no interval */);

timeout_trampoline(t, 100, "Expected setInterval callback to be called two times");
}, "Calling setInterval with no interval should be the same as if called with 0 interval");

async_test(function(t) {
let ctr = 0;
let h = setInterval(t.step_func(function() {
if (++ctr == 2) {
clearInterval(h);
t.done();
return;
}
}), undefined);

timeout_trampoline(t, 100, "Expected setInterval callback to be called two times");
}, "Calling setInterval with undefined interval should be the same as if called with 0 interval");
17 changes: 17 additions & 0 deletions test/fixtures/wpt/html/webappapis/timers/negative-setinterval.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<title>Negative timeout in setInterval</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
var i = 0;
var interval;
function next() {
i++;
if (i === 20) {
clearInterval(interval);
done();
}
}
setTimeout(assert_unreached, 1000);
interval = setInterval(next, -100);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!doctype html>
<title>Negative timeout in setTimeout</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setTimeout(done, -100);
setTimeout(assert_unreached, 10);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<title>Type long timeout for setInterval</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>