@@ -861,41 +861,55 @@ if ($.support.pjax) {
861861 asyncTest ( "clicking back while loading cancels XHR" , function ( ) {
862862 var frame = this . frame
863863
864- frame . $ ( '#main' ) . on ( 'pjax:timeout' , function ( event ) {
865- event . preventDefault ( )
864+ equal ( frame . location . pathname , "/home.html" )
865+ equal ( frame . document . title , "Home" )
866+
867+ frame . $ ( "#main" ) . on ( 'pjax:timeout' , function ( e ) {
868+ e . preventDefault ( ) ;
866869 } )
867870
868- frame . $ ( "#main" ) . one ( 'pjax:send ' , function ( ) {
871+ frame . $ ( "#main" ) . one ( 'pjax:complete ' , function ( ) {
869872
870- // Check that our request is aborted (need to check
871- // how robust this is across browsers)
872- frame . $ ( "#main" ) . one ( 'pjax:complete' , function ( e , xhr , textStatus ) {
873- equal ( xhr . status , 0 )
874- equal ( textStatus , 'abort' )
875- } )
873+ equal ( frame . location . pathname , "/hello.html" )
874+ equal ( frame . document . title , "Hello" )
876875
877- setTimeout ( function ( ) {
878- frame . history . back ( )
879- } , 250 )
876+ frame . $ ( "#main" ) . one ( 'pjax:send' , function ( ) {
880877
881- // Make sure the URL and content remain the same after the
882- // XHR would have arrived (delay on timeout.html is 1s)
883- setTimeout ( function ( ) {
884- var afterBackLocation = frame . location . pathname
885- var afterBackTitle = frame . document . title
878+ // don't use goBack here, because pjax:end isn't triggered
879+ // when clicking back while loading
880+
881+ frame . $ ( "#main" ) . one ( 'pjax:complete' , function ( e , xhr , textStatus ) {
882+ equal ( xhr . status , 0 ) ;
883+ equal ( textStatus , 'abort' )
884+ } )
885+
886+ frame . history . back ( ) ;
886887
888+ // Make sure the URL and content remain the same after the
889+ // XHR would have arrived (delay on timeout.html is 1s)
887890 setTimeout ( function ( ) {
888- equal ( frame . location . pathname , afterBackLocation )
889- equal ( frame . document . title , afterBackTitle )
890- start ( )
891- } , 1000 )
892- } , 500 )
891+ var afterBackLocation = frame . location . pathname
892+ var afterBackTitle = frame . document . title
893+
894+ setTimeout ( function ( ) {
895+ equal ( frame . location . pathname , afterBackLocation )
896+ equal ( frame . document . title , afterBackTitle )
897+ start ( )
898+ } , 1000 )
899+ } , 500 )
900+ } )
901+
902+ frame . $ . pjax ( {
903+ url : "timeout.html" ,
904+ container : "#main"
905+ } )
893906 } )
894907
895908 frame . $ . pjax ( {
896- url : "timeout .html" ,
909+ url : "hello .html" ,
897910 container : "#main"
898911 } )
912+
899913 } )
900914
901915 asyncTest ( "clicking back while loading maintains history" , function ( ) {
0 commit comments