Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ FOUNDATION_EXPORT double RunnerControlledScrollProgress(double t);
typedef NS_ENUM(NSInteger, RunnerTapSynthesisStatus) {
RunnerTapSynthesisStatusSucceeded,
RunnerTapSynthesisStatusDeadlineExceeded,
// The record failed before XCTest was handed it, so nothing ran.
RunnerTapSynthesisStatusFailed,
// The record failed after XCTest was handed it, so the tap may have run.
RunnerTapSynthesisStatusFailedAfterHandOff,
};

typedef struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ + (RunnerTapSynthesisStatus)synthesizeTapWithApplication:(id)application
errorMessage:(NSString * _Nullable * _Nullable)errorMessage {
if (errorMessage != NULL) *errorMessage = nil;
@try {
return RunnerTrySynthesizeTap(application, resolvedWindow, interfaceOrientation, point, deadline, errorMessage);
return RunnerTrySynthesizeTap(
application, resolvedWindow, interfaceOrientation, point, deadline, errorMessage
);
} @catch (NSException *exception) {
if (errorMessage != NULL) {
*errorMessage = RunnerFormatXCTestException(exception, @"private XCTest event synthesis failed");
Expand Down Expand Up @@ -247,9 +249,13 @@ static RunnerTapSynthesisStatus RunnerTrySynthesizeTap(
if (deadline != nil && deadline.timeIntervalSinceNow <= 0) {
return RunnerTapSynthesisStatusDeadlineExceeded;
}
error = RunnerSynthesizeEventRecord(&bridge, record);
@try {
error = RunnerSynthesizeEventRecord(&bridge, record);
} @catch (NSException *exception) {
error = RunnerFormatXCTestException(exception, @"private XCTest event synthesis failed");
}
if (errorMessage != NULL) *errorMessage = error;
return error == nil ? RunnerTapSynthesisStatusSucceeded : RunnerTapSynthesisStatusFailed;
return error == nil ? RunnerTapSynthesisStatusSucceeded : RunnerTapSynthesisStatusFailedAfterHandOff;
}

static NSString * _Nullable RunnerResolveGestureEventBridge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ extension RunnerTests {
context: hostContext,
deadline: deadline
)
} catch let refusal as RunnerGestureRefusedWithoutFallback {
} catch let refusal as RunnerGestureNotSent {
outcome = .unsupported(message: refusal.message, hint: refusal.hint)
return
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ extension RunnerTests {
y: touchPoint.y
)
func selectorTapResponse(
timing: (gestureStartUptimeMs: Double, gestureEndUptimeMs: Double),
fallback: GestureFallback? = nil
timing: (gestureStartUptimeMs: Double, gestureEndUptimeMs: Double)
) throws -> Response {
if isTextEntry {
try waitForTextEntryReadinessAfterTap(app: activeApp, element: element)
Expand All @@ -127,20 +126,16 @@ extension RunnerTests {
message: match.usedNonHittableFallback ? "tapped via non-hittable coordinate fallback" : "tapped",
timing: timing,
frame: .touch(touchFrame),
fallback: fallback,
maestroNonHittableCoordinateFallbackUsed:
command.allowNonHittableCoordinateFallback == true
? match.usedNonHittableFallback
: nil
)
}
var fallback: GestureFallback?
if command.synthesized == true {
switch try performSynthesizedTapGesture(app: activeApp, x: touchPoint.x, y: touchPoint.y) {
case .performed(let timing):
return try selectorTapResponse(timing: timing)
case .xctestFallback(let message, let hint):
fallback = .coordinateTap(message, hint: hint)
case .refused(_, let refusal):
return refusedTapResponse(refusal)
}
Expand All @@ -159,7 +154,7 @@ extension RunnerTests {
clearRememberedTextEntryTap()
return response
}
return try selectorTapResponse(timing: timing, fallback: fallback)
return try selectorTapResponse(timing: timing)
}
clearRememberedTextEntryTap()
return Response(ok: false, error: ErrorPayload(code: RunnerWireErrorCode.elementNotFound, message: "element not found"))
Expand Down Expand Up @@ -187,15 +182,12 @@ extension RunnerTests {
xCTestChannelPenalized ? "penalized-xctest-channel" : "evidence"
)
}
var fallback: GestureFallback?
if command.synthesized == true {
let context = deferredWindowTapContext(app: activeApp)
switch try performSynthesizedTapGesture(app: activeApp, x: x, y: y, context: context) {
case .performed(let timing):
rememberTextEntryTap(textInput)
return gestureResponse(message: "tapped", timing: timing)
case .xctestFallback(let message, let hint):
fallback = .coordinateTap(message, hint: hint)
case .refused(_, let refusal):
return refusedTapResponse(refusal)
}
Expand All @@ -207,12 +199,7 @@ extension RunnerTests {
return response
}
rememberTextEntryTap(textInput)
return gestureResponse(
message: "tapped",
timing: timing,
frame: .touch(touchFrame),
fallback: fallback
)
return gestureResponse(message: "tapped", timing: timing, frame: .touch(touchFrame))
}
clearRememberedTextEntryTap()
return Response(ok: false, error: ErrorPayload(message: "tap requires a selector or x/y"))
Expand Down Expand Up @@ -244,37 +231,27 @@ extension RunnerTests {
return Response(ok: false, error: ErrorPayload(message: "longPress requires x and y"))
}
let durationMs = command.durationMs ?? 800
let fallback: GestureFallback?
#if os(iOS)
let policyKind = SynthesizedGesturePolicyKind.coordinateLongPress
let context = try synthesizedCoordinateContext(app: activeApp)
switch try performSynthesizedGesture(activeApp, kind: policyKind, context: context, synthesize: {
switch try performSynthesizedGesture({
try synthesizedLongPressAt(app: activeApp, x: x, y: y, durationMs: durationMs, context: context)
}) {
case .performed(let timing):
let touchFrame = context.map { touchVisualizationFrame(point: SurfacePoint(CGPoint(x: x, y: y)), context: $0) }
return gestureResponse(message: "long pressed", timing: timing, frame: .touch(touchFrame))
case .xctestFallback(let message, let hint):
fallback = GestureFallback(strategy: "xctest-coordinate-long-press", message: message, hint: hint)
case .refused(_, let refusal):
return refusalResponse(refusal)
}
#else
fallback = nil
#endif
let touchFrame = try resolvedTouchVisualizationFrame(app: activeApp, x: x, y: y)
let (timing, outcome) = try performGesture(activeApp) {
try longPressAt(app: activeApp, x: x, y: y, duration: durationMs / 1000.0)
}
if let response = unsupportedResponse(for: outcome) {
return response
}
return gestureResponse(
message: "long pressed",
timing: timing,
frame: .touch(touchFrame),
fallback: fallback
)
return gestureResponse(message: "long pressed", timing: timing, frame: .touch(touchFrame))
#endif
case .drag:
guard let x = command.x, let y = command.y, let x2 = command.x2, let y2 = command.y2 else {
return Response(ok: false, error: ErrorPayload(message: "drag requires x, y, x2, and y2"))
Expand Down Expand Up @@ -684,7 +661,7 @@ extension RunnerTests {
y2: last.y,
durationMs: plan.durationMs,
message: plan.intent,
synthesized: (profile: .fastSwipe, policyKind: .synthesizedDrag)
synthesizedProfile: .fastSwipe
)
)
case .sampled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ extension RunnerTests {
return (gestureStartUptimeMs, currentUptimeMs())
}

func synthesizedSwipeFallbackHoldDuration(durationMs: Double) -> TimeInterval {
/// The hold of an XCTest coordinate drag a caller asked to run as a synthesized swipe, which only
/// platforms without the synthesized lane perform.
func profiledCoordinateDragHoldDuration(durationMs: Double) -> TimeInterval {
min(max((durationMs / 5.0) / 1000.0, 0.016), 0.120)
}

Expand Down Expand Up @@ -56,17 +58,6 @@ extension RunnerTests {
case drag(DragVisualizationFrame)
}

struct GestureFallback {
let strategy: String
let message: String
let hint: String?

static func coordinateTap(_ message: String, hint: String?) -> Self {
Self(strategy: "xctest-coordinate-tap", message: message, hint: hint)
}
}


/// Runs a gesture action with uniform timing capture. Touch gestures pass `idleTimeout: true`
/// (the default) to run inside the scroll idle-timeout + quiescence-skip wrapper; synthesis
/// pointer-plan gestures pass `false` because RunnerSynthesizedGesture governs their
Expand Down Expand Up @@ -99,7 +90,6 @@ extension RunnerTests {
message: String,
timing: (gestureStartUptimeMs: Double, gestureEndUptimeMs: Double),
frame: GestureFrame = .none,
fallback: GestureFallback? = nil,
maestroNonHittableCoordinateFallbackUsed: Bool? = nil
) -> Response {
let data: DataPayload
Expand All @@ -109,9 +99,6 @@ extension RunnerTests {
message: message,
gestureStartUptimeMs: timing.gestureStartUptimeMs,
gestureEndUptimeMs: timing.gestureEndUptimeMs,
gestureFallback: fallback?.strategy,
gestureFallbackMessage: fallback?.message,
gestureFallbackHint: fallback?.hint,
maestroNonHittableCoordinateFallbackUsed: maestroNonHittableCoordinateFallbackUsed
)
case .touch(let f):
Expand All @@ -123,9 +110,6 @@ extension RunnerTests {
y: f?.y,
referenceWidth: f?.referenceWidth,
referenceHeight: f?.referenceHeight,
gestureFallback: fallback?.strategy,
gestureFallbackMessage: fallback?.message,
gestureFallbackHint: fallback?.hint,
maestroNonHittableCoordinateFallbackUsed: maestroNonHittableCoordinateFallbackUsed
)
case .drag(let f):
Expand All @@ -138,17 +122,14 @@ extension RunnerTests {
x2: f.x2,
y2: f.y2,
referenceWidth: f.referenceWidth,
referenceHeight: f.referenceHeight,
gestureFallback: fallback?.strategy,
gestureFallbackMessage: fallback?.message,
gestureFallbackHint: fallback?.hint
referenceHeight: f.referenceHeight
)
}
return Response(ok: true, data: data)
}

/// Gesture plans already return canonical centroid endpoints from the portable runtime.
/// Keep runner timing/fallback diagnostics, but do not leak the coordinate-drag adapter's
/// Keep runner timing, but do not leak the coordinate-drag adapter's
/// visualization frame into only the fast-fling response shape.
func canonicalPlannedGestureResponse(_ response: Response) -> Response {
guard response.ok, let data = response.data else { return response }
Expand All @@ -157,10 +138,7 @@ extension RunnerTests {
data: DataPayload(
message: data.message,
gestureStartUptimeMs: data.gestureStartUptimeMs,
gestureEndUptimeMs: data.gestureEndUptimeMs,
gestureFallback: data.gestureFallback,
gestureFallbackMessage: data.gestureFallbackMessage,
gestureFallbackHint: data.gestureFallbackHint
gestureEndUptimeMs: data.gestureEndUptimeMs
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ struct RunnerCoordinateRefusal: Error {
let hint: String?
}

/// A synthesized gesture that failed after its events reached XCTest, so it may have run. Thrown
/// rather than returned so that no XCTest fallback repeats it: a fallback would press a second time.
/// `executeOnMainPrepared` answers it as `SYNTHESIZED_GESTURE_OUTCOME_UNKNOWN`.
/// A synthesized gesture that failed after its events reached XCTest, so it may have run and nothing
/// may repeat it. `executeOnMainPrepared` answers it as `SYNTHESIZED_GESTURE_OUTCOME_UNKNOWN`.
struct RunnerGestureOutcomeUnknown: Error {
let message: String
let hint: String?
}

/// A synthesized gesture that sent nothing and that no XCTest gesture may replace: on a simulator a
/// tap whose touchscreen HID contact cannot be sent. Thrown rather than returned so that no fallback
/// policy answers it; `performSynthesizedGesture` turns it into an `UNSUPPORTED_OPERATION` refusal.
struct RunnerGestureRefusedWithoutFallback: Error {
/// A synthesized gesture that sent nothing: on a simulator a tap whose touchscreen HID contact cannot
/// be sent. `performSynthesizedGesture` turns it into an `UNSUPPORTED_OPERATION` refusal.
struct RunnerGestureNotSent: Error {
let message: String
let hint: String?
}
Expand Down Expand Up @@ -705,8 +703,6 @@ extension RunnerTests {
switch try performSynthesizedTapGesture(app: app, x: x, y: y, context: context) {
case .performed:
return .performed
case .xctestFallback(let message, let hint):
throw RunnerCoordinateRefusal(message: message, hint: hint)
case .refused(_, let refusal):
let text = refusal.refusalText
throw RunnerCoordinateRefusal(message: text?.message ?? "synthesized tap refused", hint: text?.hint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ extension RunnerTests {
clearRememberedTextEntryTap()
snapshotXCTestPenaltyWarmupExemption.isPending = false
lastLoggedFastAppGuardLine = nil
lastLoggedGesturePolicyLines.removeAll()
}

@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,6 @@ struct DataPayload: Codable {
/// readable. Absent when the key carries none, or there is no key to read.
var keyboardReturnKeyLabel: String?
var orientation: String?
var gestureFallback: String?
var gestureFallbackMessage: String?
var gestureFallbackHint: String?
// Scroll keyboard avoidance evidence (#2500): the swipe was clipped to the band above an
// on-screen keyboard, and where that band ended. `referenceHeight` already names the clipped axis.
var keyboardAvoided: Bool?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,10 @@ extension RunnerTests {
}
trace.found = "yes"
// The synthesized tap returns once the touch is delivered; an XCTest tap would also wait out the
// pop animation, which the bar check below reads sooner. On iOS a readable tree's XCTest tap
// either runs or throws, so its fallback needs no outcome check.
switch try performSynthesizedTapGesture(app: app, x: frame.midX, y: frame.midY, context: context) {
case .performed:
break
case .xctestFallback:
_ = try performGesture(app) { try tapAt(app: app, x: frame.midX, y: frame.midY, context: context) }
case .refused:
return nil
}
// pop animation, which the bar check below reads sooner. A refused tap sent nothing, so the swipe
// may still run; a tap that failed after it was handed off throws its unknown outcome instead.
guard case .performed = try performSynthesizedTapGesture(app: app, x: frame.midX, y: frame.midY, context: context)
Comment thread
thymikee marked this conversation as resolved.
Resolved
else { return nil }
trace.pressed = true
let tapped = currentUptimeMs()
let confirmation = navigationBarBackConfirmation(
Expand Down
Loading
Loading