Make web test for SAB in IndexedDB a WPT
The web_test checking that a SharedArrayBuffer cannot be serialized
into IndexedDB was failing because it was served inside a
non-cross-origin-isolated page, which could not create a
SharedArrayBuffer.
This CL turns that into a Web Platform Test and adds the appropriate
COOP and COEP header which make the page cross-origin-isolated,
enabling instantiation of SharedArrayBuffer.
Bug: 1194557
Change-Id: I6854a76612d237b82cb020e317459157907e77f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2846500
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Antonio Sartori <antoniosartori@chromium.org>
Cr-Commit-Position: refs/heads/master@{#875562}
diff --git a/IndexedDB/serialize-sharedarraybuffer-throws.https.html b/IndexedDB/serialize-sharedarraybuffer-throws.https.html
new file mode 100644
index 0000000..6900759
--- /dev/null
+++ b/IndexedDB/serialize-sharedarraybuffer-throws.https.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<title>IndexedDB: Attempting to serialize a SharedArrayBuffer should throw</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support.js"></script>
+<script>
+ async_test(function(t) {
+
+ // The SAB constructor throws if the page is not cross-origin-isolated.
+ assert_true(self.crossOriginIsolated,
+ "The page is served with COOP and COEP, it should be cross-origin-isolated.");
+
+ let open_rq = createdb(t);
+ open_rq.onupgradeneeded = function(e) {
+ let db = e.target.result;
+ let objStore = db.createObjectStore("test", { keyPath:"pKey" });
+
+ let sab = new SharedArrayBuffer(256);
+
+ let rq;
+ assert_throws_dom("DataCloneError", () => {
+ rq = objStore.put({sab: sab}, 'key');
+ });
+ assert_equals(rq, undefined);
+ t.done();
+ };
+ });
+</script>
diff --git a/IndexedDB/serialize-sharedarraybuffer-throws.https.html.headers b/IndexedDB/serialize-sharedarraybuffer-throws.https.html.headers
new file mode 100644
index 0000000..5f8621e
--- /dev/null
+++ b/IndexedDB/serialize-sharedarraybuffer-throws.https.html.headers
@@ -0,0 +1,2 @@
+Cross-Origin-Embedder-Policy: require-corp
+Cross-Origin-Opener-Policy: same-origin