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

Side by Side Diff: tests/isolate/multiple_timer_test.dart

Issue 12213092: Rework Timer interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « tests/html/dromaeo_smoke_test.dart ('k') | tests/isolate/timer_cancel1_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library multiple_timer_test; 5 library multiple_timer_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import '../../pkg/unittest/lib/unittest.dart'; 8 import '../../pkg/unittest/lib/unittest.dart';
9 9
10 const int TIMEOUT1 = 1000; 10 const Duration TIMEOUT1 = const Duration(seconds: 1);
11 const int TIMEOUT2 = 2000; 11 const Duration TIMEOUT2 = const Duration(seconds: 2);
12 const int TIMEOUT3 = 500; 12 const Duration TIMEOUT3 = const Duration(milliseconds: 500);
13 const int TIMEOUT4 = 1500; 13 const Duration TIMEOUT4 = const Duration(milliseconds: 1500);
14 14
15 main() { 15 main() {
16 test("multiple timer test", () { 16 test("multiple timer test", () {
17 int _startTime1; 17 Stopwatch _stopwatch1 = new Stopwatch();
18 int _startTime2; 18 Stopwatch _stopwatch2 = new Stopwatch();
19 int _startTime3; 19 Stopwatch _stopwatch3 = new Stopwatch();
20 int _startTime4; 20 Stopwatch _stopwatch4 = new Stopwatch();
21 List<int> _order; 21 List<int> _order;
22 int _message; 22 int _message;
23 23
24 void timeoutHandler1(Timer timer) { 24 void timeoutHandler1() {
25 int endTime = (new DateTime.now()).millisecondsSinceEpoch; 25 expect(_stopwatch1.elapsedMilliseconds,
26 expect(endTime - _startTime1, greaterThanOrEqualTo(TIMEOUT1)); 26 greaterThanOrEqualTo(TIMEOUT1.inMilliseconds));
27 expect(_order[_message], 0); 27 expect(_order[_message], 0);
28 _message++; 28 _message++;
29 } 29 }
30 30
31 void timeoutHandler2(Timer timer) { 31 void timeoutHandler2() {
32 int endTime = (new DateTime.now()).millisecondsSinceEpoch; 32 expect(_stopwatch2.elapsedMilliseconds,
33 expect(endTime - _startTime2, greaterThanOrEqualTo(TIMEOUT2)); 33 greaterThanOrEqualTo(TIMEOUT2.inMilliseconds));
34 expect(_order[_message], 1); 34 expect(_order[_message], 1);
35 _message++; 35 _message++;
36 } 36 }
37 37
38 void timeoutHandler3(Timer timer) { 38 void timeoutHandler3() {
39 int endTime = (new DateTime.now()).millisecondsSinceEpoch; 39 expect(_stopwatch3.elapsedMilliseconds,
40 expect(endTime - _startTime3, greaterThanOrEqualTo(TIMEOUT3)); 40 greaterThanOrEqualTo(TIMEOUT3.inMilliseconds));
41 expect(_order[_message], 2); 41 expect(_order[_message], 2);
42 _message++; 42 _message++;
43 } 43 }
44 44
45 void timeoutHandler4(Timer timer) { 45 void timeoutHandler4() {
46 int endTime = (new DateTime.now()).millisecondsSinceEpoch; 46 expect(_stopwatch4.elapsedMilliseconds,
47 expect(endTime - _startTime4, greaterThanOrEqualTo(TIMEOUT4)); 47 greaterThanOrEqualTo(TIMEOUT4.inMilliseconds));
48 expect(_order[_message], 3); 48 expect(_order[_message], 3);
49 _message++; 49 _message++;
50 } 50 }
51 51
52 _order = new List<int>.fixedLength(4); 52 _order = new List<int>.fixedLength(4);
53 _order[0] = 2; 53 _order[0] = 2;
54 _order[1] = 0; 54 _order[1] = 0;
55 _order[2] = 3; 55 _order[2] = 3;
56 _order[3] = 1; 56 _order[3] = 1;
57 _message = 0; 57 _message = 0;
58 58
59 _startTime1 = (new DateTime.now()).millisecondsSinceEpoch; 59 _stopwatch1.start();
60 new Timer(TIMEOUT1, expectAsync1(timeoutHandler1)); 60 new Timer(TIMEOUT1, expectAsync0(timeoutHandler1));
61 _startTime2 = (new DateTime.now()).millisecondsSinceEpoch; 61 _stopwatch2.start();
62 new Timer(TIMEOUT2, expectAsync1(timeoutHandler2)); 62 new Timer(TIMEOUT2, expectAsync0(timeoutHandler2));
63 _startTime3 = (new DateTime.now()).millisecondsSinceEpoch; 63 _stopwatch3.start();
64 new Timer(TIMEOUT3, expectAsync1(timeoutHandler3)); 64 new Timer(TIMEOUT3, expectAsync0(timeoutHandler3));
65 _startTime4 = (new DateTime.now()).millisecondsSinceEpoch; 65 _stopwatch4.start();
66 new Timer(TIMEOUT4, expectAsync1(timeoutHandler4)); 66 new Timer(TIMEOUT4, expectAsync0(timeoutHandler4));
67 }); 67 });
68 } 68 }
OLDNEW
« no previous file with comments | « tests/html/dromaeo_smoke_test.dart ('k') | tests/isolate/timer_cancel1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698