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

Side by Side Diff: tests/lib_strong/async/multiple_timer_test.dart

Issue 2802973005: Migrate async tests to strong (Closed)
Patch Set: Created 3 years, 8 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library multiple_timer_test;
6
7 import 'dart:async';
8 import 'package:unittest/unittest.dart';
9
10 const Duration TIMEOUT1 = const Duration(seconds: 1);
11 const Duration TIMEOUT2 = const Duration(seconds: 2);
12 const Duration TIMEOUT3 = const Duration(milliseconds: 500);
13 const Duration TIMEOUT4 = const Duration(milliseconds: 1500);
14
15 // The stopwatch is more precise than the Timer.
16 // Some browsers (Firefox and IE so far) can trigger too early. So we add more
17 // margin. We use identical(1, 1.0) as an easy way to know if the test is
18 // compiled by dart2js.
19 int get safetyMargin => identical(1, 1.0) ? 100 : 0;
20
21 main() {
22 test("multiple timer test", () {
23 Stopwatch _stopwatch1 = new Stopwatch();
24 Stopwatch _stopwatch2 = new Stopwatch();
25 Stopwatch _stopwatch3 = new Stopwatch();
26 Stopwatch _stopwatch4 = new Stopwatch();
27 List<int> _order;
28 int _message;
29
30 void timeoutHandler1() {
31 expect(_stopwatch1.elapsedMilliseconds + safetyMargin,
32 greaterThanOrEqualTo(TIMEOUT1.inMilliseconds));
33 expect(_order[_message], 0);
34 _message++;
35 }
36
37 void timeoutHandler2() {
38 expect(_stopwatch2.elapsedMilliseconds + safetyMargin,
39 greaterThanOrEqualTo(TIMEOUT2.inMilliseconds));
40 expect(_order[_message], 1);
41 _message++;
42 }
43
44 void timeoutHandler3() {
45 expect(_stopwatch3.elapsedMilliseconds + safetyMargin,
46 greaterThanOrEqualTo(TIMEOUT3.inMilliseconds));
47 expect(_order[_message], 2);
48 _message++;
49 }
50
51 void timeoutHandler4() {
52 expect(_stopwatch4.elapsedMilliseconds + safetyMargin,
53 greaterThanOrEqualTo(TIMEOUT4.inMilliseconds));
54 expect(_order[_message], 3);
55 _message++;
56 }
57
58 _order = new List<int>(4);
59 _order[0] = 2;
60 _order[1] = 0;
61 _order[2] = 3;
62 _order[3] = 1;
63 _message = 0;
64
65 _stopwatch1.start();
66 new Timer(TIMEOUT1, expectAsync(timeoutHandler1));
67 _stopwatch2.start();
68 new Timer(TIMEOUT2, expectAsync(timeoutHandler2));
69 _stopwatch3.start();
70 new Timer(TIMEOUT3, expectAsync(timeoutHandler3));
71 _stopwatch4.start();
72 new Timer(TIMEOUT4, expectAsync(timeoutHandler4));
73 });
74 }
OLDNEW
« no previous file with comments | « tests/lib_strong/async/intercept_schedule_microtask6_test.dart ('k') | tests/lib_strong/async/print_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698