diff --git a/packages/flutter/lib/src/foundation/synchronous_future.dart b/packages/flutter/lib/src/foundation/synchronous_future.dart index a635e2b763..bb589a8148 100644 --- a/packages/flutter/lib/src/foundation/synchronous_future.dart +++ b/packages/flutter/lib/src/foundation/synchronous_future.dart @@ -42,7 +42,9 @@ class SynchronousFuture implements Future { } @override - Future timeout(Duration timeLimit, { dynamic onTimeout() }) => new Completer().future; + Future timeout(Duration timeLimit, { dynamic onTimeout() }) { + return new Future.value(_value).timeout(timeLimit, onTimeout: onTimeout); + } @override Future whenComplete(dynamic action()) { @@ -55,4 +57,4 @@ class SynchronousFuture implements Future { return new Future.error(e, stack); } } -} \ No newline at end of file +} diff --git a/packages/flutter/lib/src/material/button.dart b/packages/flutter/lib/src/material/button.dart index 7e8c1992d2..7dc0377289 100644 --- a/packages/flutter/lib/src/material/button.dart +++ b/packages/flutter/lib/src/material/button.dart @@ -230,6 +230,7 @@ class _MaterialButtonState extends State { } } } else { + assert(_colorBrightness != null); switch (_colorBrightness) { case Brightness.light: return Colors.black26; @@ -237,7 +238,6 @@ class _MaterialButtonState extends State { return Colors.white30; } } - assert(_colorBrightness != null); return null; } diff --git a/packages/flutter/test/animation/animation_controller_test.dart b/packages/flutter/test/animation/animation_controller_test.dart index f3ba176efd..b6e6ee401f 100644 --- a/packages/flutter/test/animation/animation_controller_test.dart +++ b/packages/flutter/test/animation/animation_controller_test.dart @@ -269,4 +269,18 @@ void main() { controller.dispose(); expect(controller, hasOneLineDescription); }); + + test('AnimationController error handling', () { + AnimationController controller = new AnimationController( + vsync: const TestVSync(), + ); + + expect(controller.forward, throwsFlutterError); + expect(controller.reverse, throwsFlutterError); + expect(() { controller.animateTo(0.5); }, throwsFlutterError); + expect(controller.repeat, throwsFlutterError); + + controller.dispose(); + expect(controller.dispose, throwsFlutterError); + }); } diff --git a/packages/flutter/test/animation/animations_test.dart b/packages/flutter/test/animation/animations_test.dart index 2bb0050669..6b472e9f79 100644 --- a/packages/flutter/test/animation/animations_test.dart +++ b/packages/flutter/test/animation/animations_test.dart @@ -6,6 +6,11 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/animation.dart'; import 'package:flutter/widgets.dart'; +class BogusCurve extends Curve { + @override + double transform(double t) => 100.0; +} + void main() { setUp(() { WidgetsFlutterBinding.ensureInitialized(); @@ -113,7 +118,6 @@ void main() { expect(animation.toString(), contains('no next')); }); - test('AnimationMean control test', () { AnimationController left = new AnimationController( value: 0.5, @@ -148,4 +152,13 @@ void main() { expect(mean.value, equals(0.50)); expect(log, isEmpty); }); + + test('CurvedAnimation with bogus curve', () { + AnimationController controller = new AnimationController( + vsync: const TestVSync(), + ); + CurvedAnimation curved = new CurvedAnimation(parent: controller, curve: new BogusCurve()); + + expect(() { curved.value; }, throwsFlutterError); + }); } diff --git a/packages/flutter/test/foundation/caching_iterable_test.dart b/packages/flutter/test/foundation/caching_iterable_test.dart index 4834f3c7fd..24981ddd46 100644 --- a/packages/flutter/test/foundation/caching_iterable_test.dart +++ b/packages/flutter/test/foundation/caching_iterable_test.dart @@ -90,4 +90,21 @@ void main() { expect(integers, equals([1, 2, 3, 4, 5])); expect(yieldCount, equals(5)); }); + + test('The Caching Iterable: expand', () { + Iterable integers = new CachingIterable(range(1, 5).iterator); + expect(yieldCount, equals(0)); + + Iterable expanded1 = integers.expand((int i) => [i, i]); + + expect(yieldCount, equals(0)); + expect(expanded1, equals([1, 1, 2, 2, 3, 3, 4, 4, 5, 5])); + expect(yieldCount, equals(5)); + + Iterable expanded2 = integers.expand((int i) => [i, i]); + + expect(yieldCount, equals(5)); + expect(expanded2, equals([1, 1, 2, 2, 3, 3, 4, 4, 5, 5])); + expect(yieldCount, equals(5)); + }); } diff --git a/packages/flutter/test/foundation/synchronous_future_test.dart b/packages/flutter/test/foundation/synchronous_future_test.dart new file mode 100644 index 0000000000..5fdff4a1a4 --- /dev/null +++ b/packages/flutter/test/foundation/synchronous_future_test.dart @@ -0,0 +1,54 @@ +// Copyright 2017 The Chromium Authors. 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:flutter/foundation.dart'; +import 'package:test/test.dart'; + +void main() { + test('SynchronousFuture control test', () async { + Future future = new SynchronousFuture(42); + + int result; + future.then((int value) { result = value; }); + + expect(result, equals(42)); + result = null; + + Future futureWithTimeout = future.timeout(const Duration(milliseconds: 1)); + futureWithTimeout.then((int value) { result = value; }); + expect(result, isNull); + await futureWithTimeout; + expect(result, equals(42)); + result = null; + + Stream stream = future.asStream(); + + expect(await stream.single, equals(42)); + + bool ranAction = false; + Future completeResult = future.whenComplete(() { + ranAction = true; + return new Future.value(31); + }); + + expect(ranAction, isTrue); + ranAction = false; + + expect(await completeResult, equals(42)); + + Object exception; + try { + await future.whenComplete(() { + throw null; + }); + // Unreached. + expect(false, isTrue); + } catch (e) { + exception = e; + } + expect(exception, isNullThrownError); + }); +} diff --git a/packages/flutter/test/material/icon_theme_data_test.dart b/packages/flutter/test/material/icon_theme_data_test.dart new file mode 100644 index 0000000000..8684aa0b9c --- /dev/null +++ b/packages/flutter/test/material/icon_theme_data_test.dart @@ -0,0 +1,21 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + test('IconThemeData control test', () { + IconThemeData data = new IconThemeData(color: Colors.green[500], opacity: 0.5, size: 16.0); + + expect(data, hasOneLineDescription); + expect(data, equals(data.copyWith())); + expect(data.hashCode, equals(data.copyWith().hashCode)); + + IconThemeData lerped = IconThemeData.lerp(data, const IconThemeData.fallback(), 0.25); + expect(lerped.color, equals(Color.lerp(Colors.green[500], Colors.black, 0.25))); + expect(lerped.opacity, equals(0.625)); + expect(lerped.size, equals(18.0)); + }); +} diff --git a/packages/flutter/test/material/theme_data_test.dart b/packages/flutter/test/material/theme_data_test.dart index 2ddeef3fa0..a50f1f28e2 100644 --- a/packages/flutter/test/material/theme_data_test.dart +++ b/packages/flutter/test/material/theme_data_test.dart @@ -6,6 +6,20 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { + test('Theme data control test', () { + ThemeData dark = new ThemeData.dark(); + + expect(dark, hasOneLineDescription); + expect(dark, equals(dark.copyWith())); + expect(dark.hashCode, equals(dark.copyWith().hashCode)); + + ThemeData light = new ThemeData.light(); + ThemeData dawn = ThemeData.lerp(dark, light, 0.25); + + expect(dawn.brightness, Brightness.dark); + expect(dawn.primaryColor, Color.lerp(dark.primaryColor, light.primaryColor, 0.25)); + }); + test('Defaults to the default typography for the platform', () { for (TargetPlatform platform in TargetPlatform.values) { ThemeData theme = new ThemeData(platform: platform); diff --git a/packages/flutter/test/scheduler/priority_test.dart b/packages/flutter/test/scheduler/priority_test.dart new file mode 100644 index 0000000000..277ed2278a --- /dev/null +++ b/packages/flutter/test/scheduler/priority_test.dart @@ -0,0 +1,16 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/scheduler.dart'; +import 'package:test/test.dart'; + +void main() { + test('Priority operators control test', () async { + Priority priority = Priority.idle + (Priority.kMaxOffset + 100); + expect(priority.value, equals(Priority.idle.value + Priority.kMaxOffset)); + + priority = Priority.animation - (Priority.kMaxOffset + 100); + expect(priority.value, equals(Priority.animation.value - Priority.kMaxOffset)); + }); +} diff --git a/packages/flutter/test/scheduler/ticker_test.dart b/packages/flutter/test/scheduler/ticker_test.dart index 2616f2e243..a5e5aff5db 100644 --- a/packages/flutter/test/scheduler/ticker_test.dart +++ b/packages/flutter/test/scheduler/ticker_test.dart @@ -23,6 +23,8 @@ void main() { expect(ticker.isActive, isTrue); expect(tickCount, equals(0)); + expect(ticker.start, throwsFlutterError); + await tester.pump(const Duration(milliseconds: 10)); expect(tickCount, equals(1));