Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 17 matching lines...) Expand all Loading... | |
| 28 static final tag = 'x-baz'; | 28 static final tag = 'x-baz'; |
| 29 factory Baz() => new Element.tag(tag); | 29 factory Baz() => new Element.tag(tag); |
| 30 Baz.created() : super.created(); | 30 Baz.created() : super.created(); |
| 31 | 31 |
| 32 get thisIsAlsoACustomClass => true; | 32 get thisIsAlsoACustomClass => true; |
| 33 } | 33 } |
| 34 | 34 |
| 35 class BadB { | 35 class BadB { |
| 36 } | 36 } |
| 37 | 37 |
| 38 class BadE implements HtmlElement { | 38 abstract class BadC extends HtmlElement { |
| 39 static final tag = 'x-tag-e'; | 39 BadC.created() : super.created(); |
| 40 factory BadE() => new Element.tag(tag); | 40 } |
| 41 | |
| 42 class BadF implements HtmlElement { | |
| 43 static final tag = 'x-tag-f'; | |
| 44 factory BadF() => new Element.tag(tag); | |
| 41 } | 45 } |
| 42 | 46 |
| 43 main() { | 47 main() { |
| 44 useHtmlConfiguration(); | 48 useHtmlConfiguration(); |
| 45 | 49 |
| 46 // Adapted from Blink's fast/dom/custom/document-register-basic test. | 50 // Adapted from Blink's fast/dom/custom/document-register-basic test. |
| 47 | 51 |
| 48 setUp(() => customElementsReady); | 52 setUp(() => customElementsReady); |
| 49 | 53 |
| 50 test('Testing document.registerElement() basic behaviors', () { | 54 test('Testing document.registerElement() basic behaviors', () { |
| 51 document.registerElement(Foo.tag, Foo); | 55 document.registerElement(Foo.tag, Foo); |
| 52 | 56 |
| 53 // Cannot register an existing dart:html type. | 57 // Cannot register an existing dart:html type. |
| 54 expect(() => document.registerElement('x-bad-a', HtmlElement), throws); | 58 expect(() => document.registerElement('x-bad-a', HtmlElement), throws); |
| 55 | 59 |
| 56 // Invalid user type. Doesn't inherit from HtmlElement. | 60 // Invalid user type. Doesn't inherit from HtmlElement. |
| 57 expect(() => document.registerElement('x-bad-b', BadB), throws); | 61 expect(() => document.registerElement('x-bad-b', BadB), throws); |
| 58 | 62 |
| 63 // Cannot register abstract class. | |
| 64 expect(() => document.registerElement('x-bad-c', BadC), throws); | |
|
karlklose
2014/09/09 13:02:22
You could make this a multitest with label OK and
herhut
2014/09/09 13:33:26
Just for the record: It seems this is not supporte
| |
| 65 | |
| 59 // Not a type. | 66 // Not a type. |
| 60 expect(() => document.registerElement('x-bad-c', null), throws); | 67 expect(() => document.registerElement('x-bad-d', null), throws); |
| 61 | 68 |
| 62 // Cannot register system type. | 69 // Cannot register system type. |
| 63 expect(() => document.registerElement('x-bad-d', Object), throws); | 70 expect(() => document.registerElement('x-bad-e', Object), throws); |
| 64 | 71 |
| 65 // Must extend HtmlElement, not just implement it. | 72 // Must extend HtmlElement, not just implement it. |
| 66 expect(() => document.registerElement(BadE.tag, BadE), throws); | 73 expect(() => document.registerElement(BadF.tag, BadF), throws); |
| 67 | 74 |
| 68 // Constructor initiated instantiation | 75 // Constructor initiated instantiation |
| 69 var createdFoo = new Foo(); | 76 var createdFoo = new Foo(); |
| 70 expect(createdFoo.thisIsACustomClass, isTrue); | 77 expect(createdFoo.thisIsACustomClass, isTrue); |
| 71 | 78 |
| 72 // Dart type correctness | 79 // Dart type correctness |
| 73 expect(createdFoo is HtmlElement, isTrue); | 80 expect(createdFoo is HtmlElement, isTrue); |
| 74 expect(createdFoo is Foo, isTrue); | 81 expect(createdFoo is Foo, isTrue); |
| 75 expect(createdFoo.runtimeType, Foo); | 82 expect(createdFoo.runtimeType, Foo); |
| 76 | 83 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 expect(container.firstChild.tagName, "X-BAR"); | 139 expect(container.firstChild.tagName, "X-BAR"); |
| 133 expect(container.lastChild is Bar, isTrue); | 140 expect(container.lastChild is Bar, isTrue); |
| 134 expect(container.lastChild.tagName, "X-BAR"); | 141 expect(container.lastChild.tagName, "X-BAR"); |
| 135 | 142 |
| 136 // Constructors shouldn't interfere with each other | 143 // Constructors shouldn't interfere with each other |
| 137 expect((new Foo()).tagName, "X-FOO"); | 144 expect((new Foo()).tagName, "X-FOO"); |
| 138 expect((new Bar()).tagName, "X-BAR"); | 145 expect((new Bar()).tagName, "X-BAR"); |
| 139 expect((new Baz()).tagName, "X-BAZ"); | 146 expect((new Baz()).tagName, "X-BAZ"); |
| 140 }); | 147 }); |
| 141 } | 148 } |
| OLD | NEW |