diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/bindings/test/test_large_arraybuffers.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/bindings/test/test_large_arraybuffers.html')
-rw-r--r-- | dom/bindings/test/test_large_arraybuffers.html | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/dom/bindings/test/test_large_arraybuffers.html b/dom/bindings/test/test_large_arraybuffers.html new file mode 100644 index 0000000000..64f6fc7276 --- /dev/null +++ b/dom/bindings/test/test_large_arraybuffers.html @@ -0,0 +1,97 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1688616 +--> +<head> + <meta charset="utf-8"> + <title>Test for large ArrayBuffers and views</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1688616">Mozilla Bug 1688616</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +</pre> + <script type="application/javascript"> + /* global TestFunctions */ + + SimpleTest.waitForExplicitFinish(); + SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]}, go); + + function checkThrowsTooLarge(f) { + let ex; + try{ + f(); + ok(false, "Should have thrown!"); + } catch (e) { + ex = e; + } + ok(ex.toString().includes("larger than 2 GB"), "Got exception: " + ex); + } + + function go() { + let test = new TestFunctions(); + + const gb = 1 * 1024 * 1024 * 1024; + let ab = new ArrayBuffer(5 * gb); + checkThrowsTooLarge(() => test.testNotAllowShared(ab)); + checkThrowsTooLarge(() => test.testAllowShared(ab)); + checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBuffer: ab})); + checkThrowsTooLarge(() => test.testUnionOfBuffferSource(ab)); + checkThrowsTooLarge(() => { test.arrayBuffer = ab; }); + checkThrowsTooLarge(() => { test.allowSharedArrayBuffer = ab; }); + checkThrowsTooLarge(() => { test.sequenceOfArrayBuffer = [ab]; }); + checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBuffer = [ab]; }); + + let ta = new Int8Array(ab, 0, 3 * gb); + checkThrowsTooLarge(() => test.testNotAllowShared(ta)); + checkThrowsTooLarge(() => test.testAllowShared(ta)); + checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBufferView: ta})); + checkThrowsTooLarge(() => test.testUnionOfBuffferSource(ta)); + checkThrowsTooLarge(() => { test.arrayBufferView = ta; }); + checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = ta; }); + checkThrowsTooLarge(() => { test.sequenceOfArrayBufferView = [ta]; }); + checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [ta]; }); + + let dv = new DataView(ab); + checkThrowsTooLarge(() => test.testNotAllowShared(dv)); + checkThrowsTooLarge(() => test.testAllowShared(dv)); + checkThrowsTooLarge(() => test.testDictWithAllowShared({arrayBufferView: dv})); + checkThrowsTooLarge(() => test.testUnionOfBuffferSource(dv)); + checkThrowsTooLarge(() => { test.arrayBufferView = dv; }); + checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = dv; }); + checkThrowsTooLarge(() => { test.sequenceOfArrayBufferView = [dv]; }); + checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [dv]; }); + + if (this.SharedArrayBuffer) { + let sab = new SharedArrayBuffer(5 * gb); + checkThrowsTooLarge(() => test.testAllowShared(sab)); + checkThrowsTooLarge(() => test.testDictWithAllowShared({allowSharedArrayBuffer: sab})); + checkThrowsTooLarge(() => test.testUnionOfAllowSharedBuffferSource(sab)); + checkThrowsTooLarge(() => { test.allowSharedArrayBuffer = sab; }); + checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBuffer = [sab]; }); + + let sta = new Int8Array(sab); + checkThrowsTooLarge(() => test.testAllowShared(sta)); + checkThrowsTooLarge(() => test.testDictWithAllowShared({allowSharedArrayBufferView: sta})); + checkThrowsTooLarge(() => test.testUnionOfAllowSharedBuffferSource(sta)); + checkThrowsTooLarge(() => { test.allowSharedArrayBufferView = sta; }); + checkThrowsTooLarge(() => { test.sequenceOfAllowSharedArrayBufferView = [sta]; }); + } + + // Small views on large buffers are fine. + let ta2 = new Int8Array(ab, 4 * gb); + is(ta2.byteLength, 1 * gb, "Small view on large ArrayBuffer"); + test.testNotAllowShared(ta2); + test.arrayBufferView = ta2; + + SimpleTest.finish(); + } + </script> +</body> +</html> |