Files
sdk/pkg/watcher/test/ready_test.dart
T
kevmoo@j832.com 18d38085ab pkg: analysis aided cleanup
Removed a lot of warnings and hints when opening many pkg projects in the editor

R=gram@google.com

Review URL: https://codereview.chromium.org//22284003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25831 260f80e4-7a28-3924-810f-c04153c831b5
2013-08-06 20:42:04 +00:00

105 lines
2.2 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.
import 'dart:async';
import 'package:scheduled_test/scheduled_test.dart';
import 'utils.dart';
main() {
initConfig();
setUp(createSandbox);
test('ready does not complete until after subscription', () {
var watcher = createWatcher(waitForReady: false);
var ready = false;
watcher.ready.then((_) {
ready = true;
});
// Should not be ready yet.
schedule(() {
expect(ready, isFalse);
});
// Subscribe to the events.
schedule(() {
var subscription = watcher.events.listen((event) {});
currentSchedule.onComplete.schedule(() {
subscription.cancel();
});
});
// Should eventually be ready.
schedule(() => watcher.ready);
schedule(() {
expect(ready, isTrue);
});
});
test('ready completes immediately when already ready', () {
var watcher = createWatcher(waitForReady: false);
// Subscribe to the events.
schedule(() {
var subscription = watcher.events.listen((event) {});
currentSchedule.onComplete.schedule(() {
subscription.cancel();
});
});
// Should eventually be ready.
schedule(() => watcher.ready);
// Now ready should be a future that immediately completes.
var ready = false;
schedule(() {
watcher.ready.then((_) {
ready = true;
});
});
schedule(() {
expect(ready, isTrue);
});
});
test('ready returns a future that does not complete after unsubscribing', () {
var watcher = createWatcher(waitForReady: false);
// Subscribe to the events.
var subscription;
schedule(() {
subscription = watcher.events.listen((event) {});
});
var ready = false;
// Wait until ready.
schedule(() => watcher.ready);
// Now unsubscribe.
schedule(() {
subscription.cancel();
// Track when it's ready again.
ready = false;
watcher.ready.then((_) {
ready = true;
});
});
// Should be back to not ready.
schedule(() {
expect(ready, isFalse);
});
});
}