tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_multipartchannel.html (2231B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Bug 1416045/Bug 1223743 - CSP: Check baseChannel for CSP when loading multipart channel</title>
      6  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      9 </head>
     10 <body>
     11 <iframe style="width:100%;" id="testframe"></iframe>
     12 <iframe style="width:100%;" id="testPartCSPframe"></iframe>
     13 
     14 <script class="testbody" type="text/javascript">
     15 
     16 var testsToRunMultipartCSP = {
     17  rootCSP_test: false,
     18  part1CSP_test: false,
     19  part2CSP_test: false,
     20 };
     21 
     22 SimpleTest.waitForExplicitFinish();
     23 
     24 function checkTestsCompleted() {
     25  for (var prop in testsToRunMultipartCSP) {
     26    // some test hasn't run yet so we're not done
     27    if (!testsToRunMultipartCSP[prop]) {
     28      return;
     29    }
     30  }
     31  window.removeEventListener("message", receiveMessage);
     32  SimpleTest.finish();
     33 }
     34 /* Description of the test:
     35 * We apply a CSP to a multipart channel and then try to load an image
     36 * within a segment making sure the image is blocked correctly by CSP.
     37 * We also provide CSP for each part and try to load an image in each
     38 * part and make sure the image is loaded in first part and blocked in
     39 * second part correctly based on its CSP accordingly.
     40 */
     41 
     42 window.addEventListener("message", receiveMessage);
     43 function receiveMessage(event) {
     44  switch (event.data.test) {
     45    case "rootCSP_test":
     46      is(event.data.msg, "img-blocked", "image should be blocked");
     47      testsToRunMultipartCSP.rootCSP_test = true;
     48      break;
     49    case "part1CSP_test":
     50      is(event.data.msg, "part1-img-loaded", "Part1 image should be loaded");
     51      testsToRunMultipartCSP.part1CSP_test = true;
     52      break;
     53    case "part2CSP_test":
     54      is(event.data.msg, "part2-img-blocked", "Part2 image should be blocked");
     55      testsToRunMultipartCSP.part2CSP_test = true;
     56      break;
     57  }
     58  checkTestsCompleted();
     59 }
     60 
     61 // start the test
     62 document.getElementById("testframe").src = "file_multipart_testserver.sjs?doc";
     63 document.getElementById("testPartCSPframe").src =
     64                                    "file_multipart_testserver.sjs?partcspdoc";
     65 
     66 </script>
     67 </body>
     68 </html>