summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/test_ignore_xfo.html
blob: fb3aadc6c2859e07055399ac0021e061be258ee7 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 1024557: Ignore x-frame-options if CSP with frame-ancestors exists</title>
  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<iframe style="width:100%;" id="csp_testframe"></iframe>
<iframe style="width:100%;" id="csp_ro_testframe"></iframe>

<script class="testbody" type="text/javascript">

/*
 * We load two frames using:
 *   x-frame-options: deny
 * where the first frame uses a csp and the second a csp_ro including frame-ancestors.
 * We make sure that xfo is ignored for regular csp but not for csp_ro.
 */

SimpleTest.waitForExplicitFinish();

var testcounter = 0;
function checkFinished() {
  testcounter++;
  if (testcounter < 2) {
  	return;
  }
  SimpleTest.finish();
}

// 1) test XFO with CSP
var csp_testframe = document.getElementById("csp_testframe");
csp_testframe.onload = function() {
  var msg = csp_testframe.contentWindow.document.getElementById("cspmessage");
  is(msg.innerHTML, "Ignoring XFO because of CSP", "Loading frame with with XFO and CSP");
  checkFinished();
}
csp_testframe.onerror = function() {
  ok(false, "sanity: should not fire onerror for csp_testframe");
}
csp_testframe.src = "file_ignore_xfo.html";

// 2) test XFO with CSP_RO
var csp_ro_testframe = document.getElementById("csp_ro_testframe");
csp_ro_testframe.onload = function() {
  var msg = csp_ro_testframe.contentWindow.document.getElementById("cspmessage");
  is(msg, null, "Blocking frame with with XFO and CSP_RO");
  checkFinished();
}
csp_ro_testframe.onerror = function() {
  ok(false, "sanity: should not fire onerror for csp_ro_testframe");
}
csp_ro_testframe.src = "file_ro_ignore_xfo.html";

</script>
</body>
</html>