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

Side by Side Diff: pkg/polymer/test/register_test.dart

Issue 290113002: [polymer] add a new API to create an element without polymer-element in HTML (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 | « pkg/polymer/lib/src/instance.dart ('k') | pkg/polymer/test/register_test.html » ('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 import 'dart:html'; 5 import 'dart:html';
6 import 'package:polymer/polymer.dart';
6 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
7 import 'package:unittest/html_config.dart'; 8 import 'package:unittest/html_config.dart';
8 import 'package:polymer/polymer.dart';
9 9
10 @CustomTag('x-html') 10 @CustomTag('x-html')
11 class XHtmlElement extends PolymerElement { 11 class XHtmlElement extends PolymerElement {
12 XHtmlElement.created() : super.created(); 12 XHtmlElement.created() : super.created();
13 } 13 }
14 14
15 @CustomTag('x-html-two') 15 @CustomTag('x-html-two')
16 class XHtml2Element extends XHtmlElement { 16 class XHtml2Element extends XHtmlElement {
17 XHtml2Element.created() : super.created(); 17 XHtml2Element.created() : super.created();
18 } 18 }
19 19
20 @CustomTag('x-div') 20 @CustomTag('x-div')
21 class XDivElement extends DivElement with Polymer, Observable { 21 class XDivElement extends DivElement with Polymer, Observable {
22 XDivElement.created() : super.created(); 22 XDivElement.created() : super.created();
23 } 23 }
24 24
25 @CustomTag('x-div-two') 25 @CustomTag('x-div-two')
26 class XDiv2Element extends XDivElement { 26 class XDiv2Element extends XDivElement {
27 XDiv2Element.created() : super.created(); 27 XDiv2Element.created() : super.created();
28 } 28 }
29 29
30 /// Dart-specific test:
31 /// This element is registered from code without an associated polymer-element.
32 class XPolymerElement extends PolymerElement {
33 XPolymerElement.created() : super.created();
34 }
35
36 /// Dart-specific test:
37 /// This element is registered from code without an associated polymer-element.
38 class XButtonElement extends ButtonElement with Polymer, Observable {
39 XButtonElement.created() : super.created();
40 }
41
42
30 @initMethod 43 @initMethod
31 main() { 44 main() {
32 useHtmlConfiguration(); 45 useHtmlConfiguration();
33 46
34 setUp(() => Polymer.onReady); 47 setUp(() => Polymer.onReady);
35 48
36 test('elements upgraded', () { 49 test('elements upgraded', () {
37 expect(querySelector('x-html') is XHtmlElement, isTrue); 50 expect(querySelector('x-html') is XHtmlElement, isTrue);
38 expect(querySelector('x-html-two') is XHtml2Element, isTrue); 51 expect(querySelector('x-html-two') is XHtml2Element, isTrue);
39 expect(querySelector('#x-div') is XDivElement, isTrue); 52 expect(querySelector('#x-div') is XDivElement, isTrue);
40 expect(querySelector('#x-div-two') is XDiv2Element, isTrue); 53 expect(querySelector('#x-div-two') is XDiv2Element, isTrue);
41 }); 54 });
55
56 group('register without polymer-element', () {
57 test('custom element', () {
58 Polymer.registerSync('x-polymer', XPolymerElement,
59 template: new Element.html('<template>FOOBAR'));
60
61 expect(document.createElement('x-polymer') is XPolymerElement, isTrue,
62 reason: 'should have been registered');
63
64 var e = document.querySelector('x-polymer');
65 expect(e is XPolymerElement, isTrue,
66 reason: 'elements on page should be upgraded');
67 expect(e.shadowRoot, isNotNull,
68 reason: 'shadowRoot was created from template');
69 expect(e.shadowRoot.nodes[0].text, 'FOOBAR');
70 });
71
72 test('type extension', () {
73 Polymer.registerSync('x-button', XButtonElement, extendsTag: 'button');
74
75 expect(document.createElement('button', 'x-button') is XButtonElement,
76 isTrue, reason: 'should have been registered');
77 expect(document.querySelector('[is=x-button]') is XButtonElement, isTrue,
78 reason: 'elements on page should be upgraded');
79 });
80 });
42 } 81 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/polymer/test/register_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698