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

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

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 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 | « packages/polymer/test/auto_binding_test.html ('k') | packages/polymer/test/bind_mdv_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/polymer/test/bind_mdv_test.dart
diff --git a/packages/polymer/test/bind_mdv_test.dart b/packages/polymer/test/bind_mdv_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a576e3093169bb37dc6a25e879e600cc0e3eeb49
--- /dev/null
+++ b/packages/polymer/test/bind_mdv_test.dart
@@ -0,0 +1,93 @@
+// 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:template_binding/template_binding.dart';
+import 'package:observe/observe.dart';
+import 'package:observe/mirrors_used.dart'; // make test smaller.
+import 'package:unittest/html_config.dart';
+import 'package:unittest/unittest.dart';
+import 'package:web_components/polyfill.dart';
+
+main() {
+ useHtmlConfiguration();
+
+ var registered = customElementsReady.then((_) {
+ document.registerElement('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();
+ return new Future.microtask(() {
+ 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);
+ scheduleMicrotask(Observable.dirtyCheck);
+ return completer.future;
+}
« no previous file with comments | « packages/polymer/test/auto_binding_test.html ('k') | packages/polymer/test/bind_mdv_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698