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

Side by Side Diff: pkg/template_binding/test/template_binding_test.dart

Issue 355133002: switch Node.bind to interop (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library template_binding.test.template_binding_test; 5 library template_binding.test.template_binding_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:js' show JsObject; 9 import 'dart:js' show JsObject;
10 import 'dart:math' as math; 10 import 'dart:math' as math;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // Dart note: predicate changed from 0->null because 0 isn't falsey in Dart. 161 // Dart note: predicate changed from 0->null because 0 isn't falsey in Dart.
162 // See https://code.google.com/p/dart/issues/detail?id=11956 162 // See https://code.google.com/p/dart/issues/detail?id=11956
163 // Changed bound from null->1 since null is equivalent to JS undefined, 163 // Changed bound from null->1 since null is equivalent to JS undefined,
164 // and would cause the template to not be expanded. 164 // and would cause the template to not be expanded.
165 var m = toObservable({ 'predicate': null, 'bound': 1 }); 165 var m = toObservable({ 'predicate': null, 'bound': 1 });
166 var template = div.firstChild; 166 var template = div.firstChild;
167 bool errorSeen = false; 167 bool errorSeen = false;
168 runZoned(() { 168 runZoned(() {
169 templateBind(template).model = m; 169 templateBind(template).model = m;
170 }, onError: (e, s) { 170 }, onError: (e, s) {
171 expect(e, isNoSuchMethodError); 171 _expectNoSuchMethod(e);
172 errorSeen = true; 172 errorSeen = true;
173 }); 173 });
174 return new Future(() { 174 return new Future(() {
175 expect(div.nodes.length, 1); 175 expect(div.nodes.length, 1);
176 176
177 m['predicate'] = 1; 177 m['predicate'] = 1;
178 178
179 expect(errorSeen, isFalse); 179 expect(errorSeen, isFalse);
180 }).then(nextMicrotask).then((_) { 180 }).then(nextMicrotask).then((_) {
181 expect(errorSeen, isTrue); 181 expect(errorSeen, isTrue);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 '</template>'); 245 '</template>');
246 246
247 // Dart note: changed bound from null->1 since null is equivalent to JS 247 // Dart note: changed bound from null->1 since null is equivalent to JS
248 // undefined, and would cause the template to not be expanded. 248 // undefined, and would cause the template to not be expanded.
249 var m = toObservable({ 'predicate': 1, 'bound': 1 }); 249 var m = toObservable({ 'predicate': 1, 'bound': 1 });
250 var template = div.firstChild; 250 var template = div.firstChild;
251 bool errorSeen = false; 251 bool errorSeen = false;
252 runZoned(() { 252 runZoned(() {
253 templateBind(template).model = m; 253 templateBind(template).model = m;
254 }, onError: (e, s) { 254 }, onError: (e, s) {
255 expect(e, isNoSuchMethodError); 255 _expectNoSuchMethod(e);
256 errorSeen = true; 256 errorSeen = true;
257 }); 257 });
258 258
259 return new Future(() { 259 return new Future(() {
260 expect(div.nodes.length, 1); 260 expect(div.nodes.length, 1);
261 m['bound'] = toObservable({ 'value': 2 }); 261 m['bound'] = toObservable({ 'value': 2 });
262 expect(errorSeen, isTrue); 262 expect(errorSeen, isTrue);
263 }).then(endOfMicrotask).then((_) { 263 }).then(endOfMicrotask).then((_) {
264 expect(div.nodes.length, 2); 264 expect(div.nodes.length, 2);
265 expect(div.lastChild.text, 'value:2'); 265 expect(div.lastChild.text, 'value:2');
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 var contentA = templateBind(templateA).content; 2239 var contentA = templateBind(templateA).content;
2240 var contentB = templateBind(templateB).content; 2240 var contentB = templateBind(templateB).content;
2241 expect(contentA, isNotNull); 2241 expect(contentA, isNotNull);
2242 2242
2243 expect(templateA.ownerDocument, isNot(equals(contentA.ownerDocument))); 2243 expect(templateA.ownerDocument, isNot(equals(contentA.ownerDocument)));
2244 expect(templateB.ownerDocument, isNot(equals(contentB.ownerDocument))); 2244 expect(templateB.ownerDocument, isNot(equals(contentB.ownerDocument)));
2245 2245
2246 expect(templateB.ownerDocument, templateA.ownerDocument); 2246 expect(templateB.ownerDocument, templateA.ownerDocument);
2247 expect(contentB.ownerDocument, contentA.ownerDocument); 2247 expect(contentB.ownerDocument, contentA.ownerDocument);
2248 2248
2249 expect(templateA.ownerDocument.window, window); 2249 // NOTE: these tests don't work under ShadowDOM polyfill.
2250 expect(templateB.ownerDocument.window, window); 2250 // Disabled for now.
2251 //expect(templateA.ownerDocument.window, window);
2252 //expect(templateB.ownerDocument.window, window);
2251 2253
2252 expect(contentA.ownerDocument.window, null); 2254 expect(contentA.ownerDocument.window, null);
2253 expect(contentB.ownerDocument.window, null); 2255 expect(contentB.ownerDocument.window, null);
2254 2256
2255 expect(contentA.nodes.last, contentA.nodes.first); 2257 expect(contentA.nodes.last, contentA.nodes.first);
2256 expect(contentA.nodes.first.tagName, 'A'); 2258 expect(contentA.nodes.first.tagName, 'A');
2257 2259
2258 expect(contentB.nodes.last, contentB.nodes.first); 2260 expect(contentB.nodes.last, contentB.nodes.first);
2259 expect(contentB.nodes.first.tagName, 'B'); 2261 expect(contentB.nodes.first.tagName, 'B');
2260 }); 2262 });
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 expect(instance.firstChild.nextNode.text, 'bar:replaced'); 2371 expect(instance.firstChild.nextNode.text, 'bar:replaced');
2370 2372
2371 clearAllTemplates(instance); 2373 clearAllTemplates(instance);
2372 }); 2374 });
2373 2375
2374 test('CreateInstance - sync error', () { 2376 test('CreateInstance - sync error', () {
2375 var div = createTestHtml('<template>{{foo}}</template>'); 2377 var div = createTestHtml('<template>{{foo}}</template>');
2376 var outer = templateBind(div.nodes.first); 2378 var outer = templateBind(div.nodes.first);
2377 var model = 1; // model is missing 'foo' should throw. 2379 var model = 1; // model is missing 'foo' should throw.
2378 expect(() => outer.createInstance(model, new TestBindingSyntax()), 2380 expect(() => outer.createInstance(model, new TestBindingSyntax()),
2379 throwsA(isNoSuchMethodError)); 2381 throwsA(_isNoSuchMethodError));
2380 }); 2382 });
2381 2383
2382 test('CreateInstance - async error', () { 2384 test('CreateInstance - async error', () {
2383 var div = createTestHtml( 2385 var div = createTestHtml(
2384 '<template>' 2386 '<template>'
2385 '<template bind="{{b}}">' 2387 '<template bind="{{b}}">'
2386 '{{ foo }}:{{ replaceme }}' 2388 '{{ foo }}:{{ replaceme }}'
2387 '</template>' 2389 '</template>'
2388 '</template>'); 2390 '</template>');
2389 var outer = templateBind(div.nodes.first); 2391 var outer = templateBind(div.nodes.first);
2390 var model = toObservable({'b': 1}); // missing 'foo' should throw. 2392 var model = toObservable({'b': 1}); // missing 'foo' should throw.
2391 2393
2392 bool seen = false; 2394 bool seen = false;
2393 runZoned(() => outer.createInstance(model, new TestBindingSyntax()), 2395 runZoned(() => outer.createInstance(model, new TestBindingSyntax()),
2394 onError: (e) { 2396 onError: (e) {
2395 expect(e, isNoSuchMethodError); 2397 _expectNoSuchMethod(e);
2396 seen = true; 2398 seen = true;
2397 }); 2399 });
2398 return new Future(() { expect(seen, isTrue); }); 2400 return new Future(() { expect(seen, isTrue); });
2399 }); 2401 });
2400 2402
2401 test('Repeat - svg', () { 2403 test('Repeat - svg', () {
2402 var div = createTestHtml( 2404 var div = createTestHtml(
2403 '<svg width="400" height="110">' 2405 '<svg width="400" height="110">'
2404 '<template repeat>' 2406 '<template repeat>'
2405 '<rect width="{{ width }}" height="{{ height }}" />' 2407 '<rect width="{{ width }}" height="{{ height }}" />'
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 2588
2587 var a = img.nextNode; 2589 var a = img.nextNode;
2588 expect(a.attributes['href'], 'link.html'); 2590 expect(a.attributes['href'], 'link.html');
2589 2591
2590 var input = a.nextNode; 2592 var input = a.nextNode;
2591 expect(input.value, '4'); 2593 expect(input.value, '4');
2592 }); 2594 });
2593 }); 2595 });
2594 } 2596 }
2595 2597
2598 // TODO(jmesserly): ideally we could test the type with isNoSuchMethodError,
2599 // however dart:js converts the nSM into a String at some point.
2600 // So for now we do string comparison.
2601 _isNoSuchMethodError(e) => '$e'.contains('NoSuchMethodError');
2602
2603 _expectNoSuchMethod(e) {
2604 // expect(e, isNoSuchMethodError);
2605 expect('$e', contains('NoSuchMethodError'));
2606 }
2607
2596 class Issue285Syntax extends BindingDelegate { 2608 class Issue285Syntax extends BindingDelegate {
2597 prepareInstanceModel(template) { 2609 prepareInstanceModel(template) {
2598 if (template.id == 'del') return (val) => val * 2; 2610 if (template.id == 'del') return (val) => val * 2;
2599 } 2611 }
2600 } 2612 }
2601 2613
2602 class TestBindingSyntax extends BindingDelegate { 2614 class TestBindingSyntax extends BindingDelegate {
2603 prepareBinding(String path, name, node) { 2615 prepareBinding(String path, name, node) {
2604 if (path.trim() == 'replaceme') { 2616 if (path.trim() == 'replaceme') {
2605 return (m, n, oneTime) => new PathObserver('replaced', ''); 2617 return (m, n, oneTime) => new PathObserver('replaced', '');
(...skipping 28 matching lines...) Expand all
2634 class TestAccessorModel extends Observable { 2646 class TestAccessorModel extends Observable {
2635 @observable var value = 1; 2647 @observable var value = 1;
2636 var count = 0; 2648 var count = 0;
2637 2649
2638 @reflectable 2650 @reflectable
2639 get prop { 2651 get prop {
2640 count++; 2652 count++;
2641 return value; 2653 return value;
2642 } 2654 }
2643 } 2655 }
OLDNEW
« no previous file with comments | « pkg/template_binding/test/node_bind_test.html ('k') | pkg/template_binding/test/template_binding_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698