@@ -301,9 +301,9 @@ describe('$location', function() {
301
301
});
302
302
303
303
it('should not rewrite when hashbang url is not given', function() {
304
- initService(true, '!', true);
304
+ initService({html5Mode: true,hashPrefix: '!',supportHistory: true} );
305
305
inject(
306
- initBrowser('http://domain.com/base/a/b', '/base'),
306
+ initBrowser({url: 'http://domain.com/base/a/b',basePath: '/base'} ),
307
307
function($rootScope, $location, $browser) {
308
308
expect($browser.url()).toBe('http://domain.com/base/a/b');
309
309
}
@@ -536,24 +536,24 @@ describe('$location', function() {
536
536
});
537
537
538
538
539
- function initService(html5Mode, hashPrefix, supportHistory ) {
539
+ function initService(options ) {
540
540
return module(function($provide, $locationProvider){
541
- $locationProvider.html5Mode(html5Mode);
542
- $locationProvider.hashPrefix(hashPrefix);
543
- $provide.value('$sniffer', {history: supportHistory});
541
+ $locationProvider.html5Mode(options. html5Mode);
542
+ $locationProvider.hashPrefix(options. hashPrefix);
543
+ $provide.value('$sniffer', {history: options. supportHistory});
544
544
});
545
545
}
546
- function initBrowser(url, basePath ) {
546
+ function initBrowser(options ) {
547
547
return function($browser){
548
- $browser.url(url);
549
- $browser.$$baseHref = basePath;
548
+ $browser.url(options. url);
549
+ $browser.$$baseHref = options. basePath;
550
550
};
551
551
}
552
552
553
553
describe('wiring', function() {
554
554
555
- beforeEach(initService(false, '!', true));
556
- beforeEach(inject(initBrowser('http://new.com/a/b#!', 'http://new.com/a/b')));
555
+ beforeEach(initService({html5Mode: false,hashPrefix: '!',supportHistory: true} ));
556
+ beforeEach(inject(initBrowser({url: 'http://new.com/a/b#!',basePath: 'http://new.com/a/b'} )));
557
557
558
558
559
559
it('should update $location when browser url changes', inject(function($browser, $location) {
@@ -677,9 +677,9 @@ describe('$location', function() {
677
677
describe('disabled history', function() {
678
678
679
679
it('should use hashbang url with hash prefix', function() {
680
- initService(false, '!');
680
+ initService({html5Mode: false,hashPrefix: '!'} );
681
681
inject(
682
- initBrowser('http://domain.com/base/index.html#!/a/b', '/base/index.html'),
682
+ initBrowser({url: 'http://domain.com/base/index.html#!/a/b',basePath: '/base/index.html'} ),
683
683
function($rootScope, $location, $browser) {
684
684
expect($browser.url()).toBe('http://domain.com/base/index.html#!/a/b');
685
685
$location.path('/new');
@@ -692,9 +692,9 @@ describe('$location', function() {
692
692
693
693
694
694
it('should use hashbang url without hash prefix', function() {
695
- initService(false, '');
695
+ initService({html5Mode: false,hashPrefix: ''} );
696
696
inject(
697
- initBrowser('http://domain.com/base/index.html#/a/b', '/base/index.html'),
697
+ initBrowser({url: 'http://domain.com/base/index.html#/a/b',basePath: '/base/index.html'} ),
698
698
function($rootScope, $location, $browser) {
699
699
expect($browser.url()).toBe('http://domain.com/base/index.html#/a/b');
700
700
$location.path('/new');
@@ -715,9 +715,9 @@ describe('$location', function() {
715
715
}));
716
716
717
717
it('should use hashbang url with hash prefix', function() {
718
- initService(true, '!!', false);
718
+ initService({html5Mode: true,hashPrefix: '!!',supportHistory: false} );
719
719
inject(
720
- initBrowser('http://domain.com/base/index.html#!!/a/b', '/base/index.html'),
720
+ initBrowser({url: 'http://domain.com/base/index.html#!!/a/b',basePath: '/base/index.html'} ),
721
721
function($rootScope, $location, $browser) {
722
722
expect($browser.url()).toBe('http://domain.com/base/index.html#!!/a/b');
723
723
$location.path('/new');
@@ -730,19 +730,19 @@ describe('$location', function() {
730
730
731
731
732
732
it('should redirect to hashbang url when new url given', function() {
733
- initService(true, '!');
733
+ initService({html5Mode: true,hashPrefix: '!'} );
734
734
inject(
735
- initBrowser('http://domain.com/base/new-path/index.html', '/base/index.html'),
735
+ initBrowser({url: 'http://domain.com/base/new-path/index.html',basePath: '/base/index.html'} ),
736
736
function($browser, $location) {
737
737
expect($browser.url()).toBe('http://domain.com/base/index.html#!/new-path/index.html');
738
738
}
739
739
);
740
740
});
741
741
742
742
it('should correctly convert html5 url with path matching basepath to hashbang url', function () {
743
- initService(true, '!', false);
743
+ initService({html5Mode: true,hashPrefix: '!',supportHistory: false} );
744
744
inject(
745
- initBrowser('http://domain.com/base/index.html', '/base/index.html'),
745
+ initBrowser({url: 'http://domain.com/base/index.html',basePath: '/base/index.html'} ),
746
746
function($browser, $location) {
747
747
expect($browser.url()).toBe('http://domain.com/base/index.html#!/index.html');
748
748
}
@@ -759,9 +759,9 @@ describe('$location', function() {
759
759
}));
760
760
761
761
it('should use new url', function() {
762
- initService(true, '', true);
762
+ initService({html5Mode: true,hashPrefix: '',supportHistory: true} );
763
763
inject(
764
- initBrowser('http://domain.com/base/old/index.html#a', '/base/index.html'),
764
+ initBrowser({url: 'http://domain.com/base/old/index.html#a',basePath: '/base/index.html'} ),
765
765
function($rootScope, $location, $browser) {
766
766
expect($browser.url()).toBe('http://domain.com/base/old/index.html#a');
767
767
$location.path('/new');
@@ -774,9 +774,9 @@ describe('$location', function() {
774
774
775
775
776
776
it('should rewrite when hashbang url given', function() {
777
- initService(true, '!', true);
777
+ initService({html5Mode: true,hashPrefix: '!',supportHistory: true} );
778
778
inject(
779
- initBrowser('http://domain.com/base/index.html#!/a/b', '/base/index.html'),
779
+ initBrowser({url: 'http://domain.com/base/index.html#!/a/b',basePath: '/base/index.html'} ),
780
780
function($rootScope, $location, $browser) {
781
781
expect($browser.url()).toBe('http://domain.com/base/a/b');
782
782
$location.path('/new');
@@ -790,9 +790,9 @@ describe('$location', function() {
790
790
791
791
792
792
it('should rewrite when hashbang url given (without hash prefix)', function() {
793
- initService(true, '', true);
793
+ initService({html5Mode: true,hashPrefix: '',supportHistory: true} );
794
794
inject(
795
- initBrowser('http://domain.com/base/index.html#/a/b', '/base/index.html'),
795
+ initBrowser({url: 'http://domain.com/base/index.html#/a/b',basePath: '/base/index.html'} ),
796
796
function($rootScope, $location, $browser) {
797
797
expect($browser.url()).toBe('http://domain.com/base/a/b');
798
798
expect($location.path()).toBe('/a/b');
@@ -802,9 +802,9 @@ describe('$location', function() {
802
802
803
803
804
804
it('should set appBase to serverBase if base[href] is missing', function() {
805
- initService(true, '!', true);
805
+ initService({html5Mode: true,hashPrefix: '!',supportHistory: true} );
806
806
inject(
807
- initBrowser('http://domain.com/my/view1#anchor1', ''),
807
+ initBrowser({url: 'http://domain.com/my/view1#anchor1',basePath: ''} ),
808
808
function($rootScope, $location, $browser) {
809
809
expect($browser.url()).toBe('http://domain.com/my/view1#anchor1');
810
810
expect($location.path()).toBe('/my/view1');
@@ -847,12 +847,14 @@ describe('$location', function() {
847
847
848
848
var root, link, originalBrowser, lastEventPreventDefault;
849
849
850
- function configureService(linkHref, html5Mode, supportHist, relLink, attrs, content) {
851
- if (typeof relLink !== "boolean") {
852
- content = attrs;
853
- attrs = relLink;
854
- relLink = false;
855
- }
850
+ function configureService(options) {
851
+ var linkHref = options.linkHref,
852
+ html5Mode = options.html5Mode,
853
+ supportHist = options.supportHist,
854
+ relLink = options.relLink,
855
+ attrs = options.attrs,
856
+ content = options.content;
857
+
856
858
module(function($provide, $locationProvider) {
857
859
attrs = attrs ? ' ' + attrs + ' ' : '';
858
860
@@ -921,7 +923,7 @@ describe('$location', function() {
921
923
922
924
923
925
it('should rewrite rel link to new url when history enabled on new browser', function() {
924
- configureService('link?a#b', true, true);
926
+ configureService({linkHref: 'link?a#b', html5Mode: true, supportHist: true} );
925
927
inject(
926
928
initBrowser(),
927
929
initLocation(),
@@ -934,7 +936,7 @@ describe('$location', function() {
934
936
935
937
936
938
it('should do nothing if already on the same URL', function() {
937
- configureService('/base/', true, true);
939
+ configureService({linkHref: '/base/', html5Mode: true, supportHist: true} );
938
940
inject(
939
941
initBrowser(),
940
942
initLocation(),
@@ -961,7 +963,7 @@ describe('$location', function() {
961
963
962
964
963
965
it('should rewrite abs link to new url when history enabled on new browser', function() {
964
- configureService('/base/link?a#b', true, true);
966
+ configureService({linkHref: '/base/link?a#b', html5Mode: true, supportHist: true} );
965
967
inject(
966
968
initBrowser(),
967
969
initLocation(),
@@ -974,7 +976,7 @@ describe('$location', function() {
974
976
975
977
976
978
it('should rewrite rel link to hashbang url when history enabled on old browser', function() {
977
- configureService('link?a#b', true, false);
979
+ configureService({linkHref: 'link?a#b', html5Mode: true, supportHist: false} );
978
980
inject(
979
981
initBrowser(),
980
982
initLocation(),
@@ -988,7 +990,7 @@ describe('$location', function() {
988
990
989
991
// Regression (gh-7721)
990
992
it('should not throw when clicking anchor with no href attribute when history enabled on old browser', function() {
991
- configureService(null, true, false);
993
+ configureService({linkHref: null, html5Mode: true, supportHist: false} );
992
994
inject(
993
995
initBrowser(),
994
996
initLocation(),
@@ -1001,7 +1003,7 @@ describe('$location', function() {
1001
1003
1002
1004
1003
1005
it('should produce relative paths correctly when $location.path() is "/" when history enabled on old browser', function() {
1004
- configureService('partial1', true, false, true);
1006
+ configureService({linkHref: 'partial1', html5Mode: true, supportHist: false, relLink: true} );
1005
1007
inject(
1006
1008
initBrowser(),
1007
1009
initLocation(),
@@ -1015,7 +1017,7 @@ describe('$location', function() {
1015
1017
1016
1018
1017
1019
it('should rewrite abs link to hashbang url when history enabled on old browser', function() {
1018
- configureService('/base/link?a#b', true, false);
1020
+ configureService({linkHref: '/base/link?a#b', html5Mode: true, supportHist: false} );
1019
1021
inject(
1020
1022
initBrowser(),
1021
1023
initLocation(),
@@ -1028,7 +1030,7 @@ describe('$location', function() {
1028
1030
1029
1031
1030
1032
it('should not rewrite full url links do different domain', function() {
1031
- configureService('http://www.dot.abc/a?b=c', true);
1033
+ configureService({linkHref: 'http://www.dot.abc/a?b=c', html5Mode: true} );
1032
1034
inject(
1033
1035
initBrowser(),
1034
1036
initLocation(),
@@ -1041,7 +1043,7 @@ describe('$location', function() {
1041
1043
1042
1044
1043
1045
it('should not rewrite links with target="_blank"', function() {
1044
- configureService('/a?b=c', true, true, 'target="_blank"');
1046
+ configureService({linkHref: '/a?b=c', html5Mode: true, supportHist: true, attrs: 'target="_blank"'} );
1045
1047
inject(
1046
1048
initBrowser(),
1047
1049
initLocation(),
@@ -1054,7 +1056,7 @@ describe('$location', function() {
1054
1056
1055
1057
1056
1058
it('should not rewrite links with target specified', function() {
1057
- configureService('/a?b=c', true, true, 'target="some-frame"');
1059
+ configureService({linkHref: '/a?b=c', html5Mode: true, supportHist: true, attrs: 'target="some-frame"'} );
1058
1060
inject(
1059
1061
initBrowser(),
1060
1062
initLocation(),
@@ -1067,7 +1069,7 @@ describe('$location', function() {
1067
1069
1068
1070
1069
1071
it('should not rewrite links with `javascript:` URI', function() {
1070
- configureService(' jAvAsCrIpT:throw new Error("Boom!")', true, true, true);
1072
+ configureService({linkHref: ' jAvAsCrIpT:throw new Error("Boom!")', html5Mode: true, supportHist: true, relLink: true} );
1071
1073
inject(
1072
1074
initBrowser(),
1073
1075
initLocation(),
@@ -1080,7 +1082,7 @@ describe('$location', function() {
1080
1082
1081
1083
1082
1084
it('should not rewrite links with `mailto:` URI', function() {
1083
- configureService(' mAiLtO:
[email protected] ', true, true, true);
1085
+ configureService(
{linkHref: ' mAiLtO:
[email protected] ',
html5Mode: true,
supportHist: true,
relLink: true
} );
1084
1086
inject(
1085
1087
initBrowser(),
1086
1088
initLocation(),
@@ -1093,7 +1095,7 @@ describe('$location', function() {
1093
1095
1094
1096
1095
1097
it('should rewrite full url links to same domain and base path', function() {
1096
- configureService('http://host.com/base/new', true);
1098
+ configureService({linkHref: 'http://host.com/base/new', html5Mode: true} );
1097
1099
inject(
1098
1100
initBrowser(),
1099
1101
initLocation(),
@@ -1106,7 +1108,7 @@ describe('$location', function() {
1106
1108
1107
1109
1108
1110
it('should rewrite when clicked span inside link', function() {
1109
- configureService('some/link', true, true, '', '<span>link</span>');
1111
+ configureService({linkHref: 'some/link', html5Mode: true, supportHist: true, attrs: '', content: '<span>link</span>'} );
1110
1112
inject(
1111
1113
initBrowser(),
1112
1114
initLocation(),
@@ -1122,7 +1124,7 @@ describe('$location', function() {
1122
1124
1123
1125
it('should not rewrite when link to different base path when history enabled on new browser',
1124
1126
function() {
1125
- configureService('/other_base/link', true, true);
1127
+ configureService({linkHref: '/other_base/link', html5Mode: true, supportHist: true} );
1126
1128
inject(
1127
1129
initBrowser(),
1128
1130
initLocation(),
@@ -1136,7 +1138,7 @@ describe('$location', function() {
1136
1138
1137
1139
it('should not rewrite when link to different base path when history enabled on old browser',
1138
1140
function() {
1139
- configureService('/other_base/link', true, false);
1141
+ configureService({linkHref: '/other_base/link', html5Mode: true, supportHist: false} );
1140
1142
inject(
1141
1143
initBrowser(),
1142
1144
initLocation(),
@@ -1149,7 +1151,7 @@ describe('$location', function() {
1149
1151
1150
1152
1151
1153
it('should not rewrite when link to different base path when history disabled', function() {
1152
- configureService('/other_base/link', false);
1154
+ configureService({linkHref: '/other_base/link', html5Mode: false} );
1153
1155
inject(
1154
1156
initBrowser(),
1155
1157
initLocation(),
@@ -1163,7 +1165,7 @@ describe('$location', function() {
1163
1165
1164
1166
it('should not rewrite when full link to different base path when history enabled on new browser',
1165
1167
function() {
1166
- configureService('http://host.com/other_base/link', true, true);
1168
+ configureService({linkHref: 'http://host.com/other_base/link', html5Mode: true, supportHist: true} );
1167
1169
inject(
1168
1170
initBrowser(),
1169
1171
initLocation(),
@@ -1177,7 +1179,7 @@ describe('$location', function() {
1177
1179
1178
1180
it('should not rewrite when full link to different base path when history enabled on old browser',
1179
1181
function() {
1180
- configureService('http://host.com/other_base/link', true, false);
1182
+ configureService({linkHref: 'http://host.com/other_base/link', html5Mode: true, supportHist: false} );
1181
1183
inject(
1182
1184
initBrowser(),
1183
1185
initLocation(),
@@ -1190,7 +1192,7 @@ describe('$location', function() {
1190
1192
1191
1193
1192
1194
it('should not rewrite when full link to different base path when history disabled', function() {
1193
- configureService('http://host.com/other_base/link', false);
1195
+ configureService({linkHref: 'http://host.com/other_base/link', html5Mode: false} );
1194
1196
inject(
1195
1197
initBrowser(),
1196
1198
initLocation(),
@@ -1203,7 +1205,7 @@ describe('$location', function() {
1203
1205
1204
1206
1205
1207
it('should rewrite relative links relative to current path when history disabled', function() {
1206
- configureService('link', true, false, true);
1208
+ configureService({linkHref: 'link', html5Mode: true, supportHist: false, relLink: true} );
1207
1209
inject(
1208
1210
initBrowser(),
1209
1211
initLocation(),
@@ -1217,7 +1219,7 @@ describe('$location', function() {
1217
1219
1218
1220
1219
1221
it('should replace current path when link begins with "/" and history disabled', function() {
1220
- configureService('/link', true, false, true);
1222
+ configureService({linkHref: '/link', html5Mode: true, supportHist: false, relLink: true} );
1221
1223
inject(
1222
1224
initBrowser(),
1223
1225
initLocation(),
@@ -1231,7 +1233,7 @@ describe('$location', function() {
1231
1233
1232
1234
1233
1235
it('should replace current hash fragment when link begins with "#" history disabled', function() {
1234
- configureService('#link', true, false, true);
1236
+ configureService({linkHref: '#link', html5Mode: true, supportHist: false, relLink: true} );
1235
1237
inject(
1236
1238
initBrowser(),
1237
1239
initLocation(),
@@ -1251,7 +1253,7 @@ describe('$location', function() {
1251
1253
if (!msie || msie >= 9) {
1252
1254
1253
1255
it('should not rewrite when clicked with ctrl pressed', function() {
1254
- configureService('/a?b=c', true, true);
1256
+ configureService({linkHref: '/a?b=c', html5Mode: true, supportHist: true} );
1255
1257
inject(
1256
1258
initBrowser(),
1257
1259
initLocation(),
@@ -1264,7 +1266,7 @@ describe('$location', function() {
1264
1266
1265
1267
1266
1268
it('should not rewrite when clicked with meta pressed', function() {
1267
- configureService('/a?b=c', true, true);
1269
+ configureService({linkHref: '/a?b=c', html5Mode: true, supportHist: true} );
1268
1270
inject(
1269
1271
initBrowser(),
1270
1272
initLocation(),
0 commit comments