testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/hashchange_event.html
author James Graham <james@hoppipolla.co.uk>
Wed, 03 Jan 2018 16:24:44 +0000
changeset 450154 049f8d7499d7cecc60e532dfd8a74db553fa89e3
parent 301475 5e0eae94d1cc4c484e9cf210f47279d52a8bbf4a
child 479235 3f8d8f2c37e160fc95ce891620a10f6b832b8da6
permissions -rw-r--r--
Bug 1429043 - Update web-platform-tests to revision 4de5305adf3d33badc23952672bcf28168fea37e, a=testonly MozReview-Commit-ID: 8hFZiSUb5Qr

<!doctype html>
<title>Queue a task to fire hashchange event</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
t = async_test();
window.onload = t.step_func(function () {
  if (location.href.toString().indexOf("#") > -1) {
    location.href = location.href.replace(/#.*$/,'');
    return;
  }
  var root = location.href;
  var oldURLs = [];
  var newURLs = [];

  var timer = null;

  location.hash = 'foo';
  window.onhashchange = t.step_func(function (e) {
    assert_true(e.isTrusted);
    assert_equals(e.target, window);
    assert_equals(e.type, "hashchange");
    assert_true(e instanceof HashChangeEvent);
    assert_true(e.bubbles, "bubble");
    assert_false(e.cancelable, "cancelable");
    oldURLs.push(e.oldURL);
    newURLs.push(e.newURL);
    if (newURLs.length === 2) {
      check_result();
    } else if (timer === null) {
      timer = setTimeout(function() {check_result()}, 500);
    }
  })

  check_result = t.step_func(function() {
    clearTimeout(timer);
    try {
      assert_array_equals([root, root+"#foo"], oldURLs, "e.newURL");
      assert_array_equals([root+"#foo", root+"#bar"], newURLs, "e.newURL");
      t.done();
    } finally {
      location.hash = "";
    }
  });

  location.hash = 'bar';
});
</script>