<!DOCTYPE html>

<link rel="author" href="mtrzos@google.com" title="Maciek Trzos">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/fetch/sec-metadata/resources/helper.js></script>
<script>

  // TESTS //
  if (window.Worker) {

      //  Same-Origin test
      var sharedWorker = new SharedWorker('/fetch/sec-metadata/resources/record-header.py?file=sharedworker-same-origin');
      sharedWorker.port.start();

      sharedWorker.onerror = function(){
        test_same_origin();
      }
      sharedWorker.port.onmessage = function(e) {
        test_same_origin();
      }
      sharedWorker.port.postMessage("Ready");
    }

  function test_same_origin(){
    promise_test(t => {
      return new Promise((resolve, reject) => {
        let key = "sharedworker-same-origin";
        let expected = {"destination":"sharedworker", "site":"same-origin"};

        fetch("/fetch/sec-metadata/resources/record-header.py?retrieve=true&file=" + key)
          .then(response => response.text())
          .then(text => assert_header_equals(text, expected))
          .then(_ => resolve())
          .catch(e => reject(e));
      })
    }, "Same-Origin sharedworker")
  }
</script>
<body></body>
