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

Unified Diff: pkg/template_binding/test/binding_syntax.dart

Issue 335943003: merge to trunk all changes from 36817 until 37378 under the packages: polymer, (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/template_binding/pubspec.yaml ('k') | pkg/template_binding/test/custom_element_bindings_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/template_binding/test/binding_syntax.dart
===================================================================
--- pkg/template_binding/test/binding_syntax.dart (revision 37373)
+++ pkg/template_binding/test/binding_syntax.dart (working copy)
@@ -22,7 +22,10 @@
'<template bind>{{ foo }}'
'<template bind>{{ foo }}</template>'
'</template>');
- recursivelySetTemplateModel(div, model, testSyntax);
+ var template = templateBind(div.firstChild);
+ template
+ ..model = model
+ ..bindingDelegate = testSyntax;
return new Future(() {
expect(div.nodes.length, 4);
expect(div.nodes.last.text, 'bar');
@@ -49,7 +52,9 @@
var div = createTestHtml('<template repeat>{{ foo }}</template>');
var template = div.nodes[0];
- recursivelySetTemplateModel(div, model, testSyntax);
+ templateBind(template)
+ ..model = model
+ ..bindingDelegate = testSyntax;
return new Future(() {
expect(div.nodes.length, 4);
@@ -74,7 +79,9 @@
var template = div.firstChild;
var delegate = new TestInstanceModelSyntax();
- recursivelySetTemplateModel(div, model, delegate);
+ templateBind(template)
+ ..model = model
+ ..bindingDelegate = delegate;
return new Future(() {
expect(delegate.prepareCount, 1);
expect(delegate.callCount, 3);
@@ -94,7 +101,9 @@
var delegate = new TestPositionChangedSyntax();
var template = div.nodes[0];
- recursivelySetTemplateModel(div, model, delegate);
+ templateBind(template)
+ ..model = model
+ ..bindingDelegate = delegate;
return new Future(() {
expect(div.nodes.length, 4);
@@ -136,12 +145,23 @@
expect(div.nodes[1].text, 'i:0 - a:1');
expect(div.nodes[2].text, 'i:1 - a:2');
- template.bindingDelegate = new UpdateBindingDelegateB();
+ expect(() {
+ template.bindingDelegate = new UpdateBindingDelegateB();
+ }, throws);
+
+ template.clear();
+ expect(div.nodes.length, 1);
+
+ template
+ ..bindingDelegate = new UpdateBindingDelegateB()
+ ..model = model;
+
model.add(3);
}).then(nextMicrotask).then((_) {
+ // All instances should reflect delegateB
expect(4, div.nodes.length);
- expect(div.nodes[1].text, 'i:0 - a:1');
- expect(div.nodes[2].text, 'i:1 - a:2');
+ expect(div.nodes[1].text, 'I:0 - A:1-narg');
+ expect(div.nodes[2].text, 'I:2 - A:2-narg');
expect(div.nodes[3].text, 'I:4 - A:3-narg');
});
});
@@ -151,7 +171,10 @@
var div = createTestHtml(
'<template bind>'
'{{ foo }} + {{ 2x: bar }} + {{ 4x: bar }}</template>');
- recursivelySetTemplateModel(div, model, new TimesTwoSyntax());
+ var template = templateBind(div.firstChild);
+ template
+ ..model = model
+ ..bindingDelegate = new TimesTwoSyntax();
return new Future(() {
expect(div.nodes.length, 2);
expect(div.nodes.last.text, '2 + 8 + ');
@@ -163,6 +186,28 @@
});
});
+ test('CreateInstance', () {
+ var delegateFoo = new SimpleTextDelegate('foo');
+ var delegateBar = new SimpleTextDelegate('bar');
+
+ var div = createTestHtml('<template bind>[[ 2x: bar ]]</template>');
+ var template = templateBind(div.firstChild);
+ template..bindingDelegate = delegateFoo..model = {};
+
+ return new Future(() {
+ expect(div.nodes.length, 2);
+ expect(div.lastChild.text, 'foo');
+
+ var fragment = template.createInstance({});
+ expect(fragment.nodes.length, 1);
+ expect(fragment.lastChild.text, 'foo');
+
+ fragment = template.createInstance({}, delegateBar);
+ expect(fragment.nodes.length, 1);
+ expect(fragment.lastChild.text, 'bar');
+ });
+ });
+
// Note: issue-141 test not included here as it's not related to the
// BindingDelegate
}
@@ -186,6 +231,14 @@
}
}
+class SimpleTextDelegate extends BindingDelegate {
+ final String text;
+ SimpleTextDelegate(this.text);
+
+ prepareBinding(path, name, node) =>
+ name != 'text' ? null : (_, __, ___) => text;
+}
+
class TestModelSyntax extends BindingDelegate {
var log = [];
var altModels = new ListQueue();
« no previous file with comments | « pkg/template_binding/pubspec.yaml ('k') | pkg/template_binding/test/custom_element_bindings_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698