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, | 29 reachableSizes, inbounds, paths, instances); |
30 instances); | |
31 expect(e, isNotNull, reason: 'element correctly created'); | 30 expect(e, isNotNull, reason: 'element correctly created'); |
32 expect(e.isolate, equals(isolate)); | 31 expect(e.isolate, equals(isolate)); |
33 expect(e.object, equals(object)); | 32 expect(e.object, equals(object)); |
34 }); | 33 }); |
35 group('elements', () { | 34 group('elements', () { |
36 test('created after attachment', () async { | 35 test('created after attachment', () async { |
37 final e = new ObjectCommonElement(isolate, object, retainedSizes, | 36 final e = new ObjectCommonElement(isolate, object, retainedSizes, |
38 reachableSizes, inbounds, paths, | 37 reachableSizes, inbounds, paths, instances); |
39 instances); | |
40 document.body.append(e); | 38 document.body.append(e); |
41 await e.onRendered.first; | 39 await e.onRendered.first; |
42 expect(e.children.length, isNonZero, reason: 'has elements'); | 40 expect(e.children.length, isNonZero, reason: 'has elements'); |
43 expect(e.querySelectorAll(cTag).length, equals(1)); | 41 expect(e.querySelectorAll(cTag).length, equals(1)); |
44 expect(e.querySelectorAll(iTag).length, equals(1)); | 42 expect(e.querySelectorAll(iTag).length, equals(1)); |
45 expect(e.querySelectorAll(rTag).length, equals(1)); | 43 expect(e.querySelectorAll(rTag).length, equals(1)); |
46 e.remove(); | 44 e.remove(); |
47 await e.onRendered.first; | 45 await e.onRendered.first; |
48 expect(e.children.length, isZero, reason: 'is empty'); | 46 expect(e.children.length, isZero, reason: 'is empty'); |
49 }); | 47 }); |
50 test('created after attachment', () async { | 48 test('created after attachment', () async { |
51 const value = const GuardedMock<InstanceMock>.fromValue( | 49 const value = const GuardedMock<InstanceMock>.fromValue( |
52 const InstanceMock(valueAsString: '10') | 50 const InstanceMock(valueAsString: '10')); |
53 ); | |
54 bool invoked = false; | 51 bool invoked = false; |
55 final reachableSizes = new ReachableSizeRepositoryMock( | 52 final reachableSizes = new ReachableSizeRepositoryMock( |
56 getter: expectAsync((i, id) async { | 53 getter: expectAsync((i, id) async { |
57 expect(i, equals(isolate)); | 54 expect(i, equals(isolate)); |
58 expect(id, equals(object.id)); | 55 expect(id, equals(object.id)); |
59 invoked = true; | 56 invoked = true; |
60 return value; | 57 return value; |
61 }, count: 1) | 58 }, count: 1)); |
62 ); | |
63 final e = new ObjectCommonElement(isolate, object, retainedSizes, | 59 final e = new ObjectCommonElement(isolate, object, retainedSizes, |
64 reachableSizes, inbounds, paths, | 60 reachableSizes, inbounds, paths, instances); |
65 instances); | |
66 document.body.append(e); | 61 document.body.append(e); |
67 await e.onRendered.first; | 62 await e.onRendered.first; |
68 expect(invoked, isFalse); | 63 expect(invoked, isFalse); |
69 expect(e.children.length, isNonZero, reason: 'has elements'); | 64 expect(e.children.length, isNonZero, reason: 'has elements'); |
70 expect(e.querySelectorAll(cTag).length, equals(1)); | 65 expect(e.querySelectorAll(cTag).length, equals(1)); |
71 expect(e.querySelectorAll(iTag).length, equals(1)); | 66 expect(e.querySelectorAll(iTag).length, equals(1)); |
72 expect(e.querySelectorAll(rTag).length, equals(1)); | 67 expect(e.querySelectorAll(rTag).length, equals(1)); |
73 e.querySelector('.reachable_size').click(); | 68 e.querySelector('.reachable_size').click(); |
74 await e.onRendered.first; | 69 await e.onRendered.first; |
75 expect(invoked, isTrue); | 70 expect(invoked, isTrue); |
76 e.remove(); | 71 e.remove(); |
77 await e.onRendered.first; | 72 await e.onRendered.first; |
78 expect(e.children.length, isZero, reason: 'is empty'); | 73 expect(e.children.length, isZero, reason: 'is empty'); |
79 }); | 74 }); |
80 test('created after attachment', () async { | 75 test('created after attachment', () async { |
81 const value = const GuardedMock<InstanceMock>.fromValue( | 76 const value = const GuardedMock<InstanceMock>.fromValue( |
82 const InstanceMock(valueAsString: '10') | 77 const InstanceMock(valueAsString: '10')); |
83 ); | |
84 bool invoked = false; | 78 bool invoked = false; |
85 final retainedSizes = new RetainedSizeRepositoryMock( | 79 final retainedSizes = new RetainedSizeRepositoryMock( |
86 getter: expectAsync((i, id) async { | 80 getter: expectAsync((i, id) async { |
87 expect(i, equals(isolate)); | 81 expect(i, equals(isolate)); |
88 expect(id, equals(object.id)); | 82 expect(id, equals(object.id)); |
89 invoked = true; | 83 invoked = true; |
90 return value; | 84 return value; |
91 }, count: 1) | 85 }, count: 1)); |
92 ); | |
93 final e = new ObjectCommonElement(isolate, object, retainedSizes, | 86 final e = new ObjectCommonElement(isolate, object, retainedSizes, |
94 reachableSizes, inbounds, paths, | 87 reachableSizes, inbounds, paths, instances); |
95 instances); | |
96 document.body.append(e); | 88 document.body.append(e); |
97 await e.onRendered.first; | 89 await e.onRendered.first; |
98 expect(invoked, isFalse); | 90 expect(invoked, isFalse); |
99 expect(e.children.length, isNonZero, reason: 'has elements'); | 91 expect(e.children.length, isNonZero, reason: 'has elements'); |
100 expect(e.querySelectorAll(cTag).length, equals(1)); | 92 expect(e.querySelectorAll(cTag).length, equals(1)); |
101 expect(e.querySelectorAll(iTag).length, equals(1)); | 93 expect(e.querySelectorAll(iTag).length, equals(1)); |
102 expect(e.querySelectorAll(rTag).length, equals(1)); | 94 expect(e.querySelectorAll(rTag).length, equals(1)); |
103 e.querySelector('.retained_size').click(); | 95 e.querySelector('.retained_size').click(); |
104 await e.onRendered.first; | 96 await e.onRendered.first; |
105 expect(invoked, isTrue); | 97 expect(invoked, isTrue); |
106 e.remove(); | 98 e.remove(); |
107 await e.onRendered.first; | 99 await e.onRendered.first; |
108 expect(e.children.length, isZero, reason: 'is empty'); | 100 expect(e.children.length, isZero, reason: 'is empty'); |
109 }); | 101 }); |
110 }); | 102 }); |
111 } | 103 } |
OLD | NEW |