Permalink
Browse files

Merge pull request #33 from facebook/hashchange

Adding hashchange test.
  • Loading branch information...
2 parents 310b82f + 923954f commit ec530d8aa80b6d899981553f54d2a4bd75624a46 @darobin darobin committed Jun 8, 2012
Showing with 58 additions and 0 deletions.
  1. +4 −0 tests/hashchange/config.yml
  2. +1 −0 tests/hashchange/fixture.html
  3. +3 −0 tests/hashchange/iframe.html
  4. +50 −0 tests/hashchange/test.js
View
4 tests/hashchange/config.yml
@@ -0,0 +1,4 @@
+---
+ r: 1
+ spec: "http://www.w3.org/TR/html5/history.html"
+ title: "Hashchange"
View
1 tests/hashchange/fixture.html
@@ -0,0 +1 @@
+<iframe id="hashchange" src="/tests/hashchange/iframe.html"></iframe>
View
3 tests/hashchange/iframe.html
@@ -0,0 +1,3 @@
+<script>
+location.hash = (new Date()).getTime();
+</script>
View
50 tests/hashchange/test.js
@@ -0,0 +1,50 @@
+test("HashChangeEvent", function() {
+ var HashChangeEvent = window.HashChangeEvent;
+
+ assert( !!HashChangeEvent, "HashChangeEvent supported" );
+});
+
+test("onhashchange", function() {
+ assert( "onhashchange" in window, "onhashchange exists in some form" );
+ assert( window.onhashchange == null, "onhashchange is TreatNonCallableAsNull" );
+});
+
+// test("HashChangeEvent in Practice", function( async ) {
+// var HashChangeEvent = window.HashChangeEvent,
+// event;
+//
+// if ( !HashChangeEvent ) {
+// assert( false, "HashChangeEvent is not implemented" );
+// } else {
+// event = typeof HashChangeEvent === "function" ?
+// document.createEvent("HashChangeEvent") : HashChangeEvent;
+//
+// assert( "oldURL" in event, "event.oldURL supported" );
+// assert( "newURL" in event, "event.newURL supported" );
+// }
+// });
+
+asyncTest("onhashchange In Practice", function( async ) {
+ var iframe = document.getElementById("hashchange").contentWindow,
+ dead = false;
+
+ iframe.onhashchange = function( event ) {
+ if ( !dead ) {
+ async.step(function() {
+ assert( true, "onhashchange event fired" );
+ dead = true;
+ async.done();
+ });
+ }
+ };
+
+ setTimeout(function() {
+ if ( !dead ) {
+ async.step(function() {
+ assert( false, "onhashchange event did not fire" );
+ dead = true;
+ async.done();
+ });
+ }
+ }, 1000);
+});

0 comments on commit ec530d8

Please sign in to comment.