chromium/third_party/blink/web_tests/http/tests/serviceworker/resources/referer-iframe.html

<script src="/resources/get-host-info.js"></script>
<script>
function check_referer(url, expected_referer) {
  return fetch(url)
    .then(function(res) { return res.json(); })
    .then(function(headers) {
        if (headers['Referer'] === expected_referer) {
          return Promise.resolve();
        } else {
          return Promise.reject('Referer for ' + url + ' must be ' +
                                expected_referer + ' but got ' +
                                headers['Referer']);
        }
      });
}

window.addEventListener('message', function(evt) {
    var host_info = get_host_info();
    var port = evt.ports[0];
    check_referer('request-headers.php?ignore=true',
                  host_info['HTTP_ORIGIN'] +
                  '/serviceworker/resources/referer-iframe.html')
      .then(function() {
          return check_referer(
              'request-headers.php',
              host_info['HTTP_ORIGIN'] +
              '/serviceworker/resources/referer-iframe.html');
        })
      .then(function() {
          return check_referer(
              'request-headers.php?url=request-headers.php',
              host_info['HTTP_ORIGIN'] +
              '/serviceworker/resources/fetch-rewrite-worker.js');
        })
      .then(function() { port.postMessage({results: 'finish'}); })
      .catch(function(e) { port.postMessage({results: 'failure:' + e}); });
  });
</script>