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

Side by Side Diff: tests/html/custom_elements_test.dart

Issue 21124003: Refactor custom element tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Split out tests 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
« no previous file with comments | « no previous file | tests/html/custom_tags_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library blob_test; 5 library custom_elements_test;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_config.dart'; 7 import '../../pkg/unittest/lib/html_individual_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 9
10 class CustomType extends Element { 10 class CustomType extends Element {
11 bool onCreatedCalled = false; 11 bool onCreatedCalled = false;
12 void onCreated() { 12 void onCreated() {
13 onCreatedCalled = true; 13 onCreatedCalled = true;
14 } 14 }
15 } 15 }
16 16
17 class NotAnElement {} 17 class NotAnElement {}
18 18
19 main() { 19 main() {
20 useHtmlConfiguration(); 20 useHtmlIndividualConfiguration();
21 21
22 test('register', () { 22 group('register', () {
23 document.register('x-type1', CustomType); 23 test('register', () {
24 document.register('x-type1', CustomType);
24 25
25 var element = new Element.tag('x-type1'); 26 var element = new Element.tag('x-type1');
26 expect(element, isNotNull); 27 expect(element, isNotNull);
27 expect(element is CustomType, isTrue); 28 expect(element is CustomType, isTrue);
28 expect(element.onCreatedCalled, isTrue); 29 expect(element.onCreatedCalled, isTrue);
30 });
31
32 test('register twice', () {
33 document.register('x-type2', CustomType);
34 expect(() {
35 document.register('x-type2', CustomType);
36 }, throws, reason: 'Cannot register a tag more than once.');
37
38 document.register('x-type3', CustomType);
39
40 var element = new Element.tag('x-type3');
41 expect(element, isNotNull);
42 expect(element is CustomType, isTrue);
43 });
44
45 test('register null', () {
46 expect(() {
47 document.register('x-type4', null);
48 }, throws, reason: 'Cannot register a null type.');
49 });
50
51 test('register native', () {
52 expect(() {
53 document.register('x-type5', BodyElement);
54 }, throws, reason: 'Cannot register a native element.');
55 });
56
57 test('register non-element', () {
58 expect(() {
59 document.register('x-type6', NotAnElement);
60 }, throws, reason: 'Cannot register a non-element.');
61 });
29 }); 62 });
30 63
31 test('register twice', () { 64 group('preregister', () {
32 document.register('x-type2', CustomType); 65 // TODO(vsm): Modify this test once we agree on the proper semantics.
33 expect(() { 66 test('pre-registration construction', () {
34 document.register('x-type2', CustomType); 67 var dom = new Element.html('<div><x-type7></x-type7></div>');
35 }, throws, reason: 'Cannot register a tag more than once.'); 68 var preElement = dom.children[0];
69 expect(preElement, isNotNull);
70 expect(preElement is UnknownElement, isTrue);
71 var firedOnPre = false;
72 preElement.onFocus.listen((_) {
73 firedOnPre = true;
74 });
36 75
37 document.register('x-type3', CustomType); 76 document.register('x-type7', CustomType);
38 77
39 var element = new Element.tag('x-type3'); 78 var postElement = dom.children[0];
40 expect(element, isNotNull); 79 expect(postElement, isNotNull);
41 expect(element is CustomType, isTrue); 80 expect(postElement is CustomType, isTrue);
42 }); 81 expect(postElement.onCreatedCalled, isTrue);
43 82
44 test('register null', () { 83 // Element from first query remains an UnknownElement.
45 expect(() { 84 expect(preElement is UnknownElement, isTrue);
46 document.register('x-type4', null); 85 expect(preElement.parent, isNull);
47 }, throws, reason: 'Cannot register a null type.'); 86 expect(dom.children.length, 1);
48 });
49 87
50 test('register native', () { 88 var firedOnPost = false;
51 expect(() { 89 postElement.onFocus.listen((_) {
52 document.register('x-type5', BodyElement); 90 firedOnPost = true;
53 }, throws, reason: 'Cannot register a native element.'); 91 });
54 }); 92 // Event handlers should not persist to new element.
55 93 postElement.dispatchEvent(new Event('focus'));
56 test('register non-element', () { 94 expect(firedOnPre, isFalse);
57 expect(() { 95 expect(firedOnPost, isTrue);
58 document.register('x-type6', NotAnElement);
59 }, throws, reason: 'Cannot register a non-element.');
60 });
61
62 test('pre-registration construction', () {
63 var dom = new Element.html('<div><x-type7></x-type7></div>');
64 var preElement = dom.children[0];
65 expect(preElement, isNotNull);
66 expect(preElement is UnknownElement, isTrue);
67 var firedOnPre = false;
68 preElement.onFocus.listen((_) {
69 firedOnPre = true;
70 }); 96 });
71
72 document.register('x-type7', CustomType);
73
74 var postElement = dom.children[0];
75 expect(postElement, isNotNull);
76 expect(postElement is CustomType, isTrue);
77 expect(postElement.onCreatedCalled, isTrue);
78
79 // Element from first query remains an UnknownElement.
80 expect(preElement is UnknownElement, isTrue);
81 expect(preElement.parent, isNull);
82 expect(dom.children.length, 1);
83
84 var firedOnPost = false;
85 postElement.onFocus.listen((_) {
86 firedOnPost = true;
87 });
88 // Event handlers should not persist to new element.
89 postElement.dispatchEvent(new Event('focus'));
90 expect(firedOnPre, isFalse);
91 expect(firedOnPost, isTrue);
92 }); 97 });
93 } 98 }
OLDNEW
« no previous file with comments | « no previous file | tests/html/custom_tags_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698