diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/html/webappapis/timers | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/webappapis/timers')
10 files changed, 180 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/webappapis/timers/clearinterval-from-callback.any.js b/testing/web-platform/tests/html/webappapis/timers/clearinterval-from-callback.any.js new file mode 100644 index 0000000000..bf4eb7cf5a --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/clearinterval-from-callback.any.js @@ -0,0 +1,19 @@ +async_test((t) => { + let wasPreviouslyCalled = false; + + const handle = setInterval( + t.step_func(() => { + if (!wasPreviouslyCalled) { + wasPreviouslyCalled = true; + + clearInterval(handle); + + // Make the test succeed after the callback would've run next. + setInterval(t.step_func_done(), 750); + } else { + assert_unreached(); + } + }), + 500 + ); +}, "Clearing an interval from the callback should still clear it."); diff --git a/testing/web-platform/tests/html/webappapis/timers/cleartimeout-clearinterval.any.js b/testing/web-platform/tests/html/webappapis/timers/cleartimeout-clearinterval.any.js new file mode 100644 index 0000000000..44551aa8a1 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/cleartimeout-clearinterval.any.js @@ -0,0 +1,29 @@ +async_test((t) => { + const handle = setTimeout( + t.step_func(() => { + assert_unreached("Timeout was not canceled"); + }), + 0 + ); + + clearInterval(handle); + + setTimeout(() => { + t.done(); + }, 100); +}, "Clear timeout with clearInterval"); + +async_test((t) => { + const handle = setInterval( + t.step_func(() => { + assert_unreached("Interval was not canceled"); + }), + 0 + ); + + clearTimeout(handle); + + setTimeout(() => { + t.done(); + }, 100); +}, "Clear interval with clearTimeout"); diff --git a/testing/web-platform/tests/html/webappapis/timers/evil-spec-example.any.js b/testing/web-platform/tests/html/webappapis/timers/evil-spec-example.any.js new file mode 100644 index 0000000000..17215e218a --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/evil-spec-example.any.js @@ -0,0 +1,12 @@ +var t = async_test("Interaction of setTimeout and WebIDL") +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); diff --git a/testing/web-platform/tests/html/webappapis/timers/missing-timeout-setinterval.any.js b/testing/web-platform/tests/html/webappapis/timers/missing-timeout-setinterval.any.js new file mode 100644 index 0000000000..33a1cc073c --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/missing-timeout-setinterval.any.js @@ -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"); diff --git a/testing/web-platform/tests/html/webappapis/timers/negative-setinterval.any.js b/testing/web-platform/tests/html/webappapis/timers/negative-setinterval.any.js new file mode 100644 index 0000000000..5646140c2a --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/negative-setinterval.any.js @@ -0,0 +1,12 @@ +setup({ single_test: true }); +var i = 0; +var interval; +function next() { + i++; + if (i === 20) { + clearInterval(interval); + done(); + } +} +setTimeout(assert_unreached, 1000); +interval = setInterval(next, -100); diff --git a/testing/web-platform/tests/html/webappapis/timers/negative-settimeout.any.js b/testing/web-platform/tests/html/webappapis/timers/negative-settimeout.any.js new file mode 100644 index 0000000000..da191f1bf0 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/negative-settimeout.any.js @@ -0,0 +1,3 @@ +setup({ single_test: true }); +setTimeout(done, -100); +setTimeout(assert_unreached, 10); diff --git a/testing/web-platform/tests/html/webappapis/timers/setinterval-cross-realm-callback-report-exception.html b/testing/web-platform/tests/html/webappapis/timers/setinterval-cross-realm-callback-report-exception.html new file mode 100644 index 0000000000..4a780fc932 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/setinterval-cross-realm-callback-report-exception.html @@ -0,0 +1,32 @@ +<!doctype html> +<meta charset=utf-8> +<title>window.setInterval() reports the exception from its callback in the callback's global object</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<iframe></iframe> +<iframe></iframe> +<iframe></iframe> +<script> +setup({ allow_uncaught_exception: true }); + +const onerrorCalls = []; +window.onerror = () => { onerrorCalls.push("top"); }; +frames[0].onerror = () => { onerrorCalls.push("frame0"); }; +frames[1].onerror = () => { onerrorCalls.push("frame1"); }; +frames[2].onerror = () => { onerrorCalls.push("frame2"); }; + +async_test(t => { + window.onload = t.step_func(() => { + const id = frames[0].setInterval(new frames[1].Function(` + parent.clearThisInterval(); + throw new parent.frames[2].Error("PASS"); + `), 4); + window.clearThisInterval = () => { frames[0].clearInterval(id); }; + + t.step_timeout(() => { + assert_array_equals(onerrorCalls, ["frame1"]); + t.done(); + }, 8); + }); +}); +</script> diff --git a/testing/web-platform/tests/html/webappapis/timers/settimeout-cross-realm-callback-report-exception.html b/testing/web-platform/tests/html/webappapis/timers/settimeout-cross-realm-callback-report-exception.html new file mode 100644 index 0000000000..b4860151a6 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/settimeout-cross-realm-callback-report-exception.html @@ -0,0 +1,28 @@ +<!doctype html> +<meta charset=utf-8> +<title>window.setTimeout() reports the exception from its callback in the callback's global object</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<iframe></iframe> +<iframe></iframe> +<iframe></iframe> +<script> +setup({ allow_uncaught_exception: true }); + +const onerrorCalls = []; +window.onerror = () => { onerrorCalls.push("top"); }; +frames[0].onerror = () => { onerrorCalls.push("frame0"); }; +frames[1].onerror = () => { onerrorCalls.push("frame1"); }; +frames[2].onerror = () => { onerrorCalls.push("frame2"); }; + +async_test(t => { + window.onload = t.step_func(() => { + frames[0].setTimeout(new frames[1].Function(`throw new parent.frames[2].Error("PASS");`), 4); + + t.step_timeout(() => { + assert_array_equals(onerrorCalls, ["frame1"]); + t.done(); + }, 8); + }); +}); +</script> diff --git a/testing/web-platform/tests/html/webappapis/timers/type-long-setinterval.any.js b/testing/web-platform/tests/html/webappapis/timers/type-long-setinterval.any.js new file mode 100644 index 0000000000..164527f18b --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/type-long-setinterval.any.js @@ -0,0 +1,8 @@ +setup({ single_test: true }); +var interval; +function next() { + clearInterval(interval); + done(); +} +interval = setInterval(next, Math.pow(2, 32)); +setTimeout(assert_unreached, 100); diff --git a/testing/web-platform/tests/html/webappapis/timers/type-long-settimeout.any.js b/testing/web-platform/tests/html/webappapis/timers/type-long-settimeout.any.js new file mode 100644 index 0000000000..9092f13f3b --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/timers/type-long-settimeout.any.js @@ -0,0 +1,3 @@ +setup({ single_test: true }); +setTimeout(done, Math.pow(2, 32)); +setTimeout(assert_unreached, 100); |