tor-browser

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

test_websocket_self.html (1836B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Bug 1345615: Allow websocket schemes when using 'self' in CSP</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="test_ws_self_frame"></iframe>
     12 <iframe style="width:100%;" id="test_ws_explicit_frame"></iframe>
     13 
     14 <script class="testbody" type="text/javascript">
     15 
     16 /* Description of the test:
     17 * We load an iframe using connect-src 'self' and one
     18 *            iframe using connect-src ws: and make
     19 * sure that in both cases ws: as well as wss: is allowed to load.
     20 */
     21 
     22 SimpleTest.waitForExplicitFinish();
     23 
     24 function finishTest() {
     25  window.removeEventListener("message", receiveMessage);
     26  SimpleTest.finish();
     27 }
     28 
     29 const TOTAL_TESTS = 4;
     30 var counter = 0;
     31 
     32 function checkResults(result) {
     33  counter++;
     34  if (result === "self-ws-loaded" || result === "self-wss-loaded" ||
     35      result === "explicit-ws-loaded" || result === "explicit-wss-loaded") {
     36    ok(true, "Evaluating: " + result);
     37  }
     38  else {
     39    ok(false, "Evaluating: " + result);
     40  }
     41  if (counter < TOTAL_TESTS) {
     42    return;
     43  }
     44  finishTest();
     45 }
     46 
     47 window.addEventListener("message", receiveMessage);
     48 function receiveMessage(event) {
     49  checkResults(event.data.result);
     50 }
     51 
     52 const HOST = "http://example.com/tests/dom/security/test/csp/";
     53 var test_ws_self_frame = document.getElementById("test_ws_self_frame");
     54 test_ws_self_frame.src = HOST + "file_websocket_self.html";
     55 
     56 var test_ws_explicit_frame = document.getElementById("test_ws_explicit_frame");
     57 test_ws_explicit_frame.src = HOST + "file_websocket_explicit.html";
     58 
     59 </script>
     60 </body>
     61 </html>