Chromium Code Reviews| 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/containers/virtual_collection.dart'; | |
| 11 import 'package:observatory/src/elements/nav/refresh.dart'; | |
| 12 import '../mocks.dart'; | |
| 13 | |
| 14 main() { | |
| 15 AllocationProfileElement.tag.ensureRegistration(); | |
| 16 | |
| 17 final rTag = NavRefreshElement.tag.name; | |
| 18 final vTag = VirtualCollectionElement.tag.name; | |
| 19 | |
| 20 const vm = const VMMock(); | |
| 21 const isolate = const IsolateRefMock(); | |
| 22 final events = new EventRepositoryMock(); | |
| 23 final notif = new NotificationRepositoryMock(); | |
| 24 test('instantiation', () { | |
| 25 final repo = new AllocationProfileRepositoryMock(); | |
| 26 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | |
| 27 expect(e, isNotNull, reason: 'element correctly created'); | |
| 28 }); | |
| 29 test('elements created', () async { | |
| 30 final completer = new Completer<AllocationProfileMock>(); | |
| 31 final repo = new AllocationProfileRepositoryMock( | |
| 32 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | |
| 33 expect(i, equals(isolate)); | |
| 34 expect(gc, isFalse); | |
| 35 expect(reset, isFalse); | |
| 36 return completer.future; | |
| 37 }, count: 1)); | |
| 38 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | |
| 39 document.body.append(e); | |
| 40 await e.onRendered.first; | |
| 41 expect(e.children.length, isNonZero, reason: 'has elements'); | |
| 42 expect(e.querySelectorAll(vTag).length, isZero); | |
| 43 completer.complete(new AllocationProfileMock()); | |
| 44 await e.onRendered.first; | |
| 45 expect(e.querySelectorAll(vTag).length, equals(1)); | |
| 46 e.remove(); | |
| 47 await e.onRendered.first; | |
| 48 expect(e.children.length, isZero, reason: 'is empty'); | |
| 49 }); | |
| 50 group('reacts', () { | |
| 51 test('to refresh', () async { | |
| 52 final completer = new Completer<AllocationProfileMock>(); | |
| 53 int step = 0; | |
| 54 final repo = new AllocationProfileRepositoryMock( | |
| 55 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | |
| 56 expect(i, equals(isolate)); | |
| 57 switch (step) { | |
| 58 case 0: | |
| 59 expect(gc, isFalse); | |
| 60 expect(reset, isFalse); | |
| 61 break; | |
| 62 case 1: | |
| 63 expect(gc, isFalse); | |
| 64 expect(reset, isTrue); | |
| 65 break; | |
| 66 case 2: | |
| 67 expect(gc, isTrue); | |
| 68 expect(reset, isFalse); | |
| 69 break; | |
| 70 case 3: | |
| 71 expect(gc, isFalse); | |
| 72 expect(reset, isFalse); | |
| 73 break; | |
| 74 } | |
| 75 step++; | |
| 76 return completer.future; | |
| 77 }, count: 4)); | |
| 78 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | |
| 79 document.body.append(e); | |
| 80 await e.onRendered.first; | |
| 81 completer.complete(new AllocationProfileMock()); | |
| 82 await e.onRendered.first; | |
| 83 e.querySelectorAll(rTag).forEach((NavRefreshElement e) => e.refresh()); | |
| 84 e.remove(); | |
| 85 await e.onRendered.first; | |
| 86 expect(e.children.length, isZero, reason: 'is empty'); | |
| 87 }); | |
| 88 test('to gc', () async { | |
|
Cutch
2016/08/17 14:28:44
what about a test that changes the sort?
cbernaschina
2016/08/17 17:01:27
Done.
| |
| 89 final events = new EventRepositoryMock(); | |
| 90 final completer = new Completer<AllocationProfileMock>(); | |
| 91 int count = 0; | |
| 92 final repo = new AllocationProfileRepositoryMock( | |
| 93 getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { | |
| 94 expect(i, equals(isolate)); | |
| 95 expect(gc, isFalse); | |
| 96 expect(reset, isFalse); | |
| 97 count++; | |
| 98 return completer.future; | |
| 99 }, count: 2)); | |
| 100 final e = new AllocationProfileElement(vm, isolate, events, notif, repo); | |
| 101 document.body.append(e); | |
| 102 await e.onRendered.first; | |
| 103 completer.complete(new AllocationProfileMock()); | |
| 104 await e.onRendered.first; | |
| 105 e.querySelector('input[type=\'checkbox\']').click(); | |
| 106 expect(events.onGCEventHasListener, isTrue); | |
| 107 events.add(new GCEventMock(isolate: isolate)); | |
| 108 await e.onRendered.first; | |
| 109 expect(count, equals(2)); | |
| 110 // shouldn't trigger | |
| 111 events.add(new GCEventMock(isolate: new IsolateRefMock(id: 'another'))); | |
| 112 await (() async {} ()); | |
| 113 e.querySelector('input[type=\'checkbox\']').click(); | |
| 114 // shouldn't trigger | |
| 115 events.add(new GCEventMock(isolate: isolate)); | |
| 116 await (() async {} ()); | |
| 117 e.remove(); | |
| 118 await e.onRendered.first; | |
| 119 expect(e.children.length, isZero, reason: 'is empty'); | |
| 120 }); | |
| 121 }); | |
| 122 } | |
| OLD | NEW |