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

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

Issue 2798773002: Create ChromeEarlGrey waitForWebViewContainingText. (Closed)
Patch Set: better formatting Created 3 years, 8 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
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 #import "base/mac/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "components/strings/grit/components_strings.h" 12 #include "components/strings/grit/components_strings.h"
13 #include "components/version_info/version_info.h" 13 #include "components/version_info/version_info.h"
14 #import "ios/chrome/app/main_controller.h" 14 #import "ios/chrome/app/main_controller.h"
15 #include "ios/chrome/browser/chrome_switches.h" 15 #include "ios/chrome/browser/chrome_switches.h"
16 #import "ios/chrome/browser/ui/browser_view_controller.h" 16 #import "ios/chrome/browser/ui/browser_view_controller.h"
17 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 17 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
18 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 18 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
19 #include "ios/chrome/browser/ui/icons/chrome_icon.h" 19 #include "ios/chrome/browser/ui/icons/chrome_icon.h"
20 #include "ios/chrome/browser/ui/qr_scanner/camera_controller.h" 20 #include "ios/chrome/browser/ui/qr_scanner/camera_controller.h"
21 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view.h" 21 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view.h"
22 #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"
23 #include "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" 23 #include "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
24 #include "ios/chrome/grit/ios_chromium_strings.h" 24 #include "ios/chrome/grit/ios_chromium_strings.h"
25 #include "ios/chrome/grit/ios_strings.h" 25 #include "ios/chrome/grit/ios_strings.h"
26 #import "ios/chrome/test/app/chrome_test_util.h" 26 #import "ios/chrome/test/app/chrome_test_util.h"
27 #import "ios/chrome/test/base/scoped_block_swizzler.h" 27 #import "ios/chrome/test/base/scoped_block_swizzler.h"
28 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
28 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 29 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
29 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 30 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
30 #include "ios/shared/chrome/browser/ui/omnibox/location_bar_delegate.h" 31 #include "ios/shared/chrome/browser/ui/omnibox/location_bar_delegate.h"
31 #include "ios/web/public/test/http_server.h" 32 #include "ios/web/public/test/http_server.h"
32 #include "ios/web/public/test/http_server_util.h" 33 #include "ios/web/public/test/http_server_util.h"
33 #import "third_party/ocmock/OCMock/OCMock.h" 34 #import "third_party/ocmock/OCMock/OCMock.h"
34 #import "ui/base/l10n/l10n_util.h" 35 #import "ui/base/l10n/l10n_util.h"
35 #import "ui/base/l10n/l10n_util_mac.h" 36 #import "ui/base/l10n/l10n_util_mac.h"
36 37
37 using namespace chrome_test_util; 38 using namespace chrome_test_util;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 MainController* mainController = chrome_test_util::GetMainController(); 271 MainController* mainController = chrome_test_util::GetMainController();
271 return [[mainController browserViewInformation] currentBVC]; 272 return [[mainController browserViewInformation] currentBVC];
272 } 273 }
273 274
274 // Checks that the omnibox is visible and contains |text|. 275 // Checks that the omnibox is visible and contains |text|.
275 - (void)assertOmniboxIsVisibleWithText:(std::string)text { 276 - (void)assertOmniboxIsVisibleWithText:(std::string)text {
276 [[EarlGrey selectElementWithMatcher:OmniboxText(text)] 277 [[EarlGrey selectElementWithMatcher:OmniboxText(text)]
277 assertWithMatcher:grey_notNil()]; 278 assertWithMatcher:grey_notNil()];
278 } 279 }
279 280
280 // Checks that the page that is currently loaded contains the |response|.
281 - (void)assertTestURLIsLoaded:(std::string)response {
282 id<GREYMatcher> testURLResponseMatcher =
283 chrome_test_util::WebViewContainingText(response);
284 [[EarlGrey selectElementWithMatcher:testURLResponseMatcher]
285 assertWithMatcher:grey_notNil()];
286 }
287
288 #pragma mark helpers for dialogs 281 #pragma mark helpers for dialogs
289 282
290 // Checks that the modal presented by |viewController| is of class |klass|. 283 // Checks that the modal presented by |viewController| is of class |klass|.
291 - (void)assertModalOfClass:(Class)klass 284 - (void)assertModalOfClass:(Class)klass
292 isPresentedBy:(UIViewController*)viewController { 285 isPresentedBy:(UIViewController*)viewController {
293 UIViewController* modal = [viewController presentedViewController]; 286 UIViewController* modal = [viewController presentedViewController];
294 NSString* errorString = [NSString 287 NSString* errorString = [NSString
295 stringWithFormat:@"A modal of class %@ should be presented by %@.", klass, 288 stringWithFormat:@"A modal of class %@ should be presented by %@.", klass,
296 [viewController class]]; 289 [viewController class]];
297 GREYAssertTrue(modal && [modal isKindOfClass:klass], errorString); 290 GREYAssertTrue(modal && [modal isKindOfClass:klass], errorString);
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 toDisappearFromAbove:[self currentBVC]]; 772 toDisappearFromAbove:[self currentBVC]];
780 [cameraControllerMock verify]; 773 [cameraControllerMock verify];
781 774
782 // Optionally edit the text in the omnibox before pressing return. 775 // Optionally edit the text in the omnibox before pressing return.
783 [self assertOmniboxIsVisibleWithText:result]; 776 [self assertOmniboxIsVisibleWithText:result];
784 if (editString != nil) { 777 if (editString != nil) {
785 EditOmniboxTextAndTapKeyboardReturn(result, editString); 778 EditOmniboxTextAndTapKeyboardReturn(result, editString);
786 } else { 779 } else {
787 TapKeyboardReturnKeyInOmniboxWithText(result); 780 TapKeyboardReturnKeyInOmniboxWithText(result);
788 } 781 }
789 [self assertTestURLIsLoaded:response]; 782 [ChromeEarlGrey
783 waitForWebViewContainingText:base::SysUTF8ToNSString(response)];
790 784
791 // Press the back button to get back to the NTP. 785 // Press the back button to get back to the NTP.
792 TapButton(WebToolbarBackButton()); 786 TapButton(WebToolbarBackButton());
793 [self assertModalOfClass:[QRScannerViewController class] 787 [self assertModalOfClass:[QRScannerViewController class]
794 isNotPresentedBy:[self currentBVC]]; 788 isNotPresentedBy:[self currentBVC]];
795 } 789 }
796 790
797 // Test that the correct page is loaded if the scanner result is a URL. 791 // Test that the correct page is loaded if the scanner result is a URL.
798 - (void)testReceivingQRScannerURLResult { 792 - (void)testReceivingQRScannerURLResult {
799 [self doTestReceivingResult:_testURL.GetContent() 793 [self doTestReceivingResult:_testURL.GetContent()
(...skipping 18 matching lines...) Expand all
818 // Test that the correct page is loaded if the scanner result is a search query 812 // Test that the correct page is loaded if the scanner result is a search query
819 // which is then manually edited. 813 // which is then manually edited.
820 - (void)testReceivingQRScannerSearchQueryResultAndEditingTheQuery { 814 - (void)testReceivingQRScannerSearchQueryResultAndEditingTheQuery {
821 [self swizzleWebToolbarControllerLoadGURLFromLocationBar:_testQueryEdited]; 815 [self swizzleWebToolbarControllerLoadGURLFromLocationBar:_testQueryEdited];
822 [self doTestReceivingResult:kTestQuery 816 [self doTestReceivingResult:kTestQuery
823 response:kTestQueryEditedResponse 817 response:kTestQueryEditedResponse
824 edit:@"\bedited"]; 818 edit:@"\bedited"];
825 } 819 }
826 820
827 @end 821 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698