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

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

Issue 22967006: Adding polyfill support for custom elements. (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 | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/html/html.status » ('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 custom_elements_test; 5 library custom_elements_test;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import 'dart:async';
7 import '../../pkg/unittest/lib/html_individual_config.dart';
8 import 'dart:html'; 7 import 'dart:html';
8 import 'package:unittest/html_individual_config.dart';
9 import 'package:unittest/unittest.dart';
9 10
10 class CustomMixin { 11 class CustomMixin {
11 var mixinMethodCalled; 12 var mixinMethodCalled;
12 13
13 void mixinMethod() { 14 void mixinMethod() {
14 mixinMethodCalled = true; 15 mixinMethodCalled = true;
15 } 16 }
16 } 17 }
17 18
18 class CustomType extends HtmlElement with CustomMixin{ 19 class CustomType extends HtmlElement with CustomMixin{
19 factory CustomType() => null; 20 factory CustomType() => null;
20 bool onCreatedCalled; // = false; 21 bool onCreatedCalled; // = false;
21 void onCreated() { 22 void onCreated() {
22 onCreatedCalled = true; 23 onCreatedCalled = true;
23 customCreatedCount++; 24 customCreatedCount++;
24 } 25 }
25 26
26 void invokeMixinMethod() { 27 void invokeMixinMethod() {
27 mixinMethod(); 28 mixinMethod();
28 } 29 }
29 } 30 }
30 31
31 int customCreatedCount = 0; 32 int customCreatedCount = 0;
32 33
33 int nextTagId = 0; 34 int nextTagId = 0;
34 String get nextTag => 'x-type${nextTagId++}'; 35 String get nextTag => 'x-type${nextTagId++}';
35 36
36 class NotAnElement {} 37 class NotAnElement {}
37 38
39 loadPolyfills() {
40 return new Future.sync(() {
41 if (!MutationObserver.supported) {
42 return HttpRequest.getString('/root_dart/pkg/mutation_observer/lib/'
43 'mutation_observer.min.js').then((code) {
44 document.head.children.add(new ScriptElement()..text = code);
45 });
46 }
47 }).then((_) {
48 if (!document.supportsRegister) {
49 return HttpRequest.getString('/root_dart/pkg/custom_element/lib/'
50 'custom-elements.debug.js').then((code) {
51 document.head.children.add(new ScriptElement()..text = code);
52 });
53 }
54 });
55 }
56
38 main() { 57 main() {
39 useHtmlIndividualConfiguration(); 58 useHtmlIndividualConfiguration();
Jennifer Messerly 2013/08/20 19:09:59 does this need to be individual config? it slows t
40 59
60 setUp(loadPolyfills);
61
41 group('register', () { 62 group('register', () {
42 test('register', () { 63 test('register', () {
43 var tag = nextTag; 64 var tag = nextTag;
44 document.register(tag, CustomType); 65 document.register(tag, CustomType);
45 66
46 var element = new Element.tag(tag); 67 var element = new Element.tag(tag);
47 expect(element, isNotNull); 68 expect(element, isNotNull);
48 expect(element is CustomType, isTrue); 69 expect(element is CustomType, isTrue);
49 expect(element.onCreatedCalled, isTrue); 70 expect(element.onCreatedCalled, isTrue);
50 }); 71 });
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 }); 104 });
84 }); 105 });
85 106
86 // TODO(vsm): Modify this test once we agree on the proper semantics. 107 // TODO(vsm): Modify this test once we agree on the proper semantics.
87 /* 108 /*
88 group('preregister', () { 109 group('preregister', () {
89 110
90 test('pre-registration construction', () { 111 test('pre-registration construction', () {
91 var tag = nextTag; 112 var tag = nextTag;
92 var dom = new Element.html('<div><$tag></$tag></div>'); 113 var dom = new Element.html('<div><$tag></$tag></div>');
114
93 var preElement = dom.children[0]; 115 var preElement = dom.children[0];
94 expect(preElement, isNotNull); 116 expect(preElement, isNotNull);
95 expect(preElement is HtmlElement, isTrue); 117 expect(preElement is HtmlElement, isTrue);
96 expect(preElement is CustomType, isFalse); 118 expect(preElement is CustomType, isFalse);
97 var firedOnPre = false; 119 var firedOnPre = false;
98 preElement.onFocus.listen((_) { 120 preElement.onFocus.listen((_) {
99 firedOnPre = true; 121 firedOnPre = true;
100 }); 122 });
101 123
102 document.register(tag, CustomType); 124 document.register(tag, CustomType);
125 Platform.upgradeCustomElements(dom);
103 126
104 var postElement = dom.children[0]; 127 var postElement = dom.children[0];
105 expect(postElement, isNotNull); 128 expect(postElement, isNotNull);
106 expect(postElement is CustomType, isTrue); 129 expect(postElement is CustomType, isTrue);
107 expect(postElement.onCreatedCalled, isTrue); 130 expect(postElement.onCreatedCalled, isTrue);
108 131
109 // Element from first query remains an UnknownElement. 132 // Element from first query remains an UnknownElement.
110 expect(preElement is HtmlElement, isTrue); 133 expect(preElement is HtmlElement, isTrue);
111 expect(preElement.parent, dom); 134 expect(preElement.parent, dom);
112 expect(dom.children.length, 1); 135 expect(dom.children.length, 1);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 test('can invoke mixin methods', () { 189 test('can invoke mixin methods', () {
167 var tag = nextTag; 190 var tag = nextTag;
168 document.register(tag, CustomType); 191 document.register(tag, CustomType);
169 192
170 var element = new Element.tag(tag); 193 var element = new Element.tag(tag);
171 element.invokeMixinMethod(); 194 element.invokeMixinMethod();
172 expect(element.mixinMethodCalled, isTrue); 195 expect(element.mixinMethodCalled, isTrue);
173 }); 196 });
174 }); 197 });
175 } 198 }
OLDNEW
« 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