Chromium Code Reviews| Index: runtime/observatory/tests/observatory_ui/allocation_profile/element_test.dart |
| diff --git a/runtime/observatory/tests/observatory_ui/allocation_profile/element_test.dart b/runtime/observatory/tests/observatory_ui/allocation_profile/element_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..62c46390999b86d10a67505cfc83bceeef57f100 |
| --- /dev/null |
| +++ b/runtime/observatory/tests/observatory_ui/allocation_profile/element_test.dart |
| @@ -0,0 +1,122 @@ |
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'dart:html'; |
| +import 'dart:async'; |
| +import 'package:unittest/unittest.dart'; |
| +import 'package:observatory/models.dart' as M; |
| +import 'package:observatory/src/elements/allocation_profile.dart'; |
| +import 'package:observatory/src/elements/containers/virtual_collection.dart'; |
| +import 'package:observatory/src/elements/nav/refresh.dart'; |
| +import '../mocks.dart'; |
| + |
| +main() { |
| + AllocationProfileElement.tag.ensureRegistration(); |
| + |
| + final rTag = NavRefreshElement.tag.name; |
| + final vTag = VirtualCollectionElement.tag.name; |
| + |
| + const vm = const VMMock(); |
| + const isolate = const IsolateRefMock(); |
| + final events = new EventRepositoryMock(); |
| + final notif = new NotificationRepositoryMock(); |
| + test('instantiation', () { |
| + final repo = new AllocationProfileRepositoryMock(); |
| + final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
| + expect(e, isNotNull, reason: 'element correctly created'); |
| + }); |
| + test('elements created', () async { |
| + final completer = new Completer<AllocationProfileMock>(); |
| + final repo = new AllocationProfileRepositoryMock( |
| + getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { |
| + expect(i, equals(isolate)); |
| + expect(gc, isFalse); |
| + expect(reset, isFalse); |
| + return completer.future; |
| + }, count: 1)); |
| + final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
| + document.body.append(e); |
| + await e.onRendered.first; |
| + expect(e.children.length, isNonZero, reason: 'has elements'); |
| + expect(e.querySelectorAll(vTag).length, isZero); |
| + completer.complete(new AllocationProfileMock()); |
| + await e.onRendered.first; |
| + expect(e.querySelectorAll(vTag).length, equals(1)); |
| + e.remove(); |
| + await e.onRendered.first; |
| + expect(e.children.length, isZero, reason: 'is empty'); |
| + }); |
| + group('reacts', () { |
| + test('to refresh', () async { |
| + final completer = new Completer<AllocationProfileMock>(); |
| + int step = 0; |
| + final repo = new AllocationProfileRepositoryMock( |
| + getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { |
| + expect(i, equals(isolate)); |
| + switch (step) { |
| + case 0: |
| + expect(gc, isFalse); |
| + expect(reset, isFalse); |
| + break; |
| + case 1: |
| + expect(gc, isFalse); |
| + expect(reset, isTrue); |
| + break; |
| + case 2: |
| + expect(gc, isTrue); |
| + expect(reset, isFalse); |
| + break; |
| + case 3: |
| + expect(gc, isFalse); |
| + expect(reset, isFalse); |
| + break; |
| + } |
| + step++; |
| + return completer.future; |
| + }, count: 4)); |
| + final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
| + document.body.append(e); |
| + await e.onRendered.first; |
| + completer.complete(new AllocationProfileMock()); |
| + await e.onRendered.first; |
| + e.querySelectorAll(rTag).forEach((NavRefreshElement e) => e.refresh()); |
| + e.remove(); |
| + await e.onRendered.first; |
| + expect(e.children.length, isZero, reason: 'is empty'); |
| + }); |
| + 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.
|
| + final events = new EventRepositoryMock(); |
| + final completer = new Completer<AllocationProfileMock>(); |
| + int count = 0; |
| + final repo = new AllocationProfileRepositoryMock( |
| + getter: expectAsync((M.IsolateRef i, bool gc, bool reset) { |
| + expect(i, equals(isolate)); |
| + expect(gc, isFalse); |
| + expect(reset, isFalse); |
| + count++; |
| + return completer.future; |
| + }, count: 2)); |
| + final e = new AllocationProfileElement(vm, isolate, events, notif, repo); |
| + document.body.append(e); |
| + await e.onRendered.first; |
| + completer.complete(new AllocationProfileMock()); |
| + await e.onRendered.first; |
| + e.querySelector('input[type=\'checkbox\']').click(); |
| + expect(events.onGCEventHasListener, isTrue); |
| + events.add(new GCEventMock(isolate: isolate)); |
| + await e.onRendered.first; |
| + expect(count, equals(2)); |
| + // shouldn't trigger |
| + events.add(new GCEventMock(isolate: new IsolateRefMock(id: 'another'))); |
| + await (() async {} ()); |
| + e.querySelector('input[type=\'checkbox\']').click(); |
| + // shouldn't trigger |
| + events.add(new GCEventMock(isolate: isolate)); |
| + await (() async {} ()); |
| + e.remove(); |
| + await e.onRendered.first; |
| + expect(e.children.length, isZero, reason: 'is empty'); |
| + }); |
| + }); |
| +} |