Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: run html/webappapis/timers WPT #25618

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:[email protected]">
<link rel="author" title="Ms2ger" href="mailto:[email protected]">
<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>
<script>
var interval;
function next() {
clearInterval(interval);
done();
}
interval = setInterval(next, Math.pow(2, 32));
setTimeout(assert_unreached, 100);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!doctype html>
<title>Type long timeout for setTimeout</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setTimeout(done, Math.pow(2, 32));
setTimeout(assert_unreached, 100);
</script>
4 changes: 4 additions & 0 deletions test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
"html/webappapis/microtask-queuing": {
"commit": "0c3bed38df6d9dcd1441873728fb5c1bb59c92df",
"path": "html/webappapis/microtask-queuing"
},
"html/webappapis/timers": {
"commit": "ddfe9c089bab565a9d3aa37bdef63d8012c1a94c",
"path": "html/webappapis/timers"
}
}
1 change: 1 addition & 0 deletions test/wpt/status/html/webappapis/timers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
18 changes: 18 additions & 0 deletions test/wpt/test-timers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

// Flags: --expose-internals

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('html/webappapis/timers');

// Copy global descriptors from the global object
runner.copyGlobalsFromObject(global, [
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout'
]);

runner.runJsTests();