| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:html'; | |
| 6 import 'package:polymer/polymer.dart'; | |
| 7 import 'package:unittest/unittest.dart'; | |
| 8 import 'package:unittest/html_config.dart'; | |
| 9 | |
| 10 @CustomTag('x-html') | |
| 11 class XHtmlElement extends PolymerElement { | |
| 12 XHtmlElement.created() : super.created(); | |
| 13 } | |
| 14 | |
| 15 @CustomTag('x-html-two') | |
| 16 class XHtml2Element extends XHtmlElement { | |
| 17 XHtml2Element.created() : super.created(); | |
| 18 } | |
| 19 | |
| 20 @CustomTag('x-div') | |
| 21 class XDivElement extends DivElement with Polymer, Observable { | |
| 22 XDivElement.created() : super.created() { | |
| 23 polymerCreated(); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 @CustomTag('x-div-two') | |
| 28 class XDiv2Element extends XDivElement { | |
| 29 XDiv2Element.created() : super.created(); | |
| 30 } | |
| 31 | |
| 32 /// Dart-specific test: | |
| 33 /// This element is registered from code without an associated polymer-element. | |
| 34 class XPolymerElement extends PolymerElement { | |
| 35 XPolymerElement.created() : super.created(); | |
| 36 } | |
| 37 | |
| 38 /// Dart-specific test: | |
| 39 /// This element is registered from code without an associated polymer-element. | |
| 40 class XButtonElement extends ButtonElement with Polymer, Observable { | |
| 41 XButtonElement.created() : super.created() { | |
| 42 polymerCreated(); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 main() => initPolymer().then((zone) => zone.run(() { | |
| 47 useHtmlConfiguration(); | |
| 48 | |
| 49 setUp(() => Polymer.onReady); | |
| 50 | |
| 51 test('elements upgraded', () { | |
| 52 expect(querySelector('x-html') is XHtmlElement, isTrue); | |
| 53 expect(querySelector('x-html-two') is XHtml2Element, isTrue); | |
| 54 expect(querySelector('#x-div') is XDivElement, isTrue); | |
| 55 expect(querySelector('#x-div-two') is XDiv2Element, isTrue); | |
| 56 }); | |
| 57 | |
| 58 group('register without polymer-element', () { | |
| 59 test('custom element', () { | |
| 60 Polymer.registerSync('x-polymer', XPolymerElement, | |
| 61 template: new Element.html('<template>FOOBAR')); | |
| 62 | |
| 63 expect(document.createElement('x-polymer') is XPolymerElement, isTrue, | |
| 64 reason: 'should have been registered'); | |
| 65 | |
| 66 var e = document.querySelector('x-polymer'); | |
| 67 expect(e is XPolymerElement, isTrue, | |
| 68 reason: 'elements on page should be upgraded'); | |
| 69 expect(e.shadowRoot, isNotNull, | |
| 70 reason: 'shadowRoot was created from template'); | |
| 71 expect(e.shadowRoot.nodes[0].text, 'FOOBAR'); | |
| 72 }); | |
| 73 | |
| 74 test('type extension', () { | |
| 75 Polymer.registerSync('x-button', XButtonElement, extendsTag: 'button'); | |
| 76 | |
| 77 expect(document.createElement('button', 'x-button') is XButtonElement, | |
| 78 isTrue, reason: 'should have been registered'); | |
| 79 expect(document.querySelector('[is=x-button]') is XButtonElement, isTrue, | |
| 80 reason: 'elements on page should be upgraded'); | |
| 81 }); | |
| 82 }); | |
| 83 })); | |
| OLD | NEW |