summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/file_referrerdirective.html
blob: 841ffe05872a68363c9e698d8b52e187b3d1d9e9 (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
<!DOCTYPE HTML>
<html>
<head>
<title>Subframe test for bug 965727</title>

<script type="text/javascript">
// we can get the ID out of the querystring.
var args = document.location.search.substring(1).split('&');
var id = "unknown";
for (var i=0; i < args.length; i++) {
  var arg = unescape(args[i]);
  if (arg.indexOf('=') > 0 && arg.indexOf('id') == 0) {
    id = arg.split('=')[1].trim();
  }
}

var results = {
  'id': id,
  'referrer': document.location.href,
  'results': {
    'sameorigin': false,
    'crossorigin': false,
    'downgrade': false
  }
};

// this is called back by each script load.
var postResult = function(loadType, referrerLevel, referrer) {
  results.results[loadType] = referrerLevel;

  // and then check if all three have loaded.
  for (var id in results.results) {
    if (!results.results[id]) {
      return;
    }
  }
  //finished if we don't return early
  window.parent.postMessage(JSON.stringify(results), "*");
  console.log(JSON.stringify(results));
}

</script>
</head>
<body>
Testing ...

<script src="https://example.com/tests/dom/security/test/csp/referrerdirective.sjs?type=sameorigin&"
        onerror="postResult('sameorigin', 'error');"></script>
<script src="https://test2.example.com/tests/dom/security/test/csp/referrerdirective.sjs?type=crossorigin&"
        onerror="postResult('crossorigin', 'error');"></script>
<script src="http://example.com/tests/dom/security/test/csp/referrerdirective.sjs?type=downgrade&"
        onerror="postResult('downgrade', 'error');"></script>

</body>
</html>