Merge pull request #12729 from Loirooriol/css-shorthand-initial

Test that important flags are checked when serializing shorthand with "initial" values
diff --git a/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/sharedworker-failure.js b/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/sharedworker-failure.js
index a11ccbc1..8472318 100644
--- a/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/sharedworker-failure.js
+++ b/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/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/readiness.window.js b/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/readiness.window.js
new file mode 100644
index 0000000..729a958
--- /dev/null
+++ b/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/readiness.window.js
@@ -0,0 +1,25 @@
+// This tests the behavior of dynamic markup insertion APIs with a document's
+// readiness.
+
+async_test(t => {
+  const frame = document.body.appendChild(document.createElement("iframe"));
+  t.add_cleanup(() => { frame.remove(); });
+  frame.src = "/common/blank.html";
+  frame.onload = t.step_func_done(() => {
+    const states = [];
+    frame.contentDocument.onreadystatechange = t.step_func(() => {
+      states.push(frame.contentDocument.readyState);
+    });
+    assert_equals(frame.contentDocument.readyState, "complete");
+    assert_array_equals(states, []);
+
+    // When open() is called, it first removes the event listeners and handlers
+    // from all nodes in the DOM tree. Then, after a new parser is created and
+    // initialized, it changes the current document readiness to "loading".
+    // However, because all event listeners are removed, we cannot observe the
+    // readystatechange event fired for "loading" inside open().
+    frame.contentDocument.open();
+    assert_equals(frame.contentDocument.readyState, "loading");
+    assert_array_equals(states, []);
+  });
+}, "document.open() and readiness");
diff --git a/wasm/resources/frame.html b/wasm/resources/frame.html
deleted file mode 100644
index d1c83e1..0000000
--- a/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/wasm/resources/service-worker.js b/wasm/resources/service-worker.js
deleted file mode 100644
index 684eaf6..0000000
--- a/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/wasm/serialization/broadcastchannel-success-and-failure.html b/wasm/serialization/broadcastchannel-success-and-failure.html
new file mode 100644
index 0000000..0d11cc5
--- /dev/null
+++ b/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/wasm/serialization/broadcastchannel-success.html b/wasm/serialization/broadcastchannel-success.html
new file mode 100644
index 0000000..cd5f8d0
--- /dev/null
+++ b/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/wasm/serialization/identity-not-preserved.html b/wasm/serialization/identity-not-preserved.html
new file mode 100644
index 0000000..24bb3b1
--- /dev/null
+++ b/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/wasm/resources/incrementer.wasm b/wasm/serialization/incrementer.wasm
similarity index 100%
copy from wasm/resources/incrementer.wasm
copy to wasm/serialization/incrementer.wasm
Binary files differ
diff --git a/wasm/serialization/nested-worker-success.any.js b/wasm/serialization/nested-worker-success.any.js
new file mode 100644
index 0000000..5388ebc
--- /dev/null
+++ b/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/wasm/serialization/no-transferring.html b/wasm/serialization/no-transferring.html
new file mode 100644
index 0000000..a0bf11f
--- /dev/null
+++ b/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/wasm/resources/blank.html b/wasm/serialization/resources/blank.html
similarity index 100%
rename from wasm/resources/blank.html
rename to wasm/serialization/resources/blank.html
diff --git a/wasm/serialization/resources/broadcastchannel-iframe.html b/wasm/serialization/resources/broadcastchannel-iframe.html
new file mode 100644
index 0000000..83e347b
--- /dev/null
+++ b/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/wasm/serialization/resources/broadcastchannel-sharedworker.js b/wasm/serialization/resources/broadcastchannel-sharedworker.js
new file mode 100644
index 0000000..310e0e9
--- /dev/null
+++ b/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/wasm/serialization/resources/broadcastchannel-worker.js b/wasm/serialization/resources/broadcastchannel-worker.js
new file mode 100644
index 0000000..76a8177
--- /dev/null
+++ b/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/wasm/serialization/resources/create-empty-wasm-module.js b/wasm/serialization/resources/create-empty-wasm-module.js
new file mode 100644
index 0000000..7326710
--- /dev/null
+++ b/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/wasm/serialization/resources/echo-iframe.html b/wasm/serialization/resources/echo-iframe.html
new file mode 100644
index 0000000..c4fd582
--- /dev/null
+++ b/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/wasm/serialization/resources/echo-worker.js b/wasm/serialization/resources/echo-worker.js
new file mode 100644
index 0000000..cbbde8a
--- /dev/null
+++ b/wasm/serialization/resources/echo-worker.js
@@ -0,0 +1,5 @@
+"use strict";
+
+self.onmessage = ({ data }) => {
+  self.postMessage(data);
+};
diff --git a/wasm/serialization/resources/incrementer-iframe-domain.sub.html b/wasm/serialization/resources/incrementer-iframe-domain.sub.html
new file mode 100644
index 0000000..d2d18de
--- /dev/null
+++ b/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/wasm/serialization/resources/incrementer-iframe.html b/wasm/serialization/resources/incrementer-iframe.html
new file mode 100644
index 0000000..5c8bc07
--- /dev/null
+++ b/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/wasm/serialization/resources/incrementer-popup.html b/wasm/serialization/resources/incrementer-popup.html
new file mode 100644
index 0000000..660e472
--- /dev/null
+++ b/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/wasm/serialization/resources/incrementer-worker-with-channel.js b/wasm/serialization/resources/incrementer-worker-with-channel.js
new file mode 100644
index 0000000..0323b3e
--- /dev/null
+++ b/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/wasm/serialization/resources/incrementer-worker.js b/wasm/serialization/resources/incrementer-worker.js
new file mode 100644
index 0000000..1779cee
--- /dev/null
+++ b/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/wasm/resources/incrementer.wasm b/wasm/serialization/resources/incrementer.wasm
similarity index 100%
rename from wasm/resources/incrementer.wasm
rename to wasm/serialization/resources/incrementer.wasm
Binary files differ
diff --git a/wasm/serialization/resources/nested-iframe-1.html b/wasm/serialization/resources/nested-iframe-1.html
new file mode 100644
index 0000000..fe93cc0
--- /dev/null
+++ b/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/wasm/serialization/resources/nested-iframe-2.html b/wasm/serialization/resources/nested-iframe-2.html
new file mode 100644
index 0000000..fad52ce
--- /dev/null
+++ b/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/wasm/serialization/resources/nested-iframe-3.html b/wasm/serialization/resources/nested-iframe-3.html
new file mode 100644
index 0000000..7971022
--- /dev/null
+++ b/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/wasm/serialization/resources/nested-iframe-4-incrementer.html b/wasm/serialization/resources/nested-iframe-4-incrementer.html
new file mode 100644
index 0000000..f419f4b
--- /dev/null
+++ b/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/wasm/serialization/resources/serviceworker-failure.js b/wasm/serialization/resources/serviceworker-failure.js
new file mode 100644
index 0000000..39796f9
--- /dev/null
+++ b/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/wasm/serialization/resources/sharedworker-failure.js b/wasm/serialization/resources/sharedworker-failure.js
new file mode 100644
index 0000000..854c70b
--- /dev/null
+++ b/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/wasm/serialization/resources/test-incrementer.js b/wasm/serialization/resources/test-incrementer.js
new file mode 100644
index 0000000..65cb332
--- /dev/null
+++ b/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/wasm/serialization/serialization-via-history.html b/wasm/serialization/serialization-via-history.html
new file mode 100644
index 0000000..35dc17b
--- /dev/null
+++ b/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/wasm/serialization/serialization-via-idb.any.js b/wasm/serialization/serialization-via-idb.any.js
new file mode 100644
index 0000000..1d861c3
--- /dev/null
+++ b/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/wasm/serialization/serialization-via-notifications-api.any.js b/wasm/serialization/serialization-via-notifications-api.any.js
new file mode 100644
index 0000000..8410565
--- /dev/null
+++ b/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/wasm/serialization/window-domain-success.sub.html b/wasm/serialization/window-domain-success.sub.html
new file mode 100644
index 0000000..51d4c5c
--- /dev/null
+++ b/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/wasm/serialization/window-messagechannel-success.html b/wasm/serialization/window-messagechannel-success.html
new file mode 100644
index 0000000..e686c81
--- /dev/null
+++ b/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/wasm/serialization/window-serviceworker-failure.https.html b/wasm/serialization/window-serviceworker-failure.https.html
new file mode 100644
index 0000000..97c5a1d
--- /dev/null
+++ b/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/wasm/serialization/window-sharedworker-failure.html b/wasm/serialization/window-sharedworker-failure.html
new file mode 100644
index 0000000..667e985
--- /dev/null
+++ b/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/wasm/serialization/window-similar-but-cross-origin-success.sub.html b/wasm/serialization/window-similar-but-cross-origin-success.sub.html
new file mode 100644
index 0000000..070cf0a
--- /dev/null
+++ b/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/wasm/serialization/window-simple-success.html b/wasm/serialization/window-simple-success.html
new file mode 100644
index 0000000..6f2ccf4
--- /dev/null
+++ b/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/wasm/wasm_local_iframe_test.html b/wasm/wasm_local_iframe_test.html
deleted file mode 100644
index 0f4fbd0..0000000
--- a/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/wasm/wasm_serialization_tests.html b/wasm/wasm_serialization_tests.html
deleted file mode 100644
index 49766c7..0000000
--- a/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/wasm/wasm_serialization_tests.js b/wasm/wasm_serialization_tests.js
deleted file mode 100644
index 3cc4166..0000000
--- a/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/wasm/wasm_serialization_worker.js b/wasm/wasm_serialization_worker.js
deleted file mode 100644
index 3361ed7..0000000
--- a/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/wasm/wasm_service_worker_test.https.html b/wasm/wasm_service_worker_test.https.html
deleted file mode 100644
index cced4b8..0000000
--- a/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>