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

Side by Side Diff: tests/html/custom/document_register_basic_test.dart

Issue 23232005: Port custom element layout tests to Dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix dart2js and status Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library document_register_basic_test;
6 import 'package:unittest/unittest.dart';
7 import 'package:unittest/html_config.dart';
8 import 'dart:html';
9
10 class Foo extends HtmlElement {
11 static final tag = 'x-foo';
12 factory Foo() => new Element.tag(tag);
13
14 get thisIsACustomClass => true;
15 }
16
17 class Bar extends HtmlElement {
18 static final tag = 'x-bar';
19 factory Bar() => new Element.tag(tag);
20
21 get thisIsACustomClass => true;
22 }
23
24 class Baz extends Foo {
25 static final tag = 'x-baz';
26 factory Baz() => new Element.tag(tag);
27
28 get thisIsAlsoACustomClass => true;
29 }
30
31 class BadB {
32 }
33
34 class BadE implements HtmlElement {
35 static final tag = 'x-tag-e';
36 factory BadE() => new Element.tag(tag);
37 }
38
39 main() {
40 useHtmlConfiguration();
41
42 // Adapted from Blink's fast/dom/custom/document-register-basic test.
43
44 test('Testing document.register() basic behaviors', () {
45 document.register(Foo.tag, Foo);
46
47 // Cannot register an existing dart:html type.
48 expect(() => document.register('x-bad-a', HtmlElement), throws);
49
50 // Invalid user type. Doesn't inherit from HtmlElement.
51 expect(() => document.register('x-bad-b', BadB), throws);
52
53 // Not a type.
54 expect(() => document.register('x-bad-c', null), throws);
55
56 // Cannot register system type.
57 expect(() => document.register('x-bad-d', Object), throws);
58
59 // Must extend HtmlElement, not just implement it.
60 expect(() => document.register(BadE.tag, BadE), throws);
61
62 // Constructor initiated instantiation
63 var createdFoo = new Foo();
64 expect(createdFoo.thisIsACustomClass, isTrue);
65
66 // Dart type correctness
67 expect(createdFoo is HtmlElement, isTrue);
68 expect(createdFoo is Foo, isTrue);
69 expect(createdFoo.runtimeType, Foo);
70
71 // Native getter
72 expect(createdFoo.tagName, "X-FOO");
73
74 // Native setter
75 createdFoo.innerHtml = "Hello";
76 expect(createdFoo.text, "Hello");
77
78 // Native method
79 var childDiv = new DivElement();
80 createdFoo.append(childDiv);
81 expect(createdFoo.lastChild, childDiv);
82
83 // Parser initiated instantiation
84 var container = new DivElement()..id = "container";
85 document.body.append(container);
86 container.innerHtml = "<x-foo></x-foo>";
87 var parsedFoo = container.firstChild;
88
89 expect(parsedFoo is Foo, isTrue);
90 expect(parsedFoo.tagName, "X-FOO");
91
92 // Ensuring the wrapper is retained
93 var someProperty = new Expando();
94 someProperty[parsedFoo] = "hello";
95 // TODO(vsm): Fix this in Dartium.
96 // expect(someProperty[container.firstChild], someProperty[parsedFoo]);
97 // expect(container.firstChild, parsedFoo);
98
99 // Having another constructor
100 document.register(Bar.tag, Bar);
101 var createdBar = new Bar();
102 expect(createdBar is Bar, isTrue);
103 expect(createdBar is Foo, isFalse);
104 expect(createdBar.tagName, "X-BAR");
105
106 // Having a subclass
107 document.register(Baz.tag, Baz);
108 var createdBaz = new Baz();
109 expect(createdBaz.tagName, "X-BAZ");
110 expect(createdBaz.thisIsACustomClass, isTrue);
111 expect(createdBaz.thisIsAlsoACustomClass, isTrue);
112
113 // With irregular cases
114 var createdUpperBar = new Element.tag("X-BAR");
115 var createdMixedBar = new Element.tag("X-Bar");
116 expect(createdUpperBar is Bar, isTrue);
117 expect(createdUpperBar.tagName, "X-BAR");
118 expect(createdMixedBar is Bar, isTrue);
119 expect(createdMixedBar.tagName, "X-BAR");
120
121 container.innerHtml = "<X-BAR></X-BAR><X-Bar></X-Bar>";
122 expect(container.firstChild is Bar, isTrue);
123 expect(container.firstChild.tagName, "X-BAR");
124 expect(container.lastChild is Bar, isTrue);
125 expect(container.lastChild.tagName, "X-BAR");
126
127 // Constructors shouldn't interfere with each other
128 expect((new Foo()).tagName, "X-FOO");
129 expect((new Bar()).tagName, "X-BAR");
130 expect((new Baz()).tagName, "X-BAZ");
131 });
132 }
OLDNEW
« no previous file with comments | « tests/html/custom/created_callback_test.dart ('k') | tests/html/custom/document_register_type_extensions_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698