summaryrefslogtreecommitdiffstats
path: root/dom/bindings/test/test_promise_rejections_from_jsimplemented.html
blob: 5428030c574a88773cadc5c3af746386e5f90c52 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1107592
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1107592</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript">

  /** Test for Bug 1107592 **/

  SimpleTest.waitForExplicitFinish();

  function checkExn(lineNumber, name, message, code, filename, testNumber, stack, exn) {
    is(exn.lineNumber, lineNumber,
       "Should have the right line number in test " + testNumber);
    is(exn.name, name,
       "Should have the right exception name in test " + testNumber);
    is("filename" in exn ? exn.filename : exn.fileName, filename,
       "Should have the right file name in test " + testNumber);
    is(exn.message, message,
       "Should have the right message in test " + testNumber);
    is(exn.code, code, "Should have the right .code in test " + testNumber);
    if (message === "") {
      is(exn.name, "InternalError",
         "Should have one of our synthetic exceptions in test " + testNumber);
    }
    is(exn.stack, stack, "Should have the right stack in test " + testNumber);
  }

  function ensurePromiseFail(testNumber, value) {
    ok(false, "Test " + testNumber + " should not have a fulfilled promise");
  }

  function doTest() {
    var t = new TestInterfaceJS();
    /* Async parent frames from pushPrefEnv don't show up in e10s.  */
    var isE10S = !SpecialPowers.isMainProcess();
    var asyncStack = SpecialPowers.getBoolPref("javascript.options.asyncstack");
    var ourFile = location.href;
    var unwrapError = "Promise rejection value is a non-unwrappable cross-compartment wrapper.";
    var parentFrame = (asyncStack && !isE10S) ? `Async*@${ourFile}:130:3
` : "";

    Promise.all([
      t.testPromiseWithThrowingChromePromiseInit().then(
          ensurePromiseFail.bind(null, 1),
          checkExn.bind(null, 49, "InternalError", unwrapError,
                        undefined, ourFile, 1,
                        `doTest@${ourFile}:49:7
` +
                        parentFrame)),
      t.testPromiseWithThrowingContentPromiseInit(function() {
          thereIsNoSuchContentFunction1();
        }).then(
          ensurePromiseFail.bind(null, 2),
          checkExn.bind(null, 57, "ReferenceError",
                        "thereIsNoSuchContentFunction1 is not defined",
                        undefined, ourFile, 2,
                        `doTest/<@${ourFile}:57:11
doTest@${ourFile}:56:7
` +
                        parentFrame)),
      t.testPromiseWithThrowingChromeThenFunction().then(
          ensurePromiseFail.bind(null, 3),
          checkExn.bind(null, 0, "InternalError", unwrapError, undefined, "", 3, asyncStack ? (`Async*doTest@${ourFile}:67:7
` +
                        parentFrame) : "")),
      t.testPromiseWithThrowingContentThenFunction(function() {
          thereIsNoSuchContentFunction2();
        }).then(
          ensurePromiseFail.bind(null, 4),
          checkExn.bind(null, 73, "ReferenceError",
                        "thereIsNoSuchContentFunction2 is not defined",
                        undefined, ourFile, 4,
                        `doTest/<@${ourFile}:73:11
` +
                        (asyncStack ? `Async*doTest@${ourFile}:72:7
` : "") +
                        parentFrame)),
      t.testPromiseWithThrowingChromeThenable().then(
          ensurePromiseFail.bind(null, 5),
          checkExn.bind(null, 0, "InternalError", unwrapError, undefined, "", 5, asyncStack ? (`Async*doTest@${ourFile}:84:7
` +
                        parentFrame) : "")),
      t.testPromiseWithThrowingContentThenable({
            then: function() { thereIsNoSuchContentFunction3(); }
        }).then(
          ensurePromiseFail.bind(null, 6),
          checkExn.bind(null, 90, "ReferenceError",
                        "thereIsNoSuchContentFunction3 is not defined",
                        undefined, ourFile, 6,
                        `doTest/<.then@${ourFile}:90:32
` + (asyncStack ? `Async*doTest@${ourFile}:89:7\n` + parentFrame : ""))),
      t.testPromiseWithDOMExceptionThrowingPromiseInit().then(
          ensurePromiseFail.bind(null, 7),
          checkExn.bind(null, 98, "NotFoundError",
                        "We are a second DOMException",
                        DOMException.NOT_FOUND_ERR, ourFile, 7,
                        `doTest@${ourFile}:98:7
` +
                        parentFrame)),
      t.testPromiseWithDOMExceptionThrowingThenFunction().then(
          ensurePromiseFail.bind(null, 8),
          checkExn.bind(null, asyncStack ? 106 : 0, "NetworkError",
                         "We are a third DOMException",
                        DOMException.NETWORK_ERR, asyncStack ? ourFile : "", 8,
                        (asyncStack ? `Async*doTest@${ourFile}:106:7
` +
                         parentFrame : ""))),
      t.testPromiseWithDOMExceptionThrowingThenable().then(
          ensurePromiseFail.bind(null, 9),
          checkExn.bind(null, asyncStack ? 114 : 0, "TypeMismatchError",
                        "We are a fourth DOMException",
                        DOMException.TYPE_MISMATCH_ERR,
                        asyncStack ? ourFile : "", 9,
                        (asyncStack ? `Async*doTest@${ourFile}:114:7
` +
                         parentFrame : ""))),
    ]).then(SimpleTest.finish,
            function(err) {
              ok(false, "One of our catch statements totally failed with err" + err + ', stack: ' + (err ? err.stack : ''));
              SimpleTest.finish();
            });
  }

  SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
                            doTest);
  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1107592">Mozilla Bug 1107592</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>
</body>
</html>