Commit 16dfd50e authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Add test for QRScanner with VoiceOver

This CL adds a test for the QRScanner, simulating VoiceOver being
enabled.

Bug: 1012403
Change-Id: I4b352a656dae38d98825fb191476c0dfc522665b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849678
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705887}
parent fe0b903a
......@@ -34,4 +34,11 @@
@end
@interface QRScannerViewController (TestingAdditions)
// Simulates VoiceOver being enabled for this Scanner.
- (void)overrideVoiceOverCheck:(BOOL)overrideVoiceOverCheck;
@end
#endif // IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_VIEW_CONTROLLER_H_
......@@ -31,11 +31,14 @@ using base::UserMetricsAction;
@property(nonatomic, readwrite, weak) id<LoadQueryCommands> queryLoader;
// Whether VoiceOver detection has been overridden.
@property(nonatomic, assign) BOOL voiceOverCheckOverridden;
@end
@implementation QRScannerViewController
#pragma mark Lifecycle
#pragma mark - Lifecycle
- (instancetype)
initWithPresentationProvider:(id<ScannerPresenting>)presentationProvider
......@@ -79,7 +82,7 @@ using base::UserMetricsAction;
#pragma mark - QRScannerCameraControllerDelegate
- (void)receiveQRScannerResult:(NSString*)result loadImmediately:(BOOL)load {
if (UIAccessibilityIsVoiceOverRunning()) {
if ([self isVoiceOverActive]) {
// Post a notification announcing that a code was scanned. QR scanner will
// be dismissed when the UIAccessibilityAnnouncementDidFinishNotification is
// received.
......@@ -116,4 +119,17 @@ using base::UserMetricsAction;
}
}
#pragma mark - Private
// Returns whether voice over is active.
- (BOOL)isVoiceOverActive {
return UIAccessibilityIsVoiceOverRunning() || self.voiceOverCheckOverridden;
}
#pragma mark - Testing Additions
- (void)overrideVoiceOverCheck:(BOOL)overrideVoiceOverCheck {
self.voiceOverCheckOverridden = overrideVoiceOverCheck;
}
@end
......@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h>
#include "base/ios/ios_util.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "components/strings/grit/components_strings.h"
......@@ -145,6 +146,32 @@ void TapKeyboardReturnKeyInOmniboxWithText(std::string text) {
} // namespace
// Override a QRScannerViewController voice search check, simulating voice
// search being enabled. This doesn't reset the previous value, don't use
// nested.
@interface ScopedQRScannerVoiceSearchOverride : NSObject
@property(nonatomic, weak) QRScannerViewController* scanner;
@end
@implementation ScopedQRScannerVoiceSearchOverride
- (instancetype)initWithQRScanner:(QRScannerViewController*)QRScanner {
self = [super init];
if (self) {
_scanner = QRScanner;
[_scanner overrideVoiceOverCheck:YES];
}
return self;
}
- (void)dealloc {
[_scanner overrideVoiceOverCheck:NO];
}
@end
#pragma mark - Test Case
@interface QRScannerViewControllerTestCase : ChromeTestCase {
GURL _testURL;
GURL _testURLEdited;
......@@ -788,6 +815,56 @@ void TapKeyboardReturnKeyInOmniboxWithText(std::string text) {
isNotPresentedBy:[self currentViewController]];
}
// Test that the correct page is loaded if the scanner result is a URL which is
// then manually edited when VoiceOver is enabled.
- (void)testReceivingQRScannerURLResultWithVoiceOver {
id cameraControllerMock =
[self getCameraControllerMockWithAuthorizationStatus:
AVAuthorizationStatusAuthorized];
[self swizzleCameraController:cameraControllerMock];
// Open the QR scanner.
[self showQRScannerAndCheckLayoutWithCameraMock:cameraControllerMock];
[self callTorchAvailabilityChanged:YES];
[self assertQRScannerUIIsVisibleWithTorch:YES];
// Add override for the VoiceOver check.
QRScannerViewController* viewController =
base::mac::ObjCCast<QRScannerViewController>(
[[self currentViewController] presentedViewController]);
GREYAssertTrue(viewController, @"The QRScanner isn't presented.");
ScopedQRScannerVoiceSearchOverride* scopedOverride =
[[ScopedQRScannerVoiceSearchOverride alloc]
initWithQRScanner:viewController];
// Receive a scanned result from the camera.
[self addCameraControllerDismissalExpectations:cameraControllerMock];
[self callReceiveQRScannerResult:base::SysUTF8ToNSString(
_testURL.GetContent())];
// Fake the end of the VoiceOver announcement.
NSString* scannedAnnouncement = l10n_util::GetNSString(
IDS_IOS_SCANNER_SCANNED_ACCESSIBILITY_ANNOUNCEMENT);
[[NSNotificationCenter defaultCenter]
postNotificationName:UIAccessibilityAnnouncementDidFinishNotification
object:nil
userInfo:@{
UIAccessibilityAnnouncementKeyStringValue :
scannedAnnouncement
}];
[self waitForModalOfClass:[QRScannerViewController class]
toDisappearFromAbove:[self currentViewController]];
[cameraControllerMock verify];
// Optionally edit the text in the omnibox before pressing return.
[self assertOmniboxIsVisibleWithText:_testURL.GetContent()];
TapKeyboardReturnKeyInOmniboxWithText(_testURL.GetContent());
[ChromeEarlGrey waitForWebStateContainingText:kTestURLResponse];
scopedOverride = nil;
}
// Test that the correct page is loaded if the scanner result is a URL.
- (void)testReceivingQRScannerURLResult {
[self doTestReceivingResult:_testURL.GetContent()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment