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

Side by Side Diff: test/codegen/lib/html/custom/attribute_changed_callback_test.dart

Issue 1930043002: Add all dart:html tests from the sdk to test/codegen. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 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
OLDNEW
(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 library attribute_changed_callback_test;
6
7 import 'dart:async';
8 import 'dart:html';
9 import 'dart:js' as js;
10 import 'package:unittest/html_individual_config.dart';
11 import 'package:unittest/unittest.dart';
12 import '../utils.dart';
13
14 class A extends HtmlElement {
15 static final tag = 'x-a';
16 factory A() => new Element.tag(tag);
17 A.created() : super.created();
18
19 static var attributeChangedInvocations = 0;
20
21 void attributeChanged(name, oldValue, newValue) {
22 attributeChangedInvocations++;
23 }
24 }
25
26 class B extends HtmlElement {
27 static final tag = 'x-b';
28 factory B() => new Element.tag(tag);
29 B.created() : super.created() {
30 invocations.add('created');
31 }
32
33 static var invocations = [];
34
35 Completer completer;
36
37 void attributeChanged(name, oldValue, newValue) {
38 invocations.add('$name: $oldValue => $newValue');
39 if (completer != null) {
40 completer.complete('value changed to $newValue');
41 completer = null;
42 }
43 }
44 }
45
46 // Pump custom events polyfill events.
47 void customElementsTakeRecords() {
48 if (js.context.hasProperty('CustomElements')) {
49 js.context['CustomElements'].callMethod('takeRecords');
50 }
51 }
52
53 main() {
54 useHtmlIndividualConfiguration();
55
56 // Adapted from Blink's fast/dom/custom/attribute-changed-callback test.
57
58 var registered = false;
59 setUp(() => customElementsReady.then((_) {
60 if (!registered) {
61 registered = true;
62 document.registerElement(A.tag, A);
63 document.registerElement(B.tag, B);
64 }
65 }));
66
67 group('fully_supported', () {
68 test('transfer attribute changed callback', () {
69 var element = new A();
70
71 element.attributes['a'] = 'b';
72 expect(A.attributeChangedInvocations, 1);
73 });
74
75 test('add, change and remove an attribute', () {
76 var b = new B();
77
78 B.invocations = [];
79 b.attributes['data-s'] = 't';
80 expect(B.invocations, ['data-s: null => t']);
81
82 b.attributes['data-v'] = 'w';
83 B.invocations = [];
84 b.attributes['data-v'] = 'x';
85 expect(B.invocations, ['data-v: w => x']);
86
87 B.invocations = [];
88 b.attributes['data-v'] = 'x';
89 expect(B.invocations, []);
90
91 b.attributes.remove('data-v');
92 expect(B.invocations, ['data-v: x => null']);
93 });
94
95 test('add, change ID', () {
96 B.invocations = [];
97
98 var b = new B();
99 var completer = new Completer();
100 b.completer = completer;
101 b.id = 'x';
102 return completer.future
103 .then((_) => expect(B.invocations, ['created', 'id: null => x']))
104 .then((_) {
105 B.invocations = [];
106 var secondCompleter = new Completer();
107 b.completer = secondCompleter;
108 b.attributes.remove('id');
109 return secondCompleter.future;
110 })
111 .then((_) => expect(B.invocations, ['id: x => null']));
112 });
113 });
114
115 group('unsupported_on_polyfill', () {
116
117 // If these tests start passing, don't remove the status suppression. Move
118 // the tests to the fullYy_supported group.
119
120 test('add, change classes', () {
121 var b = new B();
122
123 B.invocations = [];
124 b.classes.toggle('u');
125 expect(B.invocations, ['class: null => u']);
126 });
127 });
128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698