OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
7 import 'package:observatory/src/elements/class_ref.dart'; | 7 import 'package:observatory/src/elements/class_ref.dart'; |
8 import 'package:observatory/src/elements/inbound_references.dart'; | 8 import 'package:observatory/src/elements/inbound_references.dart'; |
9 import 'package:observatory/src/elements/object_common.dart'; | 9 import 'package:observatory/src/elements/object_common.dart'; |
10 import 'package:observatory/src/elements/retaining_path.dart'; | 10 import 'package:observatory/src/elements/retaining_path.dart'; |
11 import '../mocks.dart'; | 11 import '../mocks.dart'; |
12 | 12 |
13 main() { | 13 main() { |
14 ObjectCommonElement.tag.ensureRegistration(); | 14 ObjectCommonElement.tag.ensureRegistration(); |
15 | 15 |
16 final cTag = ClassRefElement.tag.name; | 16 final cTag = ClassRefElement.tag.name; |
17 final iTag = InboundReferencesElement.tag.name; | 17 final iTag = InboundReferencesElement.tag.name; |
18 final rTag = RetainingPathElement.tag.name; | 18 final rTag = RetainingPathElement.tag.name; |
19 | 19 |
20 const isolate = const IsolateRefMock(); | 20 const isolate = const IsolateRefMock(); |
21 const object = const InstanceMock(); | 21 const object = const InstanceMock(); |
22 final reachableSizes = new ReachableSizeRepositoryMock(); | 22 final reachableSizes = new ReachableSizeRepositoryMock(); |
23 final retainedSizes = new RetainedSizeRepositoryMock(); | 23 final retainedSizes = new RetainedSizeRepositoryMock(); |
24 final inbounds = new InboundReferencesRepositoryMock(); | 24 final inbounds = new InboundReferencesRepositoryMock(); |
25 final paths = new RetainingPathRepositoryMock(); | 25 final paths = new RetainingPathRepositoryMock(); |
26 final instances = new InstanceRepositoryMock(); | 26 final instances = new InstanceRepositoryMock(); |
27 test('instantiation', () { | 27 test('instantiation', () { |
28 final e = new ObjectCommonElement(isolate, object, retainedSizes, | 28 final e = new ObjectCommonElement(isolate, object, retainedSizes, |
29 reachableSizes, inbounds, paths, instances); | 29 reachableSizes, inbounds, paths, |
| 30 instances); |
30 expect(e, isNotNull, reason: 'element correctly created'); | 31 expect(e, isNotNull, reason: 'element correctly created'); |
31 expect(e.isolate, equals(isolate)); | 32 expect(e.isolate, equals(isolate)); |
32 expect(e.object, equals(object)); | 33 expect(e.object, equals(object)); |
33 }); | 34 }); |
34 group('elements', () { | 35 group('elements', () { |
35 test('created after attachment', () async { | 36 test('created after attachment', () async { |
36 final e = new ObjectCommonElement(isolate, object, retainedSizes, | 37 final e = new ObjectCommonElement(isolate, object, retainedSizes, |
37 reachableSizes, inbounds, paths, instances); | 38 reachableSizes, inbounds, paths, |
| 39 instances); |
38 document.body.append(e); | 40 document.body.append(e); |
39 await e.onRendered.first; | 41 await e.onRendered.first; |
40 expect(e.children.length, isNonZero, reason: 'has elements'); | 42 expect(e.children.length, isNonZero, reason: 'has elements'); |
41 expect(e.querySelectorAll(cTag).length, equals(1)); | 43 expect(e.querySelectorAll(cTag).length, equals(1)); |
42 expect(e.querySelectorAll(iTag).length, equals(1)); | 44 expect(e.querySelectorAll(iTag).length, equals(1)); |
43 expect(e.querySelectorAll(rTag).length, equals(1)); | 45 expect(e.querySelectorAll(rTag).length, equals(1)); |
44 e.remove(); | 46 e.remove(); |
45 await e.onRendered.first; | 47 await e.onRendered.first; |
46 expect(e.children.length, isZero, reason: 'is empty'); | 48 expect(e.children.length, isZero, reason: 'is empty'); |
47 }); | 49 }); |
48 test('created after attachment', () async { | 50 test('created after attachment', () async { |
49 const value = const GuardedMock<InstanceMock>.fromValue( | 51 const value = const GuardedMock<InstanceMock>.fromValue( |
50 const InstanceMock(valueAsString: '10')); | 52 const InstanceMock(valueAsString: '10') |
| 53 ); |
51 bool invoked = false; | 54 bool invoked = false; |
52 final reachableSizes = new ReachableSizeRepositoryMock( | 55 final reachableSizes = new ReachableSizeRepositoryMock( |
53 getter: expectAsync((i, id) async { | 56 getter: expectAsync((i, id) async { |
54 expect(i, equals(isolate)); | 57 expect(i, equals(isolate)); |
55 expect(id, equals(object.id)); | 58 expect(id, equals(object.id)); |
56 invoked = true; | 59 invoked = true; |
57 return value; | 60 return value; |
58 }, count: 1)); | 61 }, count: 1) |
| 62 ); |
59 final e = new ObjectCommonElement(isolate, object, retainedSizes, | 63 final e = new ObjectCommonElement(isolate, object, retainedSizes, |
60 reachableSizes, inbounds, paths, instances); | 64 reachableSizes, inbounds, paths, |
| 65 instances); |
61 document.body.append(e); | 66 document.body.append(e); |
62 await e.onRendered.first; | 67 await e.onRendered.first; |
63 expect(invoked, isFalse); | 68 expect(invoked, isFalse); |
64 expect(e.children.length, isNonZero, reason: 'has elements'); | 69 expect(e.children.length, isNonZero, reason: 'has elements'); |
65 expect(e.querySelectorAll(cTag).length, equals(1)); | 70 expect(e.querySelectorAll(cTag).length, equals(1)); |
66 expect(e.querySelectorAll(iTag).length, equals(1)); | 71 expect(e.querySelectorAll(iTag).length, equals(1)); |
67 expect(e.querySelectorAll(rTag).length, equals(1)); | 72 expect(e.querySelectorAll(rTag).length, equals(1)); |
68 e.querySelector('.reachable_size').click(); | 73 e.querySelector('.reachable_size').click(); |
69 await e.onRendered.first; | 74 await e.onRendered.first; |
70 expect(invoked, isTrue); | 75 expect(invoked, isTrue); |
71 e.remove(); | 76 e.remove(); |
72 await e.onRendered.first; | 77 await e.onRendered.first; |
73 expect(e.children.length, isZero, reason: 'is empty'); | 78 expect(e.children.length, isZero, reason: 'is empty'); |
74 }); | 79 }); |
75 test('created after attachment', () async { | 80 test('created after attachment', () async { |
76 const value = const GuardedMock<InstanceMock>.fromValue( | 81 const value = const GuardedMock<InstanceMock>.fromValue( |
77 const InstanceMock(valueAsString: '10')); | 82 const InstanceMock(valueAsString: '10') |
| 83 ); |
78 bool invoked = false; | 84 bool invoked = false; |
79 final retainedSizes = new RetainedSizeRepositoryMock( | 85 final retainedSizes = new RetainedSizeRepositoryMock( |
80 getter: expectAsync((i, id) async { | 86 getter: expectAsync((i, id) async { |
81 expect(i, equals(isolate)); | 87 expect(i, equals(isolate)); |
82 expect(id, equals(object.id)); | 88 expect(id, equals(object.id)); |
83 invoked = true; | 89 invoked = true; |
84 return value; | 90 return value; |
85 }, count: 1)); | 91 }, count: 1) |
| 92 ); |
86 final e = new ObjectCommonElement(isolate, object, retainedSizes, | 93 final e = new ObjectCommonElement(isolate, object, retainedSizes, |
87 reachableSizes, inbounds, paths, instances); | 94 reachableSizes, inbounds, paths, |
| 95 instances); |
88 document.body.append(e); | 96 document.body.append(e); |
89 await e.onRendered.first; | 97 await e.onRendered.first; |
90 expect(invoked, isFalse); | 98 expect(invoked, isFalse); |
91 expect(e.children.length, isNonZero, reason: 'has elements'); | 99 expect(e.children.length, isNonZero, reason: 'has elements'); |
92 expect(e.querySelectorAll(cTag).length, equals(1)); | 100 expect(e.querySelectorAll(cTag).length, equals(1)); |
93 expect(e.querySelectorAll(iTag).length, equals(1)); | 101 expect(e.querySelectorAll(iTag).length, equals(1)); |
94 expect(e.querySelectorAll(rTag).length, equals(1)); | 102 expect(e.querySelectorAll(rTag).length, equals(1)); |
95 e.querySelector('.retained_size').click(); | 103 e.querySelector('.retained_size').click(); |
96 await e.onRendered.first; | 104 await e.onRendered.first; |
97 expect(invoked, isTrue); | 105 expect(invoked, isTrue); |
98 e.remove(); | 106 e.remove(); |
99 await e.onRendered.first; | 107 await e.onRendered.first; |
100 expect(e.children.length, isZero, reason: 'is empty'); | 108 expect(e.children.length, isZero, reason: 'is empty'); |
101 }); | 109 }); |
102 }); | 110 }); |
103 } | 111 } |
OLD | NEW |