<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="create-wasm-module.js"></script>
<script>
async_test(t => {
  parent.postMessage('init done', '*');
  window.addEventListener('message', async evt => {
    if (evt.data.constructor.name !== 'WritableStream') {
      return;
    }
    const ws = evt.data;
    const writer = ws.getWriter();
    const module = await createWasmModule();
    writer.write(module);
    await promise_rejects_dom(t, 'DataCloneError', writer.closed,
                              'should reject with a DataCloneError');
    t.done();
    // Signal that this test is done. When both tests are done the iframe will
    // be removed.
    parent.postMessage('ws done', '*');
  });
}, 'a WritableStream deserialization failure should result in a DataCloneError');

async_test(t => {
  window.addEventListener('message', async evt => {
    if (evt.data.constructor.name !== 'ReadableStream') {
      return;
    }
    const rs = evt.data;
    const reader = rs.getReader();
    await promise_rejects_dom(t, 'DataCloneError', reader.read(),
                              'should reject with a DataCloneError');
    t.done();
    // Signal that this test is done. When both tests are done the iframe will
    // be removed.
    parent.postMessage('rs done', '*');
  });
}, 'a ReadableStream deserialization failure should result in a DataCloneError');
</script>
