tor-browser

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

test_bug802557.html (4163B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=802557
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 802557</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12 
     13  /** Test for Bug 802557 **/
     14  SimpleTest.waitForExplicitFinish();
     15 
     16  function checkThrows(fun, desc) {
     17    try {
     18      fun();
     19      ok(false, "Didn't throw when " + desc);
     20    } catch(e) {
     21      ok(true, "Threw when " + desc + " " + e);
     22      ok(/denied|insecure/.exec(e), "Should be security exception");
     23    }
     24  }
     25 
     26  var loadCount = 0;
     27  function go() {
     28    ++loadCount;
     29    window.ifr = document.getElementById('ifr');
     30    window.iWin = ifr.contentWindow;
     31 
     32    if (loadCount == 1) {
     33      gLoc = iWin.location;
     34      // Note that accessors pulled off Xrays are currently bound. This is bug 658909.
     35      // [getter, description, locationObj, bound]
     36      gGetters = [[ location.toString, 'toString from LW' ],
     37                  [ gLoc.toString, 'toString from XLW' ],
     38                  [ Object.__lookupGetter__.call(location, 'href'), 'href getter from LW' ],
     39                  [ Object.__lookupGetter__.call(gLoc, 'href'), 'href getter from XLW' ],
     40                  [ Object.getOwnPropertyDescriptor(location, 'href').get, 'href getter from location' ],
     41                  [ Object.getOwnPropertyDescriptor(gLoc, 'href').get, 'href getter from iWin.location' ],
     42                  [ function() { return this + ''; }, 'implicit conversion via [[DefaultValue]]', /* doMessageCheck = */ true ]];
     43      gGetters.forEach(function(item) {
     44        try {
     45          is(item[0].call(location), location.toString(), 'Same-origin LW: ' + item[1]);
     46          is(item[0].call(gLoc), gLoc.toString(), 'Same-origin XLW: ' + item[1]);
     47        } catch (e) {
     48          ok(false, "Threw while applying " + item[1] + " to same-origin location object: " + e);
     49        }
     50      });
     51      ifr.src = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
     52    }
     53    else if (loadCount == 2) {
     54      gGetters.forEach(function(item) {
     55        checkThrows(function() { item[0].call(gLoc); },
     56                    'call()ing ' + item[1] + ' after navigation cross-origin');
     57      });
     58      ifr.src = 'http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
     59    }
     60    else if (loadCount == 3) {
     61      gTestFunctions = ifr.contentWindow.getAllTests();
     62      var win = ifr.contentWindow;
     63      for (fun in gTestFunctions)
     64         is(gTestFunctions[fun](), win.location.toString(), "allowed via " + fun);
     65      win.location = 'http://example.org/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
     66    }
     67    else if (loadCount == 4) {
     68      for (fun in gTestFunctions) {
     69        var f = gTestFunctions[fun];
     70        checkThrows(f, "calling " + fun);
     71      }
     72 
     73      // Verify that URL.prototype.toString can't be applied to Location
     74      var threw = false;
     75      try {
     76        URL.prototype.toString.call(location);
     77      } catch (e) {
     78        threw = true;
     79      }
     80      ok(threw,
     81         "Should not be able to use URL.prototype.toString on a Location instance");
     82  
     83      // Verify that URL.prototype.href getter can't be applied to Location
     84      threw = false;
     85      var reachedTest = false;
     86      try {
     87        var get = Object.getOwnPropertyDescriptor(URL.prototype, "href").get;
     88        is(typeof(get), "function", "Should have an href getter on URL.prototype");
     89        var reachedTest = true;
     90        get.call(location);
     91      } catch (e) {
     92        threw = true;
     93      }
     94      ok(reachedTest,
     95         "Should not be able to find URL.prototype.href getter");
     96      ok(threw,
     97         "Should not be able to use URL.prototype.href getter on a Location instance");
     98      SimpleTest.finish();
     99    }
    100  }
    101 
    102 
    103 
    104 </script>
    105 </head>
    106 <body>
    107 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=802557">Mozilla Bug 802557</a>
    108 <p id="display"></p>
    109 <div id="content" style="display: none">
    110  
    111 </div>
    112 <iframe id="ifr" onload="go();" src="file_empty.html"></iframe>
    113 <pre id="test">
    114 </pre>
    115 </body>
    116 </html>