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

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

Issue 25325004: Implementing CustomElement's attributeChanged callback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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/html/dartium/html_dartium.dart ('k') | tests/html/custom/entered_left_view_test.dart » ('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 attribute_changed_callback_test; 5 library attribute_changed_callback_test;
6
7 import 'dart:html';
8 import 'dart:js' as js;
9 import 'package:unittest/html_individual_config.dart';
6 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
7 import 'package:unittest/html_config.dart'; 11 import '../utils.dart';
8 import 'dart:html';
9 12
10 class A extends HtmlElement { 13 class A extends HtmlElement {
11 static final tag = 'x-a'; 14 static final tag = 'x-a';
12 factory A() => new Element.tag(tag); 15 factory A() => new Element.tag(tag);
13 A.created() : super.created(); 16 A.created() : super.created();
14 17
15 static var attributeChangedInvocations = 0; 18 static var attributeChangedInvocations = 0;
16 19
17 void attributeChanged(name, oldValue, newValue) { 20 void attributeChanged(name, oldValue, newValue) {
18 attributeChangedInvocations++; 21 attributeChangedInvocations++;
19 } 22 }
20 } 23 }
21 24
22 class B extends HtmlElement { 25 class B extends HtmlElement {
23 static final tag = 'x-b'; 26 static final tag = 'x-b';
24 factory B() => new Element.tag(tag); 27 factory B() => new Element.tag(tag);
25 B.created() : super.created(); 28 B.created() : super.created();
26 29
27 static var invocations = []; 30 static var invocations = [];
28 31
29 void createdCallback() { 32 void createdCallback() {
30 invocations.add('created'); 33 invocations.add('created');
31 } 34 }
32 35
33 void attributeChanged(name, oldValue, newValue) { 36 void attributeChanged(name, oldValue, newValue) {
34 invocations.add('$name: $oldValue => $newValue'); 37 invocations.add('$name: $oldValue => $newValue');
35 } 38 }
36 } 39 }
37 40
41 // Pump custom events polyfill events.
42 void customElementsTakeRecords() {
43 if (js.context.hasProperty('CustomElements')) {
44 js.context['CustomElements'].callMethod('takeRecords');
45 }
46 }
47
38 main() { 48 main() {
39 useHtmlConfiguration(); 49 useHtmlIndividualConfiguration();
40 50
41 // Adapted from Blink's fast/dom/custom/attribute-changed-callback test. 51 // Adapted from Blink's fast/dom/custom/attribute-changed-callback test.
42 52
43 test('transfer attribute changed callback', () { 53 var registered = false;
44 document.register(A.tag, A); 54 setUp(() {
45 var element = new A(); 55 return loadPolyfills().then((_) {
46 56 if (!registered) {
47 element.attributes['a'] = 'b'; 57 registered = true;
48 expect(A.attributeChangedInvocations, 1); 58 document.register(A.tag, A);
59 document.register(B.tag, B);
60 }
61 });
49 }); 62 });
50 63
51 test('add, change and remove an attribute', () { 64 group('fully supported', () {
52 document.register(B.tag, B); 65 test('transfer attribute changed callback', () {
53 var b = new B(); 66 var element = new A();
54 b.id = 'x';
55 expect(B.invocations, ['created', 'id: null => x']);
56 67
57 B.invocations = []; 68 element.attributes['a'] = 'b';
58 b.attributes.remove('id'); 69 expect(A.attributeChangedInvocations, 1);
59 expect(B.invocations, ['id: x => null']); 70 });
60 71
61 B.invocations = []; 72 test('add, change and remove an attribute', () {
62 b.attributes['data-s'] = 't'; 73 var b = new B();
63 expect(B.invocations, ['data-s: null => t']);
64 74
65 B.invocations = []; 75 B.invocations = [];
66 b.classList.toggle('u'); 76 b.attributes['data-s'] = 't';
67 expect(B.invocations, ['class: null => u']); 77 expect(B.invocations, ['data-s: null => t']);
68 78
69 b.attributes['data-v'] = 'w'; 79 b.attributes['data-v'] = 'w';
70 B.invocations = []; 80 B.invocations = [];
71 b.attributes['data-v'] = 'x'; 81 b.attributes['data-v'] = 'x';
72 expect(B.invocations, ['data-v: w => x']); 82 expect(B.invocations, ['data-v: w => x']);
73 83
74 B.invocations = []; 84 B.invocations = [];
75 b.attributes['data-v'] = 'x'; 85 b.attributes['data-v'] = 'x';
76 expect(B.invocations, []); 86 expect(B.invocations, []);
87
88 b.attributes.remove('data-v');
89 expect(B.invocations, ['data-v: x => null']);
90 });
91 });
92
93 group('unsupported_on_polyfill', () {
94 test('add, change ID', () {
95 var b = new B();
96 b.id = 'x';
97 expect(B.invocations, ['created', 'id: null => x']);
98
99 B.invocations = [];
100 b.attributes.remove('id');
101 expect(B.invocations, ['id: x => null']);
102 });
103
104 test('add, change classes', () {
105 var b = new B();
106
107 B.invocations = [];
108 b.classes.toggle('u');
109 expect(B.invocations, ['class: null => u']);
110 });
77 }); 111 });
78 } 112 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/html/custom/entered_left_view_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698