content/base/test/csp/test_CSP_evalscript_getCRMFRequest.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

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test for Content Security Policy "no eval" in crypto.getCRMFRequest()</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     7 </head>
     8 <body>
     9 <p id="display"></p>
    10 <div id="content" style="display: none">
    11 </div>
    12 <iframe style="width:100%;height:300px;" id='cspframe'></iframe>
    13 <iframe style="width:100%;height:300px;" id='cspframe2'></iframe>
    14 <iframe style="width:100%;height:300px;" id='cspframe3'></iframe>
    15 <iframe style="width:100%;height:300px;" id='cspframe4'></iframe>
    16 <script class="testbody" type="text/javascript">
    18 var path = "/tests/content/base/test/csp/";
    20 var evalScriptsThatRan = 0;
    21 var evalScriptsBlocked = 0;
    22 var evalScriptsTotal = 4;
    24 // called by scripts that run
    25 var scriptRan = function(shouldrun, testname, data) {
    26   evalScriptsThatRan++;
    27   ok(shouldrun, 'EVAL SCRIPT RAN: ' + testname + '(' + data + ')');
    28   checkTestResults();
    29 }
    31 // called when a script is blocked
    32 var scriptBlocked = function(shouldrun, testname, data) {
    33   evalScriptsBlocked++;
    34   ok(!shouldrun, 'EVAL SCRIPT BLOCKED: ' + testname + '(' + data + ')');
    35   checkTestResults();
    36 }
    38 // Check to see if all the tests have run
    39 var checkTestResults = function() {
    40   // if any test is incomplete, keep waiting
    41   if (evalScriptsTotal - evalScriptsBlocked - evalScriptsThatRan > 0)
    42     return;
    44   // ... otherwise, finish
    45   SimpleTest.finish();
    46 }
    48 //////////////////////////////////////////////////////////////////////
    49 // set up and go
    50 SimpleTest.waitForExplicitFinish();
    52 SpecialPowers.pushPrefEnv(
    53   {'set':[["security.csp.speccompliant", true]]},
    54     function() {
    55       // save this for last so that our listeners are registered.
    56       // ... this loads the testbed of good and bad requests.
    57       document.getElementById('cspframe').src = 'file_CSP_evalscript_main_getCRMFRequest.html';
    58       document.getElementById('cspframe2').src = 'file_CSP_evalscript_main_spec_compliant_getCRMFRequest.html';
    59       document.getElementById('cspframe3').src = 'file_CSP_evalscript_main_spec_compliant_allowed_getCRMFRequest.html';
    60       document.getElementById('cspframe4').src = 'file_CSP_evalscript_no_CSP_at_all.html';
    61     });
    62 </script>
    63 </pre>
    64 </body>
    65 </html>

mercurial