Add WPT serialization tests for wasm modules
These WPT tests are based on similar tests in
wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/
This also fixes some test failures for the SharedArrayBuffer tests.
Bug: chromium:798572
Change-Id: I50b0edbebe4e97f5358513d248657d2831f48201
Reviewed-on: https://chromium-review.googlesource.com/1175490
Reviewed-by: Marijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Ben Smith <binji@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586480}
diff --git a/third_party/WebKit/LayoutTests/FlagExpectations/site-per-process b/third_party/WebKit/LayoutTests/FlagExpectations/site-per-process
index 7f75769..c1c1a2e 100644
--- a/third_party/WebKit/LayoutTests/FlagExpectations/site-per-process
+++ b/third_party/WebKit/LayoutTests/FlagExpectations/site-per-process
@@ -99,6 +99,10 @@
Bug(none) external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-similar-but-cross-origin-success.sub.html [ Skip ]
Bug(none) virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-domain-success.sub.html [ Skip ]
Bug(none) virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-similar-but-cross-origin-success.sub.html [ Skip ]
+Bug(none) external/wpt/wasm/serialization/window-domain-success.sub.html [ Skip ]
+Bug(none) external/wpt/wasm/serialization/window-similar-but-cross-origin-success.sub.html [ Skip ]
+Bug(none) virtual/enable_wasm/external/wpt/wasm/serialization/window-domain-success.sub.html [ Skip ]
+Bug(none) virtual/enable_wasm/external/wpt/wasm/serialization/window-similar-but-cross-origin-success.sub.html [ Skip ]
# Layout tests don't work for printing cross-site frames.
crbug.com/822372 http/tests/printing/cross-site-frame.html [ Crash ]
diff --git a/third_party/WebKit/LayoutTests/MSANExpectations b/third_party/WebKit/LayoutTests/MSANExpectations
index b1be99d..302e1949 100644
--- a/third_party/WebKit/LayoutTests/MSANExpectations
+++ b/third_party/WebKit/LayoutTests/MSANExpectations
@@ -100,9 +100,6 @@
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-profile.js [ Skip ]
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
-# Crashes on Linux Trusty MSAN
-crbug.com/842262 [ Linux ] virtual/enable_wasm/external/wpt/wasm/wasm_indexeddb_test.https.html [ Crash ]
-
# The following test is flaky and timing out on chromium.webkit/WebKit Linux Trusty MSAN.
crbug.com/851497 http/tests/devtools/tracing/timeline-style/timeline-style-recalc-all-invalidator-types.js [ Pass Timeout ]
diff --git a/third_party/WebKit/LayoutTests/SlowTests b/third_party/WebKit/LayoutTests/SlowTests
index 551536a..c2cb384 100644
--- a/third_party/WebKit/LayoutTests/SlowTests
+++ b/third_party/WebKit/LayoutTests/SlowTests
@@ -1467,3 +1467,5 @@
crbug.com/874695 virtual/video-surface-layer/media/video-poster-after-playing.html [ Slow ]
crbug.com/874695 virtual/video-surface-layer/media/video-poster-load-after-playing.html [ Slow ]
crbug.com/874695 virtual/webrtc-wpt-unified-plan/external/wpt/webrtc/RTCDTMFSender-ontonechange.https.html [ Slow ]
+
+crbug.com/798572 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-simple-success.html [ Slow ]
diff --git a/third_party/WebKit/LayoutTests/TestExpectations b/third_party/WebKit/LayoutTests/TestExpectations
index fe7e32f..0b30ccd 100644
--- a/third_party/WebKit/LayoutTests/TestExpectations
+++ b/third_party/WebKit/LayoutTests/TestExpectations
@@ -3365,9 +3365,6 @@
crbug.com/648295 virtual/service-worker-servicification/external/wpt/service-workers/service-worker/update-bytecheck.https.html [ Timeout ]
crbug.com/626703 external/wpt/speech-api/SpeechSynthesis-speak-twice.html [ Timeout ]
crbug.com/626703 external/wpt/svg/linking/reftests/href-filter-element.html [ Failure ]
-crbug.com/642912 external/wpt/wasm/wasm_local_iframe_test.html [ Failure ]
-crbug.com/642912 external/wpt/wasm/wasm_serialization_tests.html [ Failure ]
-crbug.com/642912 external/wpt/wasm/wasm_service_worker_test.https.html [ Failure ]
crbug.com/626703 external/wpt/webrtc/RTCPeerConnection-setRemoteDescription.html [ Pass Failure ]
crbug.com/626703 virtual/webrtc-wpt-unified-plan/external/wpt/webrtc/RTCPeerConnection-setRemoteDescription.html [ Pass Failure ]
crbug.com/626703 external/wpt/webvtt/rendering/cues-with-video/processing-model/2_cues_overlapping_completely_move_up.html [ Failure ]
@@ -3929,11 +3926,29 @@
crbug.com/798864 [ Android ] external/wpt/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/canblock-sharedworker.html [ Failure ]
crbug.com/798864 [ Android ] external/wpt/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/canblock-window.html [ Failure ]
-crbug.com/716320 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/broadcastchannel-success-and-failure.html [ Timeout ]
-crbug.com/716320 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/broadcastchannel-success.html [ Timeout ]
-crbug.com/716320 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-sharedworker-failure.html [ Timeout ]
+# Requires --enable-features=WebAssembly
+crbug.com/746486 external/wpt/wasm/serialization/broadcastchannel-success-and-failure.html [ Timeout ]
+crbug.com/746486 external/wpt/wasm/serialization/broadcastchannel-success.html [ Failure ]
+crbug.com/746486 external/wpt/wasm/serialization/identity-not-preserved.html [ Timeout ]
+crbug.com/746486 external/wpt/wasm/serialization/nested-worker-success.any.worker.html [ Failure ]
+crbug.com/746486 external/wpt/wasm/serialization/no-transferring.html [ Failure ]
+crbug.com/746486 external/wpt/wasm/serialization/window-domain-success.sub.html [ Failure ]
+crbug.com/746486 external/wpt/wasm/serialization/window-messagechannel-success.html [ Failure ]
+crbug.com/746486 external/wpt/wasm/serialization/window-serviceworker-failure.https.html [ Failure ]
+crbug.com/746486 external/wpt/wasm/serialization/window-sharedworker-failure.html [ Failure ]
+crbug.com/746486 external/wpt/wasm/serialization/window-similar-but-cross-origin-success.sub.html [ Failure ]
+crbug.com/746486 external/wpt/wasm/serialization/window-simple-success.html [ Failure ]
-crbug.com/798572 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-simple-success.html [ Timeout ]
+crbug.com/874302 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/broadcastchannel-success-and-failure.html [ Timeout ]
+crbug.com/874302 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/broadcastchannel-success.html [ Timeout ]
+crbug.com/874302 virtual/enable_wasm/external/wpt/wasm/serialization/broadcastchannel-success-and-failure.html [ Timeout ]
+crbug.com/874302 virtual/enable_wasm/external/wpt/wasm/serialization/broadcastchannel-success.html [ Timeout ]
+
+crbug.com/877286 virtual/enable_wasm/external/wpt/wasm/serialization/no-transferring.html [ Failure ]
+crbug.com/877286 virtual/enable_wasm/external/wpt/wasm/serialization/serialization-via-history.html [ Failure ]
+crbug.com/877286 virtual/enable_wasm/external/wpt/wasm/serialization/serialization-via-notifications-api.any.html [ Failure ]
+crbug.com/877286 virtual/enable_wasm/external/wpt/wasm/serialization/serialization-via-notifications-api.any.worker.html [ Failure ]
+crbug.com/877296 virtual/enable_wasm/external/wpt/wasm/serialization/window-serviceworker-failure.https.html [ Failure ]
crbug.com/831509 external/wpt/service-workers/service-worker/skip-waiting-installed.https.html [ Failure Pass ]
crbug.com/831509 virtual/navigation-mojo-response/external/wpt/service-workers/service-worker/skip-waiting-installed.https.html [ Failure Pass ]
diff --git a/third_party/WebKit/LayoutTests/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/sharedworker-failure.js b/third_party/WebKit/LayoutTests/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/sharedworker-failure.js
index a11ccbc1f..8472318 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/sharedworker-failure.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/sharedworker-failure.js
@@ -1,16 +1,17 @@
let state = "send-sw-failure"
onconnect = initialE => {
- initialE.source.postMessage(state)
- initialE.source.onmessage = e => {
+ let port = initialE.source;
+ port.postMessage(state)
+ port.onmessage = e => {
if(state === "" && e.data === "send-window-failure") {
- e.postMessage(new SharedArrayBuffer())
+ port.postMessage(new SharedArrayBuffer())
} else {
- e.postMessage("failure")
+ port.postMessage("failure")
}
}
- initialE.source.onmessageerror = e => {
+ port.onmessageerror = e => {
if(state === "send-sw-failure") {
- e.postMessage("send-sw-failure-success")
+ port.postMessage("send-sw-failure-success")
state = ""
}
}
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/OWNERS b/third_party/WebKit/LayoutTests/external/wpt/wasm/OWNERS
index b9938be..317ea70 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/wasm/OWNERS
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/OWNERS
@@ -1,2 +1,2 @@
# COMPONENT: Blink>JavaScript>WebAssembly
-mtrofin@chromium.org
+binji@chromium.org
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/resources/frame.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/resources/frame.html
deleted file mode 100644
index d1c83e1..0000000
--- a/third_party/WebKit/LayoutTests/external/wpt/wasm/resources/frame.html
+++ /dev/null
@@ -1,18 +0,0 @@
-<script>
-function listener(event) {
- var mod = event.data;
- try {
- var i = new WebAssembly.Instance(mod);
- var ans = i.exports.increment(42);
- event.source.postMessage(ans, event.origin);
- } catch (e) {
- event.source.postMessage(e, event.origin);
- }
-}
-
-if (window.addEventListener){
- addEventListener("message", listener, false)
-} else {
- attachEvent("onmessage", listener)
-}
-</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/resources/service-worker.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/resources/service-worker.js
deleted file mode 100644
index 684eaf6..0000000
--- a/third_party/WebKit/LayoutTests/external/wpt/wasm/resources/service-worker.js
+++ /dev/null
@@ -1,30 +0,0 @@
-var port;
-
-importScripts('load_wasm.js');
-
-self.onmessage = function(e) {
- var message = e.data;
- if ('port' in message) {
- port = message.port;
- }
-};
-
-// And an event listener:
-self.addEventListener('message', function(e) {
- var message = e.data;
- if ("compile" in message) {
- createWasmModule()
- .then(m => {
- try {
- port.postMessage({type:"OK", module:m});
- } catch (e) {
- port.postMessage({type:"SEND ERROR"});
- }
- })
- .catch(e => port.postMessage({type:"OTHER ERROR"}));
- }
-});
-
-self.addEventListener('messageerror', function(e) {
- port.postMessage({type:"RECEIVE ERROR"});
-});
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/broadcastchannel-success-and-failure.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/broadcastchannel-success-and-failure.html
new file mode 100644
index 0000000..0d11cc595
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/broadcastchannel-success-and-failure.html
@@ -0,0 +1,38 @@
+<!doctype html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<title>WebAssembly.Module cannot cross agent clusters, BroadcastChannel edition</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/test-incrementer.js"></script>
+<script>
+async_test(t => {
+ const channel = new BroadcastChannel("anne was here"),
+ dw = new Worker("resources/broadcastchannel-worker.js"),
+ sw = new SharedWorker("resources/broadcastchannel-sharedworker.js");
+ let startCounter = 0,
+ dwStatus = "unknown",
+ swStatus = "unknown";
+
+ channel.onmessage = t.step_func(({ data }) => {
+ if(data === "hi") {
+ startCounter++;
+ if(startCounter === 2) {
+ createWasmModule().then(module => {
+ channel.postMessage(module);
+ });
+ } else if(startCounter > 2) {
+ assert_unreached();
+ }
+ } else if(data === "dw-success") {
+ dwStatus = "success";
+ } else if(data === "sw-success") {
+ swStatus = "success";
+ } else {
+ assert_unreached();
+ }
+ if(dwStatus === "success" && swStatus === "success") {
+ t.done();
+ }
+ });
+});
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/broadcastchannel-success.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/broadcastchannel-success.html
new file mode 100644
index 0000000..cd5f8d0
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/broadcastchannel-success.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<meta charset="utf-8">
+<title>Structured cloning of WebAssembly.Module: BroadcastChannel within the same agent cluster</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/test-incrementer.js"></script>
+
+<div id="log"></div>
+
+<script>
+"use strict";
+
+promise_test(t => {
+ return createWasmModule().then(module => {
+ let loadedIframes = 0;
+ return Promise.all([
+ createIFrame("resources/broadcastchannel-iframe.html"),
+ createIFrame("resources/broadcastchannel-iframe.html"),
+ createIFrame("resources/broadcastchannel-iframe.html")
+ ]).then(() => {
+ const thisIframe = loadedIframes++;
+ const channel = new BroadcastChannel("channel name");
+
+ return new Promise(resolve => {
+ let soFar = 0;
+ channel.onmessage = t.step_func(msg => {
+ if (msg.module) {
+ // We only care about "broadcasts" from the workers.
+ return;
+ }
+
+ let {i, result} = msg;
+
+ assert_in_array(i, [0, 1, 2], "Any message events must come from expected sources");
+ assert_equals(result, i + 1, `iframe ${i} must return ${i+1}`);
+ ++soFar;
+
+ if (soFar === 3) {
+ resolve();
+ }
+ });
+
+ channel.postMessage({ module, i: thisIframe });
+ });
+ });
+ });
+});
+
+function createIFrame(src) {
+ return new Promise((resolve, reject) => {
+ const iframe = document.createElement("iframe");
+ iframe.src = src;
+ iframe.onload = () => resolve(iframe);
+ iframe.onerror = () => reject(`iframe with URL ${src} failed to load`);
+ document.body.appendChild(iframe);
+ });
+}
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/identity-not-preserved.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/identity-not-preserved.html
new file mode 100644
index 0000000..24bb3b1
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/identity-not-preserved.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<meta charset="utf-8">
+<title>WebAssembly.Modules, when cloned, do not give back the same object</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/test-incrementer.js"></script>
+
+<div id="log"></div>
+
+<script>
+"use strict";
+
+async_test(t => {
+ createWasmModule().then(module => {
+ window.addEventListener("message", t.step_func(({ data }) => {
+ if (data.testId !== 1) {
+ return;
+ }
+
+ assert_not_equals(data.module, module);
+
+ t.done();
+ }));
+
+ window.postMessage({ module, testId: 1 }, "*");
+ });
+}, "postMessaging to this window does not give back the same WebAssembly.Module");
+
+async_test(t => {
+ createWasmModule().then(module => {
+ const worker = new Worker("resources/echo-worker.js");
+
+ worker.addEventListener("message", t.step_func(({ data }) => {
+ if (data.testId !== 2) {
+ return;
+ }
+
+ assert_not_equals(data.module, module);
+ t.done();
+ }));
+
+ worker.postMessage({ testId: 2, module });
+ });
+}, "postMessaging to a worker and back does not give back the same WebAssembly.Module");
+
+async_test(t => {
+ createWasmModule().then(module => {
+ window.addEventListener("message", t.step_func(({ data }) => {
+ if (data.testId !== 3) {
+ return;
+ }
+
+ assert_not_equals(data.module, module);
+ t.done();
+ }));
+
+ const iframe = document.createElement("iframe");
+ iframe.onload = t.step_func(() => {
+ iframe.contentWindow.postMessage({ testId: 3, module }, "*");
+ });
+ iframe.src = "resources/echo-iframe.html";
+ document.body.appendChild(iframe);
+ });
+}, "postMessaging to an iframe and back does not give back the same WebAssembly.Module");
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/resources/incrementer.wasm b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/incrementer.wasm
similarity index 100%
copy from third_party/WebKit/LayoutTests/external/wpt/wasm/resources/incrementer.wasm
copy to third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/incrementer.wasm
Binary files differ
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/nested-worker-success-sharedworker-expected.txt b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/nested-worker-success-sharedworker-expected.txt
new file mode 100644
index 0000000..7b70ea2
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/nested-worker-success-sharedworker-expected.txt
@@ -0,0 +1,4 @@
+This is a testharness.js-based test.
+FAIL postMessaging to a dedicated sub-worker allows them to see each others' modifications Worker is not defined
+Harness: the test ran to completion.
+
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/nested-worker-success.any.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/nested-worker-success.any.js
new file mode 100644
index 0000000..5388ebcc
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/nested-worker-success.any.js
@@ -0,0 +1,9 @@
+// META: global=!default,dedicatedworker,sharedworker
+// META: script=resources/test-incrementer.js
+"use strict";
+
+promise_test(t => {
+ const worker = new Worker("resources/incrementer-worker.js");
+
+ return testSharingViaIncrementerScript(t, worker, "parent worker", worker, "sub-worker");
+}, "postMessaging to a dedicated sub-worker allows them to see each others' modifications");
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/nested-worker-success.any.sharedworker-expected.txt b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/nested-worker-success.any.sharedworker-expected.txt
new file mode 100644
index 0000000..7b70ea2
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/nested-worker-success.any.sharedworker-expected.txt
@@ -0,0 +1,4 @@
+This is a testharness.js-based test.
+FAIL postMessaging to a dedicated sub-worker allows them to see each others' modifications Worker is not defined
+Harness: the test ran to completion.
+
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/no-transferring.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/no-transferring.html
new file mode 100644
index 0000000..a0bf11f
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/no-transferring.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<meta charset="utf-8">
+<title>WebAssembly.Modules cannot be transferred</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/create-empty-wasm-module.js"></script>
+
+<script>
+"use strict";
+
+test(() => {
+ const module = createEmptyWasmModule();
+ assert_throws("DataCloneError", () => window.postMessage(module, "*", [module]));
+ assert_throws("DataCloneError", () => window.postMessage("test", "*", [module]));
+}, "Trying to transfer a WebAssembly.Module to this window throws");
+
+test(() => {
+ const module = createEmptyWasmModule();
+ const worker = new Worker("resources/echo-worker.js");
+ assert_throws("DataCloneError", () => worker.postMessage(module, [module]));
+ assert_throws("DataCloneError", () => worker.postMessage("test", [module]));
+}, "Trying to transfer a WebAssembly.Module to a worker throws");
+
+test(() => {
+ const module = createEmptyWasmModule();
+ const channel = new MessageChannel();
+ assert_throws("DataCloneError", () => channel.port1.postMessage(module, [module]));
+ assert_throws("DataCloneError", () => channel.port1.postMessage("test", [module]));
+}, "Trying to transfer a WebAssembly.Module through a MessagePort throws");
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/resources/blank.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/blank.html
similarity index 100%
rename from third_party/WebKit/LayoutTests/external/wpt/wasm/resources/blank.html
rename to third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/blank.html
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/broadcastchannel-iframe.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/broadcastchannel-iframe.html
new file mode 100644
index 0000000..83e347b5
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/broadcastchannel-iframe.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>A test page that uses a given WebAssembly.Module sent from a BroadcastChannel</title>
+
+<script>
+"use strict";
+const channel = new BroadcastChannel("channel name");
+
+channel.onmessage = ({ data: { module, i }, source }) => {
+ if (!module) {
+ // We only care about "broadcasts" from the window
+ return;
+ }
+
+ let instance = new WebAssembly.Instance(module);
+ let increment = instance.exports["increment"];
+ let result = increment(i);
+ channel.postMessage({i, result});
+};
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/broadcastchannel-sharedworker.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/broadcastchannel-sharedworker.js
new file mode 100644
index 0000000..310e0e93
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/broadcastchannel-sharedworker.js
@@ -0,0 +1,7 @@
+const channel = new BroadcastChannel("anne was here");
+channel.onmessageerror = ({ data }) => {
+ if(data === null) {
+ channel.postMessage("sw-success");
+ }
+}
+channel.postMessage("hi");
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/broadcastchannel-worker.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/broadcastchannel-worker.js
new file mode 100644
index 0000000..76a8177
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/broadcastchannel-worker.js
@@ -0,0 +1,9 @@
+const channel = new BroadcastChannel("anne was here");
+channel.onmessage = ({ data }) => {
+ if(data === "hi" || data === "sw-success") {
+ return;
+ } else if(data instanceof WebAssembly.Module) {
+ channel.postMessage("dw-success");
+ }
+}
+channel.postMessage("hi");
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/create-empty-wasm-module.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/create-empty-wasm-module.js
new file mode 100644
index 0000000..7326710
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/create-empty-wasm-module.js
@@ -0,0 +1,4 @@
+function createEmptyWasmModule() {
+ return new WebAssembly.Module(
+ new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]));
+}
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/echo-iframe.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/echo-iframe.html
new file mode 100644
index 0000000..c4fd582
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/echo-iframe.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>A test page that echos back anything postMessaged to it to its parent</title>
+
+<script>
+"use strict";
+
+window.onmessage = ({ data }) => {
+ parent.postMessage(data, "*");
+};
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/echo-worker.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/echo-worker.js
new file mode 100644
index 0000000..cbbde8a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/echo-worker.js
@@ -0,0 +1,5 @@
+"use strict";
+
+self.onmessage = ({ data }) => {
+ self.postMessage(data);
+};
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-iframe-domain.sub.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-iframe-domain.sub.html
new file mode 100644
index 0000000..d2d18de
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-iframe-domain.sub.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>A test page that is sent a WebAssembly Module</title>
+<script src="/resources/testharness.js"></script>
+<script src="test-incrementer.js"></script>
+
+<script>
+"use strict";
+
+document.domain = "{{host}}";
+setupDestinationIncrementer(self, parent, "*");
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-iframe.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-iframe.html
new file mode 100644
index 0000000..5c8bc07
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-iframe.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>A test page that is sent a WebAssembly Module</title>
+<script src="/resources/testharness.js"></script>
+<script src="test-incrementer.js"></script>
+
+<script>
+"use strict";
+
+setupDestinationIncrementer(self, parent, "*");
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-popup.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-popup.html
new file mode 100644
index 0000000..660e472b
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-popup.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>A test page that is sent a WebAssembly Module</title>
+<script src="/resources/testharness.js"></script>
+<script src="test-incrementer.js"></script>
+
+<script>
+"use strict";
+
+setupDestinationIncrementer(self, opener, "*");
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-worker-with-channel.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-worker-with-channel.js
new file mode 100644
index 0000000..0323b3e5
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-worker-with-channel.js
@@ -0,0 +1,8 @@
+"use strict";
+importScripts("/resources/testharness.js");
+importScripts("./test-incrementer.js");
+
+self.onmessage = ({ data }) => {
+ // data will be a MessagePort
+ setupDestinationIncrementer(data, data);
+};
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-worker.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-worker.js
new file mode 100644
index 0000000..1779cee
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer-worker.js
@@ -0,0 +1,5 @@
+"use strict";
+importScripts("/resources/testharness.js");
+importScripts("./test-incrementer.js");
+
+setupDestinationIncrementer(self, self);
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/resources/incrementer.wasm b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer.wasm
similarity index 100%
rename from third_party/WebKit/LayoutTests/external/wpt/wasm/resources/incrementer.wasm
rename to third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/incrementer.wasm
Binary files differ
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-1.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-1.html
new file mode 100644
index 0000000..fe93cc0
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-1.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Nesting level 1</title>
+
+<iframe src="nested-iframe-2.html"></iframe>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-2.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-2.html
new file mode 100644
index 0000000..fad52ce
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-2.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Nesting level 2</title>
+
+<iframe src="nested-iframe-3.html"></iframe>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-3.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-3.html
new file mode 100644
index 0000000..7971022b
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-3.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Nesting level 3</title>
+
+<iframe src="nested-iframe-4-incrementer.html"></iframe>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-4-incrementer.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-4-incrementer.html
new file mode 100644
index 0000000..f419f4b
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/nested-iframe-4-incrementer.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>A test page that is sent a WebAssembly Module, nested 4 levels deep in iframes</title>
+<script src="/resources/testharness.js"></script>
+<script src="test-incrementer.js"></script>
+
+<script>
+"use strict";
+
+setupDestinationIncrementer(self, parent.parent.parent.parent.parent, "*");
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/serviceworker-failure.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/serviceworker-failure.js
new file mode 100644
index 0000000..39796f9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/serviceworker-failure.js
@@ -0,0 +1,34 @@
+// Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/.
+"use strict";
+self.importScripts("/resources/testharness.js");
+self.importScripts("./create-empty-wasm-module.js");
+
+let state = "start in worker";
+
+self.onmessage = e => {
+ if (e.data === "start in window") {
+ assert_equals(state, "start in worker");
+ e.source.postMessage(state);
+ state = "we are expecting a messageerror due to the window sending us a WebAssembly.Module";
+ } else if (e.data === "we are expecting a messageerror due to the worker sending us a WebAssembly.Module") {
+ assert_equals(state, "onmessageerror was received in worker");
+ e.source.postMessage(createEmptyWasmModule());
+ state = "done in worker";
+ } else {
+ e.source.postMessage(`worker onmessage was reached when in state "${state}" and data ${e.data}`);
+ }
+};
+
+self.onmessageerror = e => {
+ if (state === "we are expecting a messageerror due to the window sending us a WebAssembly.Module") {
+ assert_equals(e.data, null, "data");
+ assert_equals(e.origin, self.origin, "origin");
+ assert_not_equals(e.source, null, "source");
+ assert_equals(e.ports.length, 0, "ports length");
+
+ state = "onmessageerror was received in worker";
+ e.source.postMessage(state);
+ } else {
+ e.source.postMessage(`worker onmessageerror was reached when in state "${state}" and data ${e.data}`);
+ }
+};
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/sharedworker-failure.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/sharedworker-failure.js
new file mode 100644
index 0000000..854c70b9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/sharedworker-failure.js
@@ -0,0 +1,21 @@
+importScripts("./test-incrementer.js");
+importScripts("./create-empty-wasm-module.js");
+
+let state = "send-sw-failure"
+onconnect = initialE => {
+ let port = initialE.source;
+ port.postMessage(state)
+ port.onmessage = e => {
+ if(state === "" && e.data === "send-window-failure") {
+ port.postMessage(createEmptyWasmModule())
+ } else {
+ port.postMessage("failure")
+ }
+ }
+ port.onmessageerror = e => {
+ if(state === "send-sw-failure") {
+ port.postMessage("send-sw-failure-success")
+ state = ""
+ }
+ }
+}
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/test-incrementer.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/test-incrementer.js
new file mode 100644
index 0000000..65cb3322
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/resources/test-incrementer.js
@@ -0,0 +1,57 @@
+// Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/.
+//
+// This file is simplified from the one there, because it only tests that the
+// module can be passed and that functions can be run. The SharedArrayBuffer
+// version also tests that the memory is shared between the agents.
+
+"use strict";
+
+function createWasmModule() {
+ return fetch('incrementer.wasm')
+ .then(response => {
+ if (!response.ok)
+ throw new Error(response.statusText);
+ return response.arrayBuffer();
+ })
+ .then(WebAssembly.compile);
+}
+
+function testModule(module) {
+ let instance = new WebAssembly.Instance(module);
+ let increment = instance.exports["increment"];
+ assert_equals(typeof increment, "function", `The type of the increment export should be "function", got ${typeof increment}`);
+ let result = increment(42);
+ assert_equals(result, 43, `increment(42) should be 43, got ${result}`);
+}
+
+self.testSharingViaIncrementerScript = (t, whereToListen, whereToListenLabel, whereToSend, whereToSendLabel, origin) => {
+ return createWasmModule().then(module => {
+ return new Promise(resolve => {
+
+ whereToListen.onmessage = t.step_func(({ data }) => {
+ switch (data.message) {
+ case "module received": {
+ testModule(data.module);
+ resolve();
+ break;
+ }
+ }
+ });
+
+ whereToSend.postMessage({ message: "send module", module }, origin);
+ });
+ });
+};
+
+self.setupDestinationIncrementer = (whereToListen, whereToSendBackTo, origin) => {
+ whereToListen.onmessage = ({ data }) => {
+ switch (data.message) {
+ case "send module": {
+ let module = data.module;
+ testModule(data.module);
+ whereToSendBackTo.postMessage({ message: "module received", module }, origin);
+ break;
+ }
+ }
+ };
+};
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/serialization-via-history.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/serialization-via-history.html
new file mode 100644
index 0000000..35dc17b6
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/serialization-via-history.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<meta charset="utf-8">
+<title>WebAssembly.Module cloning via history's methods invoking StructuredSerializeForStorage</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/create-empty-wasm-module.js"></script>
+
+<script>
+"use strict";
+
+for (const method of ["pushState", "replaceState"]) {
+ test(() => {
+ assert_throws("DataCloneError", () => {
+ history[method](createEmptyWasmModule(), "dummy title");
+ });
+ }, `history.${method}(): simple case`);
+
+ test(() => {
+ let getter1Called = false;
+ let getter2Called = false;
+ assert_throws("DataCloneError", () => {
+ history[method]([
+ { get x() { getter1Called = true; return 5; } },
+ createEmptyWasmModule(),
+ { get x() { getter2Called = true; return 5; } }
+ ], "dummy title");
+ });
+
+ assert_true(getter1Called, "The getter before the WebAssembly.Module must have been called");
+ assert_false(getter2Called, "The getter after the WebAssembly.Module must not have been called");
+ }, `history.${method}(): is interleaved correctly`);
+}
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/serialization-via-idb.any.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/serialization-via-idb.any.js
new file mode 100644
index 0000000..1d861c3d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/serialization-via-idb.any.js
@@ -0,0 +1,45 @@
+// META: script=/IndexedDB/support.js
+"use strict";
+
+function createEmptyWasmModule() {
+ return new WebAssembly.Module(
+ new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]));
+}
+
+async_test(t => {
+ const openReq = createdb(t);
+
+ openReq.onupgradeneeded = e => {
+ const db = e.target.result;
+ const store = db.createObjectStore("store", { keyPath: "key" });
+
+ assert_throws("DataCloneError", () => {
+ store.put({ key: 1, property: createEmptyWasmModule() });
+ });
+ t.done();
+ };
+}, "WebAssembly.Module cloning via IndexedDB: basic case");
+
+async_test(t => {
+ const openReq = createdb(t);
+
+ openReq.onupgradeneeded = e => {
+ const db = e.target.result;
+ const store = db.createObjectStore("store", { keyPath: "key" });
+
+ let getter1Called = false;
+ let getter2Called = false;
+
+ assert_throws("DataCloneError", () => {
+ store.put({ key: 1, property: [
+ { get x() { getter1Called = true; return 5; } },
+ createEmptyWasmModule(),
+ { get x() { getter2Called = true; return 5; } }
+ ]});
+ });
+
+ assert_true(getter1Called, "The getter before the WebAssembly.Module must have been called");
+ assert_false(getter2Called, "The getter after the WebAssembly.Module must not have been called");
+ t.done();
+ };
+}, "WebAssembly.Module cloning via the IndexedDB: is interleaved correctly");
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/serialization-via-notifications-api.any.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/serialization-via-notifications-api.any.js
new file mode 100644
index 0000000..8410565
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/serialization-via-notifications-api.any.js
@@ -0,0 +1,28 @@
+"use strict";
+
+function createEmptyWasmModule() {
+ return new WebAssembly.Module(
+ new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]));
+}
+
+test(() => {
+ assert_throws("DataCloneError", () => {
+ new Notification("Bob: Hi", { data: createEmptyWasmModule() });
+ })
+}, "WebAssembly.Module cloning via the Notifications API's data member: basic case");
+
+test(() => {
+ let getter1Called = false;
+ let getter2Called = false;
+
+ assert_throws("DataCloneError", () => {
+ new Notification("Bob: Hi", { data: [
+ { get x() { getter1Called = true; return 5; } },
+ createEmptyWasmModule(),
+ { get x() { getter2Called = true; return 5; } }
+ ]});
+ });
+
+ assert_true(getter1Called, "The getter before the SAB must have been called");
+ assert_false(getter2Called, "The getter after the SAB must not have been called");
+}, "WebAssembly.Module cloning via the Notifications API's data member: is interleaved correctly");
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-domain-success.sub.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-domain-success.sub.html
new file mode 100644
index 0000000..51d4c5c
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-domain-success.sub.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<meta charset="utf-8">
+<title>Structured cloning of WebAssembly.Module into same-origin-domain windows</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/test-incrementer.js"></script>
+
+<div id="log"></div>
+
+<script>
+"use strict";
+document.domain = "{{host}}";
+
+promise_test(t => {
+ return new Promise(resolve => {
+ const iframe = document.createElement("iframe");
+ iframe.onload = t.step_func(() => {
+ resolve(testSharingViaIncrementerScript(t, window, "window", iframe.contentWindow, "iframe", "*"));
+ });
+ iframe.src = "//{{domains[www1]}}:{{location[port]}}/wasm/serialization/resources/incrementer-iframe-domain.sub.html";
+ document.body.appendChild(iframe);
+ });
+}, "postMessaging to a same-origin-domain (but not same-origin) iframe allows them to instantiate");
+
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-messagechannel-success.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-messagechannel-success.html
new file mode 100644
index 0000000..e686c81
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-messagechannel-success.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<meta charset="utf-8">
+<title>Structured cloning of WebAssembly.Module using MessageChannel</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/test-incrementer.js"></script>
+
+<div id="log"></div>
+
+<script>
+"use strict";
+
+promise_test(t => {
+ const worker = new Worker("resources/incrementer-worker-with-channel.js");
+ const channel = new MessageChannel();
+ worker.postMessage(channel.port2, [channel.port2]);
+
+ return testSharingViaIncrementerScript(t, channel.port1, "window", channel.port1, "worker");
+}, "postMessaging to a dedicated worker via MessageChannel allows them to instantiate");
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-serviceworker-failure.https.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-serviceworker-failure.https.html
new file mode 100644
index 0000000..97c5a1d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-serviceworker-failure.https.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<title>WebAssembly.Module cannot cross agent clusters, service worker edition</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
+<script src="./resources/create-empty-wasm-module.js"></script>
+
+<script>
+"use strict";
+promise_test(t => {
+ const scope = "resources/blank.html";
+ return service_worker_unregister_and_register(t, "resources/serviceworker-failure.js", scope).then(reg => {
+ return wait_for_state(t, reg.installing, "activated");
+ })
+ .then(() => {
+ return with_iframe(scope);
+ }).then(iframe => {
+ const sw = iframe.contentWindow.navigator.serviceWorker;
+ let state = "start in window";
+
+ return new Promise(resolve => {
+ sw.onmessage = t.step_func(e => {
+ if (e.data === "start in worker") {
+ assert_equals(state, "start in window");
+ sw.controller.postMessage(createEmptyWasmModule());
+ state = "we are expecting confirmation of an onmessageerror in the worker";
+ } else if (e.data === "onmessageerror was received in worker") {
+ assert_equals(state, "we are expecting confirmation of an onmessageerror in the worker");
+ state = "we are expecting a messageerror due to the worker sending us a WebAssembly.Module";
+ sw.controller.postMessage(state);
+ } else {
+ assert_unreached("Got an unexpected message from the service worker: " + e.data);
+ }
+ });
+
+ sw.onmessageerror = t.step_func(e => {
+ assert_equals(state, "we are expecting a messageerror due to the worker sending us a WebAssembly.Module");
+
+ assert_equals(e.data, null, "data");
+ assert_equals(e.origin, self.origin, "origin");
+ assert_equals(e.source, null, "source");
+ assert_equals(e.ports.length, 0, "ports length");
+
+ state = "done in window";
+ resolve();
+ });
+
+ sw.controller.postMessage(state);
+ });
+ });
+});
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-sharedworker-failure.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-sharedworker-failure.html
new file mode 100644
index 0000000..667e985
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-sharedworker-failure.html
@@ -0,0 +1,33 @@
+<!doctype html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<title>WebAssembly.Modules cannot cross agent clusters, shared worker edition</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/create-empty-wasm-module.js"></script>
+<script>
+async_test(t => {
+ const sw = new SharedWorker("resources/sharedworker-failure.js")
+ let state = ""
+ sw.port.onmessage = t.step_func(e => {
+ if(e.data === "send-sw-failure") {
+ sw.port.postMessage(createEmptyWasmModule())
+ } else if(e.data === "send-sw-failure-success") {
+ state = "send-window-failure"
+ sw.port.postMessage(state)
+ } else {
+ assert_unreached()
+ }
+ })
+ sw.port.onmessageerror = t.step_func(e => {
+ if(state === "send-window-failure") {
+ assert_equals(e.data, null, "data")
+ assert_equals(e.origin, "", "origin")
+ assert_equals(e.source, null, "source")
+ assert_equals(e.ports.length, 0, "ports length")
+ t.done()
+ } else {
+ assert_unreached()
+ }
+ })
+})
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-similar-but-cross-origin-success.sub.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-similar-but-cross-origin-success.sub.html
new file mode 100644
index 0000000..070cf0a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-similar-but-cross-origin-success.sub.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<meta charset="utf-8">
+<title>Structured cloning of WebAssembly.Module to similar-origin, but not same-origin, windows</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/test-incrementer.js"></script>
+
+<div id="log"></div>
+
+<script>
+"use strict";
+document.domain = "{{host}}";
+
+promise_test(t => {
+ return new Promise(resolve => {
+ const iframe = document.createElement("iframe");
+ iframe.onload = t.step_func(() => {
+ resolve(testSharingViaIncrementerScript(t, window, "window", iframe.contentWindow, "iframe", "*"));
+ });
+ iframe.src = "//{{domains[www1]}}:{{location[port]}}/wasm/serialization/resources/incrementer-iframe.html";
+ document.body.appendChild(iframe);
+ });
+}, "postMessaging to a not same-origin-domain, but similar origin, iframe allows them to instantiate");
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-simple-success.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-simple-success.html
new file mode 100644
index 0000000..6f2ccf4
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/wasm/serialization/window-simple-success.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<!-- Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/ -->
+<meta charset="utf-8">
+<title>Structured cloning of WebAssembly.Module: simple success cases that don't need dedicated files</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/test-incrementer.js"></script>
+
+<div id="log"></div>
+
+<script>
+"use strict";
+
+promise_test(t => {
+ const worker = new Worker("resources/incrementer-worker.js");
+
+ return testSharingViaIncrementerScript(t, worker, "window", worker, "worker", undefined);
+}, "postMessaging to a dedicated worker allows them to instantiate");
+
+promise_test(t => {
+ return new Promise(resolve => {
+ const iframe = document.createElement("iframe");
+ iframe.onload = t.step_func(() => {
+ resolve(testSharingViaIncrementerScript(t, window, "window", iframe.contentWindow, "iframe", "*"));
+ });
+ iframe.src = "resources/incrementer-iframe.html";
+ document.body.appendChild(iframe);
+ });
+}, "postMessaging to a same-origin iframe allows them to instantiate");
+
+promise_test(t => {
+ return new Promise(resolve => {
+ const iframe = document.createElement("iframe");
+ iframe.onload = t.step_func(() => {
+ const level1 = iframe.contentWindow;
+ const level2 = level1.frames[0];
+ const level3 = level2.frames[0];
+ const targetWindow = level3.frames[0];
+ resolve(testSharingViaIncrementerScript(t, window, "window", targetWindow, "nested iframe", "*"));
+ });
+ iframe.src = "resources/nested-iframe-1.html";
+ document.body.appendChild(iframe);
+ });
+}, "postMessaging to a same-origin deeply-nested iframe allows them to instantiate");
+
+promise_test(t => {
+ return new Promise(resolve => {
+ const w = window.open("resources/incrementer-popup.html");
+ w.onload = t.step_func(() => {
+ resolve(testSharingViaIncrementerScript(t, window, "window", w, "popup window", "*").then(() => {
+ w.close();
+ }));
+ });
+ });
+}, "postMessaging to a same-origin opened window allows them to instantiate");
+
+</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_local_iframe_test.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_local_iframe_test.html
deleted file mode 100644
index 0f4fbd0..0000000
--- a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_local_iframe_test.html
+++ /dev/null
@@ -1,19 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/load_wasm.js"></script>
-<script>
- function runTests(iframe) {
- iframe = iframe.contentWindow;
- promise_test(async function() {
- var mod = await createWasmModule();
- assert_true(mod instanceof WebAssembly.Module);
- var ans = await new Promise((resolve, reject) => {
- iframe.postMessage(mod, '*');
- window.addEventListener("message", (reply) => resolve(reply.data), false);
- });
- assert_equals(ans, 43);
- }, "send wasm module to iframe");
- }
-</script>
-<iframe src="resources/frame.html" onload="runTests(this)"></iframe>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_serialization_tests.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_serialization_tests.html
deleted file mode 100644
index 49766c77..0000000
--- a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_serialization_tests.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<!DOCTYPE html>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/load_wasm.js"></script>
-<script src="wasm_serialization_tests.js"></script>
-<script>
- promise_test(TestInstantiateInWorker, "serialize wasm to worker");
-</script>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_serialization_tests.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_serialization_tests.js
deleted file mode 100644
index 3cc41661..0000000
--- a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_serialization_tests.js
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-function TestInstantiateInWorker() {
- return createWasmModule()
- .then((mod) => {
- var worker = new Worker("wasm_serialization_worker.js");
- return new Promise((resolve, reject) => {
- worker.postMessage(mod);
- worker.onmessage = function(event) {
- resolve(event.data);
- }
- });
- })
- .then(data => assert_equals(data, 43))
- .catch(error => assert_unreached(error));
-}
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_serialization_worker.js b/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_serialization_worker.js
deleted file mode 100644
index 3361ed7..0000000
--- a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_serialization_worker.js
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-onmessage = function(e) {
- var compiled_module = e.data;
- var instance = new WebAssembly.Instance(compiled_module);
- if (instance === undefined) {
- postMessage("error!");
- return;
- }
- var entrypoint = instance.exports["increment"];
-
- if (typeof entrypoint !== "function") {
- postMessage("error!");
- return;
- }
-
- var ret = entrypoint(42);
- postMessage(ret);
-}
diff --git a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_service_worker_test.https.html b/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_service_worker_test.https.html
deleted file mode 100644
index cced4b8..0000000
--- a/third_party/WebKit/LayoutTests/external/wpt/wasm/wasm_service_worker_test.https.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!DOCTYPE html>
-<title>Service Worker: postMessage with wasm</title>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="/common/get-host-info.sub.js"></script>
-<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
-<script>
- promise_test(async test => {
- var registration = await service_worker_unregister_and_register(
- test, 'resources/service-worker.js', 'resources/blank.html');
- add_completion_callback(() => registration.unregister());
- var worker = registration.installing;
- var event = await new Promise((resolve, reject) => {
- var messageChannel = new MessageChannel();
- worker.postMessage({port: messageChannel.port2}, [messageChannel.port2]);
- worker.postMessage({compile: true});
- messageChannel.port1.onmessage = event => reject(event);
- messageChannel.port1.onmessageerror = event => resolve(event);
- });
- assert_equals(event.type, "messageerror");
- assert_equals(event.data, null);
- }, 'postMessaging wasm from a service worker should fail');
-</script>