ios: Speed up XCUITests by swizzling away Xcode crash check.

Change-Id: Iadda950544448d771960d35fd064f5287bce0484
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3410579
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
This commit is contained in:
Justin Cohen 2022-01-26 14:43:08 -05:00 committed by Crashpad LUCI CQ
parent 496d522cc4
commit 30d302a8ca

View File

@ -34,15 +34,8 @@
@implementation CPTestTestCase
+ (void)setUp {
// Swizzle away the handleCrashUnderSymbol callback. Without this, any time
// the host app is intentionally crashed, the test is immediately failed.
SEL originalSelector = NSSelectorFromString(@"handleCrashUnderSymbol:");
SEL swizzledSelector = @selector(handleCrashUnderSymbol:);
Method originalMethod = class_getInstanceMethod(
objc_getClass("XCUIApplicationImpl"), originalSelector);
Method swizzledMethod =
class_getInstanceMethod([self class], swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
[CPTestTestCase swizzleHandleCrashUnderSymbol];
[CPTestTestCase swizleMayTerminateOutOfBandWithoutCrashReport];
// Override EDO default error handler. Without this, the default EDO error
// handler will throw an error and fail the test.
@ -51,12 +44,43 @@
});
}
// Swizzle away the -[XCUIApplicationImpl handleCrashUnderSymbol:] callback.
// Without this, any time the host app is intentionally crashed, the test is
// immediately failed.
+ (void)swizzleHandleCrashUnderSymbol {
SEL originalSelector = NSSelectorFromString(@"handleCrashUnderSymbol:");
SEL swizzledSelector = @selector(handleCrashUnderSymbol:);
Method originalMethod = class_getInstanceMethod(
objc_getClass("XCUIApplicationImpl"), originalSelector);
Method swizzledMethod =
class_getInstanceMethod([self class], swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
}
// Swizzle away the time consuming 'Checking for crash reports corresponding to'
// from -[XCUIApplicationProcess swizleMayTerminateOutOfBandWithoutCrashReport]
// that is unnecessary for these tests.
+ (void)swizleMayTerminateOutOfBandWithoutCrashReport {
SEL originalSelector =
NSSelectorFromString(@"mayTerminateOutOfBandWithoutCrashReport");
SEL swizzledSelector = @selector(mayTerminateOutOfBandWithoutCrashReport);
Method originalMethod = class_getInstanceMethod(
objc_getClass("XCUIApplicationProcess"), originalSelector);
Method swizzledMethod =
class_getInstanceMethod([self class], swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
}
// This gets called after tearDown, so there's no straightforward way to
// test that this is called. However, not swizzling this out will cause every
// crashing test to fail.
- (void)handleCrashUnderSymbol:(id)arg1 {
}
- (BOOL)mayTerminateOutOfBandWithoutCrashReport {
return YES;
}
- (void)setUp {
app_ = [[XCUIApplication alloc] init];
[app_ launch];