Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: runtime/observatory/tests/observatory_ui/nav/notify/element_test.dart

Issue 2173373002: Revert "Use Timer and not AnimationFrame during Observatory UI tests" (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Revert "Use Timer and not AnimationFrame during Observatory UI tests" Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import 'dart:html' hide Notification, NotificationEvent; 4 import 'dart:html' hide Notification, NotificationEvent;
5 import 'package:unittest/unittest.dart'; 5 import 'package:unittest/unittest.dart';
6 import 'package:observatory/mocks.dart'; 6 import 'package:observatory/mocks.dart';
7 import 'package:observatory/models.dart' as M; 7 import 'package:observatory/models.dart' as M;
8 import 'package:observatory/src/elements/helpers/rendering_queue.dart';
9 import 'package:observatory/src/elements/nav/notify.dart'; 8 import 'package:observatory/src/elements/nav/notify.dart';
10 import 'package:observatory/src/elements/nav/notify_event.dart'; 9 import 'package:observatory/src/elements/nav/notify_event.dart';
11 import 'package:observatory/src/elements/nav/notify_exception.dart'; 10 import 'package:observatory/src/elements/nav/notify_exception.dart';
12 11
13 main() { 12 main() {
14 NavNotifyElement.tag.ensureRegistration(); 13 NavNotifyElement.tag.ensureRegistration();
15 14
16 final evTag = NavNotifyEventElement.tag.name; 15 final evTag = NavNotifyEventElement.tag.name;
17 final exTag = NavNotifyExceptionElement.tag.name; 16 final exTag = NavNotifyExceptionElement.tag.name;
18 17
19 final TimedRenderingBarrier barrier = new TimedRenderingBarrier();
20 final RenderingQueue queue = new RenderingQueue.fromBarrier(barrier);
21
22 const vm = const VMRefMock(); 18 const vm = const VMRefMock();
23 const isolate = const IsolateRefMock(id: 'i-id', name: 'i-name'); 19 const isolate = const IsolateRefMock(id: 'i-id', name: 'i-name');
24 20
25 group('instantiation', () { 21 group('instantiation', () {
26 test('default', () { 22 test('default', () {
27 final NavNotifyElement e = new NavNotifyElement( 23 final NavNotifyElement e = new NavNotifyElement(
28 new NotificationRepositoryMock()); 24 new NotificationRepositoryMock());
29 expect(e, isNotNull, reason: 'element correctly created'); 25 expect(e, isNotNull, reason: 'element correctly created');
30 expect(e.notifyOnPause, isTrue, reason: 'notifyOnPause is default'); 26 expect(e.notifyOnPause, isTrue, reason: 'notifyOnPause is default');
31 }); 27 });
32 test('notify on pause', () { 28 test('notify on pause', () {
33 final NavNotifyElement e = new NavNotifyElement( 29 final NavNotifyElement e = new NavNotifyElement(
34 new NotificationRepositoryMock(), notifyOnPause: true); 30 new NotificationRepositoryMock(), notifyOnPause: true);
35 expect(e, isNotNull, reason: 'element correctly created'); 31 expect(e, isNotNull, reason: 'element correctly created');
36 expect(e.notifyOnPause, isTrue, reason: 'notifyOnPause is the same'); 32 expect(e.notifyOnPause, isTrue, reason: 'notifyOnPause is the same');
37 }); 33 });
38 test('do not notify on pause', () { 34 test('do not notify on pause', () {
39 final NavNotifyElement e = new NavNotifyElement( 35 final NavNotifyElement e = new NavNotifyElement(
40 new NotificationRepositoryMock(), notifyOnPause: false); 36 new NotificationRepositoryMock(), notifyOnPause: false);
41 expect(e, isNotNull, reason: 'element correctly created'); 37 expect(e, isNotNull, reason: 'element correctly created');
42 expect(e.notifyOnPause, isFalse, reason: 'notifyOnPause is the same'); 38 expect(e.notifyOnPause, isFalse, reason: 'notifyOnPause is the same');
43 }); 39 });
44 }); 40 });
45 test('is correctly listening', () async { 41 test('is correctly listening', () async {
46 final NotificationRepositoryMock repository = 42 final NotificationRepositoryMock repository =
47 new NotificationRepositoryMock(); 43 new NotificationRepositoryMock();
48 final NavNotifyElement e = new NavNotifyElement(repository, queue: queue); 44 final NavNotifyElement e = new NavNotifyElement(repository);
49 document.body.append(e); 45 document.body.append(e);
50 await e.onRendered.first; 46 await e.onRendered.first;
51 expect(repository.hasListeners, isTrue, reason: 'is listening'); 47 expect(repository.hasListeners, isTrue, reason: 'is listening');
52 e.remove(); 48 e.remove();
53 await e.onRendered.first; 49 await e.onRendered.first;
54 expect(repository.hasListeners, isFalse, reason: 'is no more listening'); 50 expect(repository.hasListeners, isFalse, reason: 'is no more listening');
55 }); 51 });
56 group('elements', () { 52 group('elements', () {
57 test('created after attachment', () async { 53 test('created after attachment', () async {
58 final NotificationRepositoryMock repository = 54 final NotificationRepositoryMock repository =
59 new NotificationRepositoryMock(list: [ 55 new NotificationRepositoryMock(list: [
60 new ExceptionNotificationMock(exception: new Exception("ex")), 56 new ExceptionNotificationMock(exception: new Exception("ex")),
61 const EventNotificationMock(event: const VMUpdateEventMock(vm: vm)), 57 const EventNotificationMock(event: const VMUpdateEventMock(vm: vm)),
62 const EventNotificationMock(event: const VMUpdateEventMock(vm: vm)) 58 const EventNotificationMock(event: const VMUpdateEventMock(vm: vm))
63 ]); 59 ]);
64 final NavNotifyElement e = new NavNotifyElement(repository, queue: queue); 60 final NavNotifyElement e = new NavNotifyElement(repository);
65 document.body.append(e); 61 document.body.append(e);
66 await e.onRendered.first; 62 await e.onRendered.first;
67 expect(repository.listInvoked, isTrue, reason: 'should invoke list()'); 63 expect(repository.listInvoked, isTrue, reason: 'should invoke list()');
68 expect(e.children.length, isNonZero, reason: 'has elements'); 64 expect(e.children.length, isNonZero, reason: 'has elements');
69 expect(e.querySelectorAll(evTag).length, equals(2)); 65 expect(e.querySelectorAll(evTag).length, equals(2));
70 expect(e.querySelectorAll(exTag).length, equals(1)); 66 expect(e.querySelectorAll(exTag).length, equals(1));
71 e.remove(); 67 e.remove();
72 await e.onRendered.first; 68 await e.onRendered.first;
73 expect(e.children.length, isZero, reason: 'is empty'); 69 expect(e.children.length, isZero, reason: 'is empty');
74 }); 70 });
75 test('react to notifyOnPause change', () async { 71 test('react to notifyOnPause change', () async {
76 final NotificationRepositoryMock repository = 72 final NotificationRepositoryMock repository =
77 new NotificationRepositoryMock(list: [ 73 new NotificationRepositoryMock(list: [
78 new ExceptionNotificationMock(exception: new Exception("ex")), 74 new ExceptionNotificationMock(exception: new Exception("ex")),
79 const EventNotificationMock(event: const VMUpdateEventMock()), 75 const EventNotificationMock(event: const VMUpdateEventMock()),
80 const EventNotificationMock( 76 const EventNotificationMock(
81 event: const PauseStartEventMock(isolate: isolate)) 77 event: const PauseStartEventMock(isolate: isolate))
82 ]); 78 ]);
83 final NavNotifyElement e = new NavNotifyElement(repository, 79 final NavNotifyElement e = new NavNotifyElement(repository,
84 notifyOnPause: true, queue: queue); 80 notifyOnPause: true);
85 document.body.append(e); 81 document.body.append(e);
86 await e.onRendered.first; 82 await e.onRendered.first;
87 expect(e.querySelectorAll(evTag).length, equals(2)); 83 expect(e.querySelectorAll(evTag).length, equals(2));
88 expect(e.querySelectorAll(exTag).length, equals(1)); 84 expect(e.querySelectorAll(exTag).length, equals(1));
89 e.notifyOnPause = false; 85 e.notifyOnPause = false;
90 await e.onRendered.first; 86 await e.onRendered.first;
91 expect(e.querySelectorAll(evTag).length, equals(1)); 87 expect(e.querySelectorAll(evTag).length, equals(1));
92 expect(e.querySelectorAll(exTag).length, equals(1)); 88 expect(e.querySelectorAll(exTag).length, equals(1));
93 e.notifyOnPause = true; 89 e.notifyOnPause = true;
94 await e.onRendered.first; 90 await e.onRendered.first;
95 expect(e.querySelectorAll(evTag).length, equals(2)); 91 expect(e.querySelectorAll(evTag).length, equals(2));
96 expect(e.querySelectorAll(exTag).length, equals(1)); 92 expect(e.querySelectorAll(exTag).length, equals(1));
97 e.remove(); 93 e.remove();
98 await e.onRendered.first; 94 await e.onRendered.first;
99 expect(e.children.length, isZero, reason: 'is empty'); 95 expect(e.children.length, isZero, reason: 'is empty');
100 }); 96 });
101 test('react to update event', () async { 97 test('react to update event', () async {
102 final List<M.Notification> list = [ 98 final List<M.Notification> list = [
103 new ExceptionNotificationMock(exception: new Exception("ex")), 99 new ExceptionNotificationMock(exception: new Exception("ex")),
104 const EventNotificationMock(event: const VMUpdateEventMock()), 100 const EventNotificationMock(event: const VMUpdateEventMock()),
105 ]; 101 ];
106 final NotificationRepositoryMock repository = 102 final NotificationRepositoryMock repository =
107 new NotificationRepositoryMock(list: list); 103 new NotificationRepositoryMock(list: list);
108 final NavNotifyElement e = new NavNotifyElement(repository, 104 final NavNotifyElement e = new NavNotifyElement(repository,
109 notifyOnPause: true, queue: queue); 105 notifyOnPause: true);
110 document.body.append(e); 106 document.body.append(e);
111 await e.onRendered.first; 107 await e.onRendered.first;
112 expect(e.querySelectorAll(evTag).length, equals(1)); 108 expect(e.querySelectorAll(evTag).length, equals(1));
113 expect(e.querySelectorAll(exTag).length, equals(1)); 109 expect(e.querySelectorAll(exTag).length, equals(1));
114 list.add(const EventNotificationMock( 110 list.add(const EventNotificationMock(
115 event: const PauseStartEventMock(isolate: isolate))); 111 event: const PauseStartEventMock(isolate: isolate)));
116 repository.triggerChangeEvent(); 112 repository.triggerChangeEvent();
117 await e.onRendered.first; 113 await e.onRendered.first;
118 expect(e.querySelectorAll(evTag).length, equals(2)); 114 expect(e.querySelectorAll(evTag).length, equals(2));
119 expect(e.querySelectorAll(exTag).length, equals(1)); 115 expect(e.querySelectorAll(exTag).length, equals(1));
120 e.remove(); 116 e.remove();
121 await e.onRendered.first; 117 await e.onRendered.first;
122 expect(e.children.length, isZero, reason: 'is empty'); 118 expect(e.children.length, isZero, reason: 'is empty');
123 }); 119 });
124 }); 120 });
125 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698