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

Unified Diff: pkg/custom_element/test/custom_element_test.dart

Issue 20886002: add custom_element package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove unused dev dep Created 7 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 side-by-side diff with in-line comments
Download patch
Index: pkg/custom_element/test/custom_element_test.dart
diff --git a/pkg/custom_element/test/custom_element_test.dart b/pkg/custom_element/test/custom_element_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..57230c79f23081739b8ab20b34a9cc7db7441b6c
--- /dev/null
+++ b/pkg/custom_element/test/custom_element_test.dart
@@ -0,0 +1,51 @@
+// 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 custom_element.test.custom_element_test;
+
+import 'dart:async';
+import 'dart:html';
+import 'package:custom_element/custom_element.dart';
+import 'package:unittest/html_config.dart';
+import 'package:unittest/unittest.dart';
+
+main() {
+ useHtmlConfiguration();
+
+ test('register creates the element and calls lifecycle methods', () {
+ // Add element to the page.
+ var element = new Element.html('<fancy-button>foo bar</fancy-button>');
+ document.body.nodes.add(element);
+
+ var xtag = null;
+ registerCustomElement('fancy-button', () => xtag = new FancyButton());
+ expect(xtag, isNotNull, reason: 'FancyButton was created');
+ expect(element.xtag, xtag, reason: 'xtag pointer should be set');
+ expect(xtag.host, element, reason: 'host pointer should be set');
+ expect(xtag.lifecycle, ['created']);
+ return new Future(() {
+ expect(xtag.lifecycle, ['created', 'inserted']);
+ element.remove();
+ return new Future(() {
+ expect(xtag.lifecycle, ['created', 'inserted', 'removed']);
+ });
+ });
+ });
+}
+
+class FancyButton extends CustomElement {
+ final lifecycle = [];
+ created() {
+ super.created();
+ lifecycle.add('created');
+ }
+ inserted() {
+ super.inserted();
+ lifecycle.add('inserted');
+ }
+ removed() {
+ super.removed();
+ lifecycle.add('removed');
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698