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

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

Issue 300393002: Merge DevTools Refactor CL to Blink36 (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/1985
Patch Set: PTAL Created 6 years, 6 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 | « LayoutTests/dart/inspector/scope-variables.html ('k') | LayoutTests/dart/inspector/utils.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 but it is safe to assume that Object will have some private
107 // members.
108 expect(_Utils.getObjectCompletions(new Object(), 'dart:core').length,
109 greaterThan(4));
110 });
111
112 test('class', () {
113 expect(_Utils.getObjectCompletions(Foo, sampleLibraryUrl),
114 orderedEquals(['namedConstructor1', 'namedFactoryConstructor1',
115 'staticField1', 'staticField2', 'staticMember1']));
116 expect(_Utils.getObjectCompletions(Bar, sampleLibraryUrl),
117 orderedEquals(['barConst1', 'barStaticMethod', 'barStaticProp']));
118 });
119
120 test('library', () {
121 expect(_Utils.getLibraryCompletions('dart:core'),
122 contains('Object'));
123
124 var completions = _Utils.getLibraryCompletions(sampleLibraryUrl);
125 expect(completions, contains('Foo'));
126 expect(completions, contains('exampleStaticMethod'));
127 expect(completions, contains('_examplePrivateStaticMethod'));
128 expect(completions, contains('_exampleProp2'));
129 expect(completions, contains('exampleProp2'));
130 // Contained only in the imported dart:html library.
131 expect(completions, isNot(contains('Node')));
132 expect(completions, isNot(contains('js')));
133
134 completions = _Utils.getLibraryCompletionsIncludingImports(sampleLibraryUr l);
135 expect(completions, contains('Node'));
136 expect(completions, contains('js'));
137 });
138 });
139
140 group('getProperties', () {
141
142 test('treat property as field', () {
143 expect(_Utils.treatPropertyAsField(
144 reflectClass(Foo).declarations[MirrorSystem.getSymbol('prop1')],
145 reflectClass(Foo).owner),
146 isFalse);
147
148 // Insure that dart:html properties are treated as fields.
149 expect(_Utils.treatPropertyAsField(
150 reflectClass(Node).declarations[MirrorSystem.getSymbol('text')],
151 reflectClass(Node).owner),
152 true);
153 });
154
155 test('describe function', () {
156 var b = new Bar();
157 expect(_Utils.describeFunction(b.barMember1), equals('barMember1() => 42;' ));
158 // Invocation trampoline for function barMember1.
159 var barMember1 = findObjectClassProperty(b, 'barMember1').value;
160 expect(_Utils.describeFunction(barMember1), equals('barMember1() => 42;')) ;
161
162 var details = _Utils.getInvocationTrampolineDetails(barMember1);
163 expect(details[0], equals(62)); // Line number.
164 expect(details[1], equals(3)); // Column number.
165 expect(details[2], endsWith('sample_library.dart')); // File name.
166 expect(details[3], equals('barMember1')); // Method name.
167 });
168
169 test('object properties', () {
170 var o = new Bar();
171 var property;
172 var properties = _Utils.getObjectProperties(o, true, false);
173
174 property = findProperty(properties, 'barField1');
175 expect(property.value, equals(9));
176 expect(property.setter, isNull);
177 expect(property.getter, isNull);
178 expect(property.hasValue, isTrue);
179 expect(property.writable, isTrue);
180 expect(property.isMethod, isFalse);
181 expect(property.isOwn, isTrue);
182 expect(property.wasThrown, isFalse);
183
184 property = findProperty(properties, 'barFinalField');
185 expect(property.value, equals(12));
186 expect(property.setter, isNull);
187 expect(property.getter, isNull);
188 expect(property.hasValue, isTrue);
189 expect(property.writable, isFalse);
190 expect(property.isMethod, isFalse);
191 expect(property.isOwn, isTrue);
192 expect(property.wasThrown, isFalse);
193
194 // verify that properties don't show up.
195 expect(findProperty(properties, "barProp1"), isNull);
196
197 properties = _Utils.getObjectClassProperties(o, true, true);
198 property = findProperty(properties, 'barProp1');
199 expect(property.value, isNull);
200 expect(property.setter, isNull);
201 expect(property.getter(), equals('bar1'));
202 expect(property.hasValue, isFalse);
203 expect(property.writable, isFalse);
204 expect(property.isMethod, isFalse);
205 expect(property.isOwn, isTrue);
206 expect(property.wasThrown, isFalse);
207
208 property = findProperty(properties, 'barProp2');
209 expect(property.value, isNull);
210 expect(property.writable, isTrue);
211 expect(property.setter is Function, isTrue);
212 expect(property.getter(), equals(11));
213 property.setter(55);
214 expect(property.getter(), equals(55));
215 expect(property.hasValue, isFalse);
216 expect(property.isMethod, isFalse);
217 expect(property.isOwn, isTrue);
218 expect(property.wasThrown, isFalse);
219 });
220
221 test('class properties', () {
222 var properties = _Utils.getClassProperties(Bar, true, false);
223 var property = findProperty(properties, 'barStaticMethod');
224 expect(property.value(10), equals(30));
225 expect(property.setter, isNull);
226 expect(property.getter, isNull);
227 expect(property.hasValue, isTrue);
228 expect(property.writable, isFalse);
229 expect(property.isMethod, isTrue);
230 expect(property.isOwn, isTrue);
231 expect(property.wasThrown, isFalse);
232
233 property = findProperty(properties, 'barConst1');
234 expect(property.value, equals(9));
235 expect(property.setter, isNull);
236 expect(property.getter, isNull);
237 expect(property.hasValue, isTrue);
238 expect(property.writable, isFalse);
239 expect(property.isMethod, isFalse);
240 expect(property.isOwn, isTrue);
241 expect(property.wasThrown, isFalse);
242
243 properties = _Utils.getClassProperties(Bar, true, true);
244 expect(findProperty(properties, 'barStaticMethod'), isNull);
245
246 property = findProperty(properties, 'barStaticProp');
247 expect(property.value, isNull);
248 expect(property.setter, isNull);
249 expect(property.getter(), equals('staticProp'));
250 expect(property.hasValue, isFalse);
251 expect(property.writable, isFalse);
252 expect(property.isMethod, isFalse);
253 expect(property.isOwn, isTrue);
254 expect(property.wasThrown, isFalse);
255 });
256
257 test('safe get property', () {
258 expect(_Utils.getObjectPropertySafe(new Bar(), "_barProp2"), equals(11));
259 expect(_Utils.getObjectPropertySafe(new Bar(), "_fooPrivate2"), equals(2)) ;
260 });
261
262 test('library properties', () {
263 var properties = _Utils.getLibraryProperties(sampleLibraryUrl, true, false );
264 var property = findProperty(properties, 'exampleStaticMethod');
265 expect(property.value(10), equals(20));
266 expect(property.setter, isNull);
267 expect(property.getter, isNull);
268 expect(property.hasValue, isTrue);
269 expect(property.writable, isFalse);
270 expect(property.isMethod, isTrue);
271 expect(property.isOwn, isTrue);
272 expect(property.wasThrown, isFalse);
273
274 property = findProperty(properties, 'exampleField');
275 expect(property.value, equals(8));
276 expect(property.setter, isNull);
277 expect(property.getter, isNull);
278 expect(property.hasValue, isTrue);
279 expect(property.writable, isTrue);
280 expect(property.isMethod, isFalse);
281 expect(property.isOwn, isTrue);
282 expect(property.wasThrown, isFalse);
283
284 property = findProperty(properties, 'exampleFinalField');
285 expect(property.value, equals(16));
286 expect(property.setter, isNull);
287 expect(property.getter, isNull);
288 expect(property.hasValue, isTrue);
289 expect(property.writable, isFalse);
290 expect(property.isMethod, isFalse);
291 expect(property.isOwn, isTrue);
292 expect(property.wasThrown, isFalse);
293
294 property = findProperty(properties, 'Foo');
295 expect(property.value.toString(), "Foo");
296 expect(property.value is Type, isTrue);
297 expect(property.setter, isNull);
298 expect(property.getter, isNull);
299 expect(property.hasValue, isTrue);
300 expect(property.writable, isFalse);
301 expect(property.isMethod, isFalse);
302 expect(property.isOwn, isTrue);
303 expect(property.wasThrown, isFalse);
304
305 properties = _Utils.getLibraryProperties(sampleLibraryUrl, true, true);
306 property = findProperty(properties, 'exampleProp1');
307 expect(property.value, isNull);
308 expect(property.setter, isNull);
309 expect(property.getter(), equals(30));
310 expect(property.hasValue, isFalse);
311 expect(property.writable, isFalse);
312 expect(property.isMethod, isFalse);
313 expect(property.isOwn, isTrue);
314 expect(property.wasThrown, isFalse);
315
316 property = findProperty(properties, 'exampleProp2');
317 expect(property.value, isNull);
318 expect(property.writable, isTrue);
319 expect(property.setter is Function, isTrue);
320 expect(property.getter(), equals(10));
321 property.setter(20);
322 expect(property.getter(), equals(20));
323 expect(property.hasValue, isFalse);
324 expect(property.isMethod, isFalse);
325 expect(property.isOwn, isTrue);
326 expect(property.wasThrown, isFalse);
327 });
328 });
329 }
OLDNEW
« no previous file with comments | « LayoutTests/dart/inspector/scope-variables.html ('k') | LayoutTests/dart/inspector/utils.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698