| 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/containers/virtual_tree.dart'; | 9 import 'package:observatory/src/elements/containers/virtual_tree.dart'; |
| 10 import 'package:observatory/src/elements/heap_snapshot.dart'; | 10 import 'package:observatory/src/elements/heap_snapshot.dart'; |
| 11 import '../mocks.dart'; | 11 import '../mocks.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 HeapSnapshotElement.tag.ensureRegistration(); | 14 HeapSnapshotElement.tag.ensureRegistration(); |
| 15 | 15 |
| 16 final tTag = VirtualTreeElement.tag.name; | 16 final tTag = VirtualTreeElement.tag.name; |
| 17 | 17 |
| 18 const vm = const VMMock(); | 18 const vm = const VMMock(); |
| 19 const isolate = const IsolateRefMock(); | 19 const isolate = const IsolateRefMock(); |
| 20 final events = new EventRepositoryMock(); | 20 final events = new EventRepositoryMock(); |
| 21 final notifs = new NotificationRepositoryMock(); | 21 final notifs = new NotificationRepositoryMock(); |
| 22 final snapshots = new HeapSnapshotRepositoryMock(); | 22 final snapshots = new HeapSnapshotRepositoryMock(); |
| 23 final instances = new InstanceRepositoryMock(); | 23 final instances = new InstanceRepositoryMock(); |
| 24 test('instantiation', () { | 24 test('instantiation', () { |
| 25 final e = new HeapSnapshotElement( | 25 final e = new HeapSnapshotElement(vm, isolate, events, notifs, snapshots, |
| 26 vm, isolate, events, notifs, snapshots, instances); | 26 instances); |
| 27 expect(e, isNotNull, reason: 'element correctly created'); | 27 expect(e, isNotNull, reason: 'element correctly created'); |
| 28 }); | 28 }); |
| 29 test('elements created', () async { | 29 test('elements created', () async { |
| 30 final controller = | 30 final controller |
| 31 new StreamController<M.HeapSnapshotLoadingProgressEvent>.broadcast(); | 31 = new StreamController<M.HeapSnapshotLoadingProgressEvent>.broadcast(); |
| 32 final snapshots = | 32 final snapshots = new HeapSnapshotRepositoryMock( |
| 33 new HeapSnapshotRepositoryMock(getter: (M.IsolateRef i, bool gc) { | 33 getter: (M.IsolateRef i, bool gc) { |
| 34 expect(i, equals(isolate)); | 34 expect(i, equals(isolate)); |
| 35 expect(gc, isFalse); | 35 expect(gc, isFalse); |
| 36 return controller.stream; | 36 return controller.stream; |
| 37 }); | 37 } |
| 38 final e = new HeapSnapshotElement( | 38 ); |
| 39 vm, isolate, events, notifs, snapshots, instances); | 39 final e = new HeapSnapshotElement(vm, isolate, events, notifs, snapshots, |
| 40 instances); |
| 40 document.body.append(e); | 41 document.body.append(e); |
| 41 await e.onRendered.first; | 42 await e.onRendered.first; |
| 42 expect(e.children.length, isNonZero, reason: 'has elements'); | 43 expect(e.children.length, isNonZero, reason: 'has elements'); |
| 43 expect(e.querySelectorAll(tTag).length, isZero); | 44 expect(e.querySelectorAll(tTag).length, isZero); |
| 44 controller.add(const HeapSnapshotLoadingProgressEventMock( | 45 controller.add(const HeapSnapshotLoadingProgressEventMock( |
| 45 progress: const HeapSnapshotLoadingProgressMock( | 46 progress: const HeapSnapshotLoadingProgressMock( |
| 46 status: M.HeapSnapshotLoadingStatus.fetching))); | 47 status: M.HeapSnapshotLoadingStatus.fetching |
| 48 ) |
| 49 )); |
| 47 await e.onRendered.first; | 50 await e.onRendered.first; |
| 48 expect(e.querySelectorAll(tTag).length, isZero); | 51 expect(e.querySelectorAll(tTag).length, isZero); |
| 49 controller.add(const HeapSnapshotLoadingProgressEventMock( | 52 controller.add(const HeapSnapshotLoadingProgressEventMock( |
| 50 progress: const HeapSnapshotLoadingProgressMock( | 53 progress: const HeapSnapshotLoadingProgressMock( |
| 51 status: M.HeapSnapshotLoadingStatus.loading))); | 54 status: M.HeapSnapshotLoadingStatus.loading |
| 55 ) |
| 56 )); |
| 52 controller.add(new HeapSnapshotLoadingProgressEventMock( | 57 controller.add(new HeapSnapshotLoadingProgressEventMock( |
| 53 progress: new HeapSnapshotLoadingProgressMock( | 58 progress: new HeapSnapshotLoadingProgressMock( |
| 54 status: M.HeapSnapshotLoadingStatus.loaded, | 59 status: M.HeapSnapshotLoadingStatus.loaded, |
| 55 snapshot: new HeapSnapshotMock(timestamp: new DateTime.now())))); | 60 snapshot: new HeapSnapshotMock(timestamp: new DateTime.now()) |
| 61 ) |
| 62 )); |
| 56 controller.close(); | 63 controller.close(); |
| 57 await e.onRendered.first; | 64 await e.onRendered.first; |
| 58 expect(e.querySelectorAll(tTag).length, equals(1)); | 65 expect(e.querySelectorAll(tTag).length, equals(1)); |
| 59 e.remove(); | 66 e.remove(); |
| 60 await e.onRendered.first; | 67 await e.onRendered.first; |
| 61 expect(e.children.length, isZero, reason: 'is empty'); | 68 expect(e.children.length, isZero, reason: 'is empty'); |
| 62 }); | 69 }); |
| 63 } | 70 } |
| OLD | NEW |