Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / bindings / test / test_large_arraybuffers.html
blob64f6fc7276c3a9c596d2335a9f157fbf08d20b66
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=1688616
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for large ArrayBuffers and views</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1688616">Mozilla Bug 1688616</a>
14 <p id="display"></p>
15 <div id="content" style="display: none">
17 </div>
18 <pre id="test">
19 </pre>
20 <script type="application/javascript">
21 /* global TestFunctions */
23 SimpleTest.waitForExplicitFinish();
24 SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]}, go);
26 function checkThrowsTooLarge(f) {
27 let ex;
28 try{
29 f();
30 ok(false, "Should have thrown!");
31 } catch (e) {
32 ex = e;
34 ok(ex.toString().includes("larger than 2 GB"), "Got exception: " + ex);
37 function go() {
38 let test = new TestFunctions();
40 const gb = 1 * 1024 * 1024 * 1024;
41 let ab = new ArrayBuffer(5 * gb);
42 checkThrowsTooLarge(() => test.testNotAllowShared(ab));
43 checkThrowsTooLarge(() => test.testAllowShared(ab));
44 checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBuffer: ab}));
45 checkThrowsTooLarge(() => test.testUnionOfBuffferSource(ab));
46 checkThrowsTooLarge(() => { test.arrayBuffer = ab; });
47 checkThrowsTooLarge(() => { test.allowSharedArrayBuffer = ab; });
48 checkThrowsTooLarge(() => { test.sequenceOfArrayBuffer = [ab]; });
49 checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBuffer = [ab]; });
51 let ta = new Int8Array(ab, 0, 3 * gb);
52 checkThrowsTooLarge(() => test.testNotAllowShared(ta));
53 checkThrowsTooLarge(() => test.testAllowShared(ta));
54 checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBufferView: ta}));
55 checkThrowsTooLarge(() => test.testUnionOfBuffferSource(ta));
56 checkThrowsTooLarge(() => { test.arrayBufferView = ta; });
57 checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = ta; });
58 checkThrowsTooLarge(() => { test.sequenceOfArrayBufferView = [ta]; });
59 checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [ta]; });
61 let dv = new DataView(ab);
62 checkThrowsTooLarge(() => test.testNotAllowShared(dv));
63 checkThrowsTooLarge(() => test.testAllowShared(dv));
64 checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBufferView: dv}));
65 checkThrowsTooLarge(() => test.testUnionOfBuffferSource(dv));
66 checkThrowsTooLarge(() => { test.arrayBufferView = dv; });
67 checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = dv; });
68 checkThrowsTooLarge(() => { test.sequenceOfArrayBufferView = [dv]; });
69 checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [dv]; });
71 if (this.SharedArrayBuffer) {
72 let sab = new SharedArrayBuffer(5 * gb);
73 checkThrowsTooLarge(() => test.testAllowShared(sab));
74 checkThrowsTooLarge(() => test.testDictWithAllowShared({allowSharedArrayBuffer: sab}));
75 checkThrowsTooLarge(() => test.testUnionOfAllowSharedBuffferSource(sab));
76 checkThrowsTooLarge(() => { test.allowSharedArrayBuffer = sab; });
77 checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBuffer = [sab]; });
79 let sta = new Int8Array(sab);
80 checkThrowsTooLarge(() => test.testAllowShared(sta));
81 checkThrowsTooLarge(() => test.testDictWithAllowShared({allowSharedArrayBufferView: sta}));
82 checkThrowsTooLarge(() => test.testUnionOfAllowSharedBuffferSource(sta));
83 checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = sta; });
84 checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [sta]; });
87 // Small views on large buffers are fine.
88 let ta2 = new Int8Array(ab, 4 * gb);
89 is(ta2.byteLength, 1 * gb, "Small view on large ArrayBuffer");
90 test.testNotAllowShared(ta2);
91 test.arrayBufferView = ta2;
93 SimpleTest.finish();
95 </script>
96 </body>
97 </html>