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

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: 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/html.status » ('j') | tests/html/html.status » ('J')
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 blob_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('basic', () {
vsm 2013/07/29 21:00:02 These tests are fixed by the accompanying blink CL
23 document.register('x-type1', CustomType); 23 test('create via custom tag', () {
24 var element = new Element.tag('x-basic1')..id = 'basic1';
25 document.body.nodes.add(element);
24 26
25 var element = new Element.tag('x-type1'); 27 var queryById = query('#basic1');
26 expect(element, isNotNull); 28 expect(queryById, equals(element));
27 expect(element is CustomType, isTrue); 29
28 expect(element.onCreatedCalled, isTrue); 30 var queryByTag = queryAll('x-basic1');
31 expect(queryByTag.length, equals(1));
32 expect(queryByTag[0], equals(element));
33 });
34
35 test('custom inner html', () {
36 var element = new DivElement();
37 element.innerHtml = "<x-basic2 id='basic2'></x-basic2>";
38 document.body.nodes.add(element);
39
40 var queryById = query('#basic2');
41 expect(queryById is Element, isTrue);
blois 2013/07/29 21:04:54 Is this an UnknownElement at this point? If so, sh
vsm 2013/07/29 21:43:35 On Dartium it specifically is not an UnknownElemen
42
43 var queryByTag = queryAll('x-basic2');
44 expect(queryByTag.length, equals(1));
45 expect(queryByTag[0], equals(queryById));
46
47 });
48
49 test('type extension inner html', () {
50 var element = new DivElement();
51 element.innerHtml = "<div is='x-basic3' id='basic3'></div>";
52 document.body.nodes.add(element);
53
54 var queryById = query('#basic3');
55 expect(queryById is DivElement, isTrue);
56 });
29 }); 57 });
30 58
31 test('register twice', () { 59 group('register', () {
vsm 2013/07/29 21:00:02 We'll get these tests to pass in the near term, bu
32 document.register('x-type2', CustomType); 60 test('register', () {
33 expect(() { 61 document.register('x-type1', CustomType);
62
63 var element = new Element.tag('x-type1');
64 expect(element, isNotNull);
65 expect(element is CustomType, isTrue);
66 expect(element.onCreatedCalled, isTrue);
67 });
68
69 test('register twice', () {
34 document.register('x-type2', CustomType); 70 document.register('x-type2', CustomType);
35 }, throws, reason: 'Cannot register a tag more than once.'); 71 expect(() {
72 document.register('x-type2', CustomType);
73 }, throws, reason: 'Cannot register a tag more than once.');
36 74
37 document.register('x-type3', CustomType); 75 document.register('x-type3', CustomType);
38 76
39 var element = new Element.tag('x-type3'); 77 var element = new Element.tag('x-type3');
40 expect(element, isNotNull); 78 expect(element, isNotNull);
41 expect(element is CustomType, isTrue); 79 expect(element is CustomType, isTrue);
80 });
81
82 test('register null', () {
83 expect(() {
84 document.register('x-type4', null);
85 }, throws, reason: 'Cannot register a null type.');
86 });
87
88 test('register native', () {
89 expect(() {
90 document.register('x-type5', BodyElement);
91 }, throws, reason: 'Cannot register a native element.');
92 });
93
94 test('register non-element', () {
95 expect(() {
96 document.register('x-type6', NotAnElement);
97 }, throws, reason: 'Cannot register a non-element.');
98 });
42 }); 99 });
43 100
44 test('register null', () { 101 group('preregister', () {
vsm 2013/07/29 21:00:02 We still need to nail down the semantics here.
45 expect(() { 102 // TODO(vsm): Modify this test once we agree on the proper semantics.
46 document.register('x-type4', null); 103 test('pre-registration construction', () {
47 }, throws, reason: 'Cannot register a null type.'); 104 var dom = new Element.html('<div><x-type7></x-type7></div>');
48 }); 105 var preElement = dom.children[0];
106 expect(preElement, isNotNull);
107 expect(preElement is UnknownElement, isTrue);
108 var firedOnPre = false;
109 preElement.onFocus.listen((_) {
110 firedOnPre = true;
111 });
49 112
50 test('register native', () { 113 document.register('x-type7', CustomType);
51 expect(() {
52 document.register('x-type5', BodyElement);
53 }, throws, reason: 'Cannot register a native element.');
54 });
55 114
56 test('register non-element', () { 115 var postElement = dom.children[0];
57 expect(() { 116 expect(postElement, isNotNull);
58 document.register('x-type6', NotAnElement); 117 expect(postElement is CustomType, isTrue);
59 }, throws, reason: 'Cannot register a non-element.'); 118 expect(postElement.onCreatedCalled, isTrue);
60 });
61 119
62 test('pre-registration construction', () { 120 // Element from first query remains an UnknownElement.
63 var dom = new Element.html('<div><x-type7></x-type7></div>'); 121 expect(preElement is UnknownElement, isTrue);
64 var preElement = dom.children[0]; 122 expect(preElement.parent, isNull);
65 expect(preElement, isNotNull); 123 expect(dom.children.length, 1);
66 expect(preElement is UnknownElement, isTrue); 124
67 var firedOnPre = false; 125 var firedOnPost = false;
68 preElement.onFocus.listen((_) { 126 postElement.onFocus.listen((_) {
69 firedOnPre = true; 127 firedOnPost = true;
128 });
129 // Event handlers should not persist to new element.
130 postElement.dispatchEvent(new Event('focus'));
131 expect(firedOnPre, isFalse);
132 expect(firedOnPost, isTrue);
70 }); 133 });
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 }); 134 });
93 } 135 }
OLDNEW
« no previous file with comments | « no previous file | tests/html/html.status » ('j') | tests/html/html.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698