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

Side by Side Diff: tests/html/utils.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
1 library TestUtils; 1 library TestUtils;
2 2
3 import 'dart:async'; 3 import 'dart:async';
4 import 'dart:html'; 4 import 'dart:html';
5 import 'dart:js' as js; 5 import 'dart:js' as js;
6 import 'dart:typed_data'; 6 import 'dart:typed_data';
7 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
8 export 'package:web_components/polyfill.dart'; 8 export 'package:web_components/polyfill.dart';
9 9
10 /** 10 /**
(...skipping 26 matching lines...) Expand all
37 if (identical(actual, aItems[i])) { 37 if (identical(actual, aItems[i])) {
38 expect(expected, same(eItems[i]), 38 expect(expected, same(eItems[i]),
39 reason: message(path, 'extra back or side edge')); 39 reason: message(path, 'extra back or side edge'));
40 return; 40 return;
41 } 41 }
42 } 42 }
43 eItems.add(expected); 43 eItems.add(expected);
44 aItems.add(actual); 44 aItems.add(actual);
45 45
46 if (expected is Blob) { 46 if (expected is Blob) {
47 expect(actual is Blob, isTrue, 47 expect(actual is Blob, isTrue, reason: '$actual is Blob');
48 reason: '$actual is Blob');
49 expect(expected.type, equals(actual.type), 48 expect(expected.type, equals(actual.type),
50 reason: message(path, '.type')); 49 reason: message(path, '.type'));
51 expect(expected.size, equals(actual.size), 50 expect(expected.size, equals(actual.size),
52 reason: message(path, '.size')); 51 reason: message(path, '.size'));
53 return; 52 return;
54 } 53 }
55 54
56 if (expected is ByteBuffer) { 55 if (expected is ByteBuffer) {
57 expect(actual is ByteBuffer, isTrue, 56 expect(actual is ByteBuffer, isTrue, reason: '$actual is ByteBuffer');
58 reason: '$actual is ByteBuffer');
59 expect(expected.lengthInBytes, equals(actual.lengthInBytes), 57 expect(expected.lengthInBytes, equals(actual.lengthInBytes),
60 reason: message(path, '.lengthInBytes')); 58 reason: message(path, '.lengthInBytes'));
61 // TODO(antonm): one can create a view on top of those 59 // TODO(antonm): one can create a view on top of those
62 // and check if contents identical. Let's do it later. 60 // and check if contents identical. Let's do it later.
63 return; 61 return;
64 } 62 }
65 63
66 if (expected is DateTime) { 64 if (expected is DateTime) {
67 expect(actual is DateTime, isTrue, 65 expect(actual is DateTime, isTrue, reason: '$actual is DateTime');
68 reason: '$actual is DateTime');
69 expect(expected.millisecondsSinceEpoch, 66 expect(expected.millisecondsSinceEpoch,
70 equals(actual.millisecondsSinceEpoch), 67 equals(actual.millisecondsSinceEpoch),
71 reason: message(path, '.millisecondsSinceEpoch')); 68 reason: message(path, '.millisecondsSinceEpoch'));
72 return; 69 return;
73 } 70 }
74 71
75 if (expected is ImageData) { 72 if (expected is ImageData) {
76 expect(actual is ImageData, isTrue, 73 expect(actual is ImageData, isTrue, reason: '$actual is ImageData');
77 reason: '$actual is ImageData');
78 expect(expected.width, equals(actual.width), 74 expect(expected.width, equals(actual.width),
79 reason: message(path, '.width')); 75 reason: message(path, '.width'));
80 expect(expected.height, equals(actual.height), 76 expect(expected.height, equals(actual.height),
81 reason: message(path, '.height')); 77 reason: message(path, '.height'));
82 walk('$path.data', expected.data, actual.data); 78 walk('$path.data', expected.data, actual.data);
83 return; 79 return;
84 } 80 }
85 81
86 if (expected is TypedData) { 82 if (expected is TypedData) {
87 expect(actual is TypedData, isTrue, 83 expect(actual is TypedData, isTrue, reason: '$actual is TypedData');
88 reason: '$actual is TypedData');
89 walk('$path/.buffer', expected.buffer, actual.buffer); 84 walk('$path/.buffer', expected.buffer, actual.buffer);
90 expect(expected.offsetInBytes, equals(actual.offsetInBytes), 85 expect(expected.offsetInBytes, equals(actual.offsetInBytes),
91 reason: message(path, '.offsetInBytes')); 86 reason: message(path, '.offsetInBytes'));
92 expect(expected.lengthInBytes, equals(actual.lengthInBytes), 87 expect(expected.lengthInBytes, equals(actual.lengthInBytes),
93 reason: message(path, '.lengthInBytes')); 88 reason: message(path, '.lengthInBytes'));
94 // And also fallback to elements check below. 89 // And also fallback to elements check below.
95 } 90 }
96 91
97 if (expected is List) { 92 if (expected is List) {
98 expect(actual, isList, reason: message(path, '$actual is List')); 93 expect(actual, isList, reason: message(path, '$actual is List'));
99 expect(actual.length, expected.length, 94 expect(actual.length, expected.length,
100 reason: message(path, 'different list lengths')); 95 reason: message(path, 'different list lengths'));
101 for (var i = 0; i < expected.length; i++) { 96 for (var i = 0; i < expected.length; i++) {
102 walk('$path[$i]', expected[i], actual[i]); 97 walk('$path[$i]', expected[i], actual[i]);
103 } 98 }
104 return; 99 return;
105 } 100 }
106 101
107 if (expected is Map) { 102 if (expected is Map) {
108 expect(actual, isMap, reason: message(path, '$actual is Map')); 103 expect(actual, isMap, reason: message(path, '$actual is Map'));
109 for (var key in expected.keys) { 104 for (var key in expected.keys) {
110 if (!actual.containsKey(key)) { 105 if (!actual.containsKey(key)) {
111 expect(false, isTrue, reason: message(path, 'missing key "$key"')); 106 expect(false, isTrue, reason: message(path, 'missing key "$key"'));
112 } 107 }
113 walk('$path["$key"]', expected[key], actual[key]); 108 walk('$path["$key"]', expected[key], actual[key]);
114 } 109 }
115 for (var key in actual.keys) { 110 for (var key in actual.keys) {
116 if (!expected.containsKey(key)) { 111 if (!expected.containsKey(key)) {
117 expect(false, isTrue, reason: message(path, 'extra key "$key"')); 112 expect(false, isTrue, reason: message(path, 'extra key "$key"'));
118 } 113 }
119 } 114 }
120 return; 115 return;
121 } 116 }
122 117
123 expect(false, isTrue, reason: 'Unhandled type: $expected'); 118 expect(false, isTrue, reason: 'Unhandled type: $expected');
124 } 119 }
125 120
126 walk('', expected, actual); 121 walk('', expected, actual);
127 } 122 }
128 123
129
130 /** 124 /**
131 * Sanitizer which does nothing. 125 * Sanitizer which does nothing.
132 */ 126 */
133 class NullTreeSanitizer implements NodeTreeSanitizer { 127 class NullTreeSanitizer implements NodeTreeSanitizer {
134 void sanitizeTree(Node node) {} 128 void sanitizeTree(Node node) {}
135 } 129 }
136 130
137
138 /** 131 /**
139 * Validate that two DOM trees are equivalent. 132 * Validate that two DOM trees are equivalent.
140 */ 133 */
141 void validateNodeTree(Node a, Node b, [String path = '']) { 134 void validateNodeTree(Node a, Node b, [String path = '']) {
142 path = '${path}${a.runtimeType}'; 135 path = '${path}${a.runtimeType}';
143 expect(a.nodeType, b.nodeType, reason: '$path nodeTypes differ'); 136 expect(a.nodeType, b.nodeType, reason: '$path nodeTypes differ');
144 expect(a.nodeValue, b.nodeValue, reason: '$path nodeValues differ'); 137 expect(a.nodeValue, b.nodeValue, reason: '$path nodeValues differ');
145 expect(a.text, b.text, reason: '$path texts differ'); 138 expect(a.text, b.text, reason: '$path texts differ');
146 expect(a.nodes.length, b.nodes.length, reason: '$path nodes.lengths differ'); 139 expect(a.nodes.length, b.nodes.length, reason: '$path nodes.lengths differ');
147 140
(...skipping 19 matching lines...) Expand all
167 * 160 *
168 * This is needed to cover timing scenarios which the custom element polyfill 161 * This is needed to cover timing scenarios which the custom element polyfill
169 * does not cover. 162 * does not cover.
170 */ 163 */
171 void upgradeCustomElements(Node node) { 164 void upgradeCustomElements(Node node) {
172 if (js.context.hasProperty('CustomElements') && 165 if (js.context.hasProperty('CustomElements') &&
173 js.context['CustomElements'].hasProperty('upgradeAll')) { 166 js.context['CustomElements'].hasProperty('upgradeAll')) {
174 js.context['CustomElements'].callMethod('upgradeAll', [node]); 167 js.context['CustomElements'].callMethod('upgradeAll', [node]);
175 } 168 }
176 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698