Skip to content

Commit 3381fec

Browse files
fix($location): do not get caught in infinite digest in IE9
Closes angular#11439 Closes angular#11675 Closes angular#11935
1 parent f7b1a6c commit 3381fec

File tree

1 file changed

+13
-45
lines changed

1 file changed

+13
-45
lines changed

test/ng/locationSpec.js

+13-45
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,17 @@ describe('$location', function() {
669669
mockUpBrowser({initialUrl:'http://server/base/home', baseHref:'/base/'});
670670
inject(
671671
function($browser, $location, $rootScope, $window) {
672+
var handlerCalled = false;
672673
$rootScope.$on('$locationChangeSuccess', function() {
674+
handlerCalled = true;
673675
if ($location.path() !== '/') {
674676
$location.path('/').replace();
675677
}
676678
});
679+
expect($browser.url()).toEqual('http://server/base/#/home');
677680
$rootScope.$digest();
681+
expect(handlerCalled).toEqual(true);
682+
expect($browser.url()).toEqual('http://server/base/#/');
678683
}
679684
);
680685
});
@@ -768,10 +773,10 @@ describe('$location', function() {
768773

769774

770775
describe('location watch for HTML5 browsers', function() {
771-
beforeEach(initService({html5Mode: true, supportHistory: true}));
772-
beforeEach(inject(initBrowser({basePath: '/app/'})));
773776

774777
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/'});
775780
inject(function($rootScope, $injector, $browser) {
776781
var $browserUrl = spyOnlyCallsWithArgs($browser, 'url').andCallThrough();
777782

@@ -790,6 +795,8 @@ describe('$location', function() {
790795
});
791796

792797
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/'});
793800
inject(function($rootScope, $injector, $browser) {
794801
var $browserUrl = spyOnlyCallsWithArgs($browser, 'url').andCallThrough();
795802

@@ -808,6 +815,8 @@ describe('$location', function() {
808815
});
809816

810817
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/'});
811820
inject(function($rootScope, $injector, $browser) {
812821
var $browserUrl = spyOnlyCallsWithArgs($browser, 'url').andCallThrough();
813822

@@ -826,6 +835,8 @@ describe('$location', function() {
826835
});
827836

828837
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/'});
829840
inject(function($rootScope, $injector, $browser) {
830841
var $browserUrl = spyOnlyCallsWithArgs($browser, 'url').andCallThrough();
831842

@@ -1212,49 +1223,6 @@ describe('$location', function() {
12121223
}
12131224
);
12141225
});
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-
});
12581226
});
12591227

12601228

0 commit comments

Comments
 (0)