From 6593a3e0823f3c08079f05010f9628fc4503cd43 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Wed, 13 Jun 2012 15:37:52 -0700
Subject: fix($location): fix URL interception in hash-bang mode
Closes #1051
---
test/ng/locationSpec.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 60 insertions(+), 2 deletions(-)
(limited to 'test/ng')
diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js
index 91f3688c..88747dff 100644
--- a/test/ng/locationSpec.js
+++ b/test/ng/locationSpec.js
@@ -1029,6 +1029,64 @@ describe('$location', function() {
expect($browser.url()).toEqual(base + '#!/view2');
});
});
+
+
+ it('should not intercept link clicks outside the app base url space', function() {
+ var base, clickHandler;
+ module(function($provide) {
+ $provide.value('$rootElement', {
+ bind: function(event, handler) {
+ expect(event).toEqual('click');
+ clickHandler = handler;
+ }
+ });
+ return function($browser) {
+ $browser.url(base = 'http://server/');
+ }
+ });
+ inject(function($rootScope, $compile, $browser, $rootElement, $document, $location) {
+ // make IE happy
+ jqLite(window.document.body).html('link');
+
+ var event = {
+ target: jqLite(window.document.body).find('a')[0],
+ preventDefault: jasmine.createSpy('preventDefault')
+ };
+
+
+ clickHandler(event);
+ expect(event.preventDefault).not.toHaveBeenCalled();
+ });
+ });
+
+
+ it('should not intercept hash link clicks outside the app base url space', function() {
+ var base, clickHandler;
+ module(function($provide) {
+ $provide.value('$rootElement', {
+ bind: function(event, handler) {
+ expect(event).toEqual('click');
+ clickHandler = handler;
+ }
+ });
+ return function($browser) {
+ $browser.url(base = 'http://server/');
+ }
+ });
+ inject(function($rootScope, $compile, $browser, $rootElement, $document, $location) {
+ // make IE happy
+ jqLite(window.document.body).html('link');
+
+ var event = {
+ target: jqLite(window.document.body).find('a')[0],
+ preventDefault: jasmine.createSpy('preventDefault')
+ };
+
+
+ clickHandler(event);
+ expect(event.preventDefault).not.toHaveBeenCalled();
+ });
+ });
});
@@ -1111,7 +1169,7 @@ describe('$location', function() {
);
- it('should listen on click events on href and prevent browser default in hasbang mode', function() {
+ it('should listen on click events on href and prevent browser default in hashbang mode', function() {
module(function() {
return function($rootElement, $compile, $rootScope) {
$rootElement.html('link');
@@ -1162,7 +1220,7 @@ describe('$location', function() {
log += '$locationChangeStart';
});
$rootScope.$on('$locationChangeSuccess', function() {
- throw new Error('after cancalation in html5 mode');
+ throw new Error('after cancelation in html5 mode');
});
browserTrigger(link, 'click');
--
cgit v1.2.3