Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: third_party/pkg/angular/test/directive/ng_src_boolean_spec.dart

Issue 256553002: Revert "Update all Angular libs (run update_all.sh)." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 library ng_src_boolean_spec; 1 library ng_src_boolean_spec;
2 2
3 import '../_specs.dart'; 3 import '../_specs.dart';
4 import 'dart:html' as dom; 4 import 'dart:html' as dom;
5 5
6 main() { 6 main() {
7 describe('boolean attr directives', () { 7 describe('boolean attr directives', () {
8 TestBed _; 8 TestBed _;
9 beforeEach((TestBed tb) => _ = tb); 9 beforeEach(inject((TestBed tb) => _ = tb));
10 10
11 11
12 it('should properly evaluate 0 as false', () { 12 it('should properly evaluate 0 as false', inject(() {
13 _.compile('<button ng-disabled="isDisabled">Button</button>'); 13 _.compile('<button ng-disabled="isDisabled">Button</button>');
14 _.rootScope.context['isDisabled'] = 0; 14 _.rootScope.context['isDisabled'] = 0;
15 _.rootScope.apply(); 15 _.rootScope.apply();
16 expect(_.rootElement.attributes['disabled']).toBeFalsy(); 16 expect(_.rootElement.attributes['disabled']).toBeFalsy();
17 _.rootScope.context['isDisabled'] = 1; 17 _.rootScope.context['isDisabled'] = 1;
18 _.rootScope.apply(); 18 _.rootScope.apply();
19 expect(_.rootElement.attributes['disabled']).toBeTruthy(); 19 expect(_.rootElement.attributes['disabled']).toBeTruthy();
20 }); 20 }));
21 21
22 22
23 it('should bind disabled', () { 23 it('should bind disabled', inject(() {
24 _.compile('<button ng-disabled="isDisabled">Button</button>'); 24 _.compile('<button ng-disabled="isDisabled">Button</button>');
25 _.rootScope.context['isDisabled'] = false; 25 _.rootScope.context['isDisabled'] = false;
26 _.rootScope.apply(); 26 _.rootScope.apply();
27 expect(_.rootElement.attributes['disabled']).toBeFalsy(); 27 expect(_.rootElement.attributes['disabled']).toBeFalsy();
28 _.rootScope.context['isDisabled'] = true; 28 _.rootScope.context['isDisabled'] = true;
29 _.rootScope.apply(); 29 _.rootScope.apply();
30 expect(_.rootElement.attributes['disabled']).toBeTruthy(); 30 expect(_.rootElement.attributes['disabled']).toBeTruthy();
31 }); 31 }));
32 32
33 33
34 it('should bind checked', () { 34 it('should bind checked', inject(() {
35 _.compile('<input type="checkbox" ng-checked="isChecked" />'); 35 _.compile('<input type="checkbox" ng-checked="isChecked" />');
36 _.rootScope.context['isChecked'] = false; 36 _.rootScope.context['isChecked'] = false;
37 _.rootScope.apply(); 37 _.rootScope.apply();
38 expect(_.rootElement.attributes['checked']).toBeFalsy(); 38 expect(_.rootElement.attributes['checked']).toBeFalsy();
39 _.rootScope.context['isChecked']=true; 39 _.rootScope.context['isChecked']=true;
40 _.rootScope.apply(); 40 _.rootScope.apply();
41 expect(_.rootElement.attributes['checked']).toBeTruthy(); 41 expect(_.rootElement.attributes['checked']).toBeTruthy();
42 }); 42 }));
43 43
44 44
45 it('should bind selected', () { 45 it('should bind selected', inject(() {
46 _.compile('<select><option value=""></option><option ng-selected="isSelect ed">Greetings!</option></select>'); 46 _.compile('<select><option value=""></option><option ng-selected="isSelect ed">Greetings!</option></select>');
47 _.rootScope.context['isSelected']=false; 47 _.rootScope.context['isSelected']=false;
48 _.rootScope.apply(); 48 _.rootScope.apply();
49 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeFa lsy(); 49 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeFa lsy();
50 _.rootScope.context['isSelected']=true; 50 _.rootScope.context['isSelected']=true;
51 _.rootScope.apply(); 51 _.rootScope.apply();
52 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeTr uthy(); 52 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeTr uthy();
53 }); 53 }));
54 54
55 55
56 it('should bind readonly', () { 56 it('should bind readonly', inject(() {
57 _.compile('<input type="text" ng-readonly="isReadonly" />'); 57 _.compile('<input type="text" ng-readonly="isReadonly" />');
58 _.rootScope.context['isReadonly']=false; 58 _.rootScope.context['isReadonly']=false;
59 _.rootScope.apply(); 59 _.rootScope.apply();
60 expect(_.rootElement.attributes['readOnly']).toBeFalsy(); 60 expect(_.rootElement.attributes['readOnly']).toBeFalsy();
61 _.rootScope.context['isReadonly']=true; 61 _.rootScope.context['isReadonly']=true;
62 _.rootScope.apply(); 62 _.rootScope.apply();
63 expect(_.rootElement.attributes['readOnly']).toBeTruthy(); 63 expect(_.rootElement.attributes['readOnly']).toBeTruthy();
64 }); 64 }));
65 65
66 66
67 it('should bind open', () { 67 it('should bind open', inject(() {
68 _.compile('<details ng-open="isOpen"></details>'); 68 _.compile('<details ng-open="isOpen"></details>');
69 _.rootScope.context['isOpen']=false; 69 _.rootScope.context['isOpen']=false;
70 _.rootScope.apply(); 70 _.rootScope.apply();
71 expect(_.rootElement.attributes['open']).toBeFalsy(); 71 expect(_.rootElement.attributes['open']).toBeFalsy();
72 _.rootScope.context['isOpen']=true; 72 _.rootScope.context['isOpen']=true;
73 _.rootScope.apply(); 73 _.rootScope.apply();
74 expect(_.rootElement.attributes['open']).toBeTruthy(); 74 expect(_.rootElement.attributes['open']).toBeTruthy();
75 }); 75 }));
76 76
77 77
78 describe('multiple', () { 78 describe('multiple', () {
79 it('should NOT bind to multiple via ngMultiple', () { 79 it('should NOT bind to multiple via ngMultiple', inject(() {
80 _.compile('<select ng-multiple="isMultiple"></select>'); 80 _.compile('<select ng-multiple="isMultiple"></select>');
81 _.rootScope.context['isMultiple']=false; 81 _.rootScope.context['isMultiple']=false;
82 _.rootScope.apply(); 82 _.rootScope.apply();
83 expect(_.rootElement.attributes['multiple']).toBeFalsy(); 83 expect(_.rootElement.attributes['multiple']).toBeFalsy();
84 _.rootScope.context['isMultiple']='multiple'; 84 _.rootScope.context['isMultiple']='multiple';
85 _.rootScope.apply(); 85 _.rootScope.apply();
86 expect(_.rootElement.attributes['multiple']).toBeFalsy(); // ignore 86 expect(_.rootElement.attributes['multiple']).toBeFalsy(); // ignore
87 }); 87 }));
88 }); 88 });
89 }); 89 });
90 90
91 91
92 describe('ngSrc', () { 92 describe('ngSrc', () {
93 TestBed _; 93 TestBed _;
94 beforeEach((TestBed tb) => _ = tb); 94 beforeEach(inject((TestBed tb) => _ = tb));
95 95
96 it('should interpolate the expression and bind to src with raw same-domain v alue', () { 96 it('should interpolate the expression and bind to src with raw same-domain v alue',
97 inject(() {
98 _.compile('<div ng-src="{{id}}"></div>');
99
100 _.rootScope.apply();
101 expect(_.rootElement.attributes['src']).toEqual('');
102
103 _.rootScope.apply(() {
104 _.rootScope.context['id'] = '/somewhere/here';
105 });
106 expect(_.rootElement.attributes['src']).toEqual('/somewhere/here');
107 }));
108
109
110 xit('should interpolate the expression and bind to src with a trusted value' , inject(($sce) {
97 _.compile('<div ng-src="{{id}}"></div>'); 111 _.compile('<div ng-src="{{id}}"></div>');
98 112
99 _.rootScope.apply(); 113 _.rootScope.apply();
100 expect(_.rootElement.attributes['src']).toEqual(null); 114 expect(_.rootElement.attributes['src']).toEqual(null);
101 115
102 _.rootScope.apply(() { 116 _.rootScope.apply(() {
103 _.rootScope.context['id'] = '/somewhere/here'; 117 _.rootScope.context['id'] = $sce.trustAsResourceUrl('http://somewhere');
104 }); 118 });
105 expect(_.rootElement.attributes['src']).toEqual('/somewhere/here'); 119 expect(_.rootElement.attributes['src']).toEqual('http://somewhere');
106 }); 120 }));
107 121
108 122
109 xit('should interpolate the expression and bind to src with a trusted value' , (sce) { 123 xit('should NOT interpolate a multi-part expression for non-img src attribut e', inject(() {
110 _.compile('<div ng-src="{{id}}"></div>');
111
112 _.rootScope.apply();
113 expect(_.rootElement.attributes['src']).toEqual(null);
114
115 _.rootScope.apply(() {
116 _.rootScope.context['id'] = sce.trustAsResourceUrl('http://somewhere');
117 });
118 expect(_.rootElement.attributes['src']).toEqual('http://somewhere');
119 });
120
121
122 xit('should NOT interpolate a multi-part expression for non-img src attribut e', () {
123 expect(() { 124 expect(() {
124 _.compile('<div ng-src="some/{{id}}"></div>'); 125 _.compile('<div ng-src="some/{{id}}"></div>');
125 }).toThrow("Error while interpolating: some/{{id}}\nStrict " + 126 }).toThrow("Error while interpolating: some/{{id}}\nStrict " +
126 "Contextual Escaping disallows interpolations that concatenate multipl e expressions " + 127 "Contextual Escaping disallows interpolations that concatenate multipl e expressions " +
127 "when a trusted value is required. See http://docs.angularjs.org/api/ ng.sce"); 128 "when a trusted value is required. See http://docs.angularjs.org/api/ ng.\$sce");
128 }); 129 }));
129 130
130 131
131 it('should interpolate a multi-part expression for regular attributes', () { 132 it('should interpolate a multi-part expression for regular attributes', inje ct(() {
132 _.compile('<div foo="some/{{id}}"></div>'); 133 _.compile('<div foo="some/{{id}}"></div>');
133 _.rootScope.apply(); 134 _.rootScope.apply();
134 expect(_.rootElement.attributes['foo']).toEqual('some/'); 135 expect(_.rootElement.attributes['foo']).toEqual('some/');
135 _.rootScope.apply(() { 136 _.rootScope.apply(() {
136 _.rootScope.context['id'] = 1; 137 _.rootScope.context['id'] = 1;
137 }); 138 });
138 expect(_.rootElement.attributes['foo']).toEqual('some/1'); 139 expect(_.rootElement.attributes['foo']).toEqual('some/1');
139 }); 140 }));
140 141
141 142
142 xit('should NOT interpolate a wrongly typed expression', (sce) { 143 xit('should NOT interpolate a wrongly typed expression', inject(($sce) {
143 expect(() { 144 expect(() {
144 _.compile('<div ng-src="{{id}}"></div>'); 145 _.compile('<div ng-src="{{id}}"></div>');
145 _.rootScope.apply(() { 146 _.rootScope.apply(() {
146 _.rootScope.context['id'] = sce.trustAsUrl('http://somewhere'); 147 _.rootScope.context['id'] = $sce.trustAsUrl('http://somewhere');
147 }); 148 });
148 _.rootElement.attributes['src']; 149 _.rootElement.attributes['src'];
149 }).toThrow("Can't interpolate: {{id}}\nError: [sce:insecurl] Viewed " + 150 }).toThrow("Can't interpolate: {{id}}\nError: [\$sce:insecurl] Blocked " +
150 "loading resource from url not allowed by sceDelegate policy. URL: ht tp://somewhere"); 151 "loading resource from url not allowed by \$sceDelegate policy. URL: http://somewhere");
151 }); 152 }));
152 153
153 }); 154 });
154 155
155 156
156 describe('ngSrcset', () { 157 describe('ngSrcset', () {
157 TestBed _; 158 TestBed _;
158 beforeEach((TestBed tb) => _ = tb); 159 beforeEach(inject((TestBed tb) => _ = tb));
159 160
160 it('should interpolate the expression and bind to srcset', () { 161 it('should interpolate the expression and bind to srcset', inject(() {
161 _.compile('<div ng-srcset="some/{{id}} 2x"></div>'); 162 _.compile('<div ng-srcset="some/{{id}} 2x"></div>');
162 163
163 _.rootScope.apply(); 164 _.rootScope.apply();
164 expect(_.rootElement.attributes['srcset']).toEqual('some/ 2x'); 165 expect(_.rootElement.attributes['srcset']).toEqual('some/ 2x');
165 166
166 _.rootScope.apply(() { 167 _.rootScope.apply(() {
167 _.rootScope.context['id'] = 1; 168 _.rootScope.context['id'] = 1;
168 }); 169 });
169 expect(_.rootElement.attributes['srcset']).toEqual('some/1 2x'); 170 expect(_.rootElement.attributes['srcset']).toEqual('some/1 2x');
170 }); 171 }));
171 }); 172 });
172 173
173 174
174 describe('ngHref', () { 175 describe('ngHref', () {
175 TestBed _; 176 TestBed _;
176 beforeEach((TestBed tb) => _ = tb); 177 beforeEach(inject((TestBed tb) => _ = tb));
177 178
178 it('should interpolate the expression and bind to href', () { 179 it('should interpolate the expression and bind to href', inject(() {
179 _.compile('<div ng-href="some/{{id}}"></div>'); 180 _.compile('<div ng-href="some/{{id}}"></div>');
180 _.rootScope.apply(); 181 _.rootScope.apply();
181 expect(_.rootElement.attributes['href']).toEqual('some/'); 182 expect(_.rootElement.attributes['href']).toEqual('some/');
182 183
183 _.rootScope.apply(() { 184 _.rootScope.apply(() {
184 _.rootScope.context['id'] = 1; 185 _.rootScope.context['id'] = 1;
185 }); 186 });
186 expect(_.rootElement.attributes['href']).toEqual('some/1'); 187 expect(_.rootElement.attributes['href']).toEqual('some/1');
187 }); 188 }));
188 189
189 190
190 it('should bind href and merge with other attrs', () { 191 it('should bind href and merge with other attrs', inject(() {
191 _.compile('<a ng-href="{{url}}" rel="{{rel}}"></a>'); 192 _.compile('<a ng-href="{{url}}" rel="{{rel}}"></a>');
192 _.rootScope.context['url'] = 'http://server'; 193 _.rootScope.context['url'] = 'http://server';
193 _.rootScope.context['rel'] = 'REL'; 194 _.rootScope.context['rel'] = 'REL';
194 _.rootScope.apply(); 195 _.rootScope.apply();
195 expect(_.rootElement.attributes['href']).toEqual('http://server'); 196 expect(_.rootElement.attributes['href']).toEqual('http://server');
196 expect(_.rootElement.attributes['rel']).toEqual('REL'); 197 expect(_.rootElement.attributes['rel']).toEqual('REL');
197 }); 198 }));
198 199
199 200
200 it('should bind href even if no interpolation', () { 201 it('should bind href even if no interpolation', inject(() {
201 _.compile('<a ng-href="http://server"></a>'); 202 _.compile('<a ng-href="http://server"></a>');
202 _.rootScope.apply(); 203 _.rootScope.apply();
203 expect(_.rootElement.attributes['href']).toEqual('http://server'); 204 expect(_.rootElement.attributes['href']).toEqual('http://server');
204 }); 205 }));
205 }); 206 });
206 207
207 describe('ngAttr', () { 208 describe('ngAttr', () {
208 TestBed _; 209 TestBed _;
209 beforeEach((TestBed tb) => _ = tb); 210 beforeEach(inject((TestBed tb) => _ = tb));
210 211
211 it('should interpolate the expression and bind to *', () { 212 it('should interpolate the expression and bind to *', inject(() {
212 _.compile('<div ng-attr-foo="some/{{id}}"></div>'); 213 _.compile('<div ng-attr-foo="some/{{id}}"></div>');
213 _.rootScope.apply(); 214 _.rootScope.apply();
214 expect(_.rootElement.attributes['foo']).toEqual('some/'); 215 expect(_.rootElement.attributes['foo']).toEqual('some/');
215 216
216 _.rootScope.apply(() { 217 _.rootScope.apply(() {
217 _.rootScope.context['id'] = 1; 218 _.rootScope.context['id'] = 1;
218 }); 219 });
219 expect(_.rootElement.attributes['foo']).toEqual('some/1'); 220 expect(_.rootElement.attributes['foo']).toEqual('some/1');
220 }); 221 }));
221 222
222 223
223 it('should bind * and merge with other attrs', () { 224 it('should bind * and merge with other attrs', inject(() {
224 _.compile('<div ng-attr-bar="{{bar}}" ng-attr-bar2="{{bar2}}" bam="{{bam}} "></a>'); 225 _.compile('<div ng-attr-bar="{{bar}}" ng-attr-bar2="{{bar2}}" bam="{{bam}} "></a>');
225 _.rootScope.context['bar'] = 'foo'; 226 _.rootScope.context['bar'] = 'foo';
226 _.rootScope.context['bar2'] = 'foo2'; 227 _.rootScope.context['bar2'] = 'foo2';
227 _.rootScope.context['bam'] = 'boom'; 228 _.rootScope.context['bam'] = 'boom';
228 _.rootScope.apply(); 229 _.rootScope.apply();
229 expect(_.rootElement.attributes['bar']).toEqual('foo'); 230 expect(_.rootElement.attributes['bar']).toEqual('foo');
230 expect(_.rootElement.attributes['bar2']).toEqual('foo2'); 231 expect(_.rootElement.attributes['bar2']).toEqual('foo2');
231 expect(_.rootElement.attributes['bam']).toEqual('boom'); 232 expect(_.rootElement.attributes['bam']).toEqual('boom');
232 _.rootScope.context['bar'] = 'FOO'; 233 _.rootScope.context['bar'] = 'FOO';
233 _.rootScope.context['bar2'] = 'FOO2'; 234 _.rootScope.context['bar2'] = 'FOO2';
234 _.rootScope.context['bam'] = 'BOOM'; 235 _.rootScope.context['bam'] = 'BOOM';
235 _.rootScope.apply(); 236 _.rootScope.apply();
236 expect(_.rootElement.attributes['bar']).toEqual('FOO'); 237 expect(_.rootElement.attributes['bar']).toEqual('FOO');
237 expect(_.rootElement.attributes['bar2']).toEqual('FOO2'); 238 expect(_.rootElement.attributes['bar2']).toEqual('FOO2');
238 expect(_.rootElement.attributes['bam']).toEqual('BOOM'); 239 expect(_.rootElement.attributes['bam']).toEqual('BOOM');
239 }); 240 }));
240 241
241 242
242 it('should bind * even if no interpolation', () { 243 it('should bind * even if no interpolation', inject(() {
243 _.compile('<a ng-attr-quack="vanilla"></a>'); 244 _.compile('<a ng-attr-quack="vanilla"></a>');
244 _.rootScope.apply(); 245 _.rootScope.apply();
245 expect(_.rootElement.attributes['quack']).toEqual('vanilla'); 246 expect(_.rootElement.attributes['quack']).toEqual('vanilla');
246 }); 247 }));
247 }); 248 });
248 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698