summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/test_bug802872.html
blob: 956159ddccfaf4723c031ac4ebce5bd09caebf00 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 802872</title>
  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <iframe style="width:100%;" id='eventframe'></iframe>

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

SimpleTest.waitForExplicitFinish();

var finishedTests = 0;
var numberOfTests = 2;

var checkExplicitFinish = function () {
  finishedTests++;
  if (finishedTests == numberOfTests) {
     SimpleTest.finish();
  }
}

// add event listeners for CSP-permitted EventSrc callbacks
addEventListener('allowedEventSrcCallbackOK', function (e) {
  ok(true, "OK: CSP allows EventSource for allowlisted domain!");
  checkExplicitFinish();
}, false);
addEventListener('allowedEventSrcCallbackFailed', function (e) {
  ok(false, "Error: CSP blocks EventSource for allowlisted domain!");
  checkExplicitFinish();
}, false);

// add event listeners for CSP-blocked EventSrc callbacks
addEventListener('blockedEventSrcCallbackOK', function (e) {
  ok(false, "Error: CSP allows EventSource to not allowlisted domain!");
  checkExplicitFinish();
}, false);
addEventListener('blockedEventSrcCallbackFailed', function (e) {
  ok(true, "OK: CSP blocks EventSource for not allowlisted domain!");
  checkExplicitFinish();
}, false);

// load it
document.getElementById('eventframe').src = 'file_bug802872.html';

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