dom/tests/mochitest/dom-level0/test_location.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test for location object behaviors</title>
     5   <script type="text/javascript" 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">
    12 </div>
    13 <pre id="test">
    14 <script class="testbody" type="text/javascript">
    16 SimpleTest.waitForExplicitFinish();
    18 var count = 0;
    19 var firstlocation;
    20 var lastlocation;
    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   }
    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   }
    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');
    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');
    58     firstlocation.href = 'http://mochi.test:8888/tests/dom/tests/mochitest/dom-level0/file_location.html';
    59     return;
    60   }
    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');
    66   SimpleTest.finish();
    67 }
    69 </script>
    70 </pre>
    71 <iframe id="ifr" onload="runTest()"></iframe>
    72 </body>
    73 </html>

mercurial