aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/directive/booleanAttrsSpec.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/ng/directive/booleanAttrsSpec.js')
-rw-r--r--test/ng/directive/booleanAttrsSpec.js104
1 files changed, 71 insertions, 33 deletions
diff --git a/test/ng/directive/booleanAttrsSpec.js b/test/ng/directive/booleanAttrsSpec.js
index be2dfb60..93e8cc20 100644
--- a/test/ng/directive/booleanAttrsSpec.js
+++ b/test/ng/directive/booleanAttrsSpec.js
@@ -102,61 +102,99 @@ describe('boolean attr directives', function() {
describe('ngSrc', function() {
- it('should interpolate the expression and bind to src', inject(function($compile, $rootScope) {
+ it('should interpolate the expression and bind to src with raw same-domain value',
+ inject(function($compile, $rootScope) {
+ var element = $compile('<div ng-src="{{id}}"></div>')($rootScope);
+
+ $rootScope.$digest();
+ expect(element.attr('src')).toBeUndefined();
+
+ $rootScope.$apply(function() {
+ $rootScope.id = '/somewhere/here';
+ });
+ expect(element.attr('src')).toEqual('/somewhere/here');
+
+ dealoc(element);
+ }));
+
+
+ it('should interpolate the expression and bind to src with a trusted value', inject(function($compile, $rootScope, $sce) {
var element = $compile('<div ng-src="{{id}}"></div>')($rootScope);
$rootScope.$digest();
expect(element.attr('src')).toBeUndefined();
$rootScope.$apply(function() {
- $rootScope.id = 1;
+ $rootScope.id = $sce.trustAsResourceUrl('http://somewhere');
});
- expect(element.attr('src')).toEqual('1');
+ expect(element.attr('src')).toEqual('http://somewhere');
dealoc(element);
}));
- describe('isTrustedContext', function() {
- it('should NOT interpolate a multi-part expression for non-img src attribute', inject(function($compile, $rootScope) {
- expect(function() {
- var element = $compile('<div ng-src="some/{{id}}"></div>')($rootScope);
- dealoc(element);
- }).toThrow(
- "[$interpolate:noconcat] Error while interpolating: some/{{id}}\nYou may not use " +
- "multiple expressions when interpolating this expression.");
- }));
- it('should interpolate a multi-part expression for regular attributes', inject(function($compile, $rootScope) {
- var element = $compile('<div foo="some/{{id}}"></div>')($rootScope);
- $rootScope.$digest();
- expect(element.attr('foo')).toBe('some/');
+ it('should NOT interpolate a multi-part expression for non-img src attribute', inject(function($compile, $rootScope) {
+ expect(function() {
+ var element = $compile('<div ng-src="some/{{id}}"></div>')($rootScope);
+ dealoc(element);
+ }).toThrow(
+ "[$interpolate:noconcat] Error while interpolating: some/{{id}}\nStrict " +
+ "Contextual Escaping disallows interpolations that concatenate multiple expressions " +
+ "when a trusted value is required. See http://docs.angularjs.org/api/ng.$sce");
+ }));
+
+
+ it('should interpolate a multi-part expression for regular attributes', inject(function($compile, $rootScope) {
+ var element = $compile('<div foo="some/{{id}}"></div>')($rootScope);
+ $rootScope.$digest();
+ expect(element.attr('foo')).toBe('some/');
+ $rootScope.$apply(function() {
+ $rootScope.id = 1;
+ });
+ expect(element.attr('foo')).toEqual('some/1');
+ }));
+
+
+ it('should NOT interpolate a wrongly typed expression', inject(function($compile, $rootScope, $sce) {
+ expect(function() {
+ var element = $compile('<div ng-src="{{id}}"></div>')($rootScope);
$rootScope.$apply(function() {
- $rootScope.id = 1;
+ $rootScope.id = $sce.trustAsUrl('http://somewhere');
});
- expect(element.attr('foo')).toEqual('some/1');
- }));
+ element.attr('src');
+ }).toThrow(
+ "[$interpolate:interr] Can't interpolate: {{id}}\nError: [$sce:isecrurl] Blocked " +
+ "loading resource from url not allowed by $sceDelegate policy. URL: http://somewhere");
+ }));
- });
if (msie) {
it('should update the element property as well as the attribute', inject(
- function($compile, $rootScope) {
- // on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist
- // then calling element.setAttribute('src', 'foo') doesn't do anything, so we need
- // to set the property as well to achieve the desired effect
+ function($compile, $rootScope, $sce) {
+ // on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist
+ // then calling element.setAttribute('src', 'foo') doesn't do anything, so we need
+ // to set the property as well to achieve the desired effect
- var element = $compile('<div ng-src="{{id}}"></div>')($rootScope);
+ var element = $compile('<div ng-src="{{id}}"></div>')($rootScope);
- $rootScope.$digest();
- expect(element.prop('src')).toBeUndefined();
+ $rootScope.$digest();
+ expect(element.prop('src')).toBeUndefined();
+ dealoc(element);
- $rootScope.$apply(function() {
- $rootScope.id = 1;
- });
- expect(element.prop('src')).toEqual('1');
+ element = $compile('<div ng-src="some/"></div>')($rootScope);
- dealoc(element);
- }));
+ $rootScope.$digest();
+ expect(element.prop('src')).toEqual('some/');
+ dealoc(element);
+
+ element = $compile('<div ng-src="{{id}}"></div>')($rootScope);
+ $rootScope.$apply(function() {
+ $rootScope.id = $sce.trustAsResourceUrl('http://somewhere');
+ });
+ expect(element.prop('src')).toEqual('http://somewhere');
+
+ dealoc(element);
+ }));
}
});