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