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