| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <AVFoundation/AVFoundation.h> | 5 #import <AVFoundation/AVFoundation.h> |
| 6 #import <EarlGrey/EarlGrey.h> | 6 #import <EarlGrey/EarlGrey.h> |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 | 8 |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
| 12 #include "components/version_info/version_info.h" | 12 #include "components/version_info/version_info.h" |
| 13 #import "ios/chrome/app/main_controller.h" | 13 #import "ios/chrome/app/main_controller.h" |
| 14 #include "ios/chrome/browser/chrome_switches.h" | 14 #include "ios/chrome/browser/chrome_switches.h" |
| 15 #include "ios/chrome/browser/experimental_flags.h" |
| 15 #import "ios/chrome/browser/ui/browser_view_controller.h" | 16 #import "ios/chrome/browser/ui/browser_view_controller.h" |
| 16 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 17 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 17 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 18 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 18 #include "ios/chrome/browser/ui/icons/chrome_icon.h" | 19 #include "ios/chrome/browser/ui/icons/chrome_icon.h" |
| 19 #include "ios/chrome/browser/ui/qr_scanner/camera_controller.h" | 20 #include "ios/chrome/browser/ui/qr_scanner/camera_controller.h" |
| 20 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view.h" | 21 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view.h" |
| 21 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller.h" | 22 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller.h" |
| 22 #include "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | 23 #include "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
| 23 #include "ios/chrome/grit/ios_chromium_strings.h" | 24 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 24 #include "ios/chrome/grit/ios_strings.h" | 25 #include "ios/chrome/grit/ios_strings.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 return ButtonWithAccessibilityLabelId(IDS_ACCNAME_BACK); | 105 return ButtonWithAccessibilityLabelId(IDS_ACCNAME_BACK); |
| 105 } | 106 } |
| 106 | 107 |
| 107 // Returns the GREYMatcher for the Cancel button to dismiss a UIAlertController. | 108 // Returns the GREYMatcher for the Cancel button to dismiss a UIAlertController. |
| 108 id<GREYMatcher> DialogCancelButton() { | 109 id<GREYMatcher> DialogCancelButton() { |
| 109 return grey_allOf( | 110 return grey_allOf( |
| 110 grey_text(l10n_util::GetNSString(IDS_IOS_QR_SCANNER_ALERT_CANCEL)), | 111 grey_text(l10n_util::GetNSString(IDS_IOS_QR_SCANNER_ALERT_CANCEL)), |
| 111 grey_accessibilityTrait(UIAccessibilityTraitStaticText), nil); | 112 grey_accessibilityTrait(UIAccessibilityTraitStaticText), nil); |
| 112 } | 113 } |
| 113 | 114 |
| 114 // Opens the QR Scanner view using a command. | 115 // Opens the QR Scanner view. |
| 115 // TODO(crbug.com/629776): Replace the command call with a UI action. | 116 void ShowQRScanner() { |
| 116 void ShowQRScannerWithCommand() { | 117 // TODO(crbug.com/738106): only show the QR Scanner via the Keyboard Accessory |
| 117 GenericChromeCommand* command = | 118 // View. |
| 118 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_QR_SCANNER]; | 119 if (experimental_flags::IsKeyboardAccessoryViewWithCameraSearchEnabled()) { |
| 119 chrome_test_util::RunCommandWithActiveViewController(command); | 120 // Tap the omnibox to get the keyboard accessory view to show up. |
| 121 id<GREYMatcher> locationbarButton = grey_allOf( |
| 122 grey_accessibilityLabel(l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)), |
| 123 grey_minimumVisiblePercent(0.2), nil); |
| 124 [[EarlGrey selectElementWithMatcher:locationbarButton] |
| 125 assertWithMatcher:grey_text(@"Search or type URL")]; |
| 126 [[EarlGrey selectElementWithMatcher:locationbarButton] |
| 127 performAction:grey_tap()]; |
| 128 |
| 129 // Tap the QR Code scanner button in the keyboard accessory view. |
| 130 id<GREYMatcher> matcher = |
| 131 grey_allOf(grey_accessibilityLabel(@"QR code Search"), |
| 132 grey_kindOfClass([UIButton class]), nil); |
| 133 |
| 134 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; |
| 135 } else { |
| 136 GenericChromeCommand* command = |
| 137 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_QR_SCANNER]; |
| 138 chrome_test_util::RunCommandWithActiveViewController(command); |
| 139 } |
| 120 } | 140 } |
| 121 | 141 |
| 122 // Taps the |button|. | 142 // Taps the |button|. |
| 123 void TapButton(id<GREYMatcher> button) { | 143 void TapButton(id<GREYMatcher> button) { |
| 124 [[EarlGrey selectElementWithMatcher:button] performAction:grey_tap()]; | 144 [[EarlGrey selectElementWithMatcher:button] performAction:grey_tap()]; |
| 125 } | 145 } |
| 126 | 146 |
| 127 // Appends the given |editText| to the |text| already in the omnibox and presses | 147 // Appends the given |editText| to the |text| already in the omnibox and presses |
| 128 // the keyboard return key. | 148 // the keyboard return key. |
| 129 void EditOmniboxTextAndTapKeyboardReturn(std::string text, NSString* editText) { | 149 void EditOmniboxTextAndTapKeyboardReturn(std::string text, NSString* editText) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // Presents the QR Scanner with a command, waits for it to be displayed, and | 264 // Presents the QR Scanner with a command, waits for it to be displayed, and |
| 245 // checks if all its views and buttons are visible. Checks that no alerts are | 265 // checks if all its views and buttons are visible. Checks that no alerts are |
| 246 // presented. | 266 // presented. |
| 247 - (void)showQRScannerAndCheckLayoutWithCameraMock:(id)mock { | 267 - (void)showQRScannerAndCheckLayoutWithCameraMock:(id)mock { |
| 248 UIViewController* bvc = [self currentBVC]; | 268 UIViewController* bvc = [self currentBVC]; |
| 249 [self assertModalOfClass:[QRScannerViewController class] | 269 [self assertModalOfClass:[QRScannerViewController class] |
| 250 isNotPresentedBy:bvc]; | 270 isNotPresentedBy:bvc]; |
| 251 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc]; | 271 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc]; |
| 252 | 272 |
| 253 [self addCameraControllerInitializationExpectations:mock]; | 273 [self addCameraControllerInitializationExpectations:mock]; |
| 254 ShowQRScannerWithCommand(); | 274 ShowQRScanner(); |
| 255 [self waitForModalOfClass:[QRScannerViewController class] toAppearAbove:bvc]; | 275 [self waitForModalOfClass:[QRScannerViewController class] toAppearAbove:bvc]; |
| 256 [self assertQRScannerUIIsVisibleWithTorch:NO]; | 276 [self assertQRScannerUIIsVisibleWithTorch:NO]; |
| 257 [self assertModalOfClass:[UIAlertController class] | 277 [self assertModalOfClass:[UIAlertController class] |
| 258 isNotPresentedBy:[bvc presentedViewController]]; | 278 isNotPresentedBy:[bvc presentedViewController]]; |
| 259 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc]; | 279 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc]; |
| 260 } | 280 } |
| 261 | 281 |
| 262 // Closes the QR scanner by tapping the close button and waits for it to | 282 // Closes the QR scanner by tapping the close button and waits for it to |
| 263 // disappear. | 283 // disappear. |
| 264 - (void)closeQRScannerWithCameraMock:(id)mock { | 284 - (void)closeQRScannerWithCameraMock:(id)mock { |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 645 |
| 626 UIViewController* bvc = [self currentBVC]; | 646 UIViewController* bvc = [self currentBVC]; |
| 627 [self assertModalOfClass:[QRScannerViewController class] | 647 [self assertModalOfClass:[QRScannerViewController class] |
| 628 isNotPresentedBy:bvc]; | 648 isNotPresentedBy:bvc]; |
| 629 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc]; | 649 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc]; |
| 630 id cameraControllerMock = | 650 id cameraControllerMock = |
| 631 [self getCameraControllerMockWithAuthorizationStatus: | 651 [self getCameraControllerMockWithAuthorizationStatus: |
| 632 AVAuthorizationStatusDenied]; | 652 AVAuthorizationStatusDenied]; |
| 633 [self swizzleCameraController:cameraControllerMock]; | 653 [self swizzleCameraController:cameraControllerMock]; |
| 634 | 654 |
| 635 ShowQRScannerWithCommand(); | 655 ShowQRScanner(); |
| 636 [self assertModalOfClass:[QRScannerViewController class] | 656 [self assertModalOfClass:[QRScannerViewController class] |
| 637 isNotPresentedBy:bvc]; | 657 isNotPresentedBy:bvc]; |
| 638 [self waitForModalOfClass:[UIAlertController class] toAppearAbove:bvc]; | 658 [self waitForModalOfClass:[UIAlertController class] toAppearAbove:bvc]; |
| 639 | 659 |
| 640 TapButton(DialogCancelButton()); | 660 TapButton(DialogCancelButton()); |
| 641 [self waitForModalOfClass:[UIAlertController class] toDisappearFromAbove:bvc]; | 661 [self waitForModalOfClass:[UIAlertController class] toDisappearFromAbove:bvc]; |
| 642 } | 662 } |
| 643 | 663 |
| 644 // Tests that a UIAlertController is presented by the QRScannerViewController if | 664 // Tests that a UIAlertController is presented by the QRScannerViewController if |
| 645 // the camera state changes after the QRScannerViewController is presented. | 665 // the camera state changes after the QRScannerViewController is presented. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 // Test that the correct page is loaded if the scanner result is a search query | 832 // Test that the correct page is loaded if the scanner result is a search query |
| 813 // which is then manually edited. | 833 // which is then manually edited. |
| 814 - (void)testReceivingQRScannerSearchQueryResultAndEditingTheQuery { | 834 - (void)testReceivingQRScannerSearchQueryResultAndEditingTheQuery { |
| 815 [self swizzleWebToolbarControllerLoadGURLFromLocationBar:_testQueryEdited]; | 835 [self swizzleWebToolbarControllerLoadGURLFromLocationBar:_testQueryEdited]; |
| 816 [self doTestReceivingResult:kTestQuery | 836 [self doTestReceivingResult:kTestQuery |
| 817 response:kTestQueryEditedResponse | 837 response:kTestQueryEditedResponse |
| 818 edit:@"\bedited"]; | 838 edit:@"\bedited"]; |
| 819 } | 839 } |
| 820 | 840 |
| 821 @end | 841 @end |
| OLD | NEW |