Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($browser): handle async href on url change in <=IE9 #9237

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ function Browser(window, document, $log, $sniffer) {

function fireUrlChange() {
newLocation = null;
checkUrlChange();
}

function checkUrlChange() {
if (lastBrowserUrl == self.url()) return;

lastBrowserUrl = self.url();
Expand Down Expand Up @@ -239,7 +243,7 @@ function Browser(window, document, $log, $sniffer) {
* Needs to be exported to be able to check for changes that have been done in sync,
* as hashchange/popstate events fire in async.
*/
self.$$checkUrlChange = fireUrlChange;
self.$$checkUrlChange = checkUrlChange;

//////////////////////////////////////////////////////////////
// Misc API
Expand Down
23 changes: 23 additions & 0 deletions test/ng/browserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,29 @@ describe('browser', function() {
expect($location.path()).toBe('/someTestHash');
});
});

});

describe('integration test with $rootScope', function() {

beforeEach(module(function($provide, $locationProvider) {
$provide.value('$browser', browser);
browser.pollFns = [];
}));

it('should not interfere with legacy browser url replace behavior', function() {
inject(function($rootScope) {
var current = fakeWindow.location.href;
var newUrl = 'notyet';
sniffer.history = false;
browser.url(newUrl, true);
expect(browser.url()).toBe(newUrl);
$rootScope.$digest();
expect(browser.url()).toBe(newUrl);
expect(fakeWindow.location.href).toBe(current);
});
});

});

});