tor-browser

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

test_bug995943.xhtml (5019B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
      3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
      4 <!--
      5 https://bugzilla.mozilla.org/show_bug.cgi?id=995943
      6 -->
      7 <window title="Mozilla Bug 995943"
      8        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
     10 
     11  <!-- test results are displayed in the html:body -->
     12  <body xmlns="http://www.w3.org/1999/xhtml">
     13  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=995943"
     14     target="_blank">Mozilla Bug 995943</a>
     15  </body>
     16 
     17  <!-- test code goes here -->
     18  <script type="application/javascript">
     19  <![CDATA[
     20  function debug(msg) { info(msg); }
     21 
     22  /** Test for CAPS file:// URI prefs. */
     23  SimpleTest.waitForExplicitFinish();
     24  SimpleTest.requestCompleteLog();
     25  if (navigator.userAgent.includes("Mac OS X 10.10"))
     26    SimpleTest.expectAssertions(5, 11); // See bug 1067022, 1307988
     27  else if (Services.appinfo.OS == "WINNT")
     28    SimpleTest.expectAssertions(0, 1); // See bug 1067022
     29  else
     30    SimpleTest.expectAssertions(0, 9); // See bug 1305241, 1145314
     31 
     32  var rootdir = Services.appinfo.OS == "WINNT" ? "file:///C:" : "file:///";
     33 
     34  function checkLoadFileURI(domain, shouldLoad) {
     35    debug("Invoking checkLoadFileURI with domain: " + domain + ", shouldLoad: " + shouldLoad);
     36    return new Promise(function(resolve) {
     37      $('ifr').addEventListener('load', function l1() {
     38        debug("Invoked l1 for " + domain);
     39        $('ifr').removeEventListener('load', l1);
     40        function l2() {
     41          debug("Invoked l2 for " + domain);
     42          $('ifr').removeEventListener('load', l2);
     43          ok(shouldLoad, "Successfully loaded file:// URI for domain: " + domain);
     44          resolve();
     45        }
     46        $('ifr').addEventListener('load', l2);
     47        try {
     48          window[0].wrappedJSObject.location = rootdir;
     49          debug("Successfully navigated for " + domain);
     50        } catch (e) {
     51          ok(!shouldLoad && /denied|insecure/.test(e),
     52             "Prevented loading of file:// URI for domain: " + domain + " - " + e);
     53          $('ifr').removeEventListener('load', l2);
     54          resolve();
     55        }
     56      });
     57      let targetURI = domain + '/tests/js/xpconnect/tests/mochitest/file_empty.html';
     58      debug("Navigating iframe to " + targetURI);
     59      $('ifr').contentWindow.location = targetURI;
     60    });
     61  }
     62 
     63  function pushPrefs(prefs) {
     64    return SpecialPowers.pushPrefEnv({ set: prefs });
     65  }
     66 
     67  function popPrefs() {
     68    return new Promise(function(resolve) { SpecialPowers.popPrefEnv(resolve); });
     69  }
     70 
     71  var gGoCount = 0;
     72  function go() {
     73    debug("Invoking go for window with id: " + window.windowGlobalChild.innerWindowId);
     74    is(++gGoCount, 1, "Should only call go once!");
     75    checkLoadFileURI('http://example.com', false).then(
     76      pushPrefs.bind(null, [['capability.policy.policynames', ' somepolicy '],
     77                            ['capability.policy.somepolicy.checkloaduri.enabled', 'AlLAcCeSs'],
     78                            ['capability.policy.somepolicy.sites', 'http://example.com']]))
     79    .then(checkLoadFileURI.bind(null, 'http://example.com', true))
     80    .then(popPrefs)
     81    .then(checkLoadFileURI.bind(null, 'http://example.com', false))
     82    .then(
     83      pushPrefs.bind(null, [['capability.policy.policynames', ',somepolicy, someotherpolicy, '],
     84                            ['capability.policy.somepolicy.checkloaduri.enabled', 'allaccess'],
     85                            ['capability.policy.someotherpolicy.checkloaduri.enabled', 'nope'],
     86                            ['capability.policy.somepolicy.sites', ' http://example.org   test1.example.com https://test2.example.com '],
     87                            ['capability.policy.someotherpolicy.sites', 'http://example.net ']]))
     88    .then(checkLoadFileURI.bind(null, 'http://example.org', true))
     89    .then(checkLoadFileURI.bind(null, 'http://test2.example.com', false))
     90    .then(checkLoadFileURI.bind(null, 'https://test2.example.com', true))
     91    .then(checkLoadFileURI.bind(null, 'http://sub1.test2.example.com', false))
     92    .then(checkLoadFileURI.bind(null, 'https://sub1.test2.example.com', true))
     93    .then(checkLoadFileURI.bind(null, 'http://example.net', false))
     94    .then(checkLoadFileURI.bind(null, 'http://test1.example.com', true))
     95    .then(checkLoadFileURI.bind(null, 'https://test1.example.com', true))
     96    .then(checkLoadFileURI.bind(null, 'http://sub1.test1.example.com', true))
     97    .then(checkLoadFileURI.bind(null, 'https://sub1.test1.example.com', true))
     98    .then(pushPrefs.bind(null, [['capability.policy.someotherpolicy.checkloaduri.enabled', 'allAccess']]))
     99    .then(checkLoadFileURI.bind(null, 'http://example.net', true))
    100    .then(popPrefs)
    101    .then(popPrefs)
    102    .then(checkLoadFileURI.bind(null, 'http://example.net', false))
    103    .then(SimpleTest.finish.bind(SimpleTest));
    104 
    105  }
    106  addLoadEvent(go);
    107 
    108  ]]>
    109  </script>
    110  <iframe id="ifr" type="content" />
    111 </window>