content/base/test/csp/test_CSP_bug802872.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/csp/test_CSP_bug802872.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Bug 802872</title>
     1.8 +  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +  <p id="display"></p>
    1.14 +  <div id="content" style="display: none"></div>
    1.15 +  <iframe style="width:100%;" id='eventframe'></iframe>
    1.16 +
    1.17 +<script class="testbody" type="text/javascript">
    1.18 +
    1.19 +SimpleTest.waitForExplicitFinish();
    1.20 +
    1.21 +var finishedTests = 0;
    1.22 +var numberOfTests = 2;
    1.23 +
    1.24 +var checkExplicitFinish = function () {
    1.25 +  finishedTests++;
    1.26 +  if (finishedTests == numberOfTests) {
    1.27 +     SimpleTest.finish();
    1.28 +  }
    1.29 +}
    1.30 +
    1.31 +SpecialPowers.pushPrefEnv(
    1.32 +  {'set':[["security.csp.speccompliant", true]]},
    1.33 +  function () {
    1.34 +    // add event listeners for CSP-permitted EventSrc callbacks
    1.35 +    addEventListener('allowedEventSrcCallbackOK', function (e) {
    1.36 +      ok(true, "OK: CSP allows EventSource for whitelisted domain!");
    1.37 +      checkExplicitFinish();
    1.38 +    }, false);
    1.39 +    addEventListener('allowedEventSrcCallbackFailed', function (e) {
    1.40 +      ok(false, "Error: CSP blocks EventSource for whitelisted domain!");
    1.41 +      checkExplicitFinish();
    1.42 +    }, false);
    1.43 +
    1.44 +    // add event listeners for CSP-blocked EventSrc callbacks
    1.45 +    addEventListener('blockedEventSrcCallbackOK', function (e) {
    1.46 +      ok(false, "Error: CSP allows EventSource to not whitelisted domain!");
    1.47 +      checkExplicitFinish();
    1.48 +    }, false);
    1.49 +    addEventListener('blockedEventSrcCallbackFailed', function (e) {
    1.50 +      ok(true, "OK: CSP blocks EventSource for not whitelisted domain!");
    1.51 +      checkExplicitFinish();
    1.52 +    }, false);
    1.53 +
    1.54 +    // load it
    1.55 +    document.getElementById('eventframe').src = 'file_CSP_bug802872.html';
    1.56 +  }
    1.57 +);
    1.58 +
    1.59 +</script>
    1.60 +</body>
    1.61 +</html>

mercurial