Skip to content

Commit

Permalink
[iOS][EG2] Handle iOS upgrade alert before EG2 tests start
Browse files Browse the repository at this point in the history
Handles unknown system dialog by catching the exception. If it's a
system update alert, choose later. If not, deny it.

Bug: 1072000
Change-Id: Ifc12a37771c247d2f68c7f73ac0169aa337e5dda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2159916
Commit-Queue: Zhaoyang Li <zhaoyangli@chromium.org>
Reviewed-by: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763491}
  • Loading branch information
zhaoyangli authored and Commit Bot committed Apr 28, 2020
1 parent 648707e commit e30b83a
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions ios/testing/earl_grey/base_earl_grey_test_case.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,56 @@ - (void)handleSystemAlertIfVisible {
GREYAssertNil(alertGetTextError, @"Error getting alert text.\n%@",
alertGetTextError);

// If the system alert is of a known type, accept it.
// Otherwise, reject it, as unknown types include alerts which are not
// desirable to accept, including OS upgrades.
if ([self grey_systemAlertType] != GREYSystemAlertTypeUnknown) {
@try {
// TODO(crbug.com/1073542): Style guide does not allow throwing
// exceptions. This call throws an NSInternalInconsistencyException when
// the system alert is unknown in EG2 framework. The exception will be
// handled in @catch. Otherwise the system alert is of a known type,
// accept it.
[self grey_systemAlertType];

DLOG(WARNING) << "Accepting iOS system alert: "
<< base::SysNSStringToUTF8(alertText);

NSError* acceptAlertError = nil;
[self grey_acceptSystemDialogWithError:&acceptAlertError];
GREYAssertNil(acceptAlertError, @"Error accepting system alert.\n%@",
acceptAlertError);
} else {
DLOG(WARNING) << "Denying iOS system alert of unknown type: "
<< base::SysNSStringToUTF8(alertText);

NSError* denyAlertError = nil;
[self grey_denySystemDialogWithError:&denyAlertError];
GREYAssertNil(denyAlertError, @"Error denying system alert.\n%@",
denyAlertError);
} @catch (NSException* exception) {
GREYAssert(
(exception.name == NSInternalInconsistencyException &&
[exception.reason rangeOfString:@"Invalid System Alert."].location !=
NSNotFound),
@"Unknown error caught when handling unknown system alert: %@",
exception.reason);
// If the unsupported alert is iOS upgrade alert, choose "Later".
// Otherwise, reject it, as unknown types include alerts which are not
// desirable to accept.
if ([alertText isEqualToString:@"Software Update"]) {
DLOG(WARNING) << "Denying iOS system alert of Software Update!";

NSError* dismissingUpgradeAlertError = nil;
[self grey_tapSystemDialogButtonWithText:@"Later"
error:&dismissingUpgradeAlertError];
GREYAssertNil(dismissingUpgradeAlertError,
@"Error denying Software Update alert.\n%@",
dismissingUpgradeAlertError);

} else {
DLOG(WARNING) << "Denying iOS system alert of unknown type: "
<< base::SysNSStringToUTF8(alertText);

NSError* denyAlertError = nil;
[self grey_denySystemDialogWithError:&denyAlertError];
GREYAssertNil(denyAlertError, @"Error denying system alert.\n%@",
denyAlertError);
}
}
}
// Ensures no visible alert after handling.
[self grey_waitForAlertVisibility:NO
withTimeout:kSystemAlertVisibilityTimeout];
#endif // CHROME_EARL_GREY_2
}

Expand Down

0 comments on commit e30b83a

Please sign in to comment.