File: unhandled-rejection.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (109 lines) | stat: -rw-r--r-- 3,464 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html>
<title>View transitions: test unhandled promise rejection</title>
<link rel="help" href="https://www.w3.org/TR/css-view-transitions-1/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<style>
  ::view-transition-group(*) {
    animation-duration: 0s;
  }
</style>
<script>
"use strict";

// This is required to prevent the test harness from failing the test
// when the unhandled promise rejection occurs.
setup({ allow_uncaught_exception: true });

function unhandledRejectionPromise(test, view_transition, promise_name) {
  return new Promise(resolve => {
    const event_type = 'unhandledrejection';
    const listener = e => {
      if (e.promise == view_transition[promise_name]) {
        // Suppress console warning.
        e.preventDefault();
        window.removeEventListener(event_type, listener);
        resolve(e.reason);
      }
    };
    window.addEventListener(event_type, listener);
    test.add_cleanup(() => {
      window.removeEventListener(event_type, listener);
    });
  });
}

promise_test(async t => {
  const vt1 = document.startViewTransition({});
  const vt2 = document.startViewTransition({});
  await promise_rejects_dom(t, "AbortError", vt1.ready);
  await vt1.finished;
  await vt2.finished;
}, 'Reject ready promise due to skipping a view-transition with an AbortError');

promise_test(async t => {
  const vt1 = document.startViewTransition({});
  const unhandled_rejection = unhandledRejectionPromise(t, vt1, 'ready');
  const vt2 = document.startViewTransition({});
  const reason = await unhandled_rejection;
  assert_true(reason instanceof DOMException,
              'expect unhandled rejection to throw a DOMException');
  await vt1.finished;
  await vt2.finished;
}, 'Unhandled rejection of ready promise due to skipping a view-transition ' +
   'throws an DOMException');

promise_test(async t => {
  const vt = document.startViewTransition(() => {
    return Promise.reject("callback_rejection");
  });

  const unhandled_callback_rejection =
      unhandledRejectionPromise(t, vt, 'updateCallbackDone');
  const unhandled_ready_rejection =
      unhandledRejectionPromise(t, vt, 'ready');
  const unhandled_finished_rejection =
      unhandledRejectionPromise(t, vt, 'finished');

  const results = await Promise.all([
    unhandled_callback_rejection,
    unhandled_ready_rejection,
    unhandled_finished_rejection
  ]);

  assert_array_equals(
      results,
      [
        "callback_rejection",
        "callback_rejection",
        "callback_rejection"
      ]);
}, 'If the promise returned by updateCallback rejects, the transition is ' +
   'skipped.');


promise_test(async t => {
  const vt = document.startViewTransition(() => { foo.bar = baz; });

  const unhandled_callback_rejection =
      unhandledRejectionPromise(t, vt, 'updateCallbackDone');
  const unhandled_ready_rejection =
      unhandledRejectionPromise(t, vt, 'ready');
  const unhandled_finished_rejection =
      unhandledRejectionPromise(t, vt, 'finished');

  const results = await Promise.all([
    unhandled_callback_rejection,
    unhandled_ready_rejection,
    unhandled_finished_rejection
  ]);

  for (let i = 0; i < 2; i++) {
    assert_true(results[i] instanceof ReferenceError);
  }
}, 'Reference error in callback triggers rejection of view-transition ' +
   'promises');
</script>
</html>