Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller_egtest.mm

Issue 2959233002: [iOS] Add EG tests for the Keyboard accessory view. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ios/chrome/browser/ui/toolbar/toolbar_egtest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (experimental_flags::IsKeyboardAccessoryViewWithCameraSearchEnabled()) {
justincohen 2017/06/28 21:20:53 Is this enabled by default?
jif 2017/06/29 15:57:04 It is. I was thinking of removing the "else" once
justincohen 2017/06/29 15:58:24 If you think it's reasonable, maybe add a comment
jif 2017/06/29 18:29:26 Done.
117 GenericChromeCommand* command = 118 // Tap the omnibox to get the keyboard accessory view to show up.
118 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_QR_SCANNER]; 119 id<GREYMatcher> locationbarButton = grey_allOf(
119 chrome_test_util::RunCommandWithActiveViewController(command); 120 grey_accessibilityLabel(l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)),
121 grey_minimumVisiblePercent(0.2), nil);
122 [[EarlGrey selectElementWithMatcher:locationbarButton]
123 assertWithMatcher:grey_text(@"Search or type URL")];
124 [[EarlGrey selectElementWithMatcher:locationbarButton]
125 performAction:grey_tap()];
126
127 // Tap the QR Code scanner button in the keyboard accessory view.
128 id<GREYMatcher> matcher =
129 grey_allOf(grey_accessibilityLabel(@"QR code Search"),
130 grey_kindOfClass([UIButton class]), nil);
131
132 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
133 } else {
134 GenericChromeCommand* command =
135 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_QR_SCANNER];
136 chrome_test_util::RunCommandWithActiveViewController(command);
137 }
120 } 138 }
121 139
122 // Taps the |button|. 140 // Taps the |button|.
123 void TapButton(id<GREYMatcher> button) { 141 void TapButton(id<GREYMatcher> button) {
124 [[EarlGrey selectElementWithMatcher:button] performAction:grey_tap()]; 142 [[EarlGrey selectElementWithMatcher:button] performAction:grey_tap()];
125 } 143 }
126 144
127 // Appends the given |editText| to the |text| already in the omnibox and presses 145 // Appends the given |editText| to the |text| already in the omnibox and presses
128 // the keyboard return key. 146 // the keyboard return key.
129 void EditOmniboxTextAndTapKeyboardReturn(std::string text, NSString* editText) { 147 void EditOmniboxTextAndTapKeyboardReturn(std::string text, NSString* editText) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // Presents the QR Scanner with a command, waits for it to be displayed, and 262 // 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 263 // checks if all its views and buttons are visible. Checks that no alerts are
246 // presented. 264 // presented.
247 - (void)showQRScannerAndCheckLayoutWithCameraMock:(id)mock { 265 - (void)showQRScannerAndCheckLayoutWithCameraMock:(id)mock {
248 UIViewController* bvc = [self currentBVC]; 266 UIViewController* bvc = [self currentBVC];
249 [self assertModalOfClass:[QRScannerViewController class] 267 [self assertModalOfClass:[QRScannerViewController class]
250 isNotPresentedBy:bvc]; 268 isNotPresentedBy:bvc];
251 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc]; 269 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc];
252 270
253 [self addCameraControllerInitializationExpectations:mock]; 271 [self addCameraControllerInitializationExpectations:mock];
254 ShowQRScannerWithCommand(); 272 ShowQRScanner();
255 [self waitForModalOfClass:[QRScannerViewController class] toAppearAbove:bvc]; 273 [self waitForModalOfClass:[QRScannerViewController class] toAppearAbove:bvc];
256 [self assertQRScannerUIIsVisibleWithTorch:NO]; 274 [self assertQRScannerUIIsVisibleWithTorch:NO];
257 [self assertModalOfClass:[UIAlertController class] 275 [self assertModalOfClass:[UIAlertController class]
258 isNotPresentedBy:[bvc presentedViewController]]; 276 isNotPresentedBy:[bvc presentedViewController]];
259 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc]; 277 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc];
260 } 278 }
261 279
262 // Closes the QR scanner by tapping the close button and waits for it to 280 // Closes the QR scanner by tapping the close button and waits for it to
263 // disappear. 281 // disappear.
264 - (void)closeQRScannerWithCameraMock:(id)mock { 282 - (void)closeQRScannerWithCameraMock:(id)mock {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 643
626 UIViewController* bvc = [self currentBVC]; 644 UIViewController* bvc = [self currentBVC];
627 [self assertModalOfClass:[QRScannerViewController class] 645 [self assertModalOfClass:[QRScannerViewController class]
628 isNotPresentedBy:bvc]; 646 isNotPresentedBy:bvc];
629 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc]; 647 [self assertModalOfClass:[UIAlertController class] isNotPresentedBy:bvc];
630 id cameraControllerMock = 648 id cameraControllerMock =
631 [self getCameraControllerMockWithAuthorizationStatus: 649 [self getCameraControllerMockWithAuthorizationStatus:
632 AVAuthorizationStatusDenied]; 650 AVAuthorizationStatusDenied];
633 [self swizzleCameraController:cameraControllerMock]; 651 [self swizzleCameraController:cameraControllerMock];
634 652
635 ShowQRScannerWithCommand(); 653 ShowQRScanner();
636 [self assertModalOfClass:[QRScannerViewController class] 654 [self assertModalOfClass:[QRScannerViewController class]
637 isNotPresentedBy:bvc]; 655 isNotPresentedBy:bvc];
638 [self waitForModalOfClass:[UIAlertController class] toAppearAbove:bvc]; 656 [self waitForModalOfClass:[UIAlertController class] toAppearAbove:bvc];
639 657
640 TapButton(DialogCancelButton()); 658 TapButton(DialogCancelButton());
641 [self waitForModalOfClass:[UIAlertController class] toDisappearFromAbove:bvc]; 659 [self waitForModalOfClass:[UIAlertController class] toDisappearFromAbove:bvc];
642 } 660 }
643 661
644 // Tests that a UIAlertController is presented by the QRScannerViewController if 662 // Tests that a UIAlertController is presented by the QRScannerViewController if
645 // the camera state changes after the QRScannerViewController is presented. 663 // the camera state changes after the QRScannerViewController is presented.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 // Test that the correct page is loaded if the scanner result is a search query 830 // Test that the correct page is loaded if the scanner result is a search query
813 // which is then manually edited. 831 // which is then manually edited.
814 - (void)testReceivingQRScannerSearchQueryResultAndEditingTheQuery { 832 - (void)testReceivingQRScannerSearchQueryResultAndEditingTheQuery {
815 [self swizzleWebToolbarControllerLoadGURLFromLocationBar:_testQueryEdited]; 833 [self swizzleWebToolbarControllerLoadGURLFromLocationBar:_testQueryEdited];
816 [self doTestReceivingResult:kTestQuery 834 [self doTestReceivingResult:kTestQuery
817 response:kTestQueryEditedResponse 835 response:kTestQueryEditedResponse
818 edit:@"\bedited"]; 836 edit:@"\bedited"];
819 } 837 }
820 838
821 @end 839 @end
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/ui/toolbar/toolbar_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698