diff options
| author | Chirayu Krishnappa | 2013-07-15 12:26:46 -0700 | 
|---|---|---|
| committer | Chirayu Krishnappa | 2013-07-19 01:44:57 -0700 | 
| commit | b99d064b6ddbcc9f59ea45004279833e9ea82928 (patch) | |
| tree | 94406ce1926027de90a43b4abf4a7c7c8b0651c6 /test/ng | |
| parent | 715d97d5c87c9250f8ac8b5801b8c7f3b197e815 (diff) | |
| download | angular.js-b99d064b6ddbcc9f59ea45004279833e9ea82928.tar.bz2 | |
fix(core): parse URLs using the browser's DOM API
Diffstat (limited to 'test/ng')
| -rw-r--r-- | test/ng/httpSpec.js | 21 | ||||
| -rw-r--r-- | test/ng/urlUtilsSpec.js | 31 | 
2 files changed, 31 insertions, 21 deletions
diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index cefc88e1..ec1cb7f1 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -1476,25 +1476,4 @@ describe('$http', function() {      $httpBackend.verifyNoOutstandingExpectation = noop;    }); - -  describe('isSameDomain', function() { -    it('should support various combinations of urls', function() { -      expect(isSameDomain('path/morepath', -                          'http://www.adomain.com')).toBe(true); -      expect(isSameDomain('http://www.adomain.com/path', -                          'http://www.adomain.com')).toBe(true); -      expect(isSameDomain('//www.adomain.com/path', -                          'http://www.adomain.com')).toBe(true); -      expect(isSameDomain('//www.adomain.com/path', -                          'https://www.adomain.com')).toBe(true); -      expect(isSameDomain('//www.adomain.com/path', -                          'http://www.adomain.com:1234')).toBe(false); -      expect(isSameDomain('https://www.adomain.com/path', -                          'http://www.adomain.com')).toBe(false); -      expect(isSameDomain('http://www.adomain.com:1234/path', -                          'http://www.adomain.com')).toBe(false); -      expect(isSameDomain('http://www.anotherdomain.com/path', -                          'http://www.adomain.com')).toBe(false); -    }); -  });  }); diff --git a/test/ng/urlUtilsSpec.js b/test/ng/urlUtilsSpec.js new file mode 100644 index 00000000..57043a5a --- /dev/null +++ b/test/ng/urlUtilsSpec.js @@ -0,0 +1,31 @@ +'use strict'; + +describe('$$urlUtils', function() { +  describe('parse', function() { +    it('should normalize a relative url', inject(function($$urlUtils) { +      expect($$urlUtils.resolve("foo")).toMatch(/^https?:\/\/[^/]+\/foo$/); +    })); + +    it('should parse relative URL into component pieces', inject(function($$urlUtils) { +      var parsed = $$urlUtils.resolve("foo", true); +      expect(parsed.href).toMatch(/https?:\/\//); +      expect(parsed.protocol).toMatch(/^https?:/); +      expect(parsed.host).not.toBe(""); +    })); +  }); + +  describe('isSameOrigin', function() { +    it('should support various combinations of urls', inject(function($$urlUtils, $document) { +      expect($$urlUtils.isSameOrigin('path')).toBe(true); +      var origin = $$urlUtils.resolve($document[0].location.href, true); +      expect($$urlUtils.isSameOrigin('//' + origin.host + '/path')).toBe(true); +      // Different domain. +      expect($$urlUtils.isSameOrigin('http://example.com/path')).toBe(false); +      // Auto fill protocol. +      expect($$urlUtils.isSameOrigin('//example.com/path')).toBe(false); +      // Should not match when the ports are different. +      // This assumes that the test is *not* running on port 22 (very unlikely). +      expect($$urlUtils.isSameOrigin('//' + origin.hostname + ':22/path')).toBe(false); +    })); +  }); +});  | 
