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

Unified Diff: pkg/polymer/test/bind_mdv_test.dart

Issue 25740006: port polymer data binding tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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/polymer/lib/src/instance.dart ('k') | pkg/polymer/test/bind_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/test/bind_mdv_test.dart
diff --git a/pkg/polymer/test/bind_mdv_test.dart b/pkg/polymer/test/bind_mdv_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6706bde6188920285b4ce3e68f9ea3d30f0cf8dc
--- /dev/null
+++ b/pkg/polymer/test/bind_mdv_test.dart
@@ -0,0 +1,95 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library polymer.test.bind_mdv_test;
+
+import 'dart:async';
+import 'dart:html';
+import 'package:custom_element/polyfill.dart';
+import 'package:template_binding/template_binding.dart';
+import 'package:observe/observe.dart';
+import 'package:observe/src/microtask.dart' show runMicrotask;
+import 'package:polymer/platform.dart' as Platform;
+import 'package:unittest/html_config.dart';
+import 'package:unittest/unittest.dart';
+
+main() {
+ useHtmlConfiguration();
+
+ var registered = loadCustomElementPolyfill().then((_) {
+ document.register('my-div', MyDivElement);
+ });
+
+ setUp(() => registered);
+
+ group('bindModel', bindModelTests);
+}
+
+bindModelTests() {
+ var div;
+
+ setUp(() {
+ div = new MyDivElement();
+ document.body.append(div);
+ });
+
+ tearDown(() {
+ div.remove();
+ });
+
+ parseAndBindHTML(html, model) =>
+ templateBind(new Element.tag('template')
+ ..setInnerHtml(html, treeSanitizer: const NullTreeSanitizer()))
+ .createInstance(model);
+
+ test('bindModel', () {
+ var fragment = parseAndBindHTML('<div id="a" foo="{{bar}}"></div>', div);
+ div.append(fragment);
+ var a = div.query('#a');
+
+ div.bar = 5;
+ return onAttributeChange(a).then((_) {
+ expect(a.attributes['foo'], '5');
+ div.bar = 8;
+ return onAttributeChange(a).then((_) {
+ expect(a.attributes['foo'], '8');
+ });
+ });
+ });
+
+ test('bind input', () {
+ var fragment = parseAndBindHTML('<input value="{{bar}}" />', div);
+ div.append(fragment);
+ var a = div.query('input');
+
+ div.bar = 'hello';
+ // TODO(sorvell): fix this when observe-js lets us explicitly listen for
+ // a change on input.value
+ Observable.dirtyCheck();
+ Platform.endOfMicrotask(expectAsync0(() {
+ expect(a.value, 'hello');
+ }));
+ });
+}
+
+class MyDivElement extends HtmlElement with Observable {
+ factory MyDivElement() => new Element.tag('my-div');
+ MyDivElement.created() : super.created();
+ @observable var bar;
+}
+
+class NullTreeSanitizer implements NodeTreeSanitizer {
+ const NullTreeSanitizer();
+ void sanitizeTree(Node node) {}
+}
+
+Future onAttributeChange(Element node) {
+ var completer = new Completer();
+ new MutationObserver((records, observer) {
+ observer.disconnect();
+ completer.complete();
+ })..observe(node, attributes: true);
+ Platform.flush();
+ return completer.future;
+}
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/polymer/test/bind_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698