tor-browser

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

location_hash.html (2153B)


      1 <!DOCTYPE HTML>
      2 <html>
      3  <head>
      4    <title>location_hash</title>
      5    <script src="/resources/testharness.js"></script>
      6    <script src="/resources/testharnessreport.js"></script>
      7  </head>
      8  <body>
      9    <div id="log"></div>
     10    <iframe id="srcdoc-iframe"
     11       srcdoc="<div style='height: 200vh'></div><div id='test'></div>"></iframe>
     12    <script>
     13    function resetHash() {
     14      location.hash = "";
     15    }
     16 
     17    test(function (t) {
     18      t.add_cleanup(resetHash);
     19      window.history.pushState(1, document.title, '#x=1');
     20      var hash = location.hash;
     21 
     22      assert_equals(hash, "#x=1", "hash");
     23 
     24    }, "location hash");
     25 
     26    var t = async_test("Setting location.hash on srcdoc iframe");
     27    addEventListener("load", t.step_func_done(function() {
     28      var frameWin = document.getElementById("srcdoc-iframe").contentWindow;
     29      assert_equals(frameWin.location.href, "about:srcdoc");
     30      assert_equals(frameWin.scrollY, 0, "Should not have scrolled yet");
     31      frameWin.location.hash = "test";
     32      assert_equals(frameWin.location.href, "about:srcdoc#test");
     33      assert_true(frameWin.scrollY > frameWin.innerHeight,
     34                  "Should have scrolled by more than one viewport height");
     35    }));
     36 
     37    test(function(t) {
     38      t.add_cleanup(resetHash);
     39      location.hash = "test";
     40      assert_equals(location.hash, "#test");
     41    }, "Setting hash should automatically include hash character");
     42 
     43    test(function(t) {
     44      t.add_cleanup(resetHash);
     45      location.hash = "#not encoded";
     46      assert_equals(location.hash, "#not%20encoded");
     47    }, "Setting hash should encode incompatible characters");
     48 
     49    test(function(t) {
     50      t.add_cleanup(resetHash);
     51      location.hash = "#already%20encoded";
     52      assert_equals(location.hash, "#already%20encoded");
     53    }, "Setting hash to an already encoded value should not double encode it");
     54 
     55    test(function(t) {
     56      t.add_cleanup(resetHash);
     57      location.hash = "#mixed encoding%20here";
     58      assert_equals(location.hash, "#mixed%20encoding%20here");
     59    }, "Setting hash which is partially encoded should only encode incompatible characters");
     60    </script>
     61  </body>
     62 </html>