@@ -297,9 +297,9 @@ describe('$location', function() {
297
297
} ) ;
298
298
299
299
it ( 'should not rewrite when hashbang url is not given' , function ( ) {
300
- initService ( true , '!' , true ) ;
300
+ initService ( { html5Mode : true , hashPrefix : '!' , supportHistory : true } ) ;
301
301
inject (
302
- initBrowser ( 'http://domain.com/base/a/b' , '/base' ) ,
302
+ initBrowser ( { url : 'http://domain.com/base/a/b' , basePath : '/base' } ) ,
303
303
function ( $rootScope , $location , $browser ) {
304
304
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/base/a/b' ) ;
305
305
}
@@ -532,24 +532,24 @@ describe('$location', function() {
532
532
} ) ;
533
533
534
534
535
- function initService ( html5Mode , hashPrefix , supportHistory ) {
535
+ function initService ( options ) {
536
536
return module ( function ( $provide , $locationProvider ) {
537
- $locationProvider . html5Mode ( html5Mode ) ;
538
- $locationProvider . hashPrefix ( hashPrefix ) ;
539
- $provide . value ( '$sniffer' , { history : supportHistory } ) ;
537
+ $locationProvider . html5Mode ( options . html5Mode ) ;
538
+ $locationProvider . hashPrefix ( options . hashPrefix ) ;
539
+ $provide . value ( '$sniffer' , { history : options . supportHistory } ) ;
540
540
} ) ;
541
541
}
542
- function initBrowser ( url , basePath ) {
542
+ function initBrowser ( options ) {
543
543
return function ( $browser ) {
544
- $browser . url ( url ) ;
545
- $browser . $$baseHref = basePath ;
544
+ $browser . url ( options . url ) ;
545
+ $browser . $$baseHref = options . basePath ;
546
546
} ;
547
547
}
548
548
549
549
describe ( 'wiring' , function ( ) {
550
550
551
- beforeEach ( initService ( false , '!' , true ) ) ;
552
- beforeEach ( inject ( initBrowser ( 'http://new.com/a/b#!' , 'http://new.com/a/b' ) ) ) ;
551
+ beforeEach ( initService ( { html5Mode : false , hashPrefix : '!' , supportHistory : true } ) ) ;
552
+ beforeEach ( inject ( initBrowser ( { url : 'http://new.com/a/b#!' , basePath : 'http://new.com/a/b' } ) ) ) ;
553
553
554
554
555
555
it ( 'should update $location when browser url changes' , inject ( function ( $browser , $location ) {
@@ -673,9 +673,9 @@ describe('$location', function() {
673
673
describe ( 'disabled history' , function ( ) {
674
674
675
675
it ( 'should use hashbang url with hash prefix' , function ( ) {
676
- initService ( false , '!' ) ;
676
+ initService ( { html5Mode : false , hashPrefix : '!' } ) ;
677
677
inject (
678
- initBrowser ( 'http://domain.com/base/index.html#!/a/b' , '/base/index.html' ) ,
678
+ initBrowser ( { url : 'http://domain.com/base/index.html#!/a/b' , basePath : '/base/index.html' } ) ,
679
679
function ( $rootScope , $location , $browser ) {
680
680
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/base/index.html#!/a/b' ) ;
681
681
$location . path ( '/new' ) ;
@@ -688,9 +688,9 @@ describe('$location', function() {
688
688
689
689
690
690
it ( 'should use hashbang url without hash prefix' , function ( ) {
691
- initService ( false , '' ) ;
691
+ initService ( { html5Mode : false , hashPrefix : '' } ) ;
692
692
inject (
693
- initBrowser ( 'http://domain.com/base/index.html#/a/b' , '/base/index.html' ) ,
693
+ initBrowser ( { url : 'http://domain.com/base/index.html#/a/b' , basePath : '/base/index.html' } ) ,
694
694
function ( $rootScope , $location , $browser ) {
695
695
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/base/index.html#/a/b' ) ;
696
696
$location . path ( '/new' ) ;
@@ -711,9 +711,9 @@ describe('$location', function() {
711
711
} ) ) ;
712
712
713
713
it ( 'should use hashbang url with hash prefix' , function ( ) {
714
- initService ( true , '!!' , false ) ;
714
+ initService ( { html5Mode : true , hashPrefix : '!!' , supportHistory : false } ) ;
715
715
inject (
716
- initBrowser ( 'http://domain.com/base/index.html#!!/a/b' , '/base/index.html' ) ,
716
+ initBrowser ( { url : 'http://domain.com/base/index.html#!!/a/b' , basePath : '/base/index.html' } ) ,
717
717
function ( $rootScope , $location , $browser ) {
718
718
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/base/index.html#!!/a/b' ) ;
719
719
$location . path ( '/new' ) ;
@@ -726,19 +726,19 @@ describe('$location', function() {
726
726
727
727
728
728
it ( 'should redirect to hashbang url when new url given' , function ( ) {
729
- initService ( true , '!' ) ;
729
+ initService ( { html5Mode : true , hashPrefix : '!' } ) ;
730
730
inject (
731
- initBrowser ( 'http://domain.com/base/new-path/index.html' , '/base/index.html' ) ,
731
+ initBrowser ( { url : 'http://domain.com/base/new-path/index.html' , basePath : '/base/index.html' } ) ,
732
732
function ( $browser , $location ) {
733
733
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/base/index.html#!/new-path/index.html' ) ;
734
734
}
735
735
) ;
736
736
} ) ;
737
737
738
738
it ( 'should correctly convert html5 url with path matching basepath to hashbang url' , function ( ) {
739
- initService ( true , '!' , false ) ;
739
+ initService ( { html5Mode : true , hashPrefix : '!' , supportHistory : false } ) ;
740
740
inject (
741
- initBrowser ( 'http://domain.com/base/index.html' , '/base/index.html' ) ,
741
+ initBrowser ( { url : 'http://domain.com/base/index.html' , basePath : '/base/index.html' } ) ,
742
742
function ( $browser , $location ) {
743
743
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/base/index.html#!/index.html' ) ;
744
744
}
@@ -755,9 +755,9 @@ describe('$location', function() {
755
755
} ) ) ;
756
756
757
757
it ( 'should use new url' , function ( ) {
758
- initService ( true , '' , true ) ;
758
+ initService ( { html5Mode : true , hashPrefix : '' , supportHistory : true } ) ;
759
759
inject (
760
- initBrowser ( 'http://domain.com/base/old/index.html#a' , '/base/index.html' ) ,
760
+ initBrowser ( { url : 'http://domain.com/base/old/index.html#a' , basePath : '/base/index.html' } ) ,
761
761
function ( $rootScope , $location , $browser ) {
762
762
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/base/old/index.html#a' ) ;
763
763
$location . path ( '/new' ) ;
@@ -770,9 +770,9 @@ describe('$location', function() {
770
770
771
771
772
772
it ( 'should rewrite when hashbang url given' , function ( ) {
773
- initService ( true , '!' , true ) ;
773
+ initService ( { html5Mode : true , hashPrefix : '!' , supportHistory : true } ) ;
774
774
inject (
775
- initBrowser ( 'http://domain.com/base/index.html#!/a/b' , '/base/index.html' ) ,
775
+ initBrowser ( { url : 'http://domain.com/base/index.html#!/a/b' , basePath : '/base/index.html' } ) ,
776
776
function ( $rootScope , $location , $browser ) {
777
777
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/base/a/b' ) ;
778
778
$location . path ( '/new' ) ;
@@ -786,9 +786,9 @@ describe('$location', function() {
786
786
787
787
788
788
it ( 'should rewrite when hashbang url given (without hash prefix)' , function ( ) {
789
- initService ( true , '' , true ) ;
789
+ initService ( { html5Mode : true , hashPrefix : '' , supportHistory : true } ) ;
790
790
inject (
791
- initBrowser ( 'http://domain.com/base/index.html#/a/b' , '/base/index.html' ) ,
791
+ initBrowser ( { url : 'http://domain.com/base/index.html#/a/b' , basePath : '/base/index.html' } ) ,
792
792
function ( $rootScope , $location , $browser ) {
793
793
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/base/a/b' ) ;
794
794
expect ( $location . path ( ) ) . toBe ( '/a/b' ) ;
@@ -798,9 +798,9 @@ describe('$location', function() {
798
798
799
799
800
800
it ( 'should set appBase to serverBase if base[href] is missing' , function ( ) {
801
- initService ( true , '!' , true ) ;
801
+ initService ( { html5Mode : true , hashPrefix : '!' , supportHistory : true } ) ;
802
802
inject (
803
- initBrowser ( 'http://domain.com/my/view1#anchor1' , '' ) ,
803
+ initBrowser ( { url : 'http://domain.com/my/view1#anchor1' , basePath : '' } ) ,
804
804
function ( $rootScope , $location , $browser ) {
805
805
expect ( $browser . url ( ) ) . toBe ( 'http://domain.com/my/view1#anchor1' ) ;
806
806
expect ( $location . path ( ) ) . toBe ( '/my/view1' ) ;
@@ -843,12 +843,14 @@ describe('$location', function() {
843
843
844
844
var root , link , originalBrowser , lastEventPreventDefault ;
845
845
846
- function configureService ( linkHref , html5Mode , supportHist , relLink , attrs , content ) {
847
- if ( typeof relLink !== "boolean" ) {
848
- content = attrs ;
849
- attrs = relLink ;
850
- relLink = false ;
851
- }
846
+ function configureService ( options ) {
847
+ var linkHref = options . linkHref ,
848
+ html5Mode = options . html5Mode ,
849
+ supportHist = options . supportHist ,
850
+ relLink = options . relLink ,
851
+ attrs = options . attrs ,
852
+ content = options . content ;
853
+
852
854
module ( function ( $provide , $locationProvider ) {
853
855
attrs = attrs ? ' ' + attrs + ' ' : '' ;
854
856
@@ -917,7 +919,7 @@ describe('$location', function() {
917
919
918
920
919
921
it ( 'should rewrite rel link to new url when history enabled on new browser' , function ( ) {
920
- configureService ( 'link?a#b' , true , true ) ;
922
+ configureService ( { linkHref : 'link?a#b' , html5Mode : true , supportHist : true } ) ;
921
923
inject (
922
924
initBrowser ( ) ,
923
925
initLocation ( ) ,
@@ -930,7 +932,7 @@ describe('$location', function() {
930
932
931
933
932
934
it ( 'should do nothing if already on the same URL' , function ( ) {
933
- configureService ( '/base/' , true , true ) ;
935
+ configureService ( { linkHref : '/base/' , html5Mode : true , supportHist : true } ) ;
934
936
inject (
935
937
initBrowser ( ) ,
936
938
initLocation ( ) ,
@@ -957,7 +959,7 @@ describe('$location', function() {
957
959
958
960
959
961
it ( 'should rewrite abs link to new url when history enabled on new browser' , function ( ) {
960
- configureService ( '/base/link?a#b' , true , true ) ;
962
+ configureService ( { linkHref : '/base/link?a#b' , html5Mode : true , supportHist : true } ) ;
961
963
inject (
962
964
initBrowser ( ) ,
963
965
initLocation ( ) ,
@@ -970,7 +972,7 @@ describe('$location', function() {
970
972
971
973
972
974
it ( 'should rewrite rel link to hashbang url when history enabled on old browser' , function ( ) {
973
- configureService ( 'link?a#b' , true , false ) ;
975
+ configureService ( { linkHref : 'link?a#b' , html5Mode : true , supportHist : false } ) ;
974
976
inject (
975
977
initBrowser ( ) ,
976
978
initLocation ( ) ,
@@ -984,7 +986,7 @@ describe('$location', function() {
984
986
985
987
// Regression (gh-7721)
986
988
it ( 'should not throw when clicking anchor with no href attribute when history enabled on old browser' , function ( ) {
987
- configureService ( null , true , false ) ;
989
+ configureService ( { linkHref : null , html5Mode : true , supportHist : false } ) ;
988
990
inject (
989
991
initBrowser ( ) ,
990
992
initLocation ( ) ,
@@ -997,7 +999,7 @@ describe('$location', function() {
997
999
998
1000
999
1001
it ( 'should produce relative paths correctly when $location.path() is "/" when history enabled on old browser' , function ( ) {
1000
- configureService ( 'partial1' , true , false , true ) ;
1002
+ configureService ( { linkHref : 'partial1' , html5Mode : true , supportHist : false , relLink : true } ) ;
1001
1003
inject (
1002
1004
initBrowser ( ) ,
1003
1005
initLocation ( ) ,
@@ -1011,7 +1013,7 @@ describe('$location', function() {
1011
1013
1012
1014
1013
1015
it ( 'should rewrite abs link to hashbang url when history enabled on old browser' , function ( ) {
1014
- configureService ( '/base/link?a#b' , true , false ) ;
1016
+ configureService ( { linkHref : '/base/link?a#b' , html5Mode : true , supportHist : false } ) ;
1015
1017
inject (
1016
1018
initBrowser ( ) ,
1017
1019
initLocation ( ) ,
@@ -1024,7 +1026,7 @@ describe('$location', function() {
1024
1026
1025
1027
1026
1028
it ( 'should not rewrite full url links do different domain' , function ( ) {
1027
- configureService ( 'http://www.dot.abc/a?b=c' , true ) ;
1029
+ configureService ( { linkHref : 'http://www.dot.abc/a?b=c' , html5Mode : true } ) ;
1028
1030
inject (
1029
1031
initBrowser ( ) ,
1030
1032
initLocation ( ) ,
@@ -1037,7 +1039,7 @@ describe('$location', function() {
1037
1039
1038
1040
1039
1041
it ( 'should not rewrite links with target="_blank"' , function ( ) {
1040
- configureService ( '/a?b=c' , true , true , 'target="_blank"' ) ;
1042
+ configureService ( { linkHref : '/a?b=c' , html5Mode : true , supportHist : true , attrs : 'target="_blank"' } ) ;
1041
1043
inject (
1042
1044
initBrowser ( ) ,
1043
1045
initLocation ( ) ,
@@ -1050,7 +1052,7 @@ describe('$location', function() {
1050
1052
1051
1053
1052
1054
it ( 'should not rewrite links with target specified' , function ( ) {
1053
- configureService ( '/a?b=c' , true , true , 'target="some-frame"' ) ;
1055
+ configureService ( { linkHref : '/a?b=c' , html5Mode : true , supportHist : true , attrs : 'target="some-frame"' } ) ;
1054
1056
inject (
1055
1057
initBrowser ( ) ,
1056
1058
initLocation ( ) ,
@@ -1063,7 +1065,7 @@ describe('$location', function() {
1063
1065
1064
1066
1065
1067
it ( 'should not rewrite links with `javascript:` URI' , function ( ) {
1066
- configureService ( ' jAvAsCrIpT:throw new Error("Boom!")' , true , true , true ) ;
1068
+ configureService ( { linkHref : ' jAvAsCrIpT:throw new Error("Boom!")' , html5Mode : true , supportHist : true , relLink : true } ) ;
1067
1069
inject (
1068
1070
initBrowser ( ) ,
1069
1071
initLocation ( ) ,
@@ -1076,7 +1078,7 @@ describe('$location', function() {
1076
1078
1077
1079
1078
1080
it ( 'should not rewrite links with `mailto:` URI' , function ( ) {
1079
- configureService ( ' mAiLtO:[email protected] ' , true , true , true ) ;
1081
+ configureService ( { linkHref : ' mAiLtO:[email protected] ' , html5Mode : true , supportHist : true , relLink : true } ) ;
1080
1082
inject (
1081
1083
initBrowser ( ) ,
1082
1084
initLocation ( ) ,
@@ -1089,7 +1091,7 @@ describe('$location', function() {
1089
1091
1090
1092
1091
1093
it ( 'should rewrite full url links to same domain and base path' , function ( ) {
1092
- configureService ( 'http://host.com/base/new' , true ) ;
1094
+ configureService ( { linkHref : 'http://host.com/base/new' , html5Mode : true } ) ;
1093
1095
inject (
1094
1096
initBrowser ( ) ,
1095
1097
initLocation ( ) ,
@@ -1102,7 +1104,7 @@ describe('$location', function() {
1102
1104
1103
1105
1104
1106
it ( 'should rewrite when clicked span inside link' , function ( ) {
1105
- configureService ( 'some/link' , true , true , '' , '<span>link</span>' ) ;
1107
+ configureService ( { linkHref : 'some/link' , html5Mode : true , supportHist : true , attrs : '' , content : '<span>link</span>' } ) ;
1106
1108
inject (
1107
1109
initBrowser ( ) ,
1108
1110
initLocation ( ) ,
@@ -1118,7 +1120,7 @@ describe('$location', function() {
1118
1120
1119
1121
it ( 'should not rewrite when link to different base path when history enabled on new browser' ,
1120
1122
function ( ) {
1121
- configureService ( '/other_base/link' , true , true ) ;
1123
+ configureService ( { linkHref : '/other_base/link' , html5Mode : true , supportHist : true } ) ;
1122
1124
inject (
1123
1125
initBrowser ( ) ,
1124
1126
initLocation ( ) ,
@@ -1132,7 +1134,7 @@ describe('$location', function() {
1132
1134
1133
1135
it ( 'should not rewrite when link to different base path when history enabled on old browser' ,
1134
1136
function ( ) {
1135
- configureService ( '/other_base/link' , true , false ) ;
1137
+ configureService ( { linkHref : '/other_base/link' , html5Mode : true , supportHist : false } ) ;
1136
1138
inject (
1137
1139
initBrowser ( ) ,
1138
1140
initLocation ( ) ,
@@ -1145,7 +1147,7 @@ describe('$location', function() {
1145
1147
1146
1148
1147
1149
it ( 'should not rewrite when link to different base path when history disabled' , function ( ) {
1148
- configureService ( '/other_base/link' , false ) ;
1150
+ configureService ( { linkHref : '/other_base/link' , html5Mode : false } ) ;
1149
1151
inject (
1150
1152
initBrowser ( ) ,
1151
1153
initLocation ( ) ,
@@ -1159,7 +1161,7 @@ describe('$location', function() {
1159
1161
1160
1162
it ( 'should not rewrite when full link to different base path when history enabled on new browser' ,
1161
1163
function ( ) {
1162
- configureService ( 'http://host.com/other_base/link' , true , true ) ;
1164
+ configureService ( { linkHref : 'http://host.com/other_base/link' , html5Mode : true , supportHist : true } ) ;
1163
1165
inject (
1164
1166
initBrowser ( ) ,
1165
1167
initLocation ( ) ,
@@ -1173,7 +1175,7 @@ describe('$location', function() {
1173
1175
1174
1176
it ( 'should not rewrite when full link to different base path when history enabled on old browser' ,
1175
1177
function ( ) {
1176
- configureService ( 'http://host.com/other_base/link' , true , false ) ;
1178
+ configureService ( { linkHref : 'http://host.com/other_base/link' , html5Mode : true , supportHist : false } ) ;
1177
1179
inject (
1178
1180
initBrowser ( ) ,
1179
1181
initLocation ( ) ,
@@ -1186,7 +1188,7 @@ describe('$location', function() {
1186
1188
1187
1189
1188
1190
it ( 'should not rewrite when full link to different base path when history disabled' , function ( ) {
1189
- configureService ( 'http://host.com/other_base/link' , false ) ;
1191
+ configureService ( { linkHref : 'http://host.com/other_base/link' , html5Mode : false } ) ;
1190
1192
inject (
1191
1193
initBrowser ( ) ,
1192
1194
initLocation ( ) ,
@@ -1199,7 +1201,7 @@ describe('$location', function() {
1199
1201
1200
1202
1201
1203
it ( 'should rewrite relative links relative to current path when history disabled' , function ( ) {
1202
- configureService ( 'link' , true , false , true ) ;
1204
+ configureService ( { linkHref : 'link' , html5Mode : true , supportHist : false , relLink : true } ) ;
1203
1205
inject (
1204
1206
initBrowser ( ) ,
1205
1207
initLocation ( ) ,
@@ -1213,7 +1215,7 @@ describe('$location', function() {
1213
1215
1214
1216
1215
1217
it ( 'should replace current path when link begins with "/" and history disabled' , function ( ) {
1216
- configureService ( '/link' , true , false , true ) ;
1218
+ configureService ( { linkHref : '/link' , html5Mode : true , supportHist : false , relLink : true } ) ;
1217
1219
inject (
1218
1220
initBrowser ( ) ,
1219
1221
initLocation ( ) ,
@@ -1227,7 +1229,7 @@ describe('$location', function() {
1227
1229
1228
1230
1229
1231
it ( 'should replace current hash fragment when link begins with "#" history disabled' , function ( ) {
1230
- configureService ( '#link' , true , false , true ) ;
1232
+ configureService ( { linkHref : '#link' , html5Mode : true , supportHist : false , relLink : true } ) ;
1231
1233
inject (
1232
1234
initBrowser ( ) ,
1233
1235
initLocation ( ) ,
@@ -1247,7 +1249,7 @@ describe('$location', function() {
1247
1249
if ( ! msie || msie >= 9 ) {
1248
1250
1249
1251
it ( 'should not rewrite when clicked with ctrl pressed' , function ( ) {
1250
- configureService ( '/a?b=c' , true , true ) ;
1252
+ configureService ( { linkHref : '/a?b=c' , html5Mode : true , supportHist : true } ) ;
1251
1253
inject (
1252
1254
initBrowser ( ) ,
1253
1255
initLocation ( ) ,
@@ -1260,7 +1262,7 @@ describe('$location', function() {
1260
1262
1261
1263
1262
1264
it ( 'should not rewrite when clicked with meta pressed' , function ( ) {
1263
- configureService ( '/a?b=c' , true , true ) ;
1265
+ configureService ( { linkHref : '/a?b=c' , html5Mode : true , supportHist : true } ) ;
1264
1266
inject (
1265
1267
initBrowser ( ) ,
1266
1268
initLocation ( ) ,
0 commit comments