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

Side by Side Diff: LayoutTests/dart/inspector/utils.dart

Issue 1532413002: Added Dartium changes onto 45.0.2454.104 (Closed) Base URL: http://src.chromium.org/blink/branches/chromium/2454
Patch Set: Created 5 years 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) 2014, 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 /**
6 * Tests for utility class used to extract debugger data defined in
7 * native_DOMImplementation.dart
8 */
9 library utilsTest;
10
11 import 'package:expect/expect.dart';
12 import 'package:unittest/html_config.dart';
13 import 'package:unittest/unittest.dart';
14 import 'dart:html';
15
16 import 'sample_library.dart';
17
18 import 'dart:mirrors';
19
20 /**
21 * Wrapper around the [dart:html] [_Utils] class that lets us invoke its
22 * methods from a different library.
23 */
24 class UtilsWrapper {
25 ClassMirror _receiver;
26
27 UtilsWrapper() {
28 var html = currentMirrorSystem().libraries[Uri.parse('dart:html')];
29 _receiver = html.declarations[MirrorSystem.getSymbol('_Utils', html)];
30 }
31
32 noSuchMethod(Invocation msg) =>
33 _receiver.invoke(msg.memberName,
34 msg.positionalArguments,
35 msg.namedArguments).reflectee;
36 }
37
38 /**
39 * Helper class to convert the packed property structure used by Dartium back
40 * to a more human readable form.
41 */
42 class _Property {
43 _Property(List input, int offset) :
44 name = input[offset],
45 setter = input[offset + 1],
46 getter = input[offset + 2],
47 value = input[offset + 3],
48 hasValue = input[offset + 4],
49 writable = input[offset + 5],
50 isMethod = input[offset + 6],
51 isOwn = input[offset + 7],
52 wasThrown = input[offset + 8];
53
54 final String name;
55 final Function setter;
56 final Function getter;
57 final value;
58 final bool hasValue;
59 final bool writable;
60 final bool isMethod;
61 final bool isOwn;
62 final bool wasThrown;
63 }
64
65 var _Utils = new UtilsWrapper();
66
67 _Property findObjectClassProperty(o, String name) =>
68 findProperty(_Utils.getObjectClassProperties(o, true, false), name);
69
70 _Property findProperty(List properties, String name) {
71 for (int i = 0; i < properties.length; i += 9) {
72 if (properties[i] == name) return new _Property(properties, i);
73 }
74 return null;
75 }
76
77 main() {
78 useHtmlConfiguration(true);
79
80 var sampleLibraryUrl = reflectClass(Foo).owner.uri.toString();
81
82 group('completions', () {
83
84 test('object', () {
85 expect(_Utils.getObjectCompletions(new Foo(), sampleLibraryUrl),
86 orderedEquals(['_fooPrivate1', '_fooPrivate2', 'blaProp', 'field1',
87 'field2', 'hashCode', 'member1', 'member2', 'noSuchMethod',
88 'prop1', 'prop2', 'runtimeType', 'toString']));
89
90 expect(_Utils.getObjectCompletions(new Baz(), sampleLibraryUrl),
91 orderedEquals(['_fooPrivate1', '_fooPrivate2', 'bazField', 'blaProp',
92 'field1', 'field2', 'hashCode', 'member1', 'member2',
93 'noSuchMethod', 'prop1', 'prop2', 'runtimeType', 'toString']));
94
95 // Should not display any privates as a different library is specified.
96 expect(_Utils.getObjectCompletions(new Foo(), 'dart:html'),
97 orderedEquals(['blaProp', 'field1', 'field2', 'hashCode', 'member1',
98 'member2', 'noSuchMethod', 'prop1', 'prop2', 'runtimeType',
99 'toString']));
100
101 expect(_Utils.getObjectCompletions(new Object(), sampleLibraryUrl),
102 orderedEquals(
103 ['hashCode', 'noSuchMethod', 'runtimeType', 'toString']));
104
105 // We don't want to make the test depend on exactly what private members
106 // Object has, or whether mirrors expose any private members.
107 expect(_Utils.getObjectCompletions(new Object(), 'dart:core').length,
108 greaterThanOrEqualTo(4));
109 });
110
111 test('class', () {
112 expect(_Utils.getObjectCompletions(Foo, sampleLibraryUrl),
113 orderedEquals(['namedConstructor1', 'namedFactoryConstructor1',
114 'staticField1', 'staticField2', 'staticMember1']));
115 expect(_Utils.getObjectCompletions(Bar, sampleLibraryUrl),
116 orderedEquals(['barConst1', 'barStaticMethod', 'barStaticProp']));
117 });
118
119 test('library', () {
120 expect(_Utils.getLibraryCompletions('dart:core'),
121 contains('Object'));
122
123 var completions = _Utils.getLibraryCompletions(sampleLibraryUrl);
124 expect(completions, contains('Foo'));
125 expect(completions, contains('exampleStaticMethod'));
126 expect(completions, contains('_examplePrivateStaticMethod'));
127 expect(completions, contains('_exampleProp2'));
128 expect(completions, contains('exampleProp2'));
129 // Contained only in the imported dart:html library.
130 expect(completions, isNot(contains('Node')));
131 expect(completions, isNot(contains('js')));
132
133 completions = _Utils.getLibraryCompletionsIncludingImports(sampleLibraryUr l);
134 expect(completions, contains('Node'));
135 expect(completions, contains('js'));
136 });
137 });
138
139 group('getProperties', () {
140
141 test('treat property as field', () {
142 expect(_Utils.treatPropertyAsField(
143 reflectClass(Foo).declarations[MirrorSystem.getSymbol('prop1')],
144 reflectClass(Foo).owner),
145 isFalse);
146
147 // Insure that dart:html properties are treated as fields.
148 expect(_Utils.treatPropertyAsField(
149 reflectClass(Node).declarations[MirrorSystem.getSymbol('text')],
150 reflectClass(Node).owner),
151 true);
152 });
153
154 test('describe function', () {
155 var b = new Bar();
156 expect(_Utils.describeFunction(b.barMember1), equals('barMember1() => 42;' ));
157 // Invocation trampoline for function barMember1.
158 var barMember1 = findObjectClassProperty(b, 'barMember1').value;
159 expect(_Utils.describeFunction(barMember1), equals('barMember1() => 42;')) ;
160
161 var details = _Utils.getInvocationTrampolineDetails(barMember1);
162 expect(details[0], equals(62)); // Line number.
163 expect(details[1], equals(3)); // Column number.
164 expect(details[2], endsWith('sample_library.dart')); // File name.
165 expect(details[3], equals('barMember1')); // Method name.
166 });
167
168 test('object properties', () {
169 var o = new Bar();
170 var property;
171 var properties = _Utils.getObjectProperties(o, true, false);
172
173 property = findProperty(properties, 'barField1');
174 expect(property.value, equals(9));
175 expect(property.setter, isNull);
176 expect(property.getter, isNull);
177 expect(property.hasValue, isTrue);
178 expect(property.writable, isTrue);
179 expect(property.isMethod, isFalse);
180 expect(property.isOwn, isTrue);
181 expect(property.wasThrown, isFalse);
182
183 property = findProperty(properties, 'barFinalField');
184 expect(property.value, equals(12));
185 expect(property.setter, isNull);
186 expect(property.getter, isNull);
187 expect(property.hasValue, isTrue);
188 expect(property.writable, isFalse);
189 expect(property.isMethod, isFalse);
190 expect(property.isOwn, isTrue);
191 expect(property.wasThrown, isFalse);
192
193 // verify that properties don't show up.
194 expect(findProperty(properties, "barProp1"), isNull);
195
196 properties = _Utils.getObjectClassProperties(o, true, true);
197 property = findProperty(properties, 'barProp1');
198 expect(property.value, isNull);
199 expect(property.setter, isNull);
200 expect(property.getter(), equals('bar1'));
201 expect(property.hasValue, isFalse);
202 expect(property.writable, isFalse);
203 expect(property.isMethod, isFalse);
204 expect(property.isOwn, isTrue);
205 expect(property.wasThrown, isFalse);
206
207 property = findProperty(properties, 'barProp2');
208 expect(property.value, isNull);
209 expect(property.writable, isTrue);
210 expect(property.setter is Function, isTrue);
211 expect(property.getter(), equals(11));
212 property.setter(55);
213 expect(property.getter(), equals(55));
214 expect(property.hasValue, isFalse);
215 expect(property.isMethod, isFalse);
216 expect(property.isOwn, isTrue);
217 expect(property.wasThrown, isFalse);
218 });
219
220 test('class properties', () {
221 var properties = _Utils.getClassProperties(Bar, true, false);
222 var property = findProperty(properties, 'barStaticMethod');
223 expect(property.value(10), equals(30));
224 expect(property.setter, isNull);
225 expect(property.getter, isNull);
226 expect(property.hasValue, isTrue);
227 expect(property.writable, isFalse);
228 expect(property.isMethod, isTrue);
229 expect(property.isOwn, isTrue);
230 expect(property.wasThrown, isFalse);
231
232 property = findProperty(properties, 'barConst1');
233 expect(property.value, equals(9));
234 expect(property.setter, isNull);
235 expect(property.getter, isNull);
236 expect(property.hasValue, isTrue);
237 expect(property.writable, isFalse);
238 expect(property.isMethod, isFalse);
239 expect(property.isOwn, isTrue);
240 expect(property.wasThrown, isFalse);
241
242 properties = _Utils.getClassProperties(Bar, true, true);
243 expect(findProperty(properties, 'barStaticMethod'), isNull);
244
245 property = findProperty(properties, 'barStaticProp');
246 expect(property.value, isNull);
247 expect(property.setter, isNull);
248 expect(property.getter(), equals('staticProp'));
249 expect(property.hasValue, isFalse);
250 expect(property.writable, isFalse);
251 expect(property.isMethod, isFalse);
252 expect(property.isOwn, isTrue);
253 expect(property.wasThrown, isFalse);
254 });
255
256 test('safe get property', () {
257 expect(_Utils.getObjectPropertySafe(new Bar(), "_barProp2"), equals(11));
258 expect(_Utils.getObjectPropertySafe(new Bar(), "_fooPrivate2"), equals(2)) ;
259 });
260
261 test('library properties', () {
262 var properties = _Utils.getLibraryProperties(sampleLibraryUrl, true, false );
263 var property = findProperty(properties, 'exampleStaticMethod');
264 expect(property.value(10), equals(20));
265 expect(property.setter, isNull);
266 expect(property.getter, isNull);
267 expect(property.hasValue, isTrue);
268 expect(property.writable, isFalse);
269 expect(property.isMethod, isTrue);
270 expect(property.isOwn, isTrue);
271 expect(property.wasThrown, isFalse);
272
273 property = findProperty(properties, 'exampleField');
274 expect(property.value, equals(8));
275 expect(property.setter, isNull);
276 expect(property.getter, isNull);
277 expect(property.hasValue, isTrue);
278 expect(property.writable, isTrue);
279 expect(property.isMethod, isFalse);
280 expect(property.isOwn, isTrue);
281 expect(property.wasThrown, isFalse);
282
283 property = findProperty(properties, 'exampleFinalField');
284 expect(property.value, equals(16));
285 expect(property.setter, isNull);
286 expect(property.getter, isNull);
287 expect(property.hasValue, isTrue);
288 expect(property.writable, isFalse);
289 expect(property.isMethod, isFalse);
290 expect(property.isOwn, isTrue);
291 expect(property.wasThrown, isFalse);
292
293 property = findProperty(properties, 'Foo');
294 expect(property.value.toString(), "Foo");
295 expect(property.value is Type, isTrue);
296 expect(property.setter, isNull);
297 expect(property.getter, isNull);
298 expect(property.hasValue, isTrue);
299 expect(property.writable, isFalse);
300 expect(property.isMethod, isFalse);
301 expect(property.isOwn, isTrue);
302 expect(property.wasThrown, isFalse);
303
304 properties = _Utils.getLibraryProperties(sampleLibraryUrl, true, true);
305 property = findProperty(properties, 'exampleProp1');
306 expect(property.value, isNull);
307 expect(property.setter, isNull);
308 expect(property.getter(), equals(30));
309 expect(property.hasValue, isFalse);
310 expect(property.writable, isFalse);
311 expect(property.isMethod, isFalse);
312 expect(property.isOwn, isTrue);
313 expect(property.wasThrown, isFalse);
314
315 property = findProperty(properties, 'exampleProp2');
316 expect(property.value, isNull);
317 expect(property.writable, isTrue);
318 expect(property.setter is Function, isTrue);
319 expect(property.getter(), equals(10));
320 property.setter(20);
321 expect(property.getter(), equals(20));
322 expect(property.hasValue, isFalse);
323 expect(property.isMethod, isFalse);
324 expect(property.isOwn, isTrue);
325 expect(property.wasThrown, isFalse);
326 });
327 });
328 }
OLDNEW
« no previous file with comments | « LayoutTests/dart/inspector/scope-variables-expected.txt ('k') | LayoutTests/dart/inspector/utils.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698