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

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

Issue 22957010: Revert "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/svg/dartium/svg_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 'dart:async'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_individual_config.dart';
7 import 'dart:html'; 8 import 'dart:html';
8 import 'package:unittest/html_individual_config.dart';
9 import 'package:unittest/unittest.dart';
10 9
11 class CustomMixin { 10 class CustomMixin {
12 var mixinMethodCalled; 11 var mixinMethodCalled;
13 12
14 void mixinMethod() { 13 void mixinMethod() {
15 mixinMethodCalled = true; 14 mixinMethodCalled = true;
16 } 15 }
17 } 16 }
18 17
19 class CustomType extends HtmlElement with CustomMixin{ 18 class CustomType extends HtmlElement with CustomMixin{
20 factory CustomType() => null; 19 factory CustomType() => null;
21 bool onCreatedCalled; // = false; 20 bool onCreatedCalled; // = false;
22 void onCreated() { 21 void onCreated() {
23 onCreatedCalled = true; 22 onCreatedCalled = true;
24 customCreatedCount++; 23 customCreatedCount++;
25 } 24 }
26 25
27 void invokeMixinMethod() { 26 void invokeMixinMethod() {
28 mixinMethod(); 27 mixinMethod();
29 } 28 }
30 } 29 }
31 30
32 int customCreatedCount = 0; 31 int customCreatedCount = 0;
33 32
34 int nextTagId = 0; 33 int nextTagId = 0;
35 String get nextTag => 'x-type${nextTagId++}'; 34 String get nextTag => 'x-type${nextTagId++}';
36 35
37 class NotAnElement {} 36 class NotAnElement {}
38 37
39 loadPolyfills() {
40 if (!document.supportsRegister) {
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
48 main() { 38 main() {
49 useHtmlIndividualConfiguration(); 39 useHtmlIndividualConfiguration();
50 40
51 setUp(loadPolyfills);
52
53 group('register', () { 41 group('register', () {
54 test('register', () { 42 test('register', () {
55 var tag = nextTag; 43 var tag = nextTag;
56 document.register(tag, CustomType); 44 document.register(tag, CustomType);
57 45
58 var element = new Element.tag(tag); 46 var element = new Element.tag(tag);
59 expect(element, isNotNull); 47 expect(element, isNotNull);
60 expect(element is CustomType, isTrue); 48 expect(element is CustomType, isTrue);
61 expect(element.onCreatedCalled, isTrue); 49 expect(element.onCreatedCalled, isTrue);
62 }); 50 });
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 }); 83 });
96 }); 84 });
97 85
98 // TODO(vsm): Modify this test once we agree on the proper semantics. 86 // TODO(vsm): Modify this test once we agree on the proper semantics.
99 /* 87 /*
100 group('preregister', () { 88 group('preregister', () {
101 89
102 test('pre-registration construction', () { 90 test('pre-registration construction', () {
103 var tag = nextTag; 91 var tag = nextTag;
104 var dom = new Element.html('<div><$tag></$tag></div>'); 92 var dom = new Element.html('<div><$tag></$tag></div>');
105
106 var preElement = dom.children[0]; 93 var preElement = dom.children[0];
107 expect(preElement, isNotNull); 94 expect(preElement, isNotNull);
108 expect(preElement is HtmlElement, isTrue); 95 expect(preElement is HtmlElement, isTrue);
109 expect(preElement is CustomType, isFalse); 96 expect(preElement is CustomType, isFalse);
110 var firedOnPre = false; 97 var firedOnPre = false;
111 preElement.onFocus.listen((_) { 98 preElement.onFocus.listen((_) {
112 firedOnPre = true; 99 firedOnPre = true;
113 }); 100 });
114 101
115 document.register(tag, CustomType); 102 document.register(tag, CustomType);
116 Platform.upgradeCustomElements(dom);
117 103
118 var postElement = dom.children[0]; 104 var postElement = dom.children[0];
119 expect(postElement, isNotNull); 105 expect(postElement, isNotNull);
120 expect(postElement is CustomType, isTrue); 106 expect(postElement is CustomType, isTrue);
121 expect(postElement.onCreatedCalled, isTrue); 107 expect(postElement.onCreatedCalled, isTrue);
122 108
123 // Element from first query remains an UnknownElement. 109 // Element from first query remains an UnknownElement.
124 expect(preElement is HtmlElement, isTrue); 110 expect(preElement is HtmlElement, isTrue);
125 expect(preElement.parent, dom); 111 expect(preElement.parent, dom);
126 expect(dom.children.length, 1); 112 expect(dom.children.length, 1);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 test('can invoke mixin methods', () { 166 test('can invoke mixin methods', () {
181 var tag = nextTag; 167 var tag = nextTag;
182 document.register(tag, CustomType); 168 document.register(tag, CustomType);
183 169
184 var element = new Element.tag(tag); 170 var element = new Element.tag(tag);
185 element.invokeMixinMethod(); 171 element.invokeMixinMethod();
186 expect(element.mixinMethodCalled, isTrue); 172 expect(element.mixinMethodCalled, isTrue);
187 }); 173 });
188 }); 174 });
189 } 175 }
OLDNEW
« no previous file with comments | « sdk/lib/svg/dartium/svg_dartium.dart ('k') | tests/html/html.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698