summaryrefslogtreecommitdiff
path: root/test/macos_trackpad.m
diff options
context:
space:
mode:
Diffstat (limited to 'test/macos_trackpad.m')
-rw-r--r--test/macos_trackpad.m37
1 files changed, 31 insertions, 6 deletions
diff --git a/test/macos_trackpad.m b/test/macos_trackpad.m
index 03c9d311..b37533ef 100644
--- a/test/macos_trackpad.m
+++ b/test/macos_trackpad.m
@@ -44,6 +44,7 @@ static BOOL swipe_enabled(id receiver, SEL selector)
@property BOOL precise;
@property BOOL horizontal, cancelled;
@property CGFloat progress, discreteDirection;
+@property NSArray<NSNumber *> *progressSequence;
@end
@implementation TrackpadEvent
- (NSPoint)locationInWindow { return NSMakePoint(25, 40); }
@@ -58,14 +59,18 @@ static BOOL swipe_enabled(id receiver, SEL selector)
dampenAmountThresholdMin:(CGFloat)min max:(CGFloat)max
usingHandler:(void (^)(CGFloat, NSEventPhase, BOOL, BOOL *))handler
{
- (void)options; assert(min == -1 && max == 1);
+ assert(options == 0 && min == -100 && max == 100);
BOOL stop = NO;
- handler(0.13, NSEventPhaseChanged, NO, &stop);
- handler(0.18, NSEventPhaseChanged, NO, &stop);
+ NSArray<NSNumber *> *samples = self.progressSequence ?: @[@0.13, @0.18];
+ for (NSNumber *sample in samples) {
+ handler(sample.doubleValue, NSEventPhaseChanged, NO, &stop);
+ assert(!stop); // a jump must not end physical tracking
+ }
if (self.cancelled) handler(self.progress, NSEventPhaseCancelled, NO, &stop);
- else handler(self.progress, NSEventPhaseChanged, NO, &stop);
+ else if (!self.progressSequence) handler(self.progress, NSEventPhaseChanged, NO, &stop);
if (!stop) handler(0, NSEventPhaseEnded, NO, &stop);
- if (!stop) handler(1, NSEventPhaseNone, YES, &stop);
+ assert(stop); // no native completion animation can cause another jump
+
}
- (NSInteger)stage { return 2; }
- (float)rotation { return 12; }
@@ -127,7 +132,7 @@ int main(void)
event.testPhase = NSEventPhaseBegan;
[view scrollWheel:event];
assert(count == 8);
- assert(haptic_spy.pulses == 1); // one early cue despite multiple progress events
+ assert(haptic_spy.pulses == 0); // command dispatch owns the haptic, never progress
assert(((UITrackpadEvent *)&queued[7])->kind == UI_TRACKPAD_HISTORY);
assert(((UITrackpadEvent *)&queued[7])->a == 1);
event.cancelled = YES;
@@ -154,7 +159,27 @@ int main(void)
event.testPhase = NSEventPhaseNone;
[view scrollWheel:event];
assert(count == 11); // remaining movement/momentum cannot jump twice
+ event.testPhase = NSEventPhaseBegan;
+ event.progressSequence = @[@0.13, @0.25, @0.25, @0.26, @0.38, @0.50,
+ @0.50, @0.37, @0.24, @0.12, @-0.01];
+ unsigned continuous_start = count;
+ [view scrollWheel:event];
+ assert(count == continuous_start + 7);
+ const int directions[] = {1, 1, 1, -1, -1, -1, -1};
+ for (unsigned i = 0; i < 7; ++i)
+ assert(((UITrackpadEvent *)&queued[continuous_start + i])->a == directions[i]);
+ // Lift resets the larger initial threshold for the next gesture.
+ event.progressSequence = @[@0.13, @0.20];
+ [view scrollWheel:event];
+ assert(count == continuous_start + 7);
+ event.progressSequence = @[@-0.13, @-0.25, @-0.25, @-0.26, @-0.38, @-0.50,
+ @-0.50, @-0.37, @-0.24, @-0.12, @0.01];
+ [view scrollWheel:event];
+ assert(count == continuous_start + 14);
+ for (unsigned i = 0; i < 7; ++i)
+ assert(((UITrackpadEvent *)&queued[continuous_start + 7 + i])->a == -directions[i]);
method_setImplementation(preference, old_preference);
+ assert(haptic_spy.pulses == 0); // no preview pulses, even across repeated/reversed swipes
NSUInteger before = haptic_spy.pulses;
ui_macos_trackpad_haptic();
method_setImplementation(performer, original);