summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/resources/fetch-header-visibility-iframe.html
blob: e0f32f75477c5fc082e3558415f963ef5a8c80fa (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<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();
  var uri = document.location + '?check-ua-header';

  var headers = new Headers();
  headers.set('User-Agent', 'custom_ua');

  // Check the custom UA case
  fetch(uri, { headers: headers }).then(function(response) {
    return response.text();
  }).then(function(text) {
    if (text == 'custom_ua') {
      parent.postMessage('PASS', '*');
    } else {
      parent.postMessage('withUA FAIL - expected "custom_ua", got "' + text + '"', '*');
    }
  }).catch(function(err) {
    parent.postMessage('withUA FAIL - unexpected error: ' + err, '*');
  });

  // Check the default UA case
  fetch(uri, {}).then(function(response) {
    return response.text();
  }).then(function(text) {
    if (text == 'NO_UA') {
      parent.postMessage('PASS', '*');
    } else {
      parent.postMessage('noUA FAIL - expected "NO_UA", got "' + text + '"', '*');
    }
  }).catch(function(err) {
    parent.postMessage('noUA FAIL - unexpected error: ' + err, '*');
  });

  var uri = document.location + '?check-accept-header';
  var headers = new Headers();
  headers.set('Accept', 'hmm');

  // Check for custom accept header
  fetch(uri, { headers: headers }).then(function(response) {
    return response.text();
  }).then(function(text) {
    if (text === headers.get('Accept')) {
      parent.postMessage('PASS', '*');
    } else {
      parent.postMessage('custom accept FAIL - expected ' + headers.get('Accept') +
                         ' got "' + text + '"', '*');
    }
  }).catch(function(err) {
    parent.postMessage('custom accept FAIL - unexpected error: ' + err, '*');
  });

  // Check for default accept header
  fetch(uri).then(function(response) {
    return response.text();
  }).then(function(text) {
    if (text === '*/*') {
      parent.postMessage('PASS', '*');
    } else {
      parent.postMessage('accept FAIL - expected */* got "' + text + '"', '*');
    }
  }).catch(function(err) {
    parent.postMessage('accept FAIL - unexpected error: ' + err, '*');
  });
</script>