| 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/allocation_profile.dart'; | 9 import 'package:observatory/src/elements/allocation_profile.dart'; |
| 10 import 'package:observatory/src/elements/class_ref.dart'; | 10 import 'package:observatory/src/elements/class_ref.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 final events = new EventRepositoryMock(); | 24 final events = new EventRepositoryMock(); |
| 25 final notif = new NotificationRepositoryMock(); | 25 final notif = new NotificationRepositoryMock(); |
| 26 test('instantiation', () { | 26 test('instantiation', () { |
| 27 final repo = new AllocationProfileRepositoryMock(); | 27 final repo = new AllocationProfileRepositoryMock(); |
| 28 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | 28 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
| 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 completer = new Completer<AllocationProfileMock>(); | 32 final completer = new Completer<AllocationProfileMock>(); |
| 33 final repo = new AllocationProfileRepositoryMock( | 33 final repo = new AllocationProfileRepositoryMock( |
| 34 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | 34 getter: |
| 35 expectAsync((M.IsolateRef i, bool gc, bool reset, bool combine) { |
| 35 expect(i, equals(isolate)); | 36 expect(i, equals(isolate)); |
| 36 expect(gc, isFalse); | 37 expect(gc, isFalse); |
| 37 expect(reset, isFalse); | 38 expect(reset, isFalse); |
| 39 expect(combine, isFalse); |
| 38 return completer.future; | 40 return completer.future; |
| 39 }, count: 1)); | 41 }, count: 1)); |
| 40 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | 42 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
| 41 document.body.append(e); | 43 document.body.append(e); |
| 42 await e.onRendered.first; | 44 await e.onRendered.first; |
| 43 expect(e.children.length, isNonZero, reason: 'has elements'); | 45 expect(e.children.length, isNonZero, reason: 'has elements'); |
| 44 expect(e.querySelectorAll(vTag).length, isZero); | 46 expect(e.querySelectorAll(vTag).length, isZero); |
| 45 completer.complete(const AllocationProfileMock()); | 47 completer.complete(const AllocationProfileMock()); |
| 46 await e.onRendered.first; | 48 await e.onRendered.first; |
| 47 expect(e.querySelectorAll(vTag).length, equals(1)); | 49 expect(e.querySelectorAll(vTag).length, equals(1)); |
| 48 e.remove(); | 50 e.remove(); |
| 49 await e.onRendered.first; | 51 await e.onRendered.first; |
| 50 expect(e.children.length, isZero, reason: 'is empty'); | 52 expect(e.children.length, isZero, reason: 'is empty'); |
| 51 }); | 53 }); |
| 52 group('reacts', () { | 54 group('reacts', () { |
| 53 test('to refresh', () async { | 55 test('to refresh', () async { |
| 54 final completer = new Completer<AllocationProfileMock>(); | 56 final completer = new Completer<AllocationProfileMock>(); |
| 55 int step = 0; | 57 int step = 0; |
| 56 final repo = new AllocationProfileRepositoryMock( | 58 final repo = new AllocationProfileRepositoryMock( |
| 57 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | 59 getter: |
| 60 expectAsync((M.IsolateRef i, bool gc, bool reset, bool combine) { |
| 58 expect(i, equals(isolate)); | 61 expect(i, equals(isolate)); |
| 62 expect(combine, isFalse); |
| 59 switch (step) { | 63 switch (step) { |
| 60 case 0: | 64 case 0: |
| 61 expect(gc, isFalse); | 65 expect(gc, isFalse); |
| 62 expect(reset, isFalse); | 66 expect(reset, isFalse); |
| 63 break; | 67 break; |
| 64 case 1: | 68 case 1: |
| 65 expect(gc, isFalse); | 69 expect(gc, isFalse); |
| 66 expect(reset, isTrue); | 70 expect(reset, isTrue); |
| 67 break; | 71 break; |
| 68 case 2: | 72 case 2: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 88 .forEach((NavRefreshElement e) => e.refresh()); | 92 .forEach((NavRefreshElement e) => e.refresh()); |
| 89 e.remove(); | 93 e.remove(); |
| 90 await e.onRendered.first; | 94 await e.onRendered.first; |
| 91 expect(e.children.length, isZero, reason: 'is empty'); | 95 expect(e.children.length, isZero, reason: 'is empty'); |
| 92 }); | 96 }); |
| 93 test('to gc', () async { | 97 test('to gc', () async { |
| 94 final events = new EventRepositoryMock(); | 98 final events = new EventRepositoryMock(); |
| 95 final completer = new Completer<AllocationProfileMock>(); | 99 final completer = new Completer<AllocationProfileMock>(); |
| 96 int count = 0; | 100 int count = 0; |
| 97 final repo = new AllocationProfileRepositoryMock( | 101 final repo = new AllocationProfileRepositoryMock( |
| 98 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | 102 getter: |
| 103 expectAsync((M.IsolateRef i, bool gc, bool reset, bool combine) { |
| 99 expect(i, equals(isolate)); | 104 expect(i, equals(isolate)); |
| 100 expect(gc, isFalse); | 105 expect(gc, isFalse); |
| 101 expect(reset, isFalse); | 106 expect(reset, isFalse); |
| 107 expect(combine, isFalse); |
| 102 count++; | 108 count++; |
| 103 return completer.future; | 109 return completer.future; |
| 104 }, count: 2)); | 110 }, count: 2)); |
| 105 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | 111 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
| 106 document.body.append(e); | 112 document.body.append(e); |
| 107 await e.onRendered.first; | 113 await e.onRendered.first; |
| 108 completer.complete(const AllocationProfileMock()); | 114 completer.complete(const AllocationProfileMock()); |
| 109 await e.onRendered.first; | 115 await e.onRendered.first; |
| 110 e.querySelector('input[type=\'checkbox\']').click(); | 116 e.querySelector('input[type=\'checkbox\']').click(); |
| 111 expect(events.onGCEventHasListener, isTrue); | 117 expect(events.onGCEventHasListener, isTrue); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 137 current: const AllocationCountMock(bytes: 2))), | 143 current: const AllocationCountMock(bytes: 2))), |
| 138 const ClassHeapStatsMock( | 144 const ClassHeapStatsMock( |
| 139 clazz: clazz3, | 145 clazz: clazz3, |
| 140 newSpace: const AllocationsMock( | 146 newSpace: const AllocationsMock( |
| 141 current: const AllocationCountMock(bytes: 5)), | 147 current: const AllocationCountMock(bytes: 5)), |
| 142 oldSpace: const AllocationsMock( | 148 oldSpace: const AllocationsMock( |
| 143 current: const AllocationCountMock(bytes: 3))) | 149 current: const AllocationCountMock(bytes: 3))) |
| 144 ]); | 150 ]); |
| 145 final completer = new Completer<AllocationProfileMock>(); | 151 final completer = new Completer<AllocationProfileMock>(); |
| 146 final repo = new AllocationProfileRepositoryMock( | 152 final repo = new AllocationProfileRepositoryMock( |
| 147 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | 153 getter: |
| 154 expectAsync((M.IsolateRef i, bool gc, bool reset, bool combine) { |
| 148 expect(i, equals(isolate)); | 155 expect(i, equals(isolate)); |
| 149 expect(gc, isFalse); | 156 expect(gc, isFalse); |
| 150 expect(reset, isFalse); | 157 expect(reset, isFalse); |
| 158 expect(combine, isFalse); |
| 151 return completer.future; | 159 return completer.future; |
| 152 }, count: 1)); | 160 }, count: 1)); |
| 153 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | 161 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
| 154 document.body.append(e); | 162 document.body.append(e); |
| 155 await e.onRendered.first; | 163 await e.onRendered.first; |
| 156 completer.complete(profile); | 164 completer.complete(profile); |
| 157 await e.onRendered.first; | 165 await e.onRendered.first; |
| 158 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz2)); | 166 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz2)); |
| 159 e.querySelector('button.name').click(); | 167 e.querySelector('button.name').click(); |
| 160 await e.onRendered.first; | 168 await e.onRendered.first; |
| 161 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz1)); | 169 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz1)); |
| 162 e.querySelector('button.name').click(); | 170 e.querySelector('button.name').click(); |
| 163 await e.onRendered.first; | 171 await e.onRendered.first; |
| 164 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz3)); | 172 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz3)); |
| 165 e.querySelectorAll('button.bytes').last.click(); | 173 e.querySelectorAll('button.bytes').last.click(); |
| 166 await e.onRendered.first; | 174 await e.onRendered.first; |
| 167 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz3)); | 175 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz3)); |
| 168 e.querySelectorAll('button.bytes').last.click(); | 176 e.querySelectorAll('button.bytes').last.click(); |
| 169 await e.onRendered.first; | 177 await e.onRendered.first; |
| 170 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz1)); | 178 expect((e.querySelector(cTag) as ClassRefElement).cls, equals(clazz1)); |
| 171 e.remove(); | 179 e.remove(); |
| 172 await e.onRendered.first; | 180 await e.onRendered.first; |
| 173 expect(e.children.length, isZero, reason: 'is empty'); | 181 expect(e.children.length, isZero, reason: 'is empty'); |
| 174 }); | 182 }); |
| 175 }); | 183 }); |
| 176 } | 184 } |
| OLD | NEW |