2018-03-01 20:14:01 -05:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2018-04-14 14:52:53 -04:00
|
|
|
import {NgForOfContext} from '@angular/common';
|
2019-04-11 16:46:47 -04:00
|
|
|
import {ɵɵpropertyInterpolate, ɵɵpropertyInterpolate1, ɵɵpropertyInterpolate2, ɵɵpropertyInterpolate3, ɵɵpropertyInterpolate4, ɵɵpropertyInterpolate5, ɵɵpropertyInterpolate6, ɵɵpropertyInterpolate7, ɵɵpropertyInterpolate8, ɵɵpropertyInterpolateV} from '@angular/core/src/render3/instructions/all';
|
2019-04-04 14:41:52 -04:00
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
import {ɵɵdefineComponent} from '../../src/render3/definition';
|
2019-05-08 14:26:40 -04:00
|
|
|
import {RenderFlags, ɵɵbind, ɵɵclassMap, ɵɵelement, ɵɵelementAttribute, ɵɵelementEnd, ɵɵelementProperty, ɵɵelementStart, ɵɵinterpolation1, ɵɵproperty, ɵɵselect, ɵɵstyleMap, ɵɵstyleProp, ɵɵstyling, ɵɵstylingApply, ɵɵtemplate, ɵɵtext, ɵɵtextBinding} from '../../src/render3/index';
|
2018-10-12 21:49:00 -04:00
|
|
|
import {AttributeMarker} from '../../src/render3/interfaces/node';
|
2018-07-11 13:58:18 -04:00
|
|
|
import {bypassSanitizationTrustHtml, bypassSanitizationTrustResourceUrl, bypassSanitizationTrustScript, bypassSanitizationTrustStyle, bypassSanitizationTrustUrl} from '../../src/sanitization/bypass';
|
2019-04-11 16:46:47 -04:00
|
|
|
import {ɵɵdefaultStyleSanitizer, ɵɵsanitizeHtml, ɵɵsanitizeResourceUrl, ɵɵsanitizeScript, ɵɵsanitizeStyle, ɵɵsanitizeUrl} from '../../src/sanitization/sanitization';
|
2018-05-09 18:30:16 -04:00
|
|
|
import {Sanitizer, SecurityContext} from '../../src/sanitization/security';
|
2018-07-11 13:58:18 -04:00
|
|
|
import {StyleSanitizeFn} from '../../src/sanitization/style_sanitizer';
|
2019-04-04 14:41:52 -04:00
|
|
|
|
2018-04-14 14:52:53 -04:00
|
|
|
import {NgForOf} from './common_with_def';
|
2018-06-06 16:38:19 -04:00
|
|
|
import {ComponentFixture, TemplateFixture} from './render_util';
|
2018-03-01 20:14:01 -05:00
|
|
|
|
|
|
|
describe('instructions', () => {
|
2018-05-09 18:30:16 -04:00
|
|
|
function createAnchor() {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementStart(0, 'a');
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyling();
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementEnd();
|
2018-05-09 18:30:16 -04:00
|
|
|
}
|
|
|
|
|
2018-12-13 18:51:47 -05:00
|
|
|
function createDiv(
|
|
|
|
initialClasses?: string[] | null, classBindingNames?: string[] | null,
|
|
|
|
initialStyles?: string[] | null, styleBindingNames?: string[] | null,
|
|
|
|
styleSanitizer?: StyleSanitizeFn) {
|
|
|
|
const attrs: any[] = [];
|
|
|
|
if (initialClasses) {
|
|
|
|
attrs.push(AttributeMarker.Classes, ...initialClasses);
|
|
|
|
}
|
|
|
|
if (initialStyles) {
|
|
|
|
attrs.push(AttributeMarker.Styles, ...initialStyles);
|
|
|
|
}
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementStart(0, 'div', attrs);
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyling(classBindingNames || null, styleBindingNames || null, styleSanitizer);
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementEnd();
|
2018-03-01 20:14:01 -05:00
|
|
|
}
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
function createScript() { ɵɵelement(0, 'script'); }
|
2018-05-09 18:30:16 -04:00
|
|
|
|
2018-05-13 15:01:37 -04:00
|
|
|
describe('bind', () => {
|
|
|
|
it('should update bindings when value changes', () => {
|
2018-08-21 03:03:21 -04:00
|
|
|
const t = new TemplateFixture(createAnchor, () => {}, 1, 1);
|
2018-05-13 15:01:37 -04:00
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'title', ɵɵbind('Hello')));
|
2018-05-13 15:01:37 -04:00
|
|
|
expect(t.html).toEqual('<a title="Hello"></a>');
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'title', ɵɵbind('World')));
|
2018-05-13 15:01:37 -04:00
|
|
|
expect(t.html).toEqual('<a title="World"></a>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for hostElement + 1 for the template under test
|
2018-09-13 19:07:23 -04:00
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
2018-05-13 15:01:37 -04:00
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update bindings when value does not change', () => {
|
2019-04-11 16:46:47 -04:00
|
|
|
const idempotentUpdate = () => ɵɵelementProperty(0, 'title', ɵɵbind('Hello'));
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createAnchor, idempotentUpdate, 1, 1);
|
2018-05-13 15:01:37 -04:00
|
|
|
|
|
|
|
t.update();
|
|
|
|
expect(t.html).toEqual('<a title="Hello"></a>');
|
|
|
|
|
|
|
|
t.update();
|
|
|
|
expect(t.html).toEqual('<a title="Hello"></a>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for hostElement + 1 for the template under test
|
2018-09-13 19:07:23 -04:00
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
2018-05-13 15:01:37 -04:00
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 1
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-08 13:48:27 -04:00
|
|
|
describe('element', () => {
|
|
|
|
it('should create an element', () => {
|
2018-08-16 21:53:21 -04:00
|
|
|
const t = new TemplateFixture(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelement(0, 'div', ['id', 'test', 'title', 'Hello']);
|
2018-08-16 21:53:21 -04:00
|
|
|
}, () => {}, 1);
|
2018-06-08 13:48:27 -04:00
|
|
|
|
2018-10-12 18:02:54 -04:00
|
|
|
const div = (t.hostElement as HTMLElement).querySelector('div') !;
|
2018-06-08 13:48:27 -04:00
|
|
|
expect(div.id).toEqual('test');
|
|
|
|
expect(div.title).toEqual('Hello');
|
2018-06-08 18:25:39 -04:00
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
2018-09-13 19:07:23 -04:00
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
2018-06-08 18:25:39 -04:00
|
|
|
rendererCreateElement: 1,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow setting namespaced attributes', () => {
|
|
|
|
const t = new TemplateFixture(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelement(0, 'div', [
|
2018-06-08 18:25:39 -04:00
|
|
|
// id="test"
|
|
|
|
'id',
|
|
|
|
'test',
|
|
|
|
// test:foo="bar"
|
|
|
|
AttributeMarker.NamespaceURI,
|
|
|
|
'http://someuri.com/2018/test',
|
|
|
|
'test:foo',
|
|
|
|
'bar',
|
|
|
|
// title="Hello"
|
|
|
|
'title',
|
|
|
|
'Hello',
|
|
|
|
]);
|
2018-08-16 21:53:21 -04:00
|
|
|
}, () => {}, 1);
|
2018-06-08 18:25:39 -04:00
|
|
|
|
2018-10-12 18:02:54 -04:00
|
|
|
const div = (t.hostElement as HTMLElement).querySelector('div') !;
|
2018-06-08 18:25:39 -04:00
|
|
|
const attrs: any = div.attributes;
|
|
|
|
|
|
|
|
expect(attrs['id'].name).toEqual('id');
|
|
|
|
expect(attrs['id'].namespaceURI).toEqual(null);
|
|
|
|
expect(attrs['id'].value).toEqual('test');
|
|
|
|
|
|
|
|
expect(attrs['test:foo'].name).toEqual('test:foo');
|
|
|
|
expect(attrs['test:foo'].namespaceURI).toEqual('http://someuri.com/2018/test');
|
|
|
|
expect(attrs['test:foo'].value).toEqual('bar');
|
|
|
|
|
|
|
|
expect(attrs['title'].name).toEqual('title');
|
|
|
|
expect(attrs['title'].namespaceURI).toEqual(null);
|
|
|
|
expect(attrs['title'].value).toEqual('Hello');
|
2018-06-08 13:48:27 -04:00
|
|
|
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
2018-09-13 19:07:23 -04:00
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
2018-06-08 13:48:27 -04:00
|
|
|
rendererCreateElement: 1,
|
2018-06-08 18:25:39 -04:00
|
|
|
rendererSetAttribute: 3
|
2018-06-08 13:48:27 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-01 20:14:01 -05:00
|
|
|
describe('elementAttribute', () => {
|
|
|
|
it('should use sanitizer function', () => {
|
2018-08-16 21:53:21 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1);
|
2018-03-01 20:14:01 -05:00
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'title', 'javascript:true', ɵɵsanitizeUrl));
|
2018-03-01 20:14:01 -05:00
|
|
|
expect(t.html).toEqual('<div title="unsafe:javascript:true"></div>');
|
|
|
|
|
|
|
|
t.update(
|
2019-04-11 16:46:47 -04:00
|
|
|
() => ɵɵelementAttribute(
|
|
|
|
0, 'title', bypassSanitizationTrustUrl('javascript:true'), ɵɵsanitizeUrl));
|
2018-03-01 20:14:01 -05:00
|
|
|
expect(t.html).toEqual('<div title="javascript:true"></div>');
|
2018-04-14 14:52:53 -04:00
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
2018-05-16 08:56:01 -04:00
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
2018-09-13 19:07:23 -04:00
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
2018-04-14 14:52:53 -04:00
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetAttribute: 2
|
|
|
|
});
|
2018-03-01 20:14:01 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵselect', () => {
|
2019-03-26 17:57:36 -04:00
|
|
|
it('should error in DevMode if index is out of range', () => {
|
|
|
|
// Only one constant added, meaning only index `0` is valid.
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 0);
|
2019-04-11 16:46:47 -04:00
|
|
|
expect(() => { t.update(() => { ɵɵselect(-1); }); }).toThrow();
|
|
|
|
expect(() => { t.update(() => { ɵɵselect(1); }); }).toThrow();
|
|
|
|
expect(() => { t.update(() => { ɵɵselect(0); }); }).not.toThrow();
|
2019-03-26 17:57:36 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('property', () => {
|
|
|
|
// TODO(benlesh): Replace with TestBed tests once the instruction is being generated.
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should set properties of the ɵɵselected element', () => {
|
2019-03-26 17:57:36 -04:00
|
|
|
// <div [title]="title"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 1);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵproperty('title', 'one');
|
2019-03-26 17:57:36 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="one"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵproperty('title', 'two');
|
2019-03-26 17:57:36 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="two"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO(benlesh): Replace with TestBed tests once the instruction is being generated.
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div [title]="title" [accesskey]="key"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 2);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵproperty('title', 'one')('accessKey', 'A');
|
2019-03-26 17:57:36 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div accesskey="A" title="one"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵproperty('title', 'two')('accessKey', 'B');
|
2019-03-26 17:57:36 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div accesskey="B" title="two"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO(benlesh): Replace with TestBed tests once the instruction is being generated.
|
|
|
|
it('should diff value changes', () => {
|
|
|
|
// <div [title]="title" [accesskey]="key"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 2);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵproperty('title', 'one')('accessKey', 'A');
|
2019-03-26 17:57:36 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div accesskey="A" title="one"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵproperty('title', 'two')('accessKey', 'A'); // Notice: only changing the title.
|
2019-03-26 17:57:36 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div accesskey="A" title="two"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 3,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error in dev mode if ɵɵselect was not called prior', () => {
|
2019-03-26 17:57:36 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 1);
|
2019-04-11 16:46:47 -04:00
|
|
|
expect(() => { t.update(() => { ɵɵproperty('title', 'test'); }); }).toThrow();
|
2019-03-26 17:57:36 -04:00
|
|
|
expect(() => {
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵproperty('title', 'test');
|
2019-03-26 17:57:36 -04:00
|
|
|
});
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-28 17:54:22 -04:00
|
|
|
/**
|
|
|
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
* TODO: REMOVE ALL OF THESE TemplateFixture TESTS FOR TestBed TESTS AFTER COMPILER IS UPDATED
|
|
|
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
*/
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolate instructions', () => {
|
|
|
|
describe('ɵɵpropertyInterpolate', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate one value', () => {
|
|
|
|
// <div title="{{123}}"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 1);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate('title', 123);
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="123"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate('title', 'abc');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="abc"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="{{123}}" accesskey="{{'A'}}"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 2);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate('title', 123)('accessKey', 'A');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div accesskey="A" title="123"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate('title', 'abc')('accessKey', 'B');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div accesskey="B" title="abc"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 1);
|
2019-04-11 16:46:47 -04:00
|
|
|
expect(() => { t.update(() => { ɵɵpropertyInterpolate('title', 123); }); }).toThrow();
|
2019-03-28 17:54:22 -04:00
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
t.update(() => { ɵɵpropertyInterpolate('title', 123); });
|
2019-03-28 17:54:22 -04:00
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolate1', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate one value', () => {
|
|
|
|
// <div title="start{{123}}end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 1);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate1('title', 'start', 123, 'end');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start123end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate1('title', 'start', 'abc', 'end');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="startabcend"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="start{{123}}end" data-teststartstart{{'A'}}end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 2);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate1('title', 'start', 123, 'end')('accessKey', 'start', 'A', 'end');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div accesskey="startAend" title="start123end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate1('title', 'start', 'abc', 'end')('accessKey', 'start', 'B', 'end');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div accesskey="startBend" title="startabcend"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 1);
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => { ɵɵpropertyInterpolate1('title', 'start', 'whatever', 'end'); });
|
2019-03-28 17:54:22 -04:00
|
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
t.update(() => { ɵɵpropertyInterpolate1('title', 'start', 'whatever', 'end'); });
|
2019-03-28 17:54:22 -04:00
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolate2', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate two values', () => {
|
|
|
|
// <div title="start: {{v0}}, 1: {{v1}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 2);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate2('title', 'start: ', 0, ', 1: ', 1, ', end');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: 0, 1: 1, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate2('title', 'start: ', 'A', ', 1: ', 'B', ', end');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: A, 1: B, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}}, end" accesskey="start: {{v0}}, 1: {{v1}},
|
|
|
|
// end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 4);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate2('title', 'start: ', 0, ', 1: ', 1, ', end')(
|
2019-03-28 17:54:22 -04:00
|
|
|
'accessKey', 'start: ', 0, ', 1: ', 1, ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: 0, 1: 1, end" title="start: 0, 1: 1, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate2('title', 'start: ', 'A', ', 1: ', 'B', ', end')(
|
2019-03-28 17:54:22 -04:00
|
|
|
'accessKey', 'start: ', 'A', ', 1: ', 'B', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: A, 1: B, end" title="start: A, 1: B, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 2);
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => { ɵɵpropertyInterpolate2('title', '', '', '', '', ''); });
|
2019-03-28 17:54:22 -04:00
|
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
t.update(() => { ɵɵpropertyInterpolate2('title', '', '', '', '', ''); });
|
2019-03-28 17:54:22 -04:00
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolate3', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate three values', () => {
|
|
|
|
// <div title="start: {{v0}}, 1: {{v1}}, 2: {{v2}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 3);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate3('title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', end');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: 0, 1: 1, 2: 2, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate3('title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', end');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: A, 1: B, 2: C, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}}, end" accesskey="start: {{v0}}, 1: {{v1}},
|
|
|
|
// 2: {{v2}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 6);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate3('title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', end')(
|
2019-03-28 17:54:22 -04:00
|
|
|
'accessKey', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: 0, 1: 1, 2: 2, end" title="start: 0, 1: 1, 2: 2, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate3('title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', end')(
|
2019-03-28 17:54:22 -04:00
|
|
|
'accessKey', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: A, 1: B, 2: C, end" title="start: A, 1: B, 2: C, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 3);
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => { ɵɵpropertyInterpolate3('title', '', '', '', '', '', '', ''); });
|
2019-03-28 17:54:22 -04:00
|
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
t.update(() => { ɵɵpropertyInterpolate3('title', '', '', '', '', '', '', ''); });
|
2019-03-28 17:54:22 -04:00
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolate4', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate four values', () => {
|
|
|
|
// <div title="start: {{v0}}, 1: {{v1}}, 2: {{v2}}, 3: {{v3}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 4);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate4(
|
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', end');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: 0, 1: 1, 2: 2, 3: 3, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate4(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: A, 1: B, 2: C, 3: D, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}}, end" accesskey="start: {{v0}} 1:
|
|
|
|
// {{v1}} 2: {{v2}} 3: {{v3}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 8);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate4(
|
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', end')(
|
2019-03-28 17:54:22 -04:00
|
|
|
'accessKey', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: 0, 1: 1, 2: 2, 3: 3, end" title="start: 0, 1: 1, 2: 2, 3: 3, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate4(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', end')(
|
|
|
|
'accessKey', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: A, 1: B, 2: C, 3: D, end" title="start: A, 1: B, 2: C, 3: D, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 4);
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => { ɵɵpropertyInterpolate4('title', '', '', '', '', '', '', '', '', ''); });
|
2019-03-28 17:54:22 -04:00
|
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
t.update(() => { ɵɵpropertyInterpolate4('title', '', '', '', '', '', '', '', '', ''); });
|
2019-03-28 17:54:22 -04:00
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolate5', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate five values', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 5);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate5(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate5(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: A, 1: B, 2: C, 3: D, 4: E, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}}, end" accesskey="start:
|
|
|
|
// {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 10);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate5(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', end')(
|
|
|
|
'accessKey', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, end" title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate5(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', end')(
|
|
|
|
'accessKey', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: A, 1: B, 2: C, 3: D, 4: E, end" title="start: A, 1: B, 2: C, 3: D, 4: E, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 5);
|
|
|
|
expect(() => {
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolate5('title', '', '', '', '', '', '', '', '', '', '', '');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
2019-03-28 17:54:22 -04:00
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolate5('title', '', '', '', '', '', '', '', '', '', '', '');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolate6', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate six values', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}}, 5: {{v5}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 6);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate6(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5,
|
|
|
|
', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate6(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', 5: ', 'F', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual('<div title="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}}, 5: {{v5}}, end"
|
|
|
|
// accesskey="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}}, 5: {{v5}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 12);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate6(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5,
|
|
|
|
', end')(
|
|
|
|
'accessKey', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5,
|
|
|
|
', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, end" title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate6(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', 5: ', 'F', ', end')(
|
|
|
|
'accessKey', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', 5: ', 'F', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, end" title="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 6);
|
|
|
|
expect(() => {
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolate6('title', '', '', '', '', '', '', '', '', '', '', '', '', '');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
2019-03-28 17:54:22 -04:00
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolate6('title', '', '', '', '', '', '', '', '', '', '', '', '', '');
|
2019-03-28 17:54:22 -04:00
|
|
|
});
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolate7', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate seven values', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}} 5: {{v5}}, 6: {{v6}},
|
|
|
|
// end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 7);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate7(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5,
|
|
|
|
', 6: ', 6, ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate7(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', 5: ', 'F', ', 6: ', 'G', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div title="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}} 5: {{v5}}, 6: {{v6}},
|
|
|
|
// 7: {{v7}} end" accesskey="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}} 5:
|
|
|
|
// {{v5}}, 6: {{v6}}, end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 14);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate7(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5,
|
|
|
|
', 6: ', 6, ', end')(
|
|
|
|
'accessKey', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5,
|
|
|
|
', 6: ', 6, ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, end" title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate7(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', 5: ', 'F', ', 6: ', 'G', ', end')(
|
|
|
|
'accessKey', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', 5: ', 'F', ', 6: ', 'G', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, end" title="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 7);
|
|
|
|
expect(() => {
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolate7(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
|
|
|
|
});
|
|
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
2019-03-28 17:54:22 -04:00
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolate7(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
|
|
|
|
});
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolate8', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate eight values', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}} 5: {{v5}}, 6: {{v6}},
|
|
|
|
// 7: {{v7}} end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 8);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate8(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5,
|
|
|
|
', 6: ', 6, ', 7: ', 7, ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate8(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', 5: ', 'F', ', 6: ', 'G', ', 7: ', 'H', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div title="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}} 5: {{v5}}, 6: {{v6}},
|
|
|
|
// 7: {{v7}} end" accesskey="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}} 5:
|
|
|
|
// {{v5}}, 6: {{v6}}, 7: {{v7}} end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 16);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate8(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5,
|
|
|
|
', 6: ', 6, ', 7: ', 7, ', end')(
|
|
|
|
'accessKey', 'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5,
|
|
|
|
', 6: ', 6, ', 7: ', 7, ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, end" title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolate8(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', 5: ', 'F', ', 6: ', 'G', ', 7: ', 'H', ', end')(
|
|
|
|
'accessKey', 'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E',
|
|
|
|
', 5: ', 'F', ', 6: ', 'G', ', 7: ', 'H', ', end');
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, end" title="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 8);
|
|
|
|
expect(() => {
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolate8(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
|
|
|
|
});
|
|
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
2019-03-28 17:54:22 -04:00
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolate8(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
|
|
|
|
});
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
describe('ɵɵpropertyInterpolateV', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
it('should interpolate eight or more values', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}} 5: {{v5}}, 6: {{v6}},
|
|
|
|
// 7: {{v7}}, 8: {{v8}} end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 9);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolateV('title', [
|
2019-03-28 17:54:22 -04:00
|
|
|
'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5, ', 6: ', 6,
|
|
|
|
', 7: ', 7, ', 8: ', 8, ', end'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolateV('title', [
|
2019-03-28 17:54:22 -04:00
|
|
|
'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E', ', 5: ', 'F',
|
|
|
|
', 6: ', 'G', ', 7: ', 'H', ', 8: ', 'I', ', end'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div title="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chain', () => {
|
|
|
|
// <div title="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}} 5: {{v5}}, 6: {{v6}},
|
|
|
|
// 7: {{v7}} end" accesskey="start: {{v0}} 1: {{v1}} 2: {{v2}} 3: {{v3}} 4: {{v4}} 5:
|
|
|
|
// {{v5}}, 6: {{v6}}, 7: {{v7}}, 8: {{v8}} end"></div>
|
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 18);
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolateV(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title',
|
|
|
|
[
|
|
|
|
'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5, ', 6: ',
|
|
|
|
6, ', 7: ', 7, ', 8: ', 8, ', end'
|
|
|
|
])(
|
|
|
|
'accessKey', [
|
|
|
|
'start: ', 0, ', 1: ', 1, ', 2: ', 2, ', 3: ', 3, ', 4: ', 4, ', 5: ', 5, ', 6: ',
|
|
|
|
6, ', 7: ', 7, ', 8: ', 8, ', end'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, end" title="start: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, end"></div>');
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
|
|
|
ɵɵpropertyInterpolateV(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title',
|
|
|
|
[
|
|
|
|
'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E', ', 5: ',
|
|
|
|
'F', ', 6: ', 'G', ', 7: ', 'H', ', 8: ', 'I', ', end'
|
|
|
|
])(
|
|
|
|
'accessKey', [
|
|
|
|
'start: ', 'A', ', 1: ', 'B', ', 2: ', 'C', ', 3: ', 'D', ', 4: ', 'E', ', 5: ',
|
|
|
|
'F', ', 6: ', 'G', ', 7: ', 'H', ', 8: ', 'I', ', end'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
expect(t.html).toEqual(
|
|
|
|
'<div accesskey="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, end" title="start: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, end"></div>');
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 4,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
it('should error if called without ɵɵselect called first', () => {
|
2019-03-28 17:54:22 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1, 9);
|
|
|
|
expect(() => {
|
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolateV(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title',
|
|
|
|
['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
|
|
|
|
});
|
|
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵselect(0);
|
2019-03-28 17:54:22 -04:00
|
|
|
t.update(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵpropertyInterpolateV(
|
2019-03-28 17:54:22 -04:00
|
|
|
'title',
|
|
|
|
['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']);
|
|
|
|
});
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-01 20:14:01 -05:00
|
|
|
describe('elementProperty', () => {
|
2018-03-09 12:32:32 -05:00
|
|
|
it('should use sanitizer function when available', () => {
|
2018-08-16 21:53:21 -04:00
|
|
|
const t = new TemplateFixture(createDiv, () => {}, 1);
|
2018-03-01 20:14:01 -05:00
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'title', 'javascript:true', ɵɵsanitizeUrl));
|
2018-03-01 20:14:01 -05:00
|
|
|
expect(t.html).toEqual('<div title="unsafe:javascript:true"></div>');
|
|
|
|
|
|
|
|
t.update(
|
2019-04-11 16:46:47 -04:00
|
|
|
() => ɵɵelementProperty(
|
|
|
|
0, 'title', bypassSanitizationTrustUrl('javascript:false'), ɵɵsanitizeUrl));
|
2018-03-01 20:14:01 -05:00
|
|
|
expect(t.html).toEqual('<div title="javascript:false"></div>');
|
2018-04-14 14:52:53 -04:00
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
2018-05-16 08:56:01 -04:00
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
2018-09-13 19:07:23 -04:00
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
2018-04-14 14:52:53 -04:00
|
|
|
rendererCreateElement: 1,
|
|
|
|
});
|
2018-03-01 20:14:01 -05:00
|
|
|
});
|
2018-03-09 12:32:32 -05:00
|
|
|
|
|
|
|
it('should not stringify non string values', () => {
|
2019-04-11 16:46:47 -04:00
|
|
|
const t = new TemplateFixture(() => { ɵɵelement(0, 'input'); }, () => {}, 1);
|
2018-03-09 12:32:32 -05:00
|
|
|
|
2019-02-05 00:42:55 -05:00
|
|
|
// Note: don't use 'hidden' here because IE10 does not support the hidden property
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'required', false));
|
2019-02-05 00:42:55 -05:00
|
|
|
// The required property would be true if `false` was stringified into `"false"`.
|
|
|
|
expect((t.hostElement as HTMLElement).querySelector('input') !.required).toEqual(false);
|
2018-04-14 14:52:53 -04:00
|
|
|
expect(ngDevMode).toHaveProperties({
|
|
|
|
firstTemplatePass: 1,
|
2018-05-16 08:56:01 -04:00
|
|
|
tNode: 2, // 1 for div, 1 for host element
|
2018-09-13 19:07:23 -04:00
|
|
|
tView: 2, // 1 for rootView + 1 for the template view
|
2018-04-14 14:52:53 -04:00
|
|
|
rendererCreateElement: 1,
|
|
|
|
rendererSetProperty: 1
|
|
|
|
});
|
2018-03-09 12:32:32 -05:00
|
|
|
});
|
2018-03-01 20:14:01 -05:00
|
|
|
});
|
|
|
|
|
2019-05-08 14:26:40 -04:00
|
|
|
describe('styleProp', () => {
|
2018-07-11 13:58:18 -04:00
|
|
|
it('should automatically sanitize unless a bypass operation is applied', () => {
|
2018-12-13 18:51:47 -05:00
|
|
|
const t = new TemplateFixture(() => {
|
2019-04-11 16:46:47 -04:00
|
|
|
return createDiv(null, null, null, ['background-image'], ɵɵdefaultStyleSanitizer);
|
2018-12-13 18:51:47 -05:00
|
|
|
}, () => {}, 1);
|
2018-06-19 15:45:00 -04:00
|
|
|
t.update(() => {
|
2019-05-07 17:02:11 -04:00
|
|
|
ɵɵselect(0);
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyleProp(0, 'url("http://server")');
|
|
|
|
ɵɵstylingApply();
|
2018-06-19 15:45:00 -04:00
|
|
|
});
|
2018-03-01 20:14:01 -05:00
|
|
|
// nothing is set because sanitizer suppresses it.
|
|
|
|
expect(t.html).toEqual('<div></div>');
|
|
|
|
|
2018-06-19 15:45:00 -04:00
|
|
|
t.update(() => {
|
2019-05-07 17:02:11 -04:00
|
|
|
ɵɵselect(0);
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyleProp(0, bypassSanitizationTrustStyle('url("http://server2")'));
|
|
|
|
ɵɵstylingApply();
|
2018-06-19 15:45:00 -04:00
|
|
|
});
|
2018-03-01 20:14:01 -05:00
|
|
|
expect((t.hostElement.firstChild as HTMLElement).style.getPropertyValue('background-image'))
|
2018-07-11 13:58:18 -04:00
|
|
|
.toEqual('url("http://server2")');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not re-apply the style value even if it is a newly bypassed again', () => {
|
|
|
|
const sanitizerInterceptor = new MockSanitizerInterceptor();
|
|
|
|
const t = createTemplateFixtureWithSanitizer(
|
2018-12-13 18:51:47 -05:00
|
|
|
() => createDiv(
|
|
|
|
null, null, null, ['background-image'], sanitizerInterceptor.getStyleSanitizer()),
|
|
|
|
1, sanitizerInterceptor);
|
2018-07-11 13:58:18 -04:00
|
|
|
|
|
|
|
t.update(() => {
|
2019-05-07 17:02:11 -04:00
|
|
|
ɵɵselect(0);
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyleProp(0, bypassSanitizationTrustStyle('apple'));
|
|
|
|
ɵɵstylingApply();
|
2018-07-11 13:58:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(sanitizerInterceptor.lastValue !).toEqual('apple');
|
|
|
|
sanitizerInterceptor.lastValue = null;
|
|
|
|
|
|
|
|
t.update(() => {
|
2019-05-07 17:02:11 -04:00
|
|
|
ɵɵselect(0);
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyleProp(0, bypassSanitizationTrustStyle('apple'));
|
|
|
|
ɵɵstylingApply();
|
2018-07-11 13:58:18 -04:00
|
|
|
});
|
|
|
|
expect(sanitizerInterceptor.lastValue).toEqual(null);
|
2018-03-01 20:14:01 -05:00
|
|
|
});
|
|
|
|
});
|
2018-03-08 16:57:56 -05:00
|
|
|
|
2019-05-08 14:26:40 -04:00
|
|
|
describe('styleMap', () => {
|
2018-03-08 16:57:56 -05:00
|
|
|
function createDivWithStyle() {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementStart(0, 'div', [AttributeMarker.Styles, 'height', '10px']);
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyling([], ['height']);
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementEnd();
|
2018-03-08 16:57:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should add style', () => {
|
2018-08-16 21:53:21 -04:00
|
|
|
const fixture = new TemplateFixture(createDivWithStyle, () => {}, 1);
|
2018-06-19 15:45:00 -04:00
|
|
|
fixture.update(() => {
|
2019-05-07 17:02:11 -04:00
|
|
|
ɵɵselect(0);
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyleMap({'background-color': 'red'});
|
|
|
|
ɵɵstylingApply();
|
2018-06-19 15:45:00 -04:00
|
|
|
});
|
2018-08-22 12:17:59 -04:00
|
|
|
expect(fixture.html).toEqual('<div style="background-color: red; height: 10px;"></div>');
|
2018-03-08 16:57:56 -05:00
|
|
|
});
|
2018-07-11 13:58:18 -04:00
|
|
|
|
|
|
|
it('should sanitize new styles that may contain `url` properties', () => {
|
|
|
|
const detectedValues: string[] = [];
|
|
|
|
const sanitizerInterceptor =
|
|
|
|
new MockSanitizerInterceptor(value => { detectedValues.push(value); });
|
|
|
|
const fixture = createTemplateFixtureWithSanitizer(
|
2018-12-13 18:51:47 -05:00
|
|
|
() => createDiv(null, null, null, null, sanitizerInterceptor.getStyleSanitizer()), 1,
|
|
|
|
sanitizerInterceptor);
|
2018-07-11 13:58:18 -04:00
|
|
|
|
|
|
|
fixture.update(() => {
|
2019-05-07 17:02:11 -04:00
|
|
|
ɵɵselect(0);
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyleMap({
|
2018-07-11 13:58:18 -04:00
|
|
|
'background-image': 'background-image',
|
|
|
|
'background': 'background',
|
|
|
|
'border-image': 'border-image',
|
|
|
|
'list-style': 'list-style',
|
|
|
|
'list-style-image': 'list-style-image',
|
|
|
|
'filter': 'filter',
|
|
|
|
'width': 'width'
|
|
|
|
});
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstylingApply();
|
2018-07-11 13:58:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const props = detectedValues.sort();
|
|
|
|
expect(props).toEqual([
|
|
|
|
'background', 'background-image', 'border-image', 'filter', 'list-style', 'list-style-image'
|
|
|
|
]);
|
|
|
|
});
|
2018-03-08 16:57:56 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('elementClass', () => {
|
2018-07-11 12:56:47 -04:00
|
|
|
function createDivWithStyling() {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementStart(0, 'div');
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵstyling();
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementEnd();
|
2018-07-11 12:56:47 -04:00
|
|
|
}
|
2018-03-08 16:57:56 -05:00
|
|
|
|
|
|
|
it('should add class', () => {
|
2018-08-16 21:53:21 -04:00
|
|
|
const fixture = new TemplateFixture(createDivWithStyling, () => {}, 1);
|
2018-07-11 12:56:47 -04:00
|
|
|
fixture.update(() => {
|
2019-05-07 17:02:11 -04:00
|
|
|
ɵɵselect(0);
|
2019-05-08 14:26:40 -04:00
|
|
|
ɵɵclassMap('multiple classes');
|
|
|
|
ɵɵstylingApply();
|
2018-07-11 12:56:47 -04:00
|
|
|
});
|
2018-03-08 16:57:56 -05:00
|
|
|
expect(fixture.html).toEqual('<div class="multiple classes"></div>');
|
|
|
|
});
|
|
|
|
});
|
2018-04-14 14:52:53 -04:00
|
|
|
|
|
|
|
describe('performance counters', () => {
|
|
|
|
it('should create tViews only once for each nested level', () => {
|
2019-03-07 03:31:31 -05:00
|
|
|
const _c0 = [AttributeMarker.Template, 'ngFor', 'ngForOf'];
|
|
|
|
const _c1 = [AttributeMarker.Template, 'ngFor', 'ngForOf'];
|
2018-08-16 21:53:21 -04:00
|
|
|
|
|
|
|
function ToDoAppComponent_NgForOf_Template_0(rf: RenderFlags, ctx0: NgForOfContext<any>) {
|
|
|
|
if (rf & RenderFlags.Create) {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementStart(0, 'ul');
|
|
|
|
ɵɵtemplate(1, ToDoAppComponent_NgForOf_NgForOf_Template_1, 2, 1, 'li', _c1);
|
|
|
|
ɵɵelementEnd();
|
2018-08-16 21:53:21 -04:00
|
|
|
}
|
|
|
|
if (rf & RenderFlags.Update) {
|
|
|
|
const row_r2 = ctx0.$implicit;
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementProperty(1, 'ngForOf', ɵɵbind(row_r2));
|
2018-08-16 21:53:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ToDoAppComponent_NgForOf_NgForOf_Template_1(
|
|
|
|
rf: RenderFlags, ctx1: NgForOfContext<any>) {
|
|
|
|
if (rf & RenderFlags.Create) {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementStart(0, 'li');
|
|
|
|
ɵɵtext(1);
|
|
|
|
ɵɵelementEnd();
|
2018-08-16 21:53:21 -04:00
|
|
|
}
|
|
|
|
if (rf & RenderFlags.Update) {
|
|
|
|
const col_r3 = ctx1.$implicit;
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵtextBinding(1, ɵɵinterpolation1('', col_r3, ''));
|
2018-08-16 21:53:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 14:52:53 -04:00
|
|
|
/**
|
|
|
|
* <ul *ngFor="let row of rows">
|
|
|
|
* <li *ngFor="let col of row.cols">{{col}}</li>
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
class NestedLoops {
|
|
|
|
rows = [['a', 'b'], ['A', 'B'], ['a', 'b'], ['A', 'B']];
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
static ngComponentDef = ɵɵdefineComponent({
|
2018-04-14 14:52:53 -04:00
|
|
|
type: NestedLoops,
|
2018-04-26 13:44:49 -04:00
|
|
|
selectors: [['nested-loops']],
|
2018-04-14 14:52:53 -04:00
|
|
|
factory: function ToDoAppComponent_Factory() { return new NestedLoops(); },
|
2018-08-16 21:53:21 -04:00
|
|
|
consts: 1,
|
2018-08-18 14:14:50 -04:00
|
|
|
vars: 1,
|
2018-04-14 14:52:53 -04:00
|
|
|
template: function ToDoAppComponent_Template(rf: RenderFlags, ctx: NestedLoops) {
|
2018-04-26 13:44:49 -04:00
|
|
|
if (rf & RenderFlags.Create) {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵtemplate(0, ToDoAppComponent_NgForOf_Template_0, 2, 1, 'ul', _c0);
|
2018-04-14 14:52:53 -04:00
|
|
|
}
|
2018-04-26 13:44:49 -04:00
|
|
|
if (rf & RenderFlags.Update) {
|
2019-04-11 16:46:47 -04:00
|
|
|
ɵɵelementProperty(0, 'ngForOf', ɵɵbind(ctx.rows));
|
2018-04-14 14:52:53 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
directives: [NgForOf]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const fixture = new ComponentFixture(NestedLoops);
|
|
|
|
expect(ngDevMode).toHaveProperties({
|
2018-04-26 13:44:49 -04:00
|
|
|
// Expect: fixture view/Host view + component + ngForRow + ngForCol
|
|
|
|
tView: 4, // should be: 4,
|
2018-04-14 14:52:53 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2018-05-09 18:30:16 -04:00
|
|
|
|
|
|
|
describe('sanitization injection compatibility', () => {
|
|
|
|
it('should work for url sanitization', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => `${value}-sanitized`);
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createAnchor, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = 'http://foo';
|
|
|
|
const outputValue = 'http://foo-sanitized';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'href', inputValue, ɵɵsanitizeUrl));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<a href="${outputValue}"></a>`);
|
|
|
|
expect(s.lastSanitizedValue).toEqual(outputValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass url sanitization if marked by the service', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createAnchor, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = s.bypassSecurityTrustUrl('http://foo');
|
|
|
|
const outputValue = 'http://foo';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'href', inputValue, ɵɵsanitizeUrl));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<a href="${outputValue}"></a>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass ivy-level url sanitization if a custom sanitizer is used', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createAnchor, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = bypassSanitizationTrustUrl('http://foo');
|
|
|
|
const outputValue = 'http://foo-ivy';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'href', inputValue, ɵɵsanitizeUrl));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<a href="${outputValue}"></a>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for style sanitization', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => `color:blue`);
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createDiv, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = 'color:red';
|
|
|
|
const outputValue = 'color:blue';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'style', inputValue, ɵɵsanitizeStyle));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(stripStyleWsCharacters(t.html)).toEqual(`<div style="${outputValue}"></div>`);
|
|
|
|
expect(s.lastSanitizedValue).toEqual(outputValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass style sanitization if marked by the service', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createDiv, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = s.bypassSecurityTrustStyle('color:maroon');
|
|
|
|
const outputValue = 'color:maroon';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'style', inputValue, ɵɵsanitizeStyle));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(stripStyleWsCharacters(t.html)).toEqual(`<div style="${outputValue}"></div>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass ivy-level style sanitization if a custom sanitizer is used', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createDiv, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = bypassSanitizationTrustStyle('font-family:foo');
|
|
|
|
const outputValue = 'font-family:foo-ivy';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'style', inputValue, ɵɵsanitizeStyle));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(stripStyleWsCharacters(t.html)).toEqual(`<div style="${outputValue}"></div>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for resourceUrl sanitization', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => `${value}-sanitized`);
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createScript, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = 'http://resource';
|
|
|
|
const outputValue = 'http://resource-sanitized';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'src', inputValue, ɵɵsanitizeResourceUrl));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<script src="${outputValue}"></script>`);
|
|
|
|
expect(s.lastSanitizedValue).toEqual(outputValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass resourceUrl sanitization if marked by the service', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createScript, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = s.bypassSecurityTrustResourceUrl('file://all-my-secrets.pdf');
|
|
|
|
const outputValue = 'file://all-my-secrets.pdf';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'src', inputValue, ɵɵsanitizeResourceUrl));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<script src="${outputValue}"></script>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass ivy-level resourceUrl sanitization if a custom sanitizer is used', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createScript, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = bypassSanitizationTrustResourceUrl('file://all-my-secrets.pdf');
|
|
|
|
const outputValue = 'file://all-my-secrets.pdf-ivy';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementAttribute(0, 'src', inputValue, ɵɵsanitizeResourceUrl));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<script src="${outputValue}"></script>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for script sanitization', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => `${value} //sanitized`);
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createScript, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = 'fn();';
|
|
|
|
const outputValue = 'fn(); //sanitized';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeScript));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<script>${outputValue}</script>`);
|
|
|
|
expect(s.lastSanitizedValue).toEqual(outputValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass script sanitization if marked by the service', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createScript, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = s.bypassSecurityTrustScript('alert("bar")');
|
|
|
|
const outputValue = 'alert("bar")';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeScript));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<script>${outputValue}</script>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass ivy-level script sanitization if a custom sanitizer is used', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createScript, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = bypassSanitizationTrustScript('alert("bar")');
|
|
|
|
const outputValue = 'alert("bar")-ivy';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeScript));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<script>${outputValue}</script>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for html sanitization', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => `${value} <!--sanitized-->`);
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createDiv, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = '<header></header>';
|
|
|
|
const outputValue = '<header></header> <!--sanitized-->';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeHtml));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<div>${outputValue}</div>`);
|
|
|
|
expect(s.lastSanitizedValue).toEqual(outputValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass html sanitization if marked by the service', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createDiv, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = s.bypassSecurityTrustHtml('<div onclick="alert(123)"></div>');
|
|
|
|
const outputValue = '<div onclick="alert(123)"></div>';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeHtml));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<div>${outputValue}</div>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bypass ivy-level script sanitization if a custom sanitizer is used', () => {
|
|
|
|
const s = new LocalMockSanitizer(value => '');
|
2018-08-18 14:14:50 -04:00
|
|
|
const t = new TemplateFixture(createDiv, undefined, 1, 0, null, null, s);
|
2018-05-09 18:30:16 -04:00
|
|
|
const inputValue = bypassSanitizationTrustHtml('<div onclick="alert(123)"></div>');
|
|
|
|
const outputValue = '<div onclick="alert(123)"></div>-ivy';
|
|
|
|
|
2019-04-11 16:46:47 -04:00
|
|
|
t.update(() => ɵɵelementProperty(0, 'innerHTML', inputValue, ɵɵsanitizeHtml));
|
2018-05-09 18:30:16 -04:00
|
|
|
expect(t.html).toEqual(`<div>${outputValue}</div>`);
|
|
|
|
expect(s.lastSanitizedValue).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
2018-03-01 20:14:01 -05:00
|
|
|
});
|
2018-05-09 18:30:16 -04:00
|
|
|
|
|
|
|
class LocalSanitizedValue {
|
|
|
|
constructor(public value: any) {}
|
|
|
|
|
|
|
|
toString() { return this.value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
class LocalMockSanitizer implements Sanitizer {
|
2018-06-18 19:38:33 -04:00
|
|
|
// TODO(issue/24571): remove '!'.
|
|
|
|
public lastSanitizedValue !: string | null;
|
2018-05-09 18:30:16 -04:00
|
|
|
|
|
|
|
constructor(private _interceptor: (value: string|null|any) => string) {}
|
|
|
|
|
|
|
|
sanitize(context: SecurityContext, value: LocalSanitizedValue|string|null|any): string|null {
|
|
|
|
if (value instanceof String) {
|
|
|
|
return value.toString() + '-ivy';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value instanceof LocalSanitizedValue) {
|
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.lastSanitizedValue = this._interceptor(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bypassSecurityTrustHtml(value: string) { return new LocalSanitizedValue(value); }
|
|
|
|
|
|
|
|
bypassSecurityTrustStyle(value: string) { return new LocalSanitizedValue(value); }
|
|
|
|
|
|
|
|
bypassSecurityTrustScript(value: string) { return new LocalSanitizedValue(value); }
|
|
|
|
|
|
|
|
bypassSecurityTrustUrl(value: string) { return new LocalSanitizedValue(value); }
|
|
|
|
|
|
|
|
bypassSecurityTrustResourceUrl(value: string) { return new LocalSanitizedValue(value); }
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:58:18 -04:00
|
|
|
class MockSanitizerInterceptor {
|
|
|
|
public lastValue: string|null = null;
|
|
|
|
constructor(private _interceptorFn?: ((value: any) => any)|null) {}
|
2019-04-11 16:46:47 -04:00
|
|
|
getStyleSanitizer() { return ɵɵdefaultStyleSanitizer; }
|
2018-07-11 13:58:18 -04:00
|
|
|
sanitize(context: SecurityContext, value: LocalSanitizedValue|string|null|any): string|null {
|
|
|
|
if (this._interceptorFn) {
|
|
|
|
this._interceptorFn(value);
|
|
|
|
}
|
|
|
|
return this.lastValue = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 18:30:16 -04:00
|
|
|
function stripStyleWsCharacters(value: string): string {
|
|
|
|
// color: blue; => color:blue
|
|
|
|
return value.replace(/;/g, '').replace(/:\s+/g, ':');
|
|
|
|
}
|
2018-07-11 13:58:18 -04:00
|
|
|
|
2018-08-16 21:53:21 -04:00
|
|
|
function createTemplateFixtureWithSanitizer(
|
|
|
|
buildFn: () => any, consts: number, sanitizer: Sanitizer) {
|
2018-08-18 14:14:50 -04:00
|
|
|
return new TemplateFixture(buildFn, () => {}, consts, 0, null, null, sanitizer);
|
2018-07-11 13:58:18 -04:00
|
|
|
}
|