tor-browser

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

test_location.html (2218B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for location object behaviors</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <p id="display"></p>
     10 <div id="content" style="display: none">
     11 
     12 </div>
     13 <pre id="test">
     14 <script class="testbody" type="text/javascript">
     15 
     16 SimpleTest.waitForExplicitFinish();
     17 
     18 var count = 0;
     19 var firstlocation;
     20 var lastlocation;
     21 
     22 function runTest() {
     23  ++count;
     24  if (count == 1) {
     25    firstlocation = $('ifr').contentWindow.location;
     26    firstlocation.existingprop = 'fail';
     27    firstlocation.href = 'file_location.html';
     28    return;
     29  }
     30 
     31  if (count == 2) {
     32    lastlocation = $('ifr').contentWindow.location;
     33    is(lastlocation.iframeprop, 42, 'can read the new prop');
     34    ok(firstlocation !== lastlocation, 'got a new location object');
     35    // firstlocation should still work.
     36    ok(firstlocation.href.indexOf('file_location.html'), 'can read location.href');
     37    firstlocation.href = 'http://example.com/tests/dom/tests/mochitest/dom-level0/file_location.html';
     38    return;
     39  }
     40 
     41  if (count == 3) {
     42    var permissionDenied = false;
     43    try {
     44      var foo = $('ifr').contentWindow.location.href == '';
     45    } catch (e) {
     46      permissionDenied = /Permission denied/.test(e.message);
     47    }
     48    ok(permissionDenied, 'correctly threw a permission denied security error when reading location.href');
     49 
     50    permissionDenied = false;
     51    try {
     52      var foo = $('ifr').contentWindow.location.iframeprop == 42;
     53    } catch (e) {
     54      permissionDenied = /Permission denied/.test(e.message);
     55    }
     56    ok(permissionDenied, 'correctly threw a permission denied security error an expando on location');
     57 
     58    firstlocation.href = 'http://mochi.test:8888/tests/dom/tests/mochitest/dom-level0/file_location.html';
     59    return;
     60  }
     61 
     62  is(lastlocation.iframeprop, 42, 'can still read old values of the location object');
     63  ok(lastlocation !== $('ifr').contentWindow.location, 'location objects are distinct');
     64  ok(firstlocation.href.indexOf('file_location.html'), 'can read location.href');
     65 
     66  SimpleTest.finish();
     67 }
     68 
     69 </script>
     70 </pre>
     71 <iframe id="ifr" onload="runTest()"></iframe>
     72 </body>
     73 </html>