diff --git a/dom/abort/AbortSignal.any.js b/dom/abort/AbortSignal.any.js index 1d7d7678eb1a6e2..3bbdc11a92f90d4 100644 --- a/dom/abort/AbortSignal.any.js +++ b/dom/abort/AbortSignal.any.js @@ -10,3 +10,31 @@ async_test(t => { s.onabort = t.unreached_func("abort event handler called"); t.step_timeout(() => { t.done(); }, 2000); }, "signal returned by AbortSignal.abort() should not fire abort event"); + +test(t => { + const signal = AbortSignal.timeout(0); + assert_true(signal instanceof AbortSignal, "returned object is an AbortSignal"); + assert_false(signal.aborted, "returned signal is not already aborted"); +}, "AbortSignal.timeout() returns a non-aborted signal"); + +async_test(t => { + const signal = AbortSignal.timeout(5); + signal.onabort = t.step_func_done(() => { + assert_true(signal.aborted, "signal is aborted"); + assert_true(signal.reason instanceof DOMException, "signal.reason is a DOMException"); + assert_equals(signal.reason.name, "TimeoutError", "signal.reason is a TimeoutError"); + }); +}, "Signal returned by AbortSignal.timeout() times out"); + +async_test(t => { + let result = ""; + for (const value of ["1", "2", "3"]) { + const signal = AbortSignal.timeout(5); + signal.onabort = t.step_func(() => { result += value; }); + } + + const signal = AbortSignal.timeout(5); + signal.onabort = t.step_func_done(() => { + assert_equals(result, "123", "Timeout order should be 123"); + }); +}, "AbortSignal timeouts fire in order"); diff --git a/dom/abort/abort-signal-timeout.html b/dom/abort/abort-signal-timeout.html new file mode 100644 index 000000000000000..2a9c13d61434b43 --- /dev/null +++ b/dom/abort/abort-signal-timeout.html @@ -0,0 +1,19 @@ + + +