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

Unified Diff: tests/html/custom_elements_test.dart

Issue 12212056: Sample test for custom elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/html/html.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/custom_elements_test.dart
diff --git a/tests/html/custom_elements_test.dart b/tests/html/custom_elements_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9ff38c007762f0bf1ea7eebfbd2cf687961a6b62
--- /dev/null
+++ b/tests/html/custom_elements_test.dart
@@ -0,0 +1,71 @@
+// 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 blob_test;
+import '../../pkg/unittest/lib/unittest.dart';
+import '../../pkg/unittest/lib/html_config.dart';
+import 'dart:html';
+
+class CustomType extends Element {
+ bool onCreatedCalled = false;
+ void onCreated() {
+ onCreatedCalled = true;
+ }
+}
+
+class NotAnElement {}
+
+main() {
+ useHtmlConfiguration();
+
+ test('register', () {
+ document.register('x-type1', CustomType);
+
+ var element = new Element.tag('x-type');
Siggi Cherem (dart-lang) 2013/02/07 17:29:39 shoudln't this be x-type1?
blois 2013/02/07 21:15:06 Done.
+ expect(element, isNotNull);
+ expect(element is CustomType, isTrue);
+ expect(element.onCreatedCalled, isTrue);
+ });
+
+ test('register twice', () {
+ document.register('x-type2', CustomType);
+ expect(() {
+ document.register('x-type2', CustomType);
+ }, throws, reason: 'Cannot register a tag more than once.');
+
+ document.register('x-type3', CustomType);
+
+ var element = new Element.tag('x-type3');
+ expect(element, isNotNull);
+ expect(element is CustomType, isTrue);
+ });
+
+ test('register null', () {
+ expect(() {
+ document.register('x-type4', null);
+ }, throws, reason: 'Cannot register a null type.');
+ });
+
+ test('register native', () {
+ expect(() {
+ document.register('x-type5', BodyElement);
+ }, throws, reason: 'Cannot register a native element.');
+ });
+
+ test('register non-element', () {
+ expect(() {
+ document.register('x-type6', NotAnElement);
+ }, throws, reason: 'Cannot register a non-element.');
+ });
+
+ test('pre-registration construction', () {
+ var dom = new Element.html('<div><x-type7></x-type7></div>');
+
+ document.register('x-type7', CustomType);
+
+ expect(element, isNotNull);
Anton Muhin 2013/02/07 15:29:33 there is no element local. how and when you're fe
blois 2013/02/07 21:15:06 Done.
+ expect(element is CustomType, isTrue);
+ expect(element.onCreatedCalled, isTrue);
+ });
+}
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/html/html.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698