summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/resources/fetch-response-xhr-iframe.https.html
blob: 3391381e38af1cf3ed969fcfa4741a78fb3ab5a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<script src="../resources/get-host-info.sub.js"></script>
<script src="test-helpers.sub.js?pipe=sub"></script>
<script>
var host_info = get_host_info();

function xhr_send(method, data) {
  return new Promise(function(resolve, reject) {
      var xhr = new XMLHttpRequest();
      xhr.onload = function() {
        resolve(xhr);
      };
      xhr.onerror = function() {
        reject('XHR should succeed.');
      };
      xhr.responseType = 'text';
      xhr.open(method, './dummy?test', true);
      xhr.send(data);
    });
}

function coalesce_headers_test() {
  return xhr_send('POST', 'test string')
  .then(function(xhr) {
      window.parent.postMessage({results: xhr.getResponseHeader('foo')},
                                host_info['HTTPS_ORIGIN']);
    });
}

window.addEventListener('message', function(evt) {
    var port = evt.ports[0];
    coalesce_headers_test()
      .then(function() { port.postMessage({results: 'finish'}); })
      .catch(function(e) { port.postMessage({results: 'failure:' + e}); });
  });
</script>