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

Unified Diff: test/src/common/behavior_test.dart

Issue 1290643006: First cut at behaviors. This just implements the lifecycle methodsportion. We may get the rest for … (Closed) Base URL: git@github.com:dart-lang/polymer-dart.git@master
Patch Set: Created 5 years, 4 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
Index: test/src/common/behavior_test.dart
diff --git a/test/src/common/behavior_test.dart b/test/src/common/behavior_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..108c453b5a43df95de5294d0026a432d73978119
--- /dev/null
+++ b/test/src/common/behavior_test.dart
@@ -0,0 +1,108 @@
+// Copyright (c) 2014, 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.
+@TestOn('browser')
+library polymer.test.src.common.js_proxy_test;
+
+import 'dart:html';
+import 'dart:js';
+import 'package:polymer/polymer.dart';
+import 'package:test/test.dart';
+import 'package:web_components/web_components.dart';
+
+main() async {
+ await initPolymer();
+ MyElement el;
+
+ group('lifecycle methods', () {
+ setUp(() {
+ el = new MyElement();
+ });
+
+ test('created', () {
+ expect(el.dartInvocations['created'], [
+ [el]
+ ]);
+ expect(el.jsElement['jsInvocations']['created'], [
+ [el]
+ ]);
+ expect(el.dartInvocations['attached'], isEmpty);
+ expect(el.dartInvocations['detached'], isEmpty);
+ expect(el.dartInvocations['attributeChanged'], isEmpty);
+ });
+
+ test('attached', () {
+ document.body.append(el);
+ expect(el.dartInvocations['attached'], [
+ [el]
+ ]);
+ expect(el.jsElement['jsInvocations']['attached'], [
+ [el]
+ ]);
+ expect(el.dartInvocations['detached'], isEmpty);
+ expect(el.dartInvocations['attributeChanged'], isEmpty);
+ });
+
+ test('detached', () {
+ document.body.append(el);
+ el.remove();
+ expect(el.dartInvocations['detached'], [
+ [el]
+ ]);
+ expect(el.jsElement['jsInvocations']['detached'], [
+ [el]
+ ]);
+ expect(el.dartInvocations['attributeChanged'], isEmpty);
+ });
+
+ test('attributeChanged', () {
+ el.attributes['foo'] = 'bar';
+ expect(el.dartInvocations['attributeChanged'], [
+ [el, 'foo', null, 'bar']
+ ]);
+ expect(el.jsElement['jsInvocations']['attributeChanged'], [
+ [el, 'foo', null, 'bar']
+ ]);
+ });
+ });
+}
+
+@BehaviorProxy(const ['JsBehavior'])
+abstract class JsBehavior implements CustomElementProxyMixin {
+ JsArray get jsInvocations => jsElement['jsInvocations'];
+}
+
+@Behavior()
+class DartBehavior {
+ Map<String, List<List>> dartInvocations = {
+ 'created': [],
+ 'attached': [],
+ 'detached': [],
+ 'attributeChanged': []
+ };
+
+ static created(DartBehavior thisArg) {
+ thisArg.dartInvocations['created'].add([thisArg]);
+ }
+
+ static attached(DartBehavior thisArg) {
+ thisArg.dartInvocations['attached'].add([thisArg]);
+ }
+
+ static detached(DartBehavior thisArg) {
+ thisArg.dartInvocations['detached'].add([thisArg]);
+ }
+
+ static attributeChanged(DartBehavior thisArg, String name, type, value) {
+ thisArg.dartInvocations['attributeChanged']
+ .add([thisArg, name, type, value]);
+ }
+}
+
+@jsProxyReflectable
+@PolymerRegister('my-element')
+class MyElement extends PolymerElement with JsBehavior, DartBehavior {
+ MyElement.created() : super.created();
+
+ factory MyElement() => document.createElement('my-element');
+}

Powered by Google App Engine
This is Rietveld 408576698