Commit 2b0d21df authored by Tanisha Mandre's avatar Tanisha Mandre Committed by Commit Bot

Tests for Add Credit Card View fields

- Enables CreditCardScanner feature flag in setup.
- Tests text fields appear - name, card number, expiry month, expiry year.
- Tests 'Use Camera' button appears only in iOS 13.

Bug:1000669

Change-Id: Idf4d39061b715bab322e88b65ccc2d31e715bb98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787378Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Commit-Queue: Tanisha Mandre <tanishamandre@google.com>
Cr-Commit-Position: refs/heads/master@{#695080}
parent 20a13e9a
...@@ -125,13 +125,13 @@ source_set("eg2_tests") { ...@@ -125,13 +125,13 @@ source_set("eg2_tests") {
"//build/config/ios:xctest_config", "//build/config/ios:xctest_config",
] ]
testonly = true testonly = true
sources = [ sources = [
"autofill_add_credit_card_egtest.mm", "autofill_add_credit_card_egtest.mm",
] ]
deps = [ deps = [
":feature_flags", ":feature_flags",
"//base",
"//ios/chrome/app/strings",
"//ios/chrome/test/earl_grey:eg_test_support+eg2", "//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib", "//ios/third_party/earl_grey2:test_lib",
...@@ -139,6 +139,5 @@ source_set("eg2_tests") { ...@@ -139,6 +139,5 @@ source_set("eg2_tests") {
"//net:test_support", "//net:test_support",
"//ui/base", "//ui/base",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
} }
...@@ -3,20 +3,57 @@ ...@@ -3,20 +3,57 @@
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/settings/autofill/features.h" #import "ios/chrome/browser/ui/settings/autofill/features.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/testing/earl_grey/app_launch_manager.h" #import "ios/testing/earl_grey/app_launch_manager.h"
#import "ios/testing/earl_grey/earl_grey_test.h" #import "ios/testing/earl_grey/earl_grey_test.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using chrome_test_util::AddPaymentMethodButton; using chrome_test_util::AddPaymentMethodButton;
using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::PaymentMethodsButton; using chrome_test_util::PaymentMethodsButton;
namespace {
// Matcher for the 'Name on Card' field in the add credit card view.
id<GREYMatcher> NameOnCardField() {
return grey_accessibilityLabel(
l10n_util::GetNSStringWithFixup(IDS_IOS_AUTOFILL_CARDHOLDER));
}
// Matcher for the 'Card Number' field in the add credit card view.
id<GREYMatcher> CardNumberField() {
return grey_accessibilityLabel(
l10n_util::GetNSStringWithFixup(IDS_IOS_AUTOFILL_CARD_NUMBER));
}
// Matcher for the 'Month of Expiry' field in the add credit card view.
id<GREYMatcher> MonthOfExpiryField() {
return grey_accessibilityLabel(
l10n_util::GetNSStringWithFixup(IDS_IOS_AUTOFILL_EXP_MONTH));
}
// Matcher for the 'Year of Expiry' field in the add credit card view.
id<GREYMatcher> YearOfExpiryField() {
return grey_accessibilityLabel(
l10n_util::GetNSStringWithFixup(IDS_IOS_AUTOFILL_EXP_YEAR));
}
// Matcher for the use camera button in the add credit card view.
id<GREYMatcher> UseCameraButton() {
return ButtonWithAccessibilityLabelId(
IDS_IOS_AUTOFILL_ADD_CREDIT_CARD_OPEN_CAMERA_BUTTON_LABEL);
}
} // namespace
// Tests for Settings Autofill add credit cards section. // Tests for Settings Autofill add credit cards section.
@interface AutofillAddCreditCardTestCase : ChromeTestCase @interface AutofillAddCreditCardTestCase : ChromeTestCase
@end @end
...@@ -26,11 +63,14 @@ using chrome_test_util::PaymentMethodsButton; ...@@ -26,11 +63,14 @@ using chrome_test_util::PaymentMethodsButton;
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
[[AppLaunchManager sharedManager] [[AppLaunchManager sharedManager]
ensureAppLaunchedWithFeaturesEnabled:{kSettingsAddPaymentMethod} ensureAppLaunchedWithFeaturesEnabled:{kSettingsAddPaymentMethod,
kCreditCardScanner}
disabled:{} disabled:{}
forceRestart:NO]; forceRestart:NO];
GREYAssertTrue([ChromeEarlGrey isSettingsAddPaymentMethodEnabled], GREYAssertTrue([ChromeEarlGrey isSettingsAddPaymentMethodEnabled],
@"SettingsAddPaymentMethod should be enabled"); @"SettingsAddPaymentMethod should be enabled");
GREYAssertTrue([ChromeEarlGrey isCreditCardScannerEnabled],
@"CreditCardScanner should be enabled");
[ChromeEarlGrey openNewTab]; [ChromeEarlGrey openNewTab];
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:PaymentMethodsButton()]; [ChromeEarlGreyUI tapSettingsMenuButton:PaymentMethodsButton()];
...@@ -38,4 +78,41 @@ using chrome_test_util::PaymentMethodsButton; ...@@ -38,4 +78,41 @@ using chrome_test_util::PaymentMethodsButton;
performAction:grey_tap()]; performAction:grey_tap()];
} }
#pragma mark - Test that all fields on the 'Add Credit Card' screen appear
// Tests that 'Name on Card' field appears on screen.
- (void)testNameOnCardFieldIsPresent {
[[EarlGrey selectElementWithMatcher:NameOnCardField()]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Tests that 'Card Number' field appears on screen.
- (void)testCardNumberFieldIsPresent {
[[EarlGrey selectElementWithMatcher:CardNumberField()]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Tests that 'Month of Expiry' field appears on screen.
- (void)testMonthOfExpiryFieldIsPresent {
[[EarlGrey selectElementWithMatcher:MonthOfExpiryField()]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Tests that 'Year of Expiry' field appears on screen.
- (void)testYearOfExpiryFieldIsPresent {
[[EarlGrey selectElementWithMatcher:YearOfExpiryField()]
assertWithMatcher:grey_sufficientlyVisible()];
}
// Tests that 'Use Camera' button appears on screen only for iOS 13.
- (void)testUseCameraButtonIsPresent {
if (@available(iOS 13, *)) {
[[EarlGrey selectElementWithMatcher:UseCameraButton()]
assertWithMatcher:grey_sufficientlyVisible()];
} else {
[[EarlGrey selectElementWithMatcher:UseCameraButton()]
assertWithMatcher:grey_nil()];
}
}
@end @end
...@@ -178,6 +178,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -178,6 +178,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
cameraButtonItem.text = l10n_util::GetNSString( cameraButtonItem.text = l10n_util::GetNSString(
IDS_IOS_AUTOFILL_ADD_CREDIT_CARD_OPEN_CAMERA_BUTTON_LABEL); IDS_IOS_AUTOFILL_ADD_CREDIT_CARD_OPEN_CAMERA_BUTTON_LABEL);
cameraButtonItem.textAlignment = NSTextAlignmentCenter; cameraButtonItem.textAlignment = NSTextAlignmentCenter;
cameraButtonItem.accessibilityTraits |= UIAccessibilityTraitButton;
if (base::FeatureList::IsEnabled(kCreditCardScanner)) { if (base::FeatureList::IsEnabled(kCreditCardScanner)) {
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
[model addSectionWithIdentifier:SectionIdentifierCameraButton]; [model addSectionWithIdentifier:SectionIdentifierCameraButton];
......
...@@ -372,6 +372,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -372,6 +372,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// Returns YES if SettingsAddPaymentMethod feature is enabled. // Returns YES if SettingsAddPaymentMethod feature is enabled.
- (BOOL)isSettingsAddPaymentMethodEnabled WARN_UNUSED_RESULT; - (BOOL)isSettingsAddPaymentMethodEnabled WARN_UNUSED_RESULT;
// Returns YES if CreditCardScanner feature is enabled.
- (BOOL)isCreditCardScannerEnabled WARN_UNUSED_RESULT;
#pragma mark - Popup Blocking #pragma mark - Popup Blocking
// Gets the current value of the popup content setting preference for the // Gets the current value of the popup content setting preference for the
......
...@@ -622,6 +622,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -622,6 +622,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface isSettingsAddPaymentMethodEnabled]; return [ChromeEarlGreyAppInterface isSettingsAddPaymentMethodEnabled];
} }
- (BOOL)isCreditCardScannerEnabled {
return [ChromeEarlGreyAppInterface isCreditCardScannerEnabled];
}
#pragma mark - ScopedBlockPopupsPref #pragma mark - ScopedBlockPopupsPref
- (ContentSetting)popupPrefValue { - (ContentSetting)popupPrefValue {
......
...@@ -305,6 +305,9 @@ ...@@ -305,6 +305,9 @@
// Returns YES if SettingsAddPaymentMethod feature is enabled. // Returns YES if SettingsAddPaymentMethod feature is enabled.
+ (BOOL)isSettingsAddPaymentMethodEnabled WARN_UNUSED_RESULT; + (BOOL)isSettingsAddPaymentMethodEnabled WARN_UNUSED_RESULT;
// Returns YES if CreditCardScanner feature is enabled.
+ (BOOL)isCreditCardScannerEnabled WARN_UNUSED_RESULT;
#pragma mark - Popup Blocking #pragma mark - Popup Blocking
// Gets the current value of the popup content setting preference for the // Gets the current value of the popup content setting preference for the
......
...@@ -520,6 +520,10 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC; ...@@ -520,6 +520,10 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
return base::FeatureList::IsEnabled(kSettingsAddPaymentMethod); return base::FeatureList::IsEnabled(kSettingsAddPaymentMethod);
} }
+ (BOOL)isCreditCardScannerEnabled {
return base::FeatureList::IsEnabled(kCreditCardScanner);
}
#pragma mark - ScopedBlockPopupsPref #pragma mark - ScopedBlockPopupsPref
+ (ContentSetting)popupPrefValue { + (ContentSetting)popupPrefValue {
......
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