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

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

Issue 2995013002: Migrated test block 170 to Dart 2.0. (Closed)
Patch Set: Fixed issues caused by bug in package:test Created 3 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
(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:async_helper/async_helper.dart';
9 import 'package:expect/expect.dart';
10
11 const Duration TIMEOUT1 = const Duration(seconds: 1);
12 const Duration TIMEOUT2 = const Duration(seconds: 2);
13 const Duration TIMEOUT3 = const Duration(milliseconds: 500);
14 const Duration TIMEOUT4 = const Duration(milliseconds: 1500);
15
16 // The stopwatch is more precise than the Timer.
17 // Some browsers (Firefox and IE so far) can trigger too early. So we add more
18 // margin. We use identical(1, 1.0) as an easy way to know if the test is
19 // compiled by dart2js.
Bob Nystrom 2017/08/23 21:40:28 Nit: "compiled by dart2js" -> "running on the web"
20 int get safetyMargin => identical(1, 1.0) ? 100 : 0;
21
22 main() {
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.isTrue((_stopwatch1.elapsedMilliseconds + safetyMargin) >=
32 TIMEOUT1.inMilliseconds);
33 Expect.equals(_order[_message], 0);
34 _message++;
35 asyncEnd();
36 }
37
38 void timeoutHandler2() {
39 Expect.isTrue((_stopwatch2.elapsedMilliseconds + safetyMargin) >=
40 TIMEOUT2.inMilliseconds);
41 Expect.equals(_order[_message], 1);
42 _message++;
43 asyncEnd();
44 }
45
46 void timeoutHandler3() {
47 Expect.isTrue((_stopwatch3.elapsedMilliseconds + safetyMargin) >=
48 TIMEOUT3.inMilliseconds);
49 Expect.equals(_order[_message], 2);
50 _message++;
51 asyncEnd();
52 }
53
54 void timeoutHandler4() {
55 Expect.isTrue((_stopwatch4.elapsedMilliseconds + safetyMargin) >=
56 TIMEOUT4.inMilliseconds);
57 Expect.equals(_order[_message], 3);
58 _message++;
59 asyncEnd();
60 }
61
62 _order = new List<int>(4);
63 _order[0] = 2;
64 _order[1] = 0;
65 _order[2] = 3;
66 _order[3] = 1;
67 _message = 0;
68
69 asyncStart();
70 _stopwatch1.start();
71 new Timer(TIMEOUT1, timeoutHandler1);
72 asyncStart();
73 _stopwatch2.start();
74 new Timer(TIMEOUT2, timeoutHandler2);
75 asyncStart();
76 _stopwatch3.start();
77 new Timer(TIMEOUT3, timeoutHandler3);
78 asyncStart();
79 _stopwatch4.start();
80 new Timer(TIMEOUT4, timeoutHandler4);
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698