content/base/test/csp/test_CSP_bug802872.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial