tor-browser

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

test_websocket_mixed_content_opener.html (5239B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
      5  <title>WebSocket mixed content opener tests - load secure and insecure websockets in secure and insecure iframes through secure and insecure opened windows</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7 
      8  <script type="text/javascript" src="websocket_helpers.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     10 </head>
     11 <body>
     12 <div id="container"></div>
     13 <script class="testbody" type="text/javascript">
     14 function runTest({ name, url, expect, httpsFirst = false }) {
     15  return new Promise((resolve) => {
     16    SpecialPowers.pushPrefEnv({
     17      set: [["dom.security.https_first", httpsFirst]],
     18    }).then(() => {
     19      let win = window.open(
     20        url,
     21        "_blank",
     22        "location=yes,height=570,width=520,scrollbars=yes,status=yes"
     23      );
     24      onmessage = function (e) {
     25        is(e.data, expect, `${name} - Unexpected message`);
     26        win.close();
     27        SpecialPowers.flushPrefEnv().then(() => {
     28          resolve();
     29        });
     30      };
     31    });
     32  });
     33 }
     34 
     35 async function testWebSockets() {
     36  await runTest({
     37    name: "testSecureWindowWSS",
     38    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html",
     39    expect: "WS onopen",
     40  });
     41 
     42  await runTest({
     43    name: "testInsecureWindowWSS",
     44    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html",
     45    expect: "WS onopen",
     46  });
     47 
     48  // ws://URI cannot be used when loaded over https
     49  await runTest({
     50    name: "testSecureWindowWS",
     51    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?insecure",
     52    expect: "SecurityError",
     53  });
     54 
     55  await runTest({
     56    name: "testInsecureWindowWS",
     57    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?insecure",
     58    expect: "WS onopen",
     59  });
     60 
     61  // ws://URI cannot be used when loaded over https
     62  await runTest({
     63    name: "testUpgradedWindowWS",
     64    httpsFirst: true,
     65    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?insecure",
     66    expect: "SecurityError",
     67  });
     68 
     69  await runTest({
     70    name: "testSecureWindowSecureIframeWSS",
     71    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_wss",
     72    expect: "WS onopen",
     73  });
     74 
     75  // ws://URI cannot be used when loaded over https
     76  await runTest({
     77    name: "testSecureWindowSecureIframeWS",
     78    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_ws",
     79    expect: "SecurityError",
     80  });
     81 
     82  // http iframe cannot be loaded in secure context (mixed content)
     83  await runTest({
     84    name: "testSecureWindowInsecureIframeWSS",
     85    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_wss",
     86    expect: "Error - iframe not loaded",
     87  });
     88 
     89  // http iframe cannot be loaded in secure context (mixed content)
     90  await runTest({
     91    name: "testSecureWindowInsecureIframeWS",
     92    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_ws",
     93    expect: "Error - iframe not loaded",
     94  });
     95 
     96  await runTest({
     97    name: "testInsecureWindowSecureIframeWSS",
     98    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_wss",
     99    expect: "WS onopen",
    100  });
    101 
    102  // ws://URI cannot be used when loaded from an https iframe
    103  await runTest({
    104    name: "testInsecureWindowSecureIframeWS",
    105    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_ws",
    106    expect: "SecurityError",
    107  });
    108 
    109  await runTest({
    110    name: "testInsecureWindowInsecureIframeWSS",
    111    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_wss",
    112    expect: "WS onopen",
    113  });
    114 
    115  await runTest({
    116    name: "testInsecureWindowInsecureIframeWS",
    117    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_ws",
    118    expect: "WS onopen",
    119  });
    120 
    121  await runTest({
    122    name: "testUpgradedWindowSecureIframeWSS",
    123    httpsFirst: true,
    124    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_wss",
    125    expect: "WS onopen",
    126  });
    127 
    128  // ws://URI cannot be used when loaded from an https iframe
    129  await runTest({
    130    name: "testUpgradedWindowSecureIframeWS",
    131    httpsFirst: true,
    132    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_ws",
    133    expect: "SecurityError",
    134  });
    135 
    136  // http iframe cannot be loaded in secure context (mixed content)
    137  await runTest({
    138    name: "testUpgradedWindowInsecureIframeWSS",
    139    httpsFirst: true,
    140    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_wss",
    141    expect: "Error - iframe not loaded",
    142  });
    143 
    144  // http iframe cannot be loaded in secure context (mixed content)
    145  await runTest({
    146    name: "testUpgradedWindowInsecureIframeWS",
    147    httpsFirst: true,
    148    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_ws",
    149    expect: "Error - iframe not loaded",
    150  });
    151 
    152  SimpleTest.finish();
    153 }
    154 
    155 SimpleTest.waitForExplicitFinish();
    156 testWebSockets();
    157 </script>
    158 </body>
    159 </html>