<!DOCTYPE html>
<!--
This test was procedurally generated. Please do not modify it directly.
Sources:
- fetch/metadata/tools/fetch-metadata.conf.yml
- fetch/metadata/tools/templates/fetch.sub.html
-->
<html lang="en">
  <meta charset="utf-8">
  <title>HTTP headers on request using the "fetch" API</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="/fetch/metadata/resources/helper.sub.js"></script>
  <body>
  <script>
  'use strict';

  function induceRequest(url, init) {
    return fetch(url, init);
  }

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsOrigin']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['same-origin']);
        });
  }, 'sec-fetch-site - Same origin, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsCrossSite']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['cross-site']);
        });
  }, 'sec-fetch-site - Cross-site, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsSameSite']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['same-site']);
        });
  }, 'sec-fetch-site - Same site, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsOrigin', 'httpsCrossSite', 'httpsOrigin']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['cross-site']);
        });
  }, 'sec-fetch-site - Same-Origin -> Cross-Site -> Same-Origin redirect, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsOrigin', 'httpsSameSite', 'httpsOrigin']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['same-site']);
        });
  }, 'sec-fetch-site - Same-Origin -> Same-Site -> Same-Origin redirect, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsCrossSite', 'httpsOrigin']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['cross-site']);
        });
  }, 'sec-fetch-site - Cross-Site -> Same Origin, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsCrossSite', 'httpsSameSite']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['cross-site']);
        });
  }, 'sec-fetch-site - Cross-Site -> Same-Site, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsCrossSite', 'httpsCrossSite']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['cross-site']);
        });
  }, 'sec-fetch-site - Cross-Site -> Cross-Site, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsOrigin', 'httpsOrigin']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['same-origin']);
        });
  }, 'sec-fetch-site - Same-Origin -> Same Origin, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsOrigin', 'httpsSameSite']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['same-site']);
        });
  }, 'sec-fetch-site - Same-Origin -> Same-Site, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsOrigin', 'httpsCrossSite']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['cross-site']);
        });
  }, 'sec-fetch-site - Same-Origin -> Cross-Site, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsSameSite', 'httpsOrigin']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['same-site']);
        });
  }, 'sec-fetch-site - Same-Site -> Same Origin, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsSameSite', 'httpsSameSite']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['same-site']);
        });
  }, 'sec-fetch-site - Same-Site -> Same-Site, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsSameSite', 'httpsCrossSite']),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-site');
          assert_array_equals(headers['sec-fetch-site'], ['cross-site']);
        });
  }, 'sec-fetch-site - Same-Site -> Cross-Site, init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, []),
        {}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-mode');
          assert_array_equals(headers['sec-fetch-mode'], ['cors']);
        });
  }, 'sec-fetch-mode - no init');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, []),
        {"mode": "cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-mode');
          assert_array_equals(headers['sec-fetch-mode'], ['cors']);
        });
  }, 'sec-fetch-mode - init: mode=cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, []),
        {"mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-mode');
          assert_array_equals(headers['sec-fetch-mode'], ['no-cors']);
        });
  }, 'sec-fetch-mode - init: mode=no-cors');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, []),
        {"mode": "same-origin"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-mode');
          assert_array_equals(headers['sec-fetch-mode'], ['same-origin']);
        });
  }, 'sec-fetch-mode - init: mode=same-origin');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, []),
        {}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-dest');
          assert_array_equals(headers['sec-fetch-dest'], ['empty']);
        });
  }, 'sec-fetch-dest - no init');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, []),
        {}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_not_own_property(headers, 'sec-fetch-user');
        });
  }, 'sec-fetch-user - no init');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsCrossSite']),
        {"credentials": "include", "mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_own_property(headers, 'sec-fetch-storage-access');
          assert_array_equals(headers['sec-fetch-storage-access'], ['none']);
        });
  }, 'sec-fetch-storage-access - Cross-site, init: mode=no-cors, credentials=include');

  promise_test(() => {
    const key = '{{uuid()}}';

    return induceRequest(
        makeRequestURL(key, ['httpsSameSite']),
        {"credentials": "include", "mode": "no-cors"}
      )
      .then(() => retrieve(key))
      .then((headers) => {
          assert_not_own_property(headers, 'sec-fetch-storage-access');
        });
  }, 'sec-fetch-storage-access - Same site, init: mode=no-cors, credentials=include');
  </script>
  </body>
</html>
