flutter_flutter/packages/flutter/test/widget/scroll_notification_test.dart
Ian Hickson 17cdc88958 Improve our scroll physics on iOS (#5340)
Changes in this patch:
- iOS now uses a different scrollDrag constant than Android.
   - ScrollConfigurationDelegate now knows about target platforms.
   - ScrollBehaviors now know about target platforms.
   - RawInputLine now has to be told what platform it's targetting.
   - PageableList now has a concept of target platform.
- make debugPrintStack filter its stack.
   - move debugPrintStack to `assertions.dart`.
- add support for limiting the number of frames to debugPrintStack.
- make defaultTargetPlatform default to android in test environments.
- remove OverscrollStyle and MaterialApp's overscrollStyle argument. You
  can now control the overscroll style using Theme.platform.
- the default scroll configuration is now private to avoid people
  relying on the defaultTargetPlatform getter in their subclasses (since
  they really should use Theme.of(context).platform).
- fix some typos I noticed in some tests.
- added a test for flinging scrollables, that checks that the behavior
  differs on the two target platforms.
- made flingFrom and fling in the test API pump the frames.
- added more docs to the test API.
- made the TestAsyncUtils.guard() method report uncaught errors to help
  debug errors when using that API.
2016-08-11 11:31:30 -07:00

100 lines
3.8 KiB
Dart

// Copyright 2015 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_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
void main() {
testWidgets('Scroll notification basics', (WidgetTester tester) async {
ScrollNotification notification;
await tester.pumpWidget(new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification value) {
notification = value;
return false;
},
child: new ScrollableViewport(
child: new SizedBox(height: 1200.0)
)
));
TestGesture gesture = await tester.startGesture(new Point(100.0, 100.0));
await tester.pump(const Duration(seconds: 1));
expect(notification.kind, equals(ScrollNotificationKind.started));
expect(notification.depth, equals(0));
expect(notification.dragStartDetails, isNotNull);
expect(notification.dragStartDetails.globalPosition, equals(new Point(100.0, 100.0)));
expect(notification.dragUpdateDetails, isNull);
expect(notification.dragEndDetails, isNull);
await gesture.moveBy(new Offset(-10.0, -10.0));
await tester.pump(const Duration(seconds: 1));
expect(notification.kind, equals(ScrollNotificationKind.updated));
expect(notification.depth, equals(0));
expect(notification.dragStartDetails, isNull);
expect(notification.dragUpdateDetails, isNotNull);
expect(notification.dragUpdateDetails.globalPosition, equals(new Point(90.0, 90.0)));
expect(notification.dragUpdateDetails.delta, equals(new Offset(0.0, -10.0)));
expect(notification.dragEndDetails, isNull);
await gesture.up();
await tester.pump(const Duration(seconds: 1));
expect(notification.kind, equals(ScrollNotificationKind.ended));
expect(notification.depth, equals(0));
expect(notification.dragStartDetails, isNull);
expect(notification.dragUpdateDetails, isNull);
expect(notification.dragEndDetails, isNotNull);
expect(notification.dragEndDetails.velocity, equals(Velocity.zero));
});
testWidgets('Scroll notification depth', (WidgetTester tester) async {
final List<ScrollNotificationKind> depth0Kinds = <ScrollNotificationKind>[];
final List<ScrollNotificationKind> depth1Kinds = <ScrollNotificationKind>[];
final List<int> depth0Values = <int>[];
final List<int> depth1Values = <int>[];
await tester.pumpWidget(new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification value) {
depth1Kinds.add(value.kind);
depth1Values.add(value.depth);
return false;
},
child: new ScrollableViewport(
child: new SizedBox(
height: 1200.0,
child: new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification value) {
depth0Kinds.add(value.kind);
depth0Values.add(value.depth);
return false;
},
child: new Container(
padding: const EdgeInsets.all(50.0),
child: new ScrollableViewport(child: new SizedBox(height: 1200.0))
)
)
)
)
));
TestGesture gesture = await tester.startGesture(new Point(100.0, 100.0));
await tester.pump(const Duration(seconds: 1));
await gesture.moveBy(new Offset(-10.0, -10.0));
await tester.pump(const Duration(seconds: 1));
await gesture.up();
await tester.pump(const Duration(seconds: 1));
final List<ScrollNotificationKind> kinds = <ScrollNotificationKind>[
ScrollNotificationKind.started,
ScrollNotificationKind.updated,
ScrollNotificationKind.ended
];
expect(depth0Kinds, equals(kinds));
expect(depth1Kinds, equals(kinds));
expect(depth0Values, equals(<int>[0, 0, 0]));
expect(depth1Values, equals(<int>[1, 1, 1]));
});
}