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