| Index: LayoutTests/dart/inspector/utils.dart
|
| diff --git a/LayoutTests/dart/inspector/utils.dart b/LayoutTests/dart/inspector/utils.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d5c001e6644118e152bc7b76b52e501906002d84
|
| --- /dev/null
|
| +++ b/LayoutTests/dart/inspector/utils.dart
|
| @@ -0,0 +1,328 @@
|
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +/**
|
| + * Tests for utility class used to extract debugger data defined in
|
| + * native_DOMImplementation.dart
|
| + */
|
| +library utilsTest;
|
| +
|
| +import 'package:expect/expect.dart';
|
| +import 'package:unittest/html_config.dart';
|
| +import 'package:unittest/unittest.dart';
|
| +import 'dart:html';
|
| +
|
| +import 'sample_library.dart';
|
| +
|
| +import 'dart:mirrors';
|
| +
|
| +/**
|
| + * Wrapper around the [dart:html] [_Utils] class that lets us invoke its
|
| + * methods from a different library.
|
| + */
|
| +class UtilsWrapper {
|
| + ClassMirror _receiver;
|
| +
|
| + UtilsWrapper() {
|
| + var html = currentMirrorSystem().libraries[Uri.parse('dart:html')];
|
| + _receiver = html.declarations[MirrorSystem.getSymbol('_Utils', html)];
|
| + }
|
| +
|
| + noSuchMethod(Invocation msg) =>
|
| + _receiver.invoke(msg.memberName,
|
| + msg.positionalArguments,
|
| + msg.namedArguments).reflectee;
|
| +}
|
| +
|
| +/**
|
| + * Helper class to convert the packed property structure used by Dartium back
|
| + * to a more human readable form.
|
| + */
|
| +class _Property {
|
| + _Property(List input, int offset) :
|
| + name = input[offset],
|
| + setter = input[offset + 1],
|
| + getter = input[offset + 2],
|
| + value = input[offset + 3],
|
| + hasValue = input[offset + 4],
|
| + writable = input[offset + 5],
|
| + isMethod = input[offset + 6],
|
| + isOwn = input[offset + 7],
|
| + wasThrown = input[offset + 8];
|
| +
|
| + final String name;
|
| + final Function setter;
|
| + final Function getter;
|
| + final value;
|
| + final bool hasValue;
|
| + final bool writable;
|
| + final bool isMethod;
|
| + final bool isOwn;
|
| + final bool wasThrown;
|
| +}
|
| +
|
| +var _Utils = new UtilsWrapper();
|
| +
|
| +_Property findObjectClassProperty(o, String name) =>
|
| + findProperty(_Utils.getObjectClassProperties(o, true, false), name);
|
| +
|
| +_Property findProperty(List properties, String name) {
|
| + for (int i = 0; i < properties.length; i += 9) {
|
| + if (properties[i] == name) return new _Property(properties, i);
|
| + }
|
| + return null;
|
| +}
|
| +
|
| +main() {
|
| + useHtmlConfiguration(true);
|
| +
|
| + var sampleLibraryUrl = reflectClass(Foo).owner.uri.toString();
|
| +
|
| + group('completions', () {
|
| +
|
| + test('object', () {
|
| + expect(_Utils.getObjectCompletions(new Foo(), sampleLibraryUrl),
|
| + orderedEquals(['_fooPrivate1', '_fooPrivate2', 'blaProp', 'field1',
|
| + 'field2', 'hashCode', 'member1', 'member2', 'noSuchMethod',
|
| + 'prop1', 'prop2', 'runtimeType', 'toString']));
|
| +
|
| + expect(_Utils.getObjectCompletions(new Baz(), sampleLibraryUrl),
|
| + orderedEquals(['_fooPrivate1', '_fooPrivate2', 'bazField', 'blaProp',
|
| + 'field1', 'field2', 'hashCode', 'member1', 'member2',
|
| + 'noSuchMethod', 'prop1', 'prop2', 'runtimeType', 'toString']));
|
| +
|
| + // Should not display any privates as a different library is specified.
|
| + expect(_Utils.getObjectCompletions(new Foo(), 'dart:html'),
|
| + orderedEquals(['blaProp', 'field1', 'field2', 'hashCode', 'member1',
|
| + 'member2', 'noSuchMethod', 'prop1', 'prop2', 'runtimeType',
|
| + 'toString']));
|
| +
|
| + expect(_Utils.getObjectCompletions(new Object(), sampleLibraryUrl),
|
| + orderedEquals(
|
| + ['hashCode', 'noSuchMethod', 'runtimeType', 'toString']));
|
| +
|
| + // We don't want to make the test depend on exactly what private members
|
| + // Object has, or whether mirrors expose any private members.
|
| + expect(_Utils.getObjectCompletions(new Object(), 'dart:core').length,
|
| + greaterThanOrEqualTo(4));
|
| + });
|
| +
|
| + test('class', () {
|
| + expect(_Utils.getObjectCompletions(Foo, sampleLibraryUrl),
|
| + orderedEquals(['namedConstructor1', 'namedFactoryConstructor1',
|
| + 'staticField1', 'staticField2', 'staticMember1']));
|
| + expect(_Utils.getObjectCompletions(Bar, sampleLibraryUrl),
|
| + orderedEquals(['barConst1', 'barStaticMethod', 'barStaticProp']));
|
| + });
|
| +
|
| + test('library', () {
|
| + expect(_Utils.getLibraryCompletions('dart:core'),
|
| + contains('Object'));
|
| +
|
| + var completions = _Utils.getLibraryCompletions(sampleLibraryUrl);
|
| + expect(completions, contains('Foo'));
|
| + expect(completions, contains('exampleStaticMethod'));
|
| + expect(completions, contains('_examplePrivateStaticMethod'));
|
| + expect(completions, contains('_exampleProp2'));
|
| + expect(completions, contains('exampleProp2'));
|
| + // Contained only in the imported dart:html library.
|
| + expect(completions, isNot(contains('Node')));
|
| + expect(completions, isNot(contains('js')));
|
| +
|
| + completions = _Utils.getLibraryCompletionsIncludingImports(sampleLibraryUrl);
|
| + expect(completions, contains('Node'));
|
| + expect(completions, contains('js'));
|
| + });
|
| + });
|
| +
|
| + group('getProperties', () {
|
| +
|
| + test('treat property as field', () {
|
| + expect(_Utils.treatPropertyAsField(
|
| + reflectClass(Foo).declarations[MirrorSystem.getSymbol('prop1')],
|
| + reflectClass(Foo).owner),
|
| + isFalse);
|
| +
|
| + // Insure that dart:html properties are treated as fields.
|
| + expect(_Utils.treatPropertyAsField(
|
| + reflectClass(Node).declarations[MirrorSystem.getSymbol('text')],
|
| + reflectClass(Node).owner),
|
| + true);
|
| + });
|
| +
|
| + test('describe function', () {
|
| + var b = new Bar();
|
| + expect(_Utils.describeFunction(b.barMember1), equals('barMember1() => 42;'));
|
| + // Invocation trampoline for function barMember1.
|
| + var barMember1 = findObjectClassProperty(b, 'barMember1').value;
|
| + expect(_Utils.describeFunction(barMember1), equals('barMember1() => 42;'));
|
| +
|
| + var details = _Utils.getInvocationTrampolineDetails(barMember1);
|
| + expect(details[0], equals(62)); // Line number.
|
| + expect(details[1], equals(3)); // Column number.
|
| + expect(details[2], endsWith('sample_library.dart')); // File name.
|
| + expect(details[3], equals('barMember1')); // Method name.
|
| + });
|
| +
|
| + test('object properties', () {
|
| + var o = new Bar();
|
| + var property;
|
| + var properties = _Utils.getObjectProperties(o, true, false);
|
| +
|
| + property = findProperty(properties, 'barField1');
|
| + expect(property.value, equals(9));
|
| + expect(property.setter, isNull);
|
| + expect(property.getter, isNull);
|
| + expect(property.hasValue, isTrue);
|
| + expect(property.writable, isTrue);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + property = findProperty(properties, 'barFinalField');
|
| + expect(property.value, equals(12));
|
| + expect(property.setter, isNull);
|
| + expect(property.getter, isNull);
|
| + expect(property.hasValue, isTrue);
|
| + expect(property.writable, isFalse);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + // verify that properties don't show up.
|
| + expect(findProperty(properties, "barProp1"), isNull);
|
| +
|
| + properties = _Utils.getObjectClassProperties(o, true, true);
|
| + property = findProperty(properties, 'barProp1');
|
| + expect(property.value, isNull);
|
| + expect(property.setter, isNull);
|
| + expect(property.getter(), equals('bar1'));
|
| + expect(property.hasValue, isFalse);
|
| + expect(property.writable, isFalse);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + property = findProperty(properties, 'barProp2');
|
| + expect(property.value, isNull);
|
| + expect(property.writable, isTrue);
|
| + expect(property.setter is Function, isTrue);
|
| + expect(property.getter(), equals(11));
|
| + property.setter(55);
|
| + expect(property.getter(), equals(55));
|
| + expect(property.hasValue, isFalse);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| + });
|
| +
|
| + test('class properties', () {
|
| + var properties = _Utils.getClassProperties(Bar, true, false);
|
| + var property = findProperty(properties, 'barStaticMethod');
|
| + expect(property.value(10), equals(30));
|
| + expect(property.setter, isNull);
|
| + expect(property.getter, isNull);
|
| + expect(property.hasValue, isTrue);
|
| + expect(property.writable, isFalse);
|
| + expect(property.isMethod, isTrue);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + property = findProperty(properties, 'barConst1');
|
| + expect(property.value, equals(9));
|
| + expect(property.setter, isNull);
|
| + expect(property.getter, isNull);
|
| + expect(property.hasValue, isTrue);
|
| + expect(property.writable, isFalse);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + properties = _Utils.getClassProperties(Bar, true, true);
|
| + expect(findProperty(properties, 'barStaticMethod'), isNull);
|
| +
|
| + property = findProperty(properties, 'barStaticProp');
|
| + expect(property.value, isNull);
|
| + expect(property.setter, isNull);
|
| + expect(property.getter(), equals('staticProp'));
|
| + expect(property.hasValue, isFalse);
|
| + expect(property.writable, isFalse);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| + });
|
| +
|
| + test('safe get property', () {
|
| + expect(_Utils.getObjectPropertySafe(new Bar(), "_barProp2"), equals(11));
|
| + expect(_Utils.getObjectPropertySafe(new Bar(), "_fooPrivate2"), equals(2));
|
| + });
|
| +
|
| + test('library properties', () {
|
| + var properties = _Utils.getLibraryProperties(sampleLibraryUrl, true, false);
|
| + var property = findProperty(properties, 'exampleStaticMethod');
|
| + expect(property.value(10), equals(20));
|
| + expect(property.setter, isNull);
|
| + expect(property.getter, isNull);
|
| + expect(property.hasValue, isTrue);
|
| + expect(property.writable, isFalse);
|
| + expect(property.isMethod, isTrue);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + property = findProperty(properties, 'exampleField');
|
| + expect(property.value, equals(8));
|
| + expect(property.setter, isNull);
|
| + expect(property.getter, isNull);
|
| + expect(property.hasValue, isTrue);
|
| + expect(property.writable, isTrue);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + property = findProperty(properties, 'exampleFinalField');
|
| + expect(property.value, equals(16));
|
| + expect(property.setter, isNull);
|
| + expect(property.getter, isNull);
|
| + expect(property.hasValue, isTrue);
|
| + expect(property.writable, isFalse);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + property = findProperty(properties, 'Foo');
|
| + expect(property.value.toString(), "Foo");
|
| + expect(property.value is Type, isTrue);
|
| + expect(property.setter, isNull);
|
| + expect(property.getter, isNull);
|
| + expect(property.hasValue, isTrue);
|
| + expect(property.writable, isFalse);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + properties = _Utils.getLibraryProperties(sampleLibraryUrl, true, true);
|
| + property = findProperty(properties, 'exampleProp1');
|
| + expect(property.value, isNull);
|
| + expect(property.setter, isNull);
|
| + expect(property.getter(), equals(30));
|
| + expect(property.hasValue, isFalse);
|
| + expect(property.writable, isFalse);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| +
|
| + property = findProperty(properties, 'exampleProp2');
|
| + expect(property.value, isNull);
|
| + expect(property.writable, isTrue);
|
| + expect(property.setter is Function, isTrue);
|
| + expect(property.getter(), equals(10));
|
| + property.setter(20);
|
| + expect(property.getter(), equals(20));
|
| + expect(property.hasValue, isFalse);
|
| + expect(property.isMethod, isFalse);
|
| + expect(property.isOwn, isTrue);
|
| + expect(property.wasThrown, isFalse);
|
| + });
|
| + });
|
| +}
|
|
|