tor-browser

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

hashchange_event.html (1394B)


      1 <!doctype html>
      2 <title>Queue a task to fire hashchange event</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <div id="log"></div>
      6 <script>
      7 t = async_test();
      8 window.onload = t.step_func(function () {
      9  if (location.href.toString().indexOf("#") > -1) {
     10    location.href = location.href.replace(/#.*$/,'');
     11    return;
     12  }
     13  var root = location.href;
     14  var oldURLs = [];
     15  var newURLs = [];
     16 
     17  var timer = null;
     18 
     19  location.hash = 'foo';
     20  window.onhashchange = t.step_func(function (e) {
     21    assert_true(e.isTrusted, "isTrusted");
     22    assert_equals(e.target, window, "target");
     23    assert_equals(e.type, "hashchange", "type");
     24    assert_true(e instanceof HashChangeEvent, "is HashChangeEvent");
     25    assert_false(e.bubbles, "bubbles");
     26    assert_false(e.cancelable, "cancelable");
     27    oldURLs.push(e.oldURL);
     28    newURLs.push(e.newURL);
     29    if (newURLs.length === 2) {
     30      check_result();
     31    } else if (timer === null) {
     32      timer = setTimeout(function() {check_result()}, 500);
     33    }
     34  })
     35 
     36  check_result = t.step_func(function() {
     37    clearTimeout(timer);
     38    try {
     39      assert_array_equals([root, root+"#foo"], oldURLs, "e.newURL");
     40      assert_array_equals([root+"#foo", root+"#bar"], newURLs, "e.newURL");
     41      t.done();
     42    } finally {
     43      location.hash = "";
     44    }
     45  });
     46 
     47  location.hash = 'bar';
     48 });
     49 </script>