1test(t => { 2 const signal = AbortSignal.abort(); 3 assert_true(signal instanceof AbortSignal, "returned object is an AbortSignal"); 4 assert_true(signal.aborted, "returned signal is already aborted"); 5}, "the AbortSignal.abort() static returns an already aborted signal"); 6 7async_test(t => { 8 const s = AbortSignal.abort(); 9 s.addEventListener("abort", t.unreached_func("abort event listener called")); 10 s.onabort = t.unreached_func("abort event handler called"); 11 t.step_timeout(() => { t.done(); }, 2000); 12}, "signal returned by AbortSignal.abort() should not fire abort event"); 13 14test(t => { 15 const signal = AbortSignal.timeout(0); 16 assert_true(signal instanceof AbortSignal, "returned object is an AbortSignal"); 17 assert_false(signal.aborted, "returned signal is not already aborted"); 18}, "AbortSignal.timeout() returns a non-aborted signal"); 19 20async_test(t => { 21 const signal = AbortSignal.timeout(5); 22 signal.onabort = t.step_func_done(() => { 23 assert_true(signal.aborted, "signal is aborted"); 24 assert_true(signal.reason instanceof DOMException, "signal.reason is a DOMException"); 25 assert_equals(signal.reason.name, "TimeoutError", "signal.reason is a TimeoutError"); 26 }); 27}, "Signal returned by AbortSignal.timeout() times out"); 28 29async_test(t => { 30 let result = ""; 31 for (const value of ["1", "2", "3"]) { 32 const signal = AbortSignal.timeout(5); 33 signal.onabort = t.step_func(() => { result += value; }); 34 } 35 36 const signal = AbortSignal.timeout(5); 37 signal.onabort = t.step_func_done(() => { 38 assert_equals(result, "123", "Timeout order should be 123"); 39 }); 40}, "AbortSignal timeouts fire in order"); 41