tor-browser

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

test_secureContexts.html (2163B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1273687
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1430164</title>
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
     11  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
     12  <iframe id="t" src="https://example.com"></iframe>
     13  <iframe id="i" src="http://example.com"></iframe>
     14  <script type="application/javascript">
     15  /** Test for Bug 1273687 */
     16  SimpleTest.waitForExplicitFinish();
     17 
     18  window.onload = () => {
     19    /* globals t, i */
     20    runTest(t, true);
     21    runTest(i, false);
     22 
     23    // Check we can inherit the system principal
     24    var s = new Cu.Sandbox(window, { wantGlobalProperties: ["isSecureContext"] } );
     25    s.ok = ok;
     26    Cu.evalInSandbox('ok(isSecureContext)', s);
     27 
     28    // Check options insecure works
     29    let sb = new Cu.Sandbox('https://www.example.com',
     30                            { forceSecureContext: false,
     31                              wantGlobalProperties:
     32                              ["isSecureContext"]
     33                            });
     34    ok(!Cu.evalInSandbox('isSecureContext', sb));
     35 
     36    // Check options secure works
     37    let sb2 = new Cu.Sandbox('https://www.example.com',
     38                            { forceSecureContext: true,
     39                              wantGlobalProperties:
     40                              ["isSecureContext"]
     41                            });
     42    ok(Cu.evalInSandbox('isSecureContext', sb2));
     43    SimpleTest.finish();
     44  };
     45 
     46  // Check dom window inheritance works
     47  function runTest(ifr, expectIsSecureContext) {
     48    let frameWin = ifr.contentWindow;
     49    let s = new Cu.Sandbox(frameWin, { wantGlobalProperties: ["isSecureContext"] });
     50    is(expectIsSecureContext, Cu.evalInSandbox('isSecureContext', s));
     51 
     52    // Ensure the implementation of 'wantGlobalProperties' matches the DOM window prototype
     53    let s2 = new Cu.Sandbox(frameWin, { sandboxPrototype: frameWin });
     54    is(expectIsSecureContext, Cu.evalInSandbox('isSecureContext', s2));
     55  }
     56  </script>
     57 </head>
     58 </html>