Skip to content
This repository
Browse code

Adding hashchange test.

  • Loading branch information...
commit 923954ff00b22536979ed30e488f31c505dcf39d 1 parent f906014
Matt Kelly authored April 09, 2012
4  tests/hashchange/config.yml
... ...
@@ -0,0 +1,4 @@
  1
+---
  2
+  r: 1
  3
+  spec: "http://www.w3.org/TR/html5/history.html"
  4
+  title: "Hashchange"
1  tests/hashchange/fixture.html
... ...
@@ -0,0 +1 @@
  1
+<iframe id="hashchange" src="/tests/hashchange/iframe.html"></iframe>
3  tests/hashchange/iframe.html
... ...
@@ -0,0 +1,3 @@
  1
+<script>
  2
+location.hash = (new Date()).getTime();
  3
+</script>
50  tests/hashchange/test.js
... ...
@@ -0,0 +1,50 @@
  1
+test("HashChangeEvent", function() {
  2
+  var HashChangeEvent = window.HashChangeEvent;
  3
+
  4
+  assert( !!HashChangeEvent, "HashChangeEvent supported" );
  5
+});
  6
+
  7
+test("onhashchange", function() {
  8
+  assert( "onhashchange" in window, "onhashchange exists in some form" );
  9
+  assert( window.onhashchange == null, "onhashchange is TreatNonCallableAsNull" );
  10
+});
  11
+
  12
+// test("HashChangeEvent in Practice", function( async ) {
  13
+//   var HashChangeEvent = window.HashChangeEvent,
  14
+//       event;
  15
+//
  16
+//   if ( !HashChangeEvent ) {
  17
+//     assert( false, "HashChangeEvent is not implemented" );
  18
+//   } else {
  19
+//     event = typeof HashChangeEvent === "function" ?
  20
+//             document.createEvent("HashChangeEvent") : HashChangeEvent;
  21
+//
  22
+//     assert( "oldURL" in event, "event.oldURL supported" );
  23
+//     assert( "newURL" in event, "event.newURL supported" );
  24
+//   }
  25
+// });
  26
+
  27
+asyncTest("onhashchange In Practice", function( async ) {
  28
+  var iframe = document.getElementById("hashchange").contentWindow,
  29
+      dead = false;
  30
+
  31
+  iframe.onhashchange = function( event ) {
  32
+    if ( !dead ) {
  33
+      async.step(function() {
  34
+        assert( true, "onhashchange event fired" );
  35
+        dead = true;
  36
+        async.done();
  37
+      });
  38
+    }
  39
+  };
  40
+
  41
+  setTimeout(function() {
  42
+    if ( !dead ) {
  43
+      async.step(function() {
  44
+        assert( false, "onhashchange event did not fire" );
  45
+        dead = true;
  46
+        async.done();
  47
+      });
  48
+    }
  49
+  }, 1000);
  50
+});

0 notes on commit 923954f

Please sign in to comment.
Something went wrong with that request. Please try again.