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 #import "base/mac/scoped_nsobject.h" | |
10 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
12 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
13 #include "components/version_info/version_info.h" | 12 #include "components/version_info/version_info.h" |
14 #import "ios/chrome/app/main_controller.h" | 13 #import "ios/chrome/app/main_controller.h" |
15 #include "ios/chrome/browser/chrome_switches.h" | 14 #include "ios/chrome/browser/chrome_switches.h" |
16 #import "ios/chrome/browser/ui/browser_view_controller.h" | 15 #import "ios/chrome/browser/ui/browser_view_controller.h" |
17 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 16 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
18 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 17 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
19 #include "ios/chrome/browser/ui/icons/chrome_icon.h" | 18 #include "ios/chrome/browser/ui/icons/chrome_icon.h" |
20 #include "ios/chrome/browser/ui/qr_scanner/camera_controller.h" | 19 #include "ios/chrome/browser/ui/qr_scanner/camera_controller.h" |
21 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view.h" | 20 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view.h" |
22 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller.h" | 21 #include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller.h" |
23 #include "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | 22 #include "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
24 #include "ios/chrome/grit/ios_chromium_strings.h" | 23 #include "ios/chrome/grit/ios_chromium_strings.h" |
25 #include "ios/chrome/grit/ios_strings.h" | 24 #include "ios/chrome/grit/ios_strings.h" |
26 #import "ios/chrome/test/app/chrome_test_util.h" | 25 #import "ios/chrome/test/app/chrome_test_util.h" |
27 #import "ios/chrome/test/base/scoped_block_swizzler.h" | 26 #import "ios/chrome/test/base/scoped_block_swizzler.h" |
28 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 27 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
29 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 28 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
30 #include "ios/shared/chrome/browser/ui/omnibox/location_bar_delegate.h" | 29 #include "ios/shared/chrome/browser/ui/omnibox/location_bar_delegate.h" |
31 #include "ios/web/public/test/http_server.h" | 30 #include "ios/web/public/test/http_server.h" |
32 #include "ios/web/public/test/http_server_util.h" | 31 #include "ios/web/public/test/http_server_util.h" |
33 #import "third_party/ocmock/OCMock/OCMock.h" | 32 #import "third_party/ocmock/OCMock/OCMock.h" |
34 #import "ui/base/l10n/l10n_util.h" | 33 #import "ui/base/l10n/l10n_util.h" |
35 #import "ui/base/l10n/l10n_util_mac.h" | 34 #import "ui/base/l10n/l10n_util_mac.h" |
36 | 35 |
36 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
37 #error "This file requires ARC support." | |
38 #endif | |
39 | |
37 using namespace chrome_test_util; | 40 using namespace chrome_test_util; |
38 using namespace qr_scanner; | 41 using namespace qr_scanner; |
39 | 42 |
40 namespace { | 43 namespace { |
41 | 44 |
42 char kTestURL[] = "http://testurl"; | 45 char kTestURL[] = "http://testurl"; |
43 char kTestURLResponse[] = "Test URL page"; | 46 char kTestURLResponse[] = "Test URL page"; |
44 char kTestQuery[] = "testquery"; | 47 char kTestQuery[] = "testquery"; |
45 char kTestQueryURL[] = "http://searchurl/testquery"; | 48 char kTestQueryURL[] = "http://searchurl/testquery"; |
46 char kTestQueryResponse[] = "Test query page"; | 49 char kTestQueryResponse[] = "Test query page"; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 // Returns the GREYMatcher for the Cancel button to dismiss a UIAlertController. | 106 // Returns the GREYMatcher for the Cancel button to dismiss a UIAlertController. |
104 id<GREYMatcher> DialogCancelButton() { | 107 id<GREYMatcher> DialogCancelButton() { |
105 return grey_allOf( | 108 return grey_allOf( |
106 grey_text(l10n_util::GetNSString(IDS_IOS_QR_SCANNER_ALERT_CANCEL)), | 109 grey_text(l10n_util::GetNSString(IDS_IOS_QR_SCANNER_ALERT_CANCEL)), |
107 grey_accessibilityTrait(UIAccessibilityTraitStaticText), nil); | 110 grey_accessibilityTrait(UIAccessibilityTraitStaticText), nil); |
108 } | 111 } |
109 | 112 |
110 // Opens the QR Scanner view using a command. | 113 // Opens the QR Scanner view using a command. |
111 // TODO(crbug.com/629776): Replace the command call with a UI action. | 114 // TODO(crbug.com/629776): Replace the command call with a UI action. |
112 void ShowQRScannerWithCommand() { | 115 void ShowQRScannerWithCommand() { |
113 base::scoped_nsobject<GenericChromeCommand> command( | 116 GenericChromeCommand* command = |
114 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_QR_SCANNER]); | 117 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_QR_SCANNER]; |
115 chrome_test_util::RunCommandWithActiveViewController(command); | 118 chrome_test_util::RunCommandWithActiveViewController(command); |
116 } | 119 } |
117 | 120 |
118 // Taps the |button|. | 121 // Taps the |button|. |
119 void TapButton(id<GREYMatcher> button) { | 122 void TapButton(id<GREYMatcher> button) { |
120 [[EarlGrey selectElementWithMatcher:button] performAction:grey_tap()]; | 123 [[EarlGrey selectElementWithMatcher:button] performAction:grey_tap()]; |
121 } | 124 } |
122 | 125 |
123 // Appends the given |editText| to the |text| already in the omnibox and presses | 126 // Appends the given |editText| to the |text| already in the omnibox and presses |
124 // the keyboard return key. | 127 // the keyboard return key. |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 } | 392 } |
390 | 393 |
391 #pragma mark - | 394 #pragma mark - |
392 #pragma mark Helpers for mocks | 395 #pragma mark Helpers for mocks |
393 | 396 |
394 // Swizzles the CameraController method cameraControllerWithDelegate: to return | 397 // Swizzles the CameraController method cameraControllerWithDelegate: to return |
395 // |cameraControllerMock| instead of a new instance of CameraController. | 398 // |cameraControllerMock| instead of a new instance of CameraController. |
396 - (void)swizzleCameraController:(id)cameraControllerMock { | 399 - (void)swizzleCameraController:(id)cameraControllerMock { |
397 CameraController* (^swizzleCameraControllerBlock)( | 400 CameraController* (^swizzleCameraControllerBlock)( |
398 id<CameraControllerDelegate>) = ^(id<CameraControllerDelegate> delegate) { | 401 id<CameraControllerDelegate>) = ^(id<CameraControllerDelegate> delegate) { |
399 // |initWithDelegate:| must return an object with a return count of 1 | 402 return cameraControllerMock; |
400 // because it is preceded by a call to |alloc|. | |
401 return [cameraControllerMock retain]; | |
baxley
2017/05/16 00:51:36
So we need to keep the retain count at 1. Current
stkhapugin
2017/05/30 14:13:56
This is not the first time ARC is blocked with thi
jif
2017/05/31 11:32:46
Fundamentally, when running tests we need the BVC
stkhapugin
2017/05/31 12:28:40
Mike, can you try swizzling the implementation wit
jif
2017/05/31 13:28:53
Landed the quick fix (https://codereview.chromium.
| |
402 }; | 403 }; |
403 | 404 |
404 camera_controller_swizzler_.reset(new ScopedBlockSwizzler( | 405 camera_controller_swizzler_.reset(new ScopedBlockSwizzler( |
405 [CameraController class], @selector(initWithDelegate:), | 406 [CameraController class], @selector(initWithDelegate:), |
406 swizzleCameraControllerBlock)); | 407 swizzleCameraControllerBlock)); |
407 } | 408 } |
408 | 409 |
409 // Swizzles the WebToolbarController loadGURLFromLocationBarBlock:transition: | 410 // Swizzles the WebToolbarController loadGURLFromLocationBarBlock:transition: |
410 // method to load |searchURL| instead of the generated search URL. | 411 // method to load |searchURL| instead of the generated search URL. |
411 - (void)swizzleWebToolbarControllerLoadGURLFromLocationBar: | 412 - (void)swizzleWebToolbarControllerLoadGURLFromLocationBar: |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
818 // Test that the correct page is loaded if the scanner result is a search query | 819 // Test that the correct page is loaded if the scanner result is a search query |
819 // which is then manually edited. | 820 // which is then manually edited. |
820 - (void)testReceivingQRScannerSearchQueryResultAndEditingTheQuery { | 821 - (void)testReceivingQRScannerSearchQueryResultAndEditingTheQuery { |
821 [self swizzleWebToolbarControllerLoadGURLFromLocationBar:_testQueryEdited]; | 822 [self swizzleWebToolbarControllerLoadGURLFromLocationBar:_testQueryEdited]; |
822 [self doTestReceivingResult:kTestQuery | 823 [self doTestReceivingResult:kTestQuery |
823 response:kTestQueryEditedResponse | 824 response:kTestQueryEditedResponse |
824 edit:@"\bedited"]; | 825 edit:@"\bedited"]; |
825 } | 826 } |
826 | 827 |
827 @end | 828 @end |
OLD | NEW |