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

Side by Side Diff: tests/html/custom/document_register_basic_test.dart

Issue 23442011: Revert "Revert "Basic functionality is working with JS native support and polyfill, still some issu… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 document_register_basic_test; 5 library document_register_basic_test;
6 import 'package:unittest/unittest.dart'; 6 import 'package:unittest/unittest.dart';
7 import 'package:unittest/html_config.dart'; 7 import 'package:unittest/html_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 import '../utils.dart'; 9 import '../utils.dart';
10 10
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 class BadB { 32 class BadB {
33 } 33 }
34 34
35 class BadE implements HtmlElement { 35 class BadE implements HtmlElement {
36 static final tag = 'x-tag-e'; 36 static final tag = 'x-tag-e';
37 factory BadE() => new Element.tag(tag); 37 factory BadE() => new Element.tag(tag);
38 } 38 }
39 39
40 loadPolyfills() {
41 if (!document.supportsRegister) {
42 // Cache blocker is a workaround for:
43 // https://code.google.com/p/dart/issues/detail?id=11834
44 var cacheBlocker = new DateTime.now().millisecondsSinceEpoch;
45 return HttpRequest.getString('/root_dart/pkg/custom_element/lib/'
46 'custom-elements.debug.js?cacheBlock=$cacheBlocker').then((code) {
47 document.head.children.add(new ScriptElement()..text = code);
48 });
49 }
50 }
51
40 main() { 52 main() {
41 useHtmlConfiguration(); 53 useHtmlConfiguration();
42 54
43 // Adapted from Blink's fast/dom/custom/document-register-basic test. 55 // Adapted from Blink's fast/dom/custom/document-register-basic test.
44 56
57 setUp(loadPolyfills);
58
45 test('Testing document.register() basic behaviors', () { 59 test('Testing document.register() basic behaviors', () {
46 document.register(Foo.tag, Foo); 60 document.register(Foo.tag, Foo);
47 61
48 // Cannot register an existing dart:html type. 62 // Cannot register an existing dart:html type.
49 expect(() => document.register('x-bad-a', HtmlElement), throws); 63 expect(() => document.register('x-bad-a', HtmlElement), throws);
50 64
51 // Invalid user type. Doesn't inherit from HtmlElement. 65 // Invalid user type. Doesn't inherit from HtmlElement.
52 expect(() => document.register('x-bad-b', BadB), throws); 66 expect(() => document.register('x-bad-b', BadB), throws);
53 67
54 // Not a type. 68 // Not a type.
(...skipping 24 matching lines...) Expand all
79 // Native method 93 // Native method
80 var childDiv = new DivElement(); 94 var childDiv = new DivElement();
81 createdFoo.append(childDiv); 95 createdFoo.append(childDiv);
82 expect(createdFoo.lastChild, childDiv); 96 expect(createdFoo.lastChild, childDiv);
83 97
84 // Parser initiated instantiation 98 // Parser initiated instantiation
85 var container = new DivElement()..id = "container"; 99 var container = new DivElement()..id = "container";
86 document.body.append(container); 100 document.body.append(container);
87 container.setInnerHtml("<x-foo></x-foo>", 101 container.setInnerHtml("<x-foo></x-foo>",
88 treeSanitizer: new NullTreeSanitizer()); 102 treeSanitizer: new NullTreeSanitizer());
103 Platform.upgradeCustomElements(container);
89 var parsedFoo = container.firstChild; 104 var parsedFoo = container.firstChild;
90 105
91 expect(parsedFoo is Foo, isTrue); 106 expect(parsedFoo is Foo, isTrue);
92 expect(parsedFoo.tagName, "X-FOO"); 107 expect(parsedFoo.tagName, "X-FOO");
93 108
94 // Ensuring the wrapper is retained 109 // Ensuring the wrapper is retained
95 var someProperty = new Expando(); 110 var someProperty = new Expando();
96 someProperty[parsedFoo] = "hello"; 111 someProperty[parsedFoo] = "hello";
97 expect(container.firstChild, parsedFoo); 112 expect(container.firstChild, parsedFoo);
98 expect(someProperty[container.firstChild], someProperty[parsedFoo]); 113 expect(someProperty[container.firstChild], someProperty[parsedFoo]);
(...skipping 15 matching lines...) Expand all
114 // With irregular cases 129 // With irregular cases
115 var createdUpperBar = new Element.tag("X-BAR"); 130 var createdUpperBar = new Element.tag("X-BAR");
116 var createdMixedBar = new Element.tag("X-Bar"); 131 var createdMixedBar = new Element.tag("X-Bar");
117 expect(createdUpperBar is Bar, isTrue); 132 expect(createdUpperBar is Bar, isTrue);
118 expect(createdUpperBar.tagName, "X-BAR"); 133 expect(createdUpperBar.tagName, "X-BAR");
119 expect(createdMixedBar is Bar, isTrue); 134 expect(createdMixedBar is Bar, isTrue);
120 expect(createdMixedBar.tagName, "X-BAR"); 135 expect(createdMixedBar.tagName, "X-BAR");
121 136
122 container.setInnerHtml("<X-BAR></X-BAR><X-Bar></X-Bar>", 137 container.setInnerHtml("<X-BAR></X-BAR><X-Bar></X-Bar>",
123 treeSanitizer: new NullTreeSanitizer()); 138 treeSanitizer: new NullTreeSanitizer());
139 Platform.upgradeCustomElements(container);
124 expect(container.firstChild is Bar, isTrue); 140 expect(container.firstChild is Bar, isTrue);
125 expect(container.firstChild.tagName, "X-BAR"); 141 expect(container.firstChild.tagName, "X-BAR");
126 expect(container.lastChild is Bar, isTrue); 142 expect(container.lastChild is Bar, isTrue);
127 expect(container.lastChild.tagName, "X-BAR"); 143 expect(container.lastChild.tagName, "X-BAR");
128 144
129 // Constructors shouldn't interfere with each other 145 // Constructors shouldn't interfere with each other
130 expect((new Foo()).tagName, "X-FOO"); 146 expect((new Foo()).tagName, "X-FOO");
131 expect((new Bar()).tagName, "X-BAR"); 147 expect((new Bar()).tagName, "X-BAR");
132 expect((new Baz()).tagName, "X-BAZ"); 148 expect((new Baz()).tagName, "X-BAZ");
133 }); 149 });
134 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698