flutter/packages/unit/test/gestures/arena_test.dart
Adam Barth bef55951a5 Scrolls should start immediately when possible
If there are no other gestures in the arena, we should kick off the scroll
gesture right away. This change pulled a refactoring of how we dispatch events
to Widgets. Now we dispatch events to Widgets interleaved with their associated
RenderObjects. (Previously we dispatched to all of the RenderObjects first.)
2015-08-29 22:30:49 -07:00

70 lines
1.8 KiB
Dart

import 'package:sky/gestures/arena.dart';
import 'package:test/test.dart';
typedef void GestureArenaCallback(Object key);
class TestGestureArenaMember extends GestureArenaMember {
TestGestureArenaMember({ this.onAcceptGesture, this.onRejectGesture });
final GestureArenaCallback onAcceptGesture;
final GestureArenaCallback onRejectGesture;
void acceptGesture(Object key) {
onAcceptGesture(key);
}
void rejectGesture(Object key) {
onRejectGesture(key);
}
}
void main() {
test('Should win by accepting', () {
GestureArena arena = new GestureArena();
int primaryKey = 4;
bool firstAcceptRan = false;
bool firstRejectRan = false;
bool secondAcceptRan = false;
bool secondRejectRan = false;
TestGestureArenaMember first = new TestGestureArenaMember(
onAcceptGesture: (int key) {
expect(key, equals(primaryKey));
firstAcceptRan = true;
},
onRejectGesture: (int key) {
expect(key, equals(primaryKey));
firstRejectRan = true;
}
);
TestGestureArenaMember second = new TestGestureArenaMember(
onAcceptGesture: (int key) {
expect(key, equals(primaryKey));
secondAcceptRan = true;
},
onRejectGesture: (int key) {
expect(key, equals(primaryKey));
secondRejectRan = true;
}
);
GestureArenaEntry firstEntry = arena.add(primaryKey, first);
arena.add(primaryKey, second);
arena.close(primaryKey);
expect(firstAcceptRan, isFalse);
expect(firstRejectRan, isFalse);
expect(secondAcceptRan, isFalse);
expect(secondRejectRan, isFalse);
firstEntry.resolve(GestureDisposition.accepted);
expect(firstAcceptRan, isTrue);
expect(firstRejectRan, isFalse);
expect(secondAcceptRan, isFalse);
expect(secondRejectRan, isTrue);
});
}