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 'dart:async'; | 6 import 'dart:async'; |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'package:observatory/models.dart' as M; | 8 import 'package:observatory/models.dart' as M; |
9 import 'package:observatory/src/elements/allocation_profile.dart'; | 9 import 'package:observatory/src/elements/allocation_profile.dart'; |
10 import 'package:observatory/src/elements/class_ref.dart'; | 10 import 'package:observatory/src/elements/class_ref.dart'; |
(...skipping 13 matching lines...) Expand all Loading... |
24 final events = new EventRepositoryMock(); | 24 final events = new EventRepositoryMock(); |
25 final notif = new NotificationRepositoryMock(); | 25 final notif = new NotificationRepositoryMock(); |
26 test('instantiation', () { | 26 test('instantiation', () { |
27 final repo = new AllocationProfileRepositoryMock(); | 27 final repo = new AllocationProfileRepositoryMock(); |
28 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | 28 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
29 expect(e, isNotNull, reason: 'element correctly created'); | 29 expect(e, isNotNull, reason: 'element correctly created'); |
30 }); | 30 }); |
31 test('elements created', () async { | 31 test('elements created', () async { |
32 final completer = new Completer<AllocationProfileMock>(); | 32 final completer = new Completer<AllocationProfileMock>(); |
33 final repo = new AllocationProfileRepositoryMock( | 33 final repo = new AllocationProfileRepositoryMock( |
34 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | 34 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { |
35 expect(i, equals(isolate)); | 35 expect(i, equals(isolate)); |
36 expect(gc, isFalse); | 36 expect(gc, isFalse); |
37 expect(reset, isFalse); | 37 expect(reset, isFalse); |
38 return completer.future; | 38 return completer.future; |
39 }, count: 1)); | 39 }, count: 1)); |
40 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | 40 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
41 document.body.append(e); | 41 document.body.append(e); |
42 await e.onRendered.first; | 42 await e.onRendered.first; |
43 expect(e.children.length, isNonZero, reason: 'has elements'); | 43 expect(e.children.length, isNonZero, reason: 'has elements'); |
44 expect(e.querySelectorAll(vTag).length, isZero); | 44 expect(e.querySelectorAll(vTag).length, isZero); |
45 completer.complete(const AllocationProfileMock()); | 45 completer.complete(const AllocationProfileMock()); |
46 await e.onRendered.first; | 46 await e.onRendered.first; |
47 expect(e.querySelectorAll(vTag).length, equals(1)); | 47 expect(e.querySelectorAll(vTag).length, equals(1)); |
48 e.remove(); | 48 e.remove(); |
49 await e.onRendered.first; | 49 await e.onRendered.first; |
50 expect(e.children.length, isZero, reason: 'is empty'); | 50 expect(e.children.length, isZero, reason: 'is empty'); |
51 }); | 51 }); |
52 group('reacts', () { | 52 group('reacts', () { |
53 test('to refresh', () async { | 53 test('to refresh', () async { |
54 final completer = new Completer<AllocationProfileMock>(); | 54 final completer = new Completer<AllocationProfileMock>(); |
55 int step = 0; | 55 int step = 0; |
56 final repo = new AllocationProfileRepositoryMock( | 56 final repo = new AllocationProfileRepositoryMock( |
57 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | 57 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { |
58 expect(i, equals(isolate)); | 58 expect(i, equals(isolate)); |
59 switch (step) { | 59 switch (step) { |
60 case 0: | 60 case 0: |
61 expect(gc, isFalse); | 61 expect(gc, isFalse); |
62 expect(reset, isFalse); | 62 expect(reset, isFalse); |
63 break; | 63 break; |
64 case 1: | 64 case 1: |
65 expect(gc, isFalse); | 65 expect(gc, isFalse); |
66 expect(reset, isTrue); | 66 expect(reset, isTrue); |
67 break; | 67 break; |
68 case 2: | 68 case 2: |
69 expect(gc, isTrue); | 69 expect(gc, isTrue); |
70 expect(reset, isFalse); | 70 expect(reset, isFalse); |
71 break; | 71 break; |
72 case 3: | 72 case 3: |
73 expect(gc, isFalse); | 73 expect(gc, isFalse); |
74 expect(reset, isFalse); | 74 expect(reset, isFalse); |
75 break; | 75 break; |
76 } | 76 } |
77 step++; | 77 step++; |
78 return completer.future; | 78 return completer.future; |
79 }, count: 4)); | 79 }, count: 4)); |
80 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | 80 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
81 document.body.append(e); | 81 document.body.append(e); |
82 await e.onRendered.first; | 82 await e.onRendered.first; |
83 completer.complete(const AllocationProfileMock()); | 83 completer.complete(const AllocationProfileMock()); |
84 await e.onRendered.first; | 84 await e.onRendered.first; |
85 e.querySelectorAll(rTag).sublist(1, 4) | 85 e |
| 86 .querySelectorAll(rTag) |
| 87 .sublist(1, 4) |
86 .forEach((NavRefreshElement e) => e.refresh()); | 88 .forEach((NavRefreshElement e) => e.refresh()); |
87 e.remove(); | 89 e.remove(); |
88 await e.onRendered.first; | 90 await e.onRendered.first; |
89 expect(e.children.length, isZero, reason: 'is empty'); | 91 expect(e.children.length, isZero, reason: 'is empty'); |
90 }); | 92 }); |
91 test('to gc', () async { | 93 test('to gc', () async { |
92 final events = new EventRepositoryMock(); | 94 final events = new EventRepositoryMock(); |
93 final completer = new Completer<AllocationProfileMock>(); | 95 final completer = new Completer<AllocationProfileMock>(); |
94 int count = 0; | 96 int count = 0; |
95 final repo = new AllocationProfileRepositoryMock( | 97 final repo = new AllocationProfileRepositoryMock( |
96 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | 98 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { |
97 expect(i, equals(isolate)); | 99 expect(i, equals(isolate)); |
98 expect(gc, isFalse); | 100 expect(gc, isFalse); |
99 expect(reset, isFalse); | 101 expect(reset, isFalse); |
100 count++; | 102 count++; |
101 return completer.future; | 103 return completer.future; |
102 }, count: 2)); | 104 }, count: 2)); |
103 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | 105 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
104 document.body.append(e); | 106 document.body.append(e); |
105 await e.onRendered.first; | 107 await e.onRendered.first; |
106 completer.complete(const AllocationProfileMock()); | 108 completer.complete(const AllocationProfileMock()); |
107 await e.onRendered.first; | 109 await e.onRendered.first; |
108 e.querySelector('input[type=\'checkbox\']').click(); | 110 e.querySelector('input[type=\'checkbox\']').click(); |
109 expect(events.onGCEventHasListener, isTrue); | 111 expect(events.onGCEventHasListener, isTrue); |
110 events.add(new GCEventMock(isolate: isolate)); | 112 events.add(new GCEventMock(isolate: isolate)); |
111 await e.onRendered.first; | 113 await e.onRendered.first; |
112 expect(count, equals(2)); | 114 expect(count, equals(2)); |
113 // shouldn't trigger | 115 // shouldn't trigger |
114 events.add(new GCEventMock(isolate: new IsolateRefMock(id: 'another'))); | 116 events.add(new GCEventMock(isolate: new IsolateRefMock(id: 'another'))); |
115 await (() async {} ()); | 117 await (() async {}()); |
116 e.querySelector('input[type=\'checkbox\']').click(); | 118 e.querySelector('input[type=\'checkbox\']').click(); |
117 // shouldn't trigger | 119 // shouldn't trigger |
118 events.add(new GCEventMock(isolate: isolate)); | 120 events.add(new GCEventMock(isolate: isolate)); |
119 await (() async {} ()); | 121 await (() async {}()); |
120 e.remove(); | 122 e.remove(); |
121 await e.onRendered.first; | 123 await e.onRendered.first; |
122 expect(e.children.length, isZero, reason: 'is empty'); | 124 expect(e.children.length, isZero, reason: 'is empty'); |
123 }); | 125 }); |
124 test('to sort change', () async { | 126 test('to sort change', () async { |
125 const clazz1 = const ClassRefMock(name: 'class1'); | 127 const clazz1 = const ClassRefMock(name: 'class1'); |
126 const clazz2 = const ClassRefMock(name: 'class2'); | 128 const clazz2 = const ClassRefMock(name: 'class2'); |
127 const clazz3 = const ClassRefMock(name: 'class3'); | 129 const clazz3 = const ClassRefMock(name: 'class3'); |
128 const profile = const AllocationProfileMock(members: const [ | 130 const profile = const AllocationProfileMock(members: const [ |
129 const ClassHeapStatsMock(clazz: clazz2, newSpace: const AllocationsMock( | 131 const ClassHeapStatsMock( |
130 accumulated: const AllocationCountMock(bytes: 10) | 132 clazz: clazz2, |
131 )), | 133 newSpace: const AllocationsMock( |
| 134 accumulated: const AllocationCountMock(bytes: 10))), |
132 const ClassHeapStatsMock(clazz: clazz3), | 135 const ClassHeapStatsMock(clazz: clazz3), |
133 const ClassHeapStatsMock(clazz: clazz1, newSpace: const AllocationsMock( | 136 const ClassHeapStatsMock( |
134 accumulated: const AllocationCountMock(bytes: 5) | 137 clazz: clazz1, |
135 )) | 138 newSpace: const AllocationsMock( |
| 139 accumulated: const AllocationCountMock(bytes: 5))) |
136 ]); | 140 ]); |
137 final completer = new Completer<AllocationProfileMock>(); | 141 final completer = new Completer<AllocationProfileMock>(); |
138 final repo = new AllocationProfileRepositoryMock( | 142 final repo = new AllocationProfileRepositoryMock( |
139 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | 143 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { |
140 expect(i, equals(isolate)); | 144 expect(i, equals(isolate)); |
141 expect(gc, isFalse); | 145 expect(gc, isFalse); |
142 expect(reset, isFalse); | 146 expect(reset, isFalse); |
143 return completer.future; | 147 return completer.future; |
144 }, count: 1)); | 148 }, count: 1)); |
145 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | 149 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
146 document.body.append(e); | 150 document.body.append(e); |
147 await e.onRendered.first; | 151 await e.onRendered.first; |
148 completer.complete(profile); | 152 completer.complete(profile); |
149 await e.onRendered.first; | 153 await e.onRendered.first; |
150 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz1)); | 154 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz1)); |
151 e.querySelector('button.bytes').click(); | 155 e.querySelector('button.bytes').click(); |
152 await e.onRendered.first; | 156 await e.onRendered.first; |
153 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz2)); | 157 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz2)); |
154 e.querySelector('button.bytes').click(); | 158 e.querySelector('button.bytes').click(); |
155 await e.onRendered.first; | 159 await e.onRendered.first; |
156 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz3)); | 160 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz3)); |
157 e.remove(); | 161 e.remove(); |
158 await e.onRendered.first; | 162 await e.onRendered.first; |
159 expect(e.children.length, isZero, reason: 'is empty'); | 163 expect(e.children.length, isZero, reason: 'is empty'); |
160 }); | 164 }); |
161 }); | 165 }); |
162 } | 166 } |
OLD | NEW |