tor-browser

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

test_bug541530.html (2972B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=541530
      5 -->
      6 <head>
      7  <title>Test for Bug 411103</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=541530">Mozilla Bug 541530</a>
     13 <p id="display"></p>
     14 <div id="content" style="display: none"></div>
     15 
     16 <pre id="test">
     17 <script class="testbody" type="text/javascript">
     18 
     19 var orig = window;
     20 window = {};
     21 
     22 var origLocation = location;
     23 
     24 ok(window === orig, "can't override window");
     25 ok(window.location === location, "properties are properly aliased");
     26 ok(document.location === location, "properties are properly aliased");
     27 
     28 var canDefine = false;
     29 /* eslint-disable no-useless-call */
     30 try {
     31    this.__defineGetter__.call(this, 'bar', function() {});
     32    this.__defineSetter__.call(this, 'bar', function() {});
     33    canDefine = true;
     34 } catch (e) {}
     35 /* eslint-enable no-useless-call */
     36 ok(canDefine, "Should have access to __defineGetter__ and __defineSetter__");
     37 
     38 try {
     39    this.__defineGetter__('window', function() {});
     40    ok(false, "should not be able to defineGetter(window)");
     41 } catch (e) {
     42 }
     43 
     44 try {
     45    this.__defineGetter__.call(window, 'location', function(){});
     46    ok(false, "should not be able to defineGetter(window.location)");
     47 } catch (e) {
     48 }
     49 
     50 try {
     51    this.__defineGetter__.call(window.location, 'href', function(){});
     52    ok(false, "shouldn't be able to override location.href");
     53 } catch (e) {
     54    ok(/shadow/.exec(e.message) ||
     55       /can't redefine non-configurable/.exec(e.message),
     56       "Should be caught by the anti-shadow mechanism.");
     57 }
     58 
     59 // Try deleting the property.
     60 delete window.location.href;
     61 ok(typeof window.location.href !== 'undefined',
     62   "shouldn't be able to delete the inherited property");
     63 delete Object.getPrototypeOf(window.location).href;
     64 ok(typeof window.location.href !== 'undefined',
     65   "shouldn't be able to delete the property off of the prototype");
     66 
     67 this.__defineGetter__.call(Object.getPrototypeOf(window.location), 'href', function(){});
     68 ok(true, "should be able to define things on the prototype");
     69 
     70 try {
     71    this.__defineSetter__.call(window.location, 'href', function(){});
     72    ok(false, "overrode a setter for location.href?");
     73 } catch (e) {
     74    ok(/shadow/.exec(e.message) ||
     75       /can't redefine non-configurable/.exec(e.message),
     76       "Should be caught by the anti-shadow mechanism.");
     77 }
     78 
     79 try {
     80    this.__defineGetter__.call(document, 'location', function(){});
     81    ok(false, "shouldn't be able to override document.location");
     82 } catch (e) {
     83 }
     84 
     85 ok(window === orig, "can't override window");
     86 ok(window.location === origLocation, "properties are properly aliased");
     87 ok(document.location === origLocation, "properties are properly aliased");
     88 
     89 location.href = 'javascript:ok(true, "was able to set location.href through a watchpoint")';
     90 
     91 </script>
     92 </pre>
     93 </body>
     94 </html>