Commit 919aab84 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF][EG2] Migrate credit card tests

Consolidate Manual Fallback matchers in one place.
Consolidate credit card Autofill helpers in the respective app
interface.

TBR= eugenebut@chromium.org

Bug: 1017685, 1016367
Change-Id: Ib91e2baba9e72f6e065e8ebf08fdd5f5d3c0c9bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1878197
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709020}
parent 8d8965d2
......@@ -30,6 +30,15 @@
// Resturns the name of the sample profile.
+ (NSString*)exampleProfileName;
// Removes the stored credit cards.
+ (void)clearCreditCardStore;
// Saves a local credit card that doesn't require CVC to be used.
+ (void)saveLocalCreditCard;
// Saves a masked credit card that requires CVC to be used.
+ (void)saveMaskedCreditCard;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_APP_INTERFACE_H_
......@@ -189,6 +189,41 @@ void AddAutofillProfile(autofill::PersonalDataManager* personalDataManager) {
return base::SysUTF16ToNSString(name);
}
+ (void)clearCreditCardStore {
autofill::PersonalDataManager* personalDataManager =
[self personalDataManager];
for (const auto* creditCard : personalDataManager->GetCreditCards()) {
personalDataManager->RemoveByGUID(creditCard->guid());
}
}
+ (void)saveLocalCreditCard {
autofill::PersonalDataManager* personalDataManager =
[self personalDataManager];
autofill::CreditCard card = autofill::test::GetCreditCard();
size_t card_count = personalDataManager->GetCreditCards().size();
personalDataManager->AddCreditCard(card);
ConditionBlock conditionBlock = ^bool {
return card_count < personalDataManager->GetCreditCards().size();
};
base::test::ios::TimeUntilCondition(
nil, conditionBlock, false,
base::TimeDelta::FromSeconds(
base::test::ios::kWaitForFileOperationTimeout));
personalDataManager->NotifyPersonalDataObserver();
}
+ (void)saveMaskedCreditCard {
autofill::PersonalDataManager* personalDataManager =
[self personalDataManager];
autofill::CreditCard card = autofill::test::GetMaskedServerCard();
DCHECK(card.record_type() != autofill::CreditCard::LOCAL_CARD);
personalDataManager->AddServerCreditCardForTest(
std::make_unique<autofill::CreditCard>(card));
personalDataManager->NotifyPersonalDataObserver();
}
#pragma mark - Private
// The PersonalDataManager instance for the current browser state.
......
......@@ -236,6 +236,7 @@ source_set("eg2_tests") {
]
testonly = true
sources = [
"card_view_controller_egtest.mm",
"fallback_coordinator_egtest.mm",
"password_view_controller_egtest.mm",
]
......@@ -244,6 +245,7 @@ source_set("eg2_tests") {
"//base/test:test_support",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/ui/autofill:eg_test_support+eg2",
"//ios/chrome/browser/ui/settings/autofill:feature_flags",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
......
......@@ -134,6 +134,7 @@ source_set("eg2_tests") {
":feature_flags",
"//base",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/autofill:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/ios/ios_util.h"
#import "ios/chrome/browser/ui/autofill/autofill_app_interface.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"
......@@ -107,7 +108,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
}
- (void)tearDown {
[ChromeEarlGrey clearCreditCards];
[AutofillAppInterface clearCreditCardStore];
[super tearDown];
}
......@@ -230,7 +231,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// and the new card number appears on the Autofill Credit Card 'Payment Methods'
// screen.
- (void)testAddButtonOnValidNumber {
[ChromeEarlGrey clearCreditCards];
[AutofillAppInterface clearCreditCardStore];
[[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
......
......@@ -370,11 +370,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// doesn't specify a title.
- (NSString*)displayTitleForURL:(const GURL&)URL;
#pragma mark - Autofill Utilities (EG2)
// Removes the stored credit cards.
- (void)clearCreditCards;
#pragma mark - JavaScript Utilities (EG2)
// Executes JavaScript on current WebState, and waits for either the completion
......
......@@ -669,12 +669,6 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface displayTitleForURL:spec];
}
#pragma mark - Autofill Utilities (EG2)
- (void)clearCreditCards {
[ChromeEarlGreyAppInterface clearCreditCards];
}
#pragma mark - Accessibility Utilities (EG2)
- (void)verifyAccessibilityForCurrentScreen {
......
......@@ -219,11 +219,6 @@
// doesn't specify a title.
+ (NSString*)displayTitleForURL:(NSString*)URL;
#pragma mark - Autofill Utilities (EG2)
// Removes the stored credit cards.
+ (void)clearCreditCards;
#pragma mark - Sync Utilities (EG2)
// Clears fake sync server data.
......
......@@ -376,17 +376,6 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
web::GetDisplayTitleForUrl(GURL(base::SysNSStringToUTF8(URL))));
}
#pragma mark - Autofill Utilities (EG2)
+ (void)clearCreditCards {
autofill::PersonalDataManager* personalDataManager =
autofill::PersonalDataManagerFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
for (const auto* creditCard : personalDataManager->GetCreditCards()) {
personalDataManager->RemoveByGUID(creditCard->guid());
}
}
#pragma mark - Sync Utilities (EG2)
+ (int)numberOfSyncEntitiesWithType:(syncer::ModelType)type {
......
......@@ -377,6 +377,9 @@ id<GREYMatcher> SettingsPasswordSearchMatcher();
// Returns a matcher for the profiles settings collection view.
id<GREYMatcher> SettingsProfileMatcher();
// Returns a matcher for the credit card settings collection view.
id<GREYMatcher> SettingsCreditCardMatcher();
// Returns a matcher for an autofill suggestion view.
id<GREYMatcher> AutofillSuggestionViewMatcher();
......@@ -428,6 +431,23 @@ id<GREYMatcher> SettingsProfileMatcher();
// Returns a matcher for the ProfileTableView window.
id<GREYMatcher> ManualFallbackProfileTableViewWindowMatcher();
// Returns a matcher for the credit card icon in the keyboard accessory bar.
id<GREYMatcher> ManualFallbackCreditCardIconMatcher();
// Returns a matcher for the credit card table view in manual fallback.
id<GREYMatcher> ManualFallbackCreditCardTableViewMatcher();
// Returns a matcher for the button to open password settings in manual
// fallback.
id<GREYMatcher> ManualFallbackManageCreditCardsMatcher();
// Returns a matcher for the button to add credit cards settings in manual
// fallback.
id<GREYMatcher> ManualFallbackAddCreditCardsMatcher();
// Returns a matcher for the CreditCardTableView window.
id<GREYMatcher> ManualFallbackCreditCardTableViewWindowMatcher();
} // namespace chrome_test_util
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_H_
......@@ -471,6 +471,10 @@ id<GREYMatcher> SettingsProfileMatcher() {
return [ChromeMatchersAppInterface settingsProfileMatcher];
}
id<GREYMatcher> SettingsCreditCardMatcher() {
return [ChromeMatchersAppInterface settingsCreditCardMatcher];
}
id<GREYMatcher> AutofillSuggestionViewMatcher() {
return [ChromeMatchersAppInterface autofillSuggestionViewMatcher];
}
......@@ -536,4 +540,27 @@ id<GREYMatcher> ManualFallbackProfileTableViewWindowMatcher() {
[ChromeMatchersAppInterface manualFallbackProfileTableViewWindowMatcher];
}
id<GREYMatcher> ManualFallbackCreditCardIconMatcher() {
return [ChromeMatchersAppInterface manualFallbackCreditCardIconMatcher];
}
id<GREYMatcher> ManualFallbackCreditCardTableViewMatcher() {
return [ChromeMatchersAppInterface manualFallbackCreditCardTableViewMatcher];
}
// Returns a matcher for the button to open password settings in manual
id<GREYMatcher> ManualFallbackManageCreditCardsMatcher() {
return [ChromeMatchersAppInterface manualFallbackManageCreditCardsMatcher];
}
// Returns a matcher for the button to add credit cards settings in manual
id<GREYMatcher> ManualFallbackAddCreditCardsMatcher() {
return [ChromeMatchersAppInterface manualFallbackAddCreditCardsMatcher];
}
id<GREYMatcher> ManualFallbackCreditCardTableViewWindowMatcher() {
return [ChromeMatchersAppInterface
manualFallbackCreditCardTableViewWindowMatcher];
}
} // namespace chrome_test_util
......@@ -382,6 +382,9 @@
// Returns a matcher for the profiles settings collection view.
+ (id<GREYMatcher>)settingsProfileMatcher;
// Returns a matcher for the credit card settings collection view.
+ (id<GREYMatcher>)settingsCreditCardMatcher;
// Returns a matcher for an autofill suggestion view.
+ (id<GREYMatcher>)autofillSuggestionViewMatcher;
......@@ -430,6 +433,23 @@
// Returns a matcher for the ProfileTableView window.
+ (id<GREYMatcher>)manualFallbackProfileTableViewWindowMatcher;
// Returns a matcher for the credit card icon in the keyboard accessory bar.
+ (id<GREYMatcher>)manualFallbackCreditCardIconMatcher;
// Returns a matcher for the credit card table view in manual fallback.
+ (id<GREYMatcher>)manualFallbackCreditCardTableViewMatcher;
// Returns a matcher for the button to open password settings in manual
// fallback.
+ (id<GREYMatcher>)manualFallbackManageCreditCardsMatcher;
// Returns a matcher for the button to add credit cards settings in manual
// fallback.
+ (id<GREYMatcher>)manualFallbackAddCreditCardsMatcher;
// Returns a matcher for the CreditCardTableView window.
+ (id<GREYMatcher>)manualFallbackCreditCardTableViewWindowMatcher;
@end
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_APP_INTERFACE_H_
......@@ -11,6 +11,9 @@
#import "ios/chrome/browser/ui/authentication/cells/signin_promo_view.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_mediator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_coordinator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_mediator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_accessory_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_password_cell.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_password_mediator.h"
......@@ -748,6 +751,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kAutofillProfileTableViewID);
}
+ (id<GREYMatcher>)settingsCreditCardMatcher {
return grey_accessibilityID(kAutofillCreditCardTableViewId);
}
+ (id<GREYMatcher>)autofillSuggestionViewMatcher {
return grey_accessibilityID(kFormSuggestionLabelAccessibilityIdentifier);
}
......@@ -825,4 +832,31 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
grey_descendant([self manualFallbackProfilesTableViewMatcher]);
return grey_allOf(classMatcher, parentMatcher, nil);
}
+ (id<GREYMatcher>)manualFallbackCreditCardIconMatcher {
return grey_accessibilityID(
manual_fill::AccessoryCreditCardAccessibilityIdentifier);
}
+ (id<GREYMatcher>)manualFallbackCreditCardTableViewMatcher {
return grey_accessibilityID(
manual_fill::CardTableViewAccessibilityIdentifier);
}
+ (id<GREYMatcher>)manualFallbackManageCreditCardsMatcher {
return grey_accessibilityID(manual_fill::ManageCardsAccessibilityIdentifier);
}
+ (id<GREYMatcher>)manualFallbackAddCreditCardsMatcher {
return grey_accessibilityID(
manual_fill::kAddCreditCardsAccessibilityIdentifier);
}
+ (id<GREYMatcher>)manualFallbackCreditCardTableViewWindowMatcher {
id<GREYMatcher> classMatcher = grey_kindOfClass([UIWindow class]);
id<GREYMatcher> parentMatcher =
grey_descendant([self manualFallbackCreditCardTableViewMatcher]);
return grey_allOf(classMatcher, parentMatcher, nil);
}
@end
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