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

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: Removing mutation observer polyfill from test. 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
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 if (!document.supportsRegister) {
Jennifer Messerly 2013/08/20 19:09:59 this doesn't need mutation observers?
blois 2013/08/20 19:36:56 It does, they are included in the file. Per-polyf
41 return HttpRequest.getString('/root_dart/pkg/custom_element/lib/'
42 'custom-elements.debug.js').then((code) {
43 document.head.children.add(new ScriptElement()..text = code);
44 });
45 }
46 }
47
38 main() { 48 main() {
39 useHtmlIndividualConfiguration(); 49 useHtmlIndividualConfiguration();
40 50
51 setUp(loadPolyfills);
52
41 group('register', () { 53 group('register', () {
42 test('register', () { 54 test('register', () {
43 var tag = nextTag; 55 var tag = nextTag;
44 document.register(tag, CustomType); 56 document.register(tag, CustomType);
45 57
46 var element = new Element.tag(tag); 58 var element = new Element.tag(tag);
47 expect(element, isNotNull); 59 expect(element, isNotNull);
48 expect(element is CustomType, isTrue); 60 expect(element is CustomType, isTrue);
49 expect(element.onCreatedCalled, isTrue); 61 expect(element.onCreatedCalled, isTrue);
50 }); 62 });
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 }); 95 });
84 }); 96 });
85 97
86 // TODO(vsm): Modify this test once we agree on the proper semantics. 98 // TODO(vsm): Modify this test once we agree on the proper semantics.
87 /* 99 /*
88 group('preregister', () { 100 group('preregister', () {
89 101
90 test('pre-registration construction', () { 102 test('pre-registration construction', () {
91 var tag = nextTag; 103 var tag = nextTag;
92 var dom = new Element.html('<div><$tag></$tag></div>'); 104 var dom = new Element.html('<div><$tag></$tag></div>');
105
93 var preElement = dom.children[0]; 106 var preElement = dom.children[0];
94 expect(preElement, isNotNull); 107 expect(preElement, isNotNull);
95 expect(preElement is HtmlElement, isTrue); 108 expect(preElement is HtmlElement, isTrue);
96 expect(preElement is CustomType, isFalse); 109 expect(preElement is CustomType, isFalse);
97 var firedOnPre = false; 110 var firedOnPre = false;
98 preElement.onFocus.listen((_) { 111 preElement.onFocus.listen((_) {
99 firedOnPre = true; 112 firedOnPre = true;
100 }); 113 });
101 114
102 document.register(tag, CustomType); 115 document.register(tag, CustomType);
116 Platform.upgradeCustomElements(dom);
103 117
104 var postElement = dom.children[0]; 118 var postElement = dom.children[0];
105 expect(postElement, isNotNull); 119 expect(postElement, isNotNull);
106 expect(postElement is CustomType, isTrue); 120 expect(postElement is CustomType, isTrue);
107 expect(postElement.onCreatedCalled, isTrue); 121 expect(postElement.onCreatedCalled, isTrue);
108 122
109 // Element from first query remains an UnknownElement. 123 // Element from first query remains an UnknownElement.
110 expect(preElement is HtmlElement, isTrue); 124 expect(preElement is HtmlElement, isTrue);
111 expect(preElement.parent, dom); 125 expect(preElement.parent, dom);
112 expect(dom.children.length, 1); 126 expect(dom.children.length, 1);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 test('can invoke mixin methods', () { 180 test('can invoke mixin methods', () {
167 var tag = nextTag; 181 var tag = nextTag;
168 document.register(tag, CustomType); 182 document.register(tag, CustomType);
169 183
170 var element = new Element.tag(tag); 184 var element = new Element.tag(tag);
171 element.invokeMixinMethod(); 185 element.invokeMixinMethod();
172 expect(element.mixinMethodCalled, isTrue); 186 expect(element.mixinMethodCalled, isTrue);
173 }); 187 });
174 }); 188 });
175 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698