• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1test(t => {
2  const c = new AbortController(),
3        s = c.signal;
4  let state = "begin";
5
6  assert_false(s.aborted);
7
8  s.addEventListener("abort",
9    t.step_func(e => {
10      assert_equals(state, "begin");
11      state = "aborted";
12    })
13  );
14  c.abort();
15
16  assert_equals(state, "aborted");
17  assert_true(s.aborted);
18
19  c.abort();
20}, "AbortController abort() should fire event synchronously");
21
22test(t => {
23  const controller = new AbortController();
24  const signal = controller.signal;
25  assert_equals(controller.signal, signal,
26                "value of controller.signal should not have changed");
27  controller.abort();
28  assert_equals(controller.signal, signal,
29                "value of controller.signal should still not have changed");
30}, "controller.signal should always return the same object");
31
32test(t => {
33  const controller = new AbortController();
34  const signal = controller.signal;
35  let eventCount = 0;
36  signal.onabort = () => {
37    ++eventCount;
38  };
39  controller.abort();
40  assert_true(signal.aborted);
41  assert_equals(eventCount, 1, "event handler should have been called once");
42  controller.abort();
43  assert_true(signal.aborted);
44  assert_equals(eventCount, 1,
45                "event handler should not have been called again");
46}, "controller.abort() should do nothing the second time it is called");
47
48test(t => {
49  const controller = new AbortController();
50  controller.abort();
51  controller.signal.onabort =
52      t.unreached_func("event handler should not be called");
53}, "event handler should not be called if added after controller.abort()");
54
55test(t => {
56  const controller = new AbortController();
57  const signal = controller.signal;
58  signal.onabort = t.step_func(e => {
59    assert_equals(e.type, "abort", "event type should be abort");
60    assert_equals(e.target, signal, "event target should be signal");
61    assert_false(e.bubbles, "event should not bubble");
62    assert_true(e.isTrusted, "event should be trusted");
63  });
64  controller.abort();
65}, "the abort event should have the right properties");
66
67test(t => {
68  const signal = AbortSignal.abort();
69  assert_true(signal.aborted);
70}, "the AbortSignal.abort() static returns an already aborted signal");
71
72done();
73