content/base/test/csp/test_CSP_bug802872.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Bug 802872</title>
     5   <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
     6   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     8 </head>
     9 <body>
    10   <p id="display"></p>
    11   <div id="content" style="display: none"></div>
    12   <iframe style="width:100%;" id='eventframe'></iframe>
    14 <script class="testbody" type="text/javascript">
    16 SimpleTest.waitForExplicitFinish();
    18 var finishedTests = 0;
    19 var numberOfTests = 2;
    21 var checkExplicitFinish = function () {
    22   finishedTests++;
    23   if (finishedTests == numberOfTests) {
    24      SimpleTest.finish();
    25   }
    26 }
    28 SpecialPowers.pushPrefEnv(
    29   {'set':[["security.csp.speccompliant", true]]},
    30   function () {
    31     // add event listeners for CSP-permitted EventSrc callbacks
    32     addEventListener('allowedEventSrcCallbackOK', function (e) {
    33       ok(true, "OK: CSP allows EventSource for whitelisted domain!");
    34       checkExplicitFinish();
    35     }, false);
    36     addEventListener('allowedEventSrcCallbackFailed', function (e) {
    37       ok(false, "Error: CSP blocks EventSource for whitelisted domain!");
    38       checkExplicitFinish();
    39     }, false);
    41     // add event listeners for CSP-blocked EventSrc callbacks
    42     addEventListener('blockedEventSrcCallbackOK', function (e) {
    43       ok(false, "Error: CSP allows EventSource to not whitelisted domain!");
    44       checkExplicitFinish();
    45     }, false);
    46     addEventListener('blockedEventSrcCallbackFailed', function (e) {
    47       ok(true, "OK: CSP blocks EventSource for not whitelisted domain!");
    48       checkExplicitFinish();
    49     }, false);
    51     // load it
    52     document.getElementById('eventframe').src = 'file_CSP_bug802872.html';
    53   }
    54 );
    56 </script>
    57 </body>
    58 </html>

mercurial