| 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/cpu_profile.dart'; |
| 10 import 'package:observatory/src/elements/cpu_profile/virtual_tree.dart'; |
| 11 import 'package:observatory/src/elements/stack_trace_tree_config.dart'; |
| 12 import 'package:observatory/src/elements/sample_buffer_control.dart'; |
| 13 import '../mocks.dart'; |
| 14 |
| 15 main() { |
| 16 CpuProfileElement.tag.ensureRegistration(); |
| 17 |
| 18 final sTag = SampleBufferControlElement.tag.name; |
| 19 final cTag = StackTraceTreeConfigElement.tag.name; |
| 20 final tTag = CpuProfileVirtualTreeElement.tag.name; |
| 21 |
| 22 const vm = const VMMock(); |
| 23 const isolate = const IsolateRefMock(); |
| 24 final events = new EventRepositoryMock(); |
| 25 final notifs = new NotificationRepositoryMock(); |
| 26 test('instantiation', () { |
| 27 final profiles = new IsolateSampleProfileRepositoryMock(); |
| 28 final e = new CpuProfileElement(vm, isolate, events, notifs, profiles); |
| 29 expect(e, isNotNull, reason: 'element correctly created'); |
| 30 }); |
| 31 test('elements created', () async { |
| 32 final controller |
| 33 = new StreamController<M.SampleProfileLoadingProgressEvent>.broadcast(); |
| 34 final profiles = new IsolateSampleProfileRepositoryMock( |
| 35 getter: (M.IsolateRef i, M.SampleProfileTag t, bool clear, |
| 36 bool forceFetch) { |
| 37 expect(i, equals(isolate)); |
| 38 expect(t, isNotNull); |
| 39 expect(clear, isFalse); |
| 40 expect(forceFetch, isFalse); |
| 41 return controller.stream; |
| 42 } |
| 43 ); |
| 44 final e = new CpuProfileElement(vm, isolate, events, notifs, profiles); |
| 45 document.body.append(e); |
| 46 await e.onRendered.first; |
| 47 expect(e.children.length, isNonZero, reason: 'has elements'); |
| 48 expect(e.querySelectorAll(sTag).length, isZero); |
| 49 expect(e.querySelectorAll(cTag).length, isZero); |
| 50 expect(e.querySelectorAll(tTag).length, isZero); |
| 51 controller.add(new SampleProfileLoadingProgressEventMock( |
| 52 progress: new SampleProfileLoadingProgressMock( |
| 53 status: M.SampleProfileLoadingStatus.fetching |
| 54 ) |
| 55 )); |
| 56 await e.onRendered.first; |
| 57 expect(e.querySelectorAll(sTag).length, equals(1)); |
| 58 expect(e.querySelectorAll(cTag).length, isZero); |
| 59 expect(e.querySelectorAll(tTag).length, isZero); |
| 60 controller.add(new SampleProfileLoadingProgressEventMock( |
| 61 progress: new SampleProfileLoadingProgressMock( |
| 62 status: M.SampleProfileLoadingStatus.loading |
| 63 ) |
| 64 )); |
| 65 controller.add(new SampleProfileLoadingProgressEventMock( |
| 66 progress: new SampleProfileLoadingProgressMock( |
| 67 status: M.SampleProfileLoadingStatus.loaded, |
| 68 profile: new SampleProfileMock() |
| 69 ) |
| 70 )); |
| 71 controller.close(); |
| 72 await e.onRendered.first; |
| 73 expect(e.querySelectorAll(sTag).length, equals(1)); |
| 74 expect(e.querySelectorAll(cTag).length, equals(1)); |
| 75 expect(e.querySelectorAll(tTag).length, equals(1)); |
| 76 e.remove(); |
| 77 await e.onRendered.first; |
| 78 expect(e.children.length, isZero, reason: 'is empty'); |
| 79 }); |
| 80 } |
| OLD | NEW |