@@ -669,12 +669,17 @@ describe('$location', function() {
669
669
mockUpBrowser ( { initialUrl :'http://server/base/home' , baseHref :'/base/' } ) ;
670
670
inject (
671
671
function ( $browser , $location , $rootScope , $window ) {
672
+ var handlerCalled = false ;
672
673
$rootScope . $on ( '$locationChangeSuccess' , function ( ) {
674
+ handlerCalled = true ;
673
675
if ( $location . path ( ) !== '/' ) {
674
676
$location . path ( '/' ) . replace ( ) ;
675
677
}
676
678
} ) ;
679
+ expect ( $browser . url ( ) ) . toEqual ( 'http://server/base/#/home' ) ;
677
680
$rootScope . $digest ( ) ;
681
+ expect ( handlerCalled ) . toEqual ( true ) ;
682
+ expect ( $browser . url ( ) ) . toEqual ( 'http://server/base/#/' ) ;
678
683
}
679
684
) ;
680
685
} ) ;
@@ -768,10 +773,10 @@ describe('$location', function() {
768
773
769
774
770
775
describe ( 'location watch for HTML5 browsers' , function ( ) {
771
- beforeEach ( initService ( { html5Mode : true , supportHistory : true } ) ) ;
772
- beforeEach ( inject ( initBrowser ( { basePath : '/app/' } ) ) ) ;
773
776
774
777
it ( 'should not infinite $digest when going to base URL without trailing slash when $locationChangeSuccess watcher changes path to /Home' , function ( ) {
778
+ initService ( { html5Mode : true , supportHistory : true } ) ;
779
+ mockUpBrowser ( { initialUrl :'http://server/app/' , baseHref :'/app/' } ) ;
775
780
inject ( function ( $rootScope , $injector , $browser ) {
776
781
var $browserUrl = spyOnlyCallsWithArgs ( $browser , 'url' ) . andCallThrough ( ) ;
777
782
@@ -790,6 +795,8 @@ describe('$location', function() {
790
795
} ) ;
791
796
792
797
it ( 'should not infinite $digest when going to base URL without trailing slash when $locationChangeSuccess watcher changes path to /' , function ( ) {
798
+ initService ( { html5Mode : true , supportHistory : true } ) ;
799
+ mockUpBrowser ( { initialUrl :'http://server/app/' , baseHref :'/app/' } ) ;
793
800
inject ( function ( $rootScope , $injector , $browser ) {
794
801
var $browserUrl = spyOnlyCallsWithArgs ( $browser , 'url' ) . andCallThrough ( ) ;
795
802
@@ -808,6 +815,8 @@ describe('$location', function() {
808
815
} ) ;
809
816
810
817
it ( 'should not infinite $digest when going to base URL with trailing slash when $locationChangeSuccess watcher changes path to /Home' , function ( ) {
818
+ initService ( { html5Mode : true , supportHistory : true } ) ;
819
+ mockUpBrowser ( { initialUrl :'http://server/app/' , baseHref :'/app/' } ) ;
811
820
inject ( function ( $rootScope , $injector , $browser ) {
812
821
var $browserUrl = spyOnlyCallsWithArgs ( $browser , 'url' ) . andCallThrough ( ) ;
813
822
@@ -826,6 +835,8 @@ describe('$location', function() {
826
835
} ) ;
827
836
828
837
it ( 'should not infinite $digest when going to base URL with trailing slash when $locationChangeSuccess watcher changes path to /' , function ( ) {
838
+ initService ( { html5Mode : true , supportHistory : true } ) ;
839
+ mockUpBrowser ( { initialUrl :'http://server/app/' , baseHref :'/app/' } ) ;
829
840
inject ( function ( $rootScope , $injector , $browser ) {
830
841
var $browserUrl = spyOnlyCallsWithArgs ( $browser , 'url' ) . andCallThrough ( ) ;
831
842
@@ -1212,49 +1223,6 @@ describe('$location', function() {
1212
1223
}
1213
1224
) ;
1214
1225
} ) ;
1215
-
1216
-
1217
- function mockUpBrowser ( options ) {
1218
- module ( function ( $windowProvider , $browserProvider ) {
1219
- $windowProvider . $get = function ( ) {
1220
- var win = { } ;
1221
- angular . extend ( win , window ) ;
1222
- win . addEventListener = angular . noop ;
1223
- win . removeEventListener = angular . noop ;
1224
- win . location = {
1225
- href : options . initialUrl ,
1226
- replace : function ( val ) {
1227
- //win.location.href = val;
1228
- }
1229
- } ;
1230
- return win ;
1231
- } ;
1232
- $browserProvider . $get = function ( $document , $window , $log , $sniffer ) {
1233
- /* global Browser: false */
1234
- var b = new Browser ( $window , $document , $log , $sniffer ) ;
1235
- b . baseHref = function ( ) {
1236
- return options . baseHref ;
1237
- } ;
1238
- return b ;
1239
- } ;
1240
- } ) ;
1241
- }
1242
-
1243
-
1244
- it ( 'should not get caught in infinite digest when replacing empty path with slash' , function ( ) {
1245
- initService ( { html5Mode :true , supportHistory :false } ) ;
1246
- mockUpBrowser ( { initialUrl :'http://server/base' , baseHref :'/base/' } ) ;
1247
- inject (
1248
- function ( $browser , $location , $rootScope , $window ) {
1249
- $rootScope . $on ( '$locationChangeSuccess' , function ( ) {
1250
- if ( $location . path ( ) !== '/' ) {
1251
- $location . path ( '/' ) . replace ( ) ;
1252
- }
1253
- } ) ;
1254
- $rootScope . $digest ( ) ;
1255
- }
1256
- ) ;
1257
- } ) ;
1258
1226
} ) ;
1259
1227
1260
1228
0 commit comments