From 35d393fcb8b40f614dd3f7583533e198531418b6 Mon Sep 17 00:00:00 2001 From: rrsivabalan Date: Wed, 4 Nov 2015 20:47:09 +0530 Subject: [PATCH 1/2] fixing code review comments and adding UT #12175 --- src/ng/location.js | 6 +++--- test/ng/locationSpec.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/ng/location.js b/src/ng/location.js index f575a653f916..c5a59a8d5d52 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -918,16 +918,16 @@ function $LocationProvider() { var oldUrl = $location.absUrl(); var oldState = $location.$$state; var defaultPrevented; - + var trimNewUrl = trimEmptyHash(newUrl); $location.$$parse(newUrl); $location.$$state = newState; - defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl, + defaultPrevented = $rootScope.$broadcast('$locationChangeStart', trimNewUrl, oldUrl, newState, oldState).defaultPrevented; // if the location was changed by a `$locationChangeStart` handler then stop // processing this location change - if ($location.absUrl() !== newUrl) return; + if ($location.absUrl() !== trimNewUrl) return; if (defaultPrevented) { $location.$$parse(oldUrl); diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 1efe3396762f..49a7b7ef275e 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -2141,6 +2141,31 @@ describe('$location', function() { }) ); + it('should fire $locationChangeSuccess when browser location changes to URL which ends with #', + inject(function($location, $browser, $rootScope, $log) { + $location.url('/somepath'); + $rootScope.$apply(); + + expect($browser.url()).toEqual('http://server/#/somepath'); + expect($location.url()).toEqual('/somepath'); + + $rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) { + $log.info('start', newUrl, oldUrl); + }); + $rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) { + $log.info('after', newUrl, oldUrl); + }); + + $browser.url('http://server/#'); + $browser.poll(); + + expect($log.info.logs.shift()). + toEqual(['start', 'http://server/', 'http://server/#/somepath']); + expect($log.info.logs.shift()). + toEqual(['after', 'http://server/', 'http://server/#/somepath']); + }) + ); + it('should allow redirect during browser url change', inject(function($location, $browser, $rootScope, $log) { $rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) { From 38bcdb16d9d6cb7240479d790ce3c8278a60da20 Mon Sep 17 00:00:00 2001 From: rrsivabalan Date: Wed, 4 Nov 2015 22:21:04 +0530 Subject: [PATCH 2/2] fixing white spaces in UT for Travis CI success --- test/ng/locationSpec.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 49a7b7ef275e..8e1607c83146 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -2141,31 +2141,31 @@ describe('$location', function() { }) ); - it('should fire $locationChangeSuccess when browser location changes to URL which ends with #', - inject(function($location, $browser, $rootScope, $log) { + it('should fire $locationChangeSuccess when browser location changes to URL which ends with #', + inject(function($location, $browser, $rootScope, $log) { $location.url('/somepath'); $rootScope.$apply(); expect($browser.url()).toEqual('http://server/#/somepath'); expect($location.url()).toEqual('/somepath'); - - $rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) { + + $rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) { $log.info('start', newUrl, oldUrl); }); - $rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) { - $log.info('after', newUrl, oldUrl); - }); - - $browser.url('http://server/#'); - $browser.poll(); - - expect($log.info.logs.shift()). - toEqual(['start', 'http://server/', 'http://server/#/somepath']); - expect($log.info.logs.shift()). - toEqual(['after', 'http://server/', 'http://server/#/somepath']); - }) - ); - + $rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) { + $log.info('after', newUrl, oldUrl); + }); + + $browser.url('http://server/#'); + $browser.poll(); + + expect($log.info.logs.shift()). + toEqual(['start', 'http://server/', 'http://server/#/somepath']); + expect($log.info.logs.shift()). + toEqual(['after', 'http://server/', 'http://server/#/somepath']); + }) + ); + it('should allow redirect during browser url change', inject(function($location, $browser, $rootScope, $log) { $rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {