<!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/metadata/resources/helper.js></script>
<script src=/common/utils.js></script>
<body></body>
<script>
  let nonce = token();

  promise_test(t => {
    return new Promise((resolve, reject) => {
      let key = "redirect-same-origin-same-origin" + nonce;

      let e = document.createElement('img');
      e.src = "/xhr/resources/redirect.py?location=http://localhost:8800/fetch/metadata/resources/record-header.py?file=" + key;
      let expected = {"site":"same-origin", "user":"", "mode": "no-cors", "dest": "image"};

      e.onload = e => {
        validate_expectations(key, expected)
          .then(_ => resolve())
          .catch(e => reject(e));
      };
      e.onerror = e => {
        validate_expectations(key, expected)
          .then(_ => resolve())
          .catch(e => reject(e));
      };

      document.body.appendChild(e);
    })
  }, "Same-Origin -> Same-Origin redirect");
</script>
