2dcd56ef43
There are far too many files here to review everyone carefully. Spot checking most of the diffs look good as test code is generally written with less care than application code so lots of ugly formatting get through. If people notice files where the automated formatting bothers them feel free to comment indicating file names and I'll move spaces within comments to make the formatting cleaner and use comments to force block formatting as I have done for other case where formatting looked bad. BUG= R=efortuna@google.com Review-Url: https://codereview.chromium.org/2771453003 .
75 lines
2.3 KiB
Dart
75 lines
2.3 KiB
Dart
// Copyright (c) 2012, 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.
|
|
|
|
library multiple_timer_test;
|
|
|
|
import 'dart:async';
|
|
import 'package:unittest/unittest.dart';
|
|
|
|
const Duration TIMEOUT1 = const Duration(seconds: 1);
|
|
const Duration TIMEOUT2 = const Duration(seconds: 2);
|
|
const Duration TIMEOUT3 = const Duration(milliseconds: 500);
|
|
const Duration TIMEOUT4 = const Duration(milliseconds: 1500);
|
|
|
|
// The stopwatch is more precise than the Timer.
|
|
// Some browsers (Firefox and IE so far) can trigger too early. So we add more
|
|
// margin. We use identical(1, 1.0) as an easy way to know if the test is
|
|
// compiled by dart2js.
|
|
int get safetyMargin => identical(1, 1.0) ? 100 : 0;
|
|
|
|
main() {
|
|
test("multiple timer test", () {
|
|
Stopwatch _stopwatch1 = new Stopwatch();
|
|
Stopwatch _stopwatch2 = new Stopwatch();
|
|
Stopwatch _stopwatch3 = new Stopwatch();
|
|
Stopwatch _stopwatch4 = new Stopwatch();
|
|
List<int> _order;
|
|
int _message;
|
|
|
|
void timeoutHandler1() {
|
|
expect(_stopwatch1.elapsedMilliseconds + safetyMargin,
|
|
greaterThanOrEqualTo(TIMEOUT1.inMilliseconds));
|
|
expect(_order[_message], 0);
|
|
_message++;
|
|
}
|
|
|
|
void timeoutHandler2() {
|
|
expect(_stopwatch2.elapsedMilliseconds + safetyMargin,
|
|
greaterThanOrEqualTo(TIMEOUT2.inMilliseconds));
|
|
expect(_order[_message], 1);
|
|
_message++;
|
|
}
|
|
|
|
void timeoutHandler3() {
|
|
expect(_stopwatch3.elapsedMilliseconds + safetyMargin,
|
|
greaterThanOrEqualTo(TIMEOUT3.inMilliseconds));
|
|
expect(_order[_message], 2);
|
|
_message++;
|
|
}
|
|
|
|
void timeoutHandler4() {
|
|
expect(_stopwatch4.elapsedMilliseconds + safetyMargin,
|
|
greaterThanOrEqualTo(TIMEOUT4.inMilliseconds));
|
|
expect(_order[_message], 3);
|
|
_message++;
|
|
}
|
|
|
|
_order = new List<int>(4);
|
|
_order[0] = 2;
|
|
_order[1] = 0;
|
|
_order[2] = 3;
|
|
_order[3] = 1;
|
|
_message = 0;
|
|
|
|
_stopwatch1.start();
|
|
new Timer(TIMEOUT1, expectAsync(timeoutHandler1));
|
|
_stopwatch2.start();
|
|
new Timer(TIMEOUT2, expectAsync(timeoutHandler2));
|
|
_stopwatch3.start();
|
|
new Timer(TIMEOUT3, expectAsync(timeoutHandler3));
|
|
_stopwatch4.start();
|
|
new Timer(TIMEOUT4, expectAsync(timeoutHandler4));
|
|
});
|
|
}
|