@@ -858,12 +858,12 @@ describe('$location', function() {
858
858
module ( function ( $provide , $locationProvider ) {
859
859
attrs = attrs ? ' ' + attrs + ' ' : '' ;
860
860
861
- // fake the base behavior
862
861
if ( typeof linkHref === 'string' ) {
863
862
if ( ! relLink ) {
864
863
if ( linkHref [ 0 ] == '/' ) {
865
864
linkHref = 'http://host.com' + linkHref ;
866
865
} else if ( ! linkHref . match ( / : \/ \/ / ) ) {
866
+ // fake the behavior of <base> tag
867
867
linkHref = 'http://host.com/base/' + linkHref ;
868
868
}
869
869
}
@@ -888,8 +888,8 @@ describe('$location', function() {
888
888
}
889
889
890
890
function initBrowser ( ) {
891
- return function ( $browser ) {
892
- $browser . url ( 'http://host.com/base' ) ;
891
+ return function ( $browser , $document ) {
892
+ $browser . url ( 'http://host.com/base/index.html ' ) ;
893
893
$browser . $$baseHref = '/base/index.html' ;
894
894
} ;
895
895
}
@@ -1003,12 +1003,14 @@ describe('$location', function() {
1003
1003
1004
1004
1005
1005
it ( 'should produce relative paths correctly when $location.path() is "/" when history enabled on old browser' , function ( ) {
1006
- configureService ( { linkHref : 'partial1' , html5Mode : true , supportHist : false , relLink : true } ) ;
1006
+ configureService ( { linkHref : 'partial1' , html5Mode : true , supportHist : false } ) ;
1007
1007
inject (
1008
1008
initBrowser ( ) ,
1009
1009
initLocation ( ) ,
1010
- function ( $browser , $location ) {
1011
- $location . path ( '/' ) ;
1010
+ function ( $browser , $location , $rootScope ) {
1011
+ $rootScope . $apply ( function ( ) {
1012
+ $location . path ( '/' ) ;
1013
+ } ) ;
1012
1014
browserTrigger ( link , 'click' ) ;
1013
1015
expectRewriteTo ( $browser , 'http://host.com/base/index.html#!/partial1' ) ;
1014
1016
}
@@ -1203,52 +1205,22 @@ describe('$location', function() {
1203
1205
) ;
1204
1206
} ) ;
1205
1207
1206
-
1207
- it ( 'should rewrite relative links relative to current path when history disabled' , function ( ) {
1208
- configureService ( { linkHref : 'link' , html5Mode : true , supportHist : false , relLink : true } ) ;
1209
- inject (
1210
- initBrowser ( ) ,
1211
- initLocation ( ) ,
1212
- function ( $browser , $location ) {
1213
- $location . path ( '/some' ) ;
1214
- browserTrigger ( link , 'click' ) ;
1215
- expectRewriteTo ( $browser , 'http://host.com/base/index.html#!/some/link' ) ;
1216
- }
1217
- ) ;
1218
- } ) ;
1219
-
1220
-
1221
- it ( 'should replace current path when link begins with "/" and history disabled' , function ( ) {
1222
- configureService ( { linkHref : '/link' , html5Mode : true , supportHist : false , relLink : true } ) ;
1223
- inject (
1224
- initBrowser ( ) ,
1225
- initLocation ( ) ,
1226
- function ( $browser , $location ) {
1227
- $location . path ( '/some' ) ;
1228
- browserTrigger ( link , 'click' ) ;
1229
- expectRewriteTo ( $browser , 'http://host.com/base/index.html#!/link' ) ;
1230
- }
1231
- ) ;
1232
- } ) ;
1233
-
1234
-
1235
1208
it ( 'should replace current hash fragment when link begins with "#" history disabled' , function ( ) {
1236
- configureService ( { linkHref : '#link' , html5Mode : true , supportHist : false , relLink : true } ) ;
1209
+ configureService ( { linkHref : '#link' , html5Mode : true , supportHist : false , relLink : false } ) ;
1237
1210
inject (
1238
1211
initBrowser ( ) ,
1239
1212
initLocation ( ) ,
1240
- function ( $browser , $location ) {
1241
- // Initialize browser URL
1242
- $location . path ( '/some ') ;
1243
- $location . hash ( 'foo' ) ;
1213
+ function ( $browser , $location , $rootScope ) {
1214
+ $rootScope . $apply ( function ( ) {
1215
+ $location . hash ( 'foo ') ;
1216
+ } ) ;
1244
1217
browserTrigger ( link , 'click' ) ;
1245
1218
expect ( $location . hash ( ) ) . toBe ( 'link' ) ;
1246
- expectRewriteTo ( $browser , 'http://host.com/base/index.html#!/some #link' ) ;
1219
+ expectRewriteTo ( $browser , 'http://host.com/base/index.html#!#link' ) ;
1247
1220
}
1248
1221
) ;
1249
1222
} ) ;
1250
1223
1251
-
1252
1224
// don't run next tests on IE<9, as browserTrigger does not simulate pressed keys
1253
1225
if ( ! msie || msie >= 9 ) {
1254
1226
@@ -1360,7 +1332,8 @@ describe('$location', function() {
1360
1332
1361
1333
var event = {
1362
1334
target : jqLite ( window . document . body ) . find ( 'a' ) [ 0 ] ,
1363
- preventDefault : jasmine . createSpy ( 'preventDefault' )
1335
+ preventDefault : jasmine . createSpy ( 'preventDefault' ) ,
1336
+ isDefaultPrevented : jasmine . createSpy ( ) . andReturn ( false )
1364
1337
} ;
1365
1338
1366
1339
@@ -1390,7 +1363,8 @@ describe('$location', function() {
1390
1363
1391
1364
var event = {
1392
1365
target : jqLite ( window . document . body ) . find ( 'a' ) [ 0 ] ,
1393
- preventDefault : jasmine . createSpy ( 'preventDefault' )
1366
+ preventDefault : jasmine . createSpy ( 'preventDefault' ) ,
1367
+ isDefaultPrevented : jasmine . createSpy ( ) . andReturn ( false )
1394
1368
} ;
1395
1369
1396
1370
@@ -1555,8 +1529,12 @@ describe('$location', function() {
1555
1529
1556
1530
1557
1531
it ( 'should listen on click events on href and prevent browser default in html5 mode' , function ( ) {
1558
- module ( function ( $locationProvider ) {
1532
+ module ( function ( $locationProvider , $provide ) {
1559
1533
$locationProvider . html5Mode ( true ) ;
1534
+ $provide . decorator ( '$browser' , function ( $delegate ) {
1535
+ $delegate . $$baseHref = '/' ;
1536
+ return $delegate ;
1537
+ } ) ;
1560
1538
return function ( $rootElement , $compile , $rootScope ) {
1561
1539
$rootElement . html ( '<a href="http://server/somePath">link</a>' ) ;
1562
1540
$compile ( $rootElement ) ( $rootScope ) ;
@@ -1613,6 +1591,13 @@ describe('$location', function() {
1613
1591
) ;
1614
1592
} ) ;
1615
1593
1594
+ function parseLinkAndReturn ( location , url , relHref ) {
1595
+ if ( location . $$parseLinkUrl ( url , relHref ) ) {
1596
+ return location . absUrl ( ) ;
1597
+ }
1598
+ return undefined ;
1599
+ }
1600
+
1616
1601
describe ( 'LocationHtml5Url' , function ( ) {
1617
1602
var location , locationIndex ;
1618
1603
@@ -1622,28 +1607,36 @@ describe('$location', function() {
1622
1607
} ) ;
1623
1608
1624
1609
it ( 'should rewrite URL' , function ( ) {
1625
- expect ( location . $$rewrite ( 'http://other' ) ) . toEqual ( undefined ) ;
1626
- expect ( location . $$rewrite ( 'http://server/pre' ) ) . toEqual ( 'http://server/pre/' ) ;
1627
- expect ( location . $$rewrite ( 'http://server/pre/' ) ) . toEqual ( 'http://server/pre/' ) ;
1628
- expect ( location . $$rewrite ( 'http://server/pre/otherPath' ) ) . toEqual ( 'http://server/pre/otherPath' ) ;
1629
- expect ( locationIndex . $$rewrite ( 'http://server/pre' ) ) . toEqual ( 'http://server/pre/' ) ;
1630
- expect ( locationIndex . $$rewrite ( 'http://server/pre/' ) ) . toEqual ( 'http://server/pre/' ) ;
1631
- expect ( locationIndex . $$rewrite ( 'http://server/pre/otherPath' ) ) . toEqual ( 'http://server/pre/otherPath' ) ;
1610
+ expect ( parseLinkAndReturn ( location , 'http://other' ) ) . toEqual ( undefined ) ;
1611
+ expect ( parseLinkAndReturn ( location , 'http://server/pre' ) ) . toEqual ( 'http://server/pre/' ) ;
1612
+ expect ( parseLinkAndReturn ( location , 'http://server/pre/' ) ) . toEqual ( 'http://server/pre/' ) ;
1613
+ expect ( parseLinkAndReturn ( location , 'http://server/pre/otherPath' ) ) . toEqual ( 'http://server/pre/otherPath' ) ;
1614
+
1615
+ expect ( parseLinkAndReturn ( locationIndex , 'http://server/pre' ) ) . toEqual ( 'http://server/pre/' ) ;
1616
+ expect ( parseLinkAndReturn ( locationIndex , 'http://server/pre/' ) ) . toEqual ( 'http://server/pre/' ) ;
1617
+ expect ( parseLinkAndReturn ( locationIndex , 'http://server/pre/otherPath' ) ) . toEqual ( 'http://server/pre/otherPath' ) ;
1632
1618
} ) ;
1633
1619
} ) ;
1634
1620
1635
1621
1636
1622
describe ( 'LocationHashbangUrl' , function ( ) {
1637
1623
var location ;
1638
1624
1625
+ function parseLinkAndReturn ( location , url , relHref ) {
1626
+ if ( location . $$parseLinkUrl ( url , relHref ) ) {
1627
+ return location . absUrl ( ) ;
1628
+ }
1629
+ return undefined ;
1630
+ }
1631
+
1639
1632
it ( 'should rewrite URL' , function ( ) {
1640
1633
/* jshint scripturl: true */
1641
1634
location = new LocationHashbangUrl ( 'http://server/pre/' , '#' ) ;
1642
1635
1643
- expect ( location . $$rewrite ( 'http://other' ) ) . toEqual ( undefined ) ;
1644
- expect ( location . $$rewrite ( 'http://server/pre/' ) ) . toEqual ( 'http://server/pre/' ) ;
1645
- expect ( location . $$rewrite ( 'http://server/pre/#otherPath' ) ) . toEqual ( 'http://server/pre/#otherPath' ) ;
1646
- expect ( location . $$rewrite ( 'javascript:void(0)' ) ) . toEqual ( undefined ) ;
1636
+ expect ( parseLinkAndReturn ( location , 'http://other' ) ) . toEqual ( undefined ) ;
1637
+ expect ( parseLinkAndReturn ( location , 'http://server/pre/' ) ) . toEqual ( 'http://server/pre/' ) ;
1638
+ expect ( parseLinkAndReturn ( location , 'http://server/pre/#otherPath' ) ) . toEqual ( 'http://server/pre/#/ otherPath' ) ;
1639
+ expect ( parseLinkAndReturn ( location , 'javascript:void(0)' ) ) . toEqual ( undefined ) ;
1647
1640
} ) ;
1648
1641
1649
1642
it ( "should not set hash if one was not originally specified" , function ( ) {
@@ -1693,13 +1686,14 @@ describe('$location', function() {
1693
1686
} ) ;
1694
1687
1695
1688
it ( 'should rewrite URL' , function ( ) {
1696
- expect ( location . $$rewrite ( 'http://other' ) ) . toEqual ( undefined ) ;
1697
- expect ( location . $$rewrite ( 'http://server/pre' ) ) . toEqual ( 'http://server/pre/' ) ;
1698
- expect ( location . $$rewrite ( 'http://server/pre/' ) ) . toEqual ( 'http://server/pre/' ) ;
1699
- expect ( location . $$rewrite ( 'http://server/pre/otherPath' ) ) . toEqual ( 'http://server/pre/#!otherPath' ) ;
1700
- expect ( locationIndex . $$rewrite ( 'http://server/pre' ) ) . toEqual ( 'http://server/pre/' ) ;
1701
- expect ( locationIndex . $$rewrite ( 'http://server/pre/' ) ) . toEqual ( undefined ) ;
1702
- expect ( locationIndex . $$rewrite ( 'http://server/pre/otherPath' ) ) . toEqual ( 'http://server/pre/index.html#!otherPath' ) ;
1689
+ expect ( parseLinkAndReturn ( location , 'http://other' ) ) . toEqual ( undefined ) ;
1690
+ expect ( parseLinkAndReturn ( location , 'http://server/pre' ) ) . toEqual ( 'http://server/pre/#!' ) ;
1691
+ expect ( parseLinkAndReturn ( location , 'http://server/pre/' ) ) . toEqual ( 'http://server/pre/#!' ) ;
1692
+ expect ( parseLinkAndReturn ( location , 'http://server/pre/otherPath' ) ) . toEqual ( 'http://server/pre/#!/otherPath' ) ;
1693
+
1694
+ expect ( parseLinkAndReturn ( locationIndex , 'http://server/pre' ) ) . toEqual ( 'http://server/pre/index.html#!' ) ;
1695
+ expect ( parseLinkAndReturn ( locationIndex , 'http://server/pre/' ) ) . toEqual ( undefined ) ;
1696
+ expect ( parseLinkAndReturn ( locationIndex , 'http://server/pre/otherPath' ) ) . toEqual ( 'http://server/pre/index.html#!/otherPath' ) ;
1703
1697
} ) ;
1704
1698
} ) ;
1705
1699
} ) ;
0 commit comments