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

Unified Diff: tests/lib/async/timer_isActive_test.dart

Issue 18325006: Add isActive field on Timer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: tests/lib/async/timer_isActive_test.dart
diff --git a/tests/lib/async/timer_isActive_test.dart b/tests/lib/async/timer_isActive_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f8da78f07859bce566a0ea59be35fb931c480cdb
--- /dev/null
+++ b/tests/lib/async/timer_isActive_test.dart
@@ -0,0 +1,55 @@
+// Copyright (c) 2011, 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.
+
+import 'dart:async';
+import '../../../pkg/unittest/lib/unittest.dart';
+
+main() {
+
+ test("timer isActive test", () {
+ Timer t;
+
+ void checkNotActive() => expect(t.isActive, equals(false));
floitsch 2013/07/01 12:49:43 nit: if the function is that small, just use it at
zarah 2013/07/01 16:15:35 Done.
+
+ t = new Timer(new Duration(seconds: 1), expectAsync0(checkNotActive));
+ expect(t.isActive, equals(true));
+ });
+
+ test("periodic timer cancel test", () {
+ Timer t;
+
+ int i = 0;
+ void checkActive(Timer timer) {
+ expect(t.isActive, equals(true));
+ if (i == 2) {
+ t.cancel();
+ expect(t.isActive, equals(false));
+ }
+ i++;
+ }
+
+ t = new Timer.periodic(new Duration(milliseconds: 1),
+ expectAsync1(checkActive, count: 3));
+ });
floitsch 2013/07/01 12:49:43 check that timer is active outside callback.
zarah 2013/07/01 16:15:35 Done.
+
+ test("timer cancel test", () {
+ Timer timer;
+ Timer canceller;
+
+ void unreachable() {
+ fail("Cancelled timer should not be reached");
+ }
+
+ void cancelOtherTimer() {
+ expect(timer.isActive, equals(true));
+ timer.cancel();
+ expect(timer.isActive, equals(t));
floitsch 2013/07/01 12:49:43 t?
zarah 2013/07/01 16:15:35 t-> true
+ }
+
+ timer = new Timer(new Duration(milliseconds: 1),
floitsch 2013/07/01 12:49:43 nits: no need to assign it if you don't use it lat
zarah 2013/07/01 16:15:35 Done.
+ expectAsync0(cancelOtherTimer));
+ timer = new Timer(new Duration(milliseconds: 1000),
floitsch 2013/07/01 12:49:43 seconds: 1
zarah 2013/07/01 16:15:35 Done.
+ expectAsync0(unreachable, count: 0));
floitsch 2013/07/01 12:49:43 this line should not be reached. -> don't expectAs
zarah 2013/07/01 16:15:35 Done.
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698