Commit 069642b5 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

[eg2] convert AutofillCreditCardSettingsTest

Tbr: eugenebut
Bug: 987646
Change-Id: I659aa88374381c8fc221efcb2287c17314b6cfa8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1892811
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711350}
parent 4d7962a1
...@@ -37,7 +37,8 @@ ...@@ -37,7 +37,8 @@
+ (void)clearCreditCardStore; + (void)clearCreditCardStore;
// Saves a local credit card that doesn't require CVC to be used. // Saves a local credit card that doesn't require CVC to be used.
+ (void)saveLocalCreditCard; // Returns the |card.NetworkAndLastFourDigits| of the card used in the UIs.
+ (NSString*)saveLocalCreditCard;
// Saves a masked credit card that requires CVC to be used. // Saves a masked credit card that requires CVC to be used.
+ (void)saveMaskedCreditCard; + (void)saveMaskedCreditCard;
......
...@@ -211,7 +211,7 @@ void AddAutofillProfile(autofill::PersonalDataManager* personalDataManager) { ...@@ -211,7 +211,7 @@ void AddAutofillProfile(autofill::PersonalDataManager* personalDataManager) {
} }
} }
+ (void)saveLocalCreditCard { + (NSString*)saveLocalCreditCard {
autofill::PersonalDataManager* personalDataManager = autofill::PersonalDataManager* personalDataManager =
[self personalDataManager]; [self personalDataManager];
autofill::CreditCard card = autofill::test::GetCreditCard(); autofill::CreditCard card = autofill::test::GetCreditCard();
...@@ -225,6 +225,7 @@ void AddAutofillProfile(autofill::PersonalDataManager* personalDataManager) { ...@@ -225,6 +225,7 @@ void AddAutofillProfile(autofill::PersonalDataManager* personalDataManager) {
base::TimeDelta::FromSeconds( base::TimeDelta::FromSeconds(
base::test::ios::kWaitForFileOperationTimeout)); base::test::ios::kWaitForFileOperationTimeout));
personalDataManager->NotifyPersonalDataObserver(); personalDataManager->NotifyPersonalDataObserver();
return base::SysUTF16ToNSString(card.NetworkAndLastFourDigits());
} }
+ (void)saveMaskedCreditCard { + (void)saveMaskedCreditCard {
......
...@@ -140,6 +140,7 @@ source_set("eg2_tests") { ...@@ -140,6 +140,7 @@ source_set("eg2_tests") {
testonly = true testonly = true
sources = [ sources = [
"autofill_add_credit_card_egtest.mm", "autofill_add_credit_card_egtest.mm",
"autofill_credit_card_settings_egtest.mm",
"autofill_profile_settings_egtest.mm", "autofill_profile_settings_egtest.mm",
] ]
deps = [ deps = [
......
...@@ -10,4 +10,9 @@ ...@@ -10,4 +10,9 @@
extern NSString* const kAutofillProfileEditTableViewId; extern NSString* const kAutofillProfileEditTableViewId;
extern NSString* const kAutofillProfileTableViewID; extern NSString* const kAutofillProfileTableViewID;
extern NSString* const kAutofillPaymentMethodsToolbarId;
extern NSString* const kAutofillCreditCardTableViewId;
extern NSString* const kAutofillCreditCardSwitchViewId;
extern NSString* const kSettingsAddPaymentMethodButtonId;
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_AUTOFILL_CONSTANTS_H_ #endif // IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_AUTOFILL_CONSTANTS_H_
...@@ -11,3 +11,10 @@ ...@@ -11,3 +11,10 @@
NSString* const kAutofillProfileEditTableViewId = NSString* const kAutofillProfileEditTableViewId =
@"kAutofillProfileEditTableViewId"; @"kAutofillProfileEditTableViewId";
NSString* const kAutofillProfileTableViewID = @"kAutofillProfileTableViewID"; NSString* const kAutofillProfileTableViewID = @"kAutofillProfileTableViewID";
NSString* const kAutofillCreditCardTableViewId = @"kAutofillTableViewId";
NSString* const kAutofillCreditCardSwitchViewId = @"cardItem_switch";
NSString* const kAutofillPaymentMethodsToolbarId =
@"kAutofillPaymentMethodsToolbarId";
NSString* const kSettingsAddPaymentMethodButtonId =
@"kSettingsAddPaymentMethodButtonId";
...@@ -2,27 +2,23 @@ ...@@ -2,27 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h" #import "ios/chrome/browser/ui/autofill/autofill_app_interface.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_table_view_controller.h" #import "ios/chrome/browser/ui/settings/autofill/autofill_constants.h"
#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" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h" #import "ios/chrome/test/earl_grey/chrome_actions.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"
#include "ios/testing/earl_grey/disabled_test_macros.h" #include "ios/testing/earl_grey/disabled_test_macros.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -59,11 +55,6 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -59,11 +55,6 @@ id<GREYMatcher> NavigationBarEditButton() {
grey_not(grey_accessibilityTrait(UIAccessibilityTraitNotEnabled)), nil); grey_not(grey_accessibilityTrait(UIAccessibilityTraitNotEnabled)), nil);
} }
// Matcher for the Delete button in the list view, located at the bottom of the
// screen.
id<GREYMatcher> BottomToolbarDeleteButton() {
return grey_accessibilityID(kSettingsToolbarDeleteButtonId);
}
// Matcher for the Delete button in the list view, located at the bottom of the // Matcher for the Delete button in the list view, located at the bottom of the
// screen. // screen.
...@@ -77,49 +68,23 @@ id<GREYMatcher> BottomToolbar() { ...@@ -77,49 +68,23 @@ id<GREYMatcher> BottomToolbar() {
@interface AutofillCreditCardSettingsTestCase : ChromeTestCase @interface AutofillCreditCardSettingsTestCase : ChromeTestCase
@end @end
@implementation AutofillCreditCardSettingsTestCase { @implementation AutofillCreditCardSettingsTestCase
// The PersonalDataManager instance for the current browser state.
autofill::PersonalDataManager* _personalDataManager;
}
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
_personalDataManager = [AutofillAppInterface clearCreditCardStore];
autofill::PersonalDataManagerFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
_personalDataManager->SetSyncingForTest(true);
} }
- (void)tearDown { - (void)tearDown {
// Clear existing credit cards. [AutofillAppInterface clearCreditCardStore];
for (const auto* creditCard : _personalDataManager->GetCreditCards()) {
_personalDataManager->RemoveByGUID(creditCard->guid());
}
[super tearDown]; [super tearDown];
} }
- (autofill::CreditCard)addCreditCard {
autofill::CreditCard creditCard = autofill::test::GetCreditCard();
size_t creditCardCount = _personalDataManager->GetCreditCards().size();
_personalDataManager->AddCreditCard(creditCard);
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForActionTimeout,
^bool() {
return creditCardCount <
_personalDataManager->GetCreditCards().size();
}),
@"Failed to add credit card.");
return creditCard;
}
// Returns the label for |creditCard| in the settings page for Autofill credit // Returns the label for |creditCard| in the settings page for Autofill credit
// cards. // cards.
- (NSString*)creditCardLabel:(const autofill::CreditCard&)creditCard { - (NSString*)creditCardLabel:(NSString*)lastDigits {
return [NSString stringWithFormat:kCreditCardLabelTemplate, return [NSString stringWithFormat:kCreditCardLabelTemplate, lastDigits];
base::SysUTF16ToNSString(
creditCard.NetworkAndLastFourDigits())];
} }
// Helper to open the settings page for Autofill credit cards. // Helper to open the settings page for Autofill credit cards.
...@@ -160,8 +125,8 @@ id<GREYMatcher> BottomToolbar() { ...@@ -160,8 +125,8 @@ id<GREYMatcher> BottomToolbar() {
// Test that the page for viewing Autofill credit card details is as expected. // Test that the page for viewing Autofill credit card details is as expected.
- (void)testCreditCardViewPage { - (void)testCreditCardViewPage {
autofill::CreditCard creditCard = [self addCreditCard]; NSString* lastDigits = [AutofillAppInterface saveLocalCreditCard];
[self openEditCreditCard:[self creditCardLabel:creditCard]]; [self openEditCreditCard:[self creditCardLabel:lastDigits]];
// Check that all fields and values match the expectations. // Check that all fields and values match the expectations.
for (const DisplayStringIDToExpectedResult& expectation : kExpectedFields) { for (const DisplayStringIDToExpectedResult& expectation : kExpectedFields) {
...@@ -183,8 +148,8 @@ id<GREYMatcher> BottomToolbar() { ...@@ -183,8 +148,8 @@ id<GREYMatcher> BottomToolbar() {
// Test that the page for viewing Autofill credit card details is accessible. // Test that the page for viewing Autofill credit card details is accessible.
- (void)testAccessibilityOnCreditCardViewPage { - (void)testAccessibilityOnCreditCardViewPage {
autofill::CreditCard creditCard = [self addCreditCard]; NSString* lastDigits = [AutofillAppInterface saveLocalCreditCard];
[self openEditCreditCard:[self creditCardLabel:creditCard]]; [self openEditCreditCard:[self creditCardLabel:lastDigits]];
[ChromeEarlGrey verifyAccessibilityForCurrentScreen]; [ChromeEarlGrey verifyAccessibilityForCurrentScreen];
...@@ -197,8 +162,8 @@ id<GREYMatcher> BottomToolbar() { ...@@ -197,8 +162,8 @@ id<GREYMatcher> BottomToolbar() {
// Test that the page for editing Autofill credit card details is accessible. // Test that the page for editing Autofill credit card details is accessible.
- (void)testAccessibilityOnCreditCardEditPage { - (void)testAccessibilityOnCreditCardEditPage {
autofill::CreditCard creditCard = [self addCreditCard]; NSString* lastDigits = [AutofillAppInterface saveLocalCreditCard];
[self openEditCreditCard:[self creditCardLabel:creditCard]]; [self openEditCreditCard:[self creditCardLabel:lastDigits]];
// Switch on edit mode. // Switch on edit mode.
[[EarlGrey selectElementWithMatcher:NavigationBarEditButton()] [[EarlGrey selectElementWithMatcher:NavigationBarEditButton()]
...@@ -215,7 +180,7 @@ id<GREYMatcher> BottomToolbar() { ...@@ -215,7 +180,7 @@ id<GREYMatcher> BottomToolbar() {
// Checks that the Autofill credit cards list view is in edit mode and the // Checks that the Autofill credit cards list view is in edit mode and the
// Autofill credit cards switch is disabled. // Autofill credit cards switch is disabled.
- (void)testListViewEditMode { - (void)testListViewEditMode {
autofill::CreditCard creditCard = [self addCreditCard]; [AutofillAppInterface saveLocalCreditCard];
[self openCreditCardsSettings]; [self openCreditCardsSettings];
// Switch on edit mode. // Switch on edit mode.
...@@ -233,7 +198,7 @@ id<GREYMatcher> BottomToolbar() { ...@@ -233,7 +198,7 @@ id<GREYMatcher> BottomToolbar() {
// Checks that the Autofill credit card switch can be toggled on/off and the // Checks that the Autofill credit card switch can be toggled on/off and the
// list of Autofill credit cards is not affected by it. // list of Autofill credit cards is not affected by it.
- (void)testToggleCreditCardSwitch { - (void)testToggleCreditCardSwitch {
autofill::CreditCard creditCard = [self addCreditCard]; NSString* lastDigits = [AutofillAppInterface saveLocalCreditCard];
[self openCreditCardsSettings]; [self openCreditCardsSettings];
// Toggle the Autofill credit cards switch off. // Toggle the Autofill credit cards switch off.
...@@ -244,7 +209,7 @@ id<GREYMatcher> BottomToolbar() { ...@@ -244,7 +209,7 @@ id<GREYMatcher> BottomToolbar() {
// Expect Autofill credit cards to remain visible. // Expect Autofill credit cards to remain visible.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
// Toggle the Autofill credit cards switch back on. // Toggle the Autofill credit cards switch back on.
...@@ -255,7 +220,7 @@ id<GREYMatcher> BottomToolbar() { ...@@ -255,7 +220,7 @@ id<GREYMatcher> BottomToolbar() {
// Expect Autofill credit cards to remain visible. // Expect Autofill credit cards to remain visible.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
[self exitSettingsMenu]; [self exitSettingsMenu];
...@@ -264,23 +229,23 @@ id<GREYMatcher> BottomToolbar() { ...@@ -264,23 +229,23 @@ id<GREYMatcher> BottomToolbar() {
// Checks that the toolbar appears in edit mode once a card is selected and // Checks that the toolbar appears in edit mode once a card is selected and
// disappears when a card is deselected. // disappears when a card is deselected.
- (void)testToolbarInEditMode { - (void)testToolbarInEditMode {
if (base::FeatureList::IsEnabled(kSettingsAddPaymentMethod)) { if ([ChromeEarlGrey isSettingsAddPaymentMethodEnabled]) {
// The toolbar is always displayed when the AddPayment feature is enabled. // The toolbar is always displayed when the AddPayment feature is enabled.
EARL_GREY_TEST_SKIPPED( EARL_GREY_TEST_SKIPPED(
@"This test makes sense only when there is no Add Payment button."); @"This test makes sense only when there is no Add Payment button.");
} }
autofill::CreditCard creditCard = [self addCreditCard]; NSString* lastDigits = [AutofillAppInterface saveLocalCreditCard];
[self openCreditCardListInEditMode]; [self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:BottomToolbar()] [[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())]; assertWithMatcher:grey_not(grey_sufficientlyVisible())];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbar()] [[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbar()] [[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())]; assertWithMatcher:grey_not(grey_sufficientlyVisible())];
...@@ -291,50 +256,54 @@ id<GREYMatcher> BottomToolbar() { ...@@ -291,50 +256,54 @@ id<GREYMatcher> BottomToolbar() {
// is selected. There should be no 'Add payment method' button if the // is selected. There should be no 'Add payment method' button if the
// kSettingsAddPaymentMethod flag is not enabled. // kSettingsAddPaymentMethod flag is not enabled.
- (void)testToolbarButtonsInEditMode { - (void)testToolbarButtonsInEditMode {
if (base::FeatureList::IsEnabled(kSettingsAddPaymentMethod)) { if ([ChromeEarlGrey isSettingsAddPaymentMethodEnabled]) {
// The toolbar is always displayed when the AddPayment feature is enabled. // The toolbar is always displayed when the AddPayment feature is enabled.
EARL_GREY_TEST_SKIPPED( EARL_GREY_TEST_SKIPPED(
@"This test makes sense only when there is no Add Payment button."); @"This test makes sense only when there is no Add Payment button.");
} }
autofill::CreditCard creditCard = [self addCreditCard]; NSString* lastDigits = [AutofillAppInterface saveLocalCreditCard];
[self openCreditCardListInEditMode]; [self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey [[EarlGrey
selectElementWithMatcher:chrome_test_util::AddPaymentMethodButton()] selectElementWithMatcher:chrome_test_util::AddPaymentMethodButton()]
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsBottomToolbarDeleteButton()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey [[EarlGrey
selectElementWithMatcher:chrome_test_util::AddPaymentMethodButton()] selectElementWithMatcher:chrome_test_util::AddPaymentMethodButton()]
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsBottomToolbarDeleteButton()]
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
} }
// Checks that the toolbar always appears in edit mode when the 'Add Payment // Checks that the toolbar always appears in edit mode when the 'Add Payment
// method' feature is enabled. // method' feature is enabled.
- (void)testToolbarInEditModeAddPaymentMethodFeatureEnabled { - (void)testToolbarInEditModeAddPaymentMethodFeatureEnabled {
base::test::ScopedFeatureList featureList; [[AppLaunchManager sharedManager]
featureList.InitAndEnableFeature(kSettingsAddPaymentMethod); ensureAppLaunchedWithFeaturesEnabled:{kSettingsAddPaymentMethod}
autofill::CreditCard creditCard = [self addCreditCard]; disabled:{}
forceRestart:NO];
NSString* lastDigits = [AutofillAppInterface saveLocalCreditCard];
[self openCreditCardListInEditMode]; [self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:BottomToolbar()] [[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbar()] [[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbar()] [[EarlGrey selectElementWithMatcher:BottomToolbar()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
...@@ -343,9 +312,11 @@ id<GREYMatcher> BottomToolbar() { ...@@ -343,9 +312,11 @@ id<GREYMatcher> BottomToolbar() {
// Checks the 'Add Payment Method' button is always visible when the feature is // Checks the 'Add Payment Method' button is always visible when the feature is
// enabled and directs a user to the Add Payent method view. // enabled and directs a user to the Add Payent method view.
- (void)testToolbarAddPaymentMethodButtonFeatureEnabled { - (void)testToolbarAddPaymentMethodButtonFeatureEnabled {
base::test::ScopedFeatureList featureList; [[AppLaunchManager sharedManager]
featureList.InitAndEnableFeature(kSettingsAddPaymentMethod); ensureAppLaunchedWithFeaturesEnabled:{kSettingsAddPaymentMethod}
autofill::CreditCard creditCard = [self addCreditCard]; disabled:{}
forceRestart:NO];
[AutofillAppInterface saveLocalCreditCard];
[self openCreditCardListInEditMode]; [self openCreditCardListInEditMode];
[[EarlGrey [[EarlGrey
...@@ -362,38 +333,46 @@ id<GREYMatcher> BottomToolbar() { ...@@ -362,38 +333,46 @@ id<GREYMatcher> BottomToolbar() {
// The button is enabled when a card is selected and disabled when a card is not // The button is enabled when a card is selected and disabled when a card is not
// selected. // selected.
- (void)testToolbarDeleteButtonWithAddPaymentMethodFeatureEnabled { - (void)testToolbarDeleteButtonWithAddPaymentMethodFeatureEnabled {
base::test::ScopedFeatureList featureList; [[AppLaunchManager sharedManager]
featureList.InitAndEnableFeature(kSettingsAddPaymentMethod); ensureAppLaunchedWithFeaturesEnabled:{kSettingsAddPaymentMethod}
disabled:{}
autofill::CreditCard creditCard = [self addCreditCard]; forceRestart:NO];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()]
NSString* lastDigits = [AutofillAppInterface saveLocalCreditCard];
[[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsBottomToolbarDeleteButton()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())]; assertWithMatcher:grey_not(grey_sufficientlyVisible())];
[self openCreditCardListInEditMode]; [self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsBottomToolbarDeleteButton()]
assertWithMatcher:grey_not(grey_enabled())]; assertWithMatcher:grey_not(grey_enabled())];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsBottomToolbarDeleteButton()]
assertWithMatcher:grey_enabled()]; assertWithMatcher:grey_enabled()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsBottomToolbarDeleteButton()]
assertWithMatcher:grey_not(grey_enabled())]; assertWithMatcher:grey_not(grey_enabled())];
} }
// Checks that deleting a card exits from edit mode. // Checks that deleting a card exits from edit mode.
- (void)testDeletingCreditCard { - (void)testDeletingCreditCard {
autofill::CreditCard creditCard = [self addCreditCard]; NSString* lastDigits = [AutofillAppInterface saveLocalCreditCard];
[self openCreditCardListInEditMode]; [self openCreditCardListInEditMode];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
[self creditCardLabel:creditCard])] [self creditCardLabel:lastDigits])]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsBottomToolbarDeleteButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:BottomToolbarDeleteButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::
SettingsBottomToolbarDeleteButton()]
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
// If the done button is nil it is no longer in edit mode. // If the done button is nil it is no longer in edit mode.
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()] [[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
......
...@@ -7,11 +7,6 @@ ...@@ -7,11 +7,6 @@
#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h" #import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h"
extern NSString* const kAutofillPaymentMethodsToolbarId;
extern NSString* const kAutofillCreditCardTableViewId;
extern NSString* const kAutofillCreditCardSwitchViewId;
extern NSString* const kSettingsAddPaymentMethodButtonId;
namespace ios { namespace ios {
class ChromeBrowserState; class ChromeBrowserState;
} // namespace ios } // namespace ios
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h" #include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_add_credit_card_coordinator.h" #import "ios/chrome/browser/ui/settings/autofill/autofill_add_credit_card_coordinator.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_constants.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_edit_table_view_controller.h" #import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_edit_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/cells/autofill_data_item.h" #import "ios/chrome/browser/ui/settings/autofill/cells/autofill_data_item.h"
#import "ios/chrome/browser/ui/settings/autofill/features.h" #import "ios/chrome/browser/ui/settings/autofill/features.h"
...@@ -36,13 +37,6 @@ ...@@ -36,13 +37,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kAutofillCreditCardTableViewId = @"kAutofillTableViewId";
NSString* const kAutofillCreditCardSwitchViewId = @"cardItem_switch";
NSString* const kAutofillPaymentMethodsToolbarId =
@"kAutofillPaymentMethodsToolbarId";
NSString* const kSettingsAddPaymentMethodButtonId =
@"kSettingsAddPaymentMethodButtonId";
namespace { namespace {
typedef NS_ENUM(NSInteger, SectionIdentifier) { typedef NS_ENUM(NSInteger, SectionIdentifier) {
......
...@@ -260,6 +260,7 @@ source_set("test_support") { ...@@ -260,6 +260,7 @@ source_set("test_support") {
"//ios/chrome/browser/ui/safe_mode", "//ios/chrome/browser/ui/safe_mode",
"//ios/chrome/browser/ui/safe_mode:test_support", "//ios/chrome/browser/ui/safe_mode:test_support",
"//ios/chrome/browser/ui/settings:settings", "//ios/chrome/browser/ui/settings:settings",
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/settings/autofill", "//ios/chrome/browser/ui/settings/autofill",
"//ios/chrome/browser/ui/settings/autofill:constants", "//ios/chrome/browser/ui/settings/autofill:constants",
"//ios/chrome/browser/ui/settings/autofill:feature_flags", "//ios/chrome/browser/ui/settings/autofill:feature_flags",
...@@ -390,6 +391,7 @@ source_set("eg_app_support+eg2") { ...@@ -390,6 +391,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/safe_mode:eg_app_support+eg2", "//ios/chrome/browser/ui/safe_mode:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings:eg_app_support+eg2", "//ios/chrome/browser/ui/settings:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings:settings", "//ios/chrome/browser/ui/settings:settings",
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/settings/autofill", "//ios/chrome/browser/ui/settings/autofill",
"//ios/chrome/browser/ui/settings/autofill:constants", "//ios/chrome/browser/ui/settings/autofill:constants",
"//ios/chrome/browser/ui/settings/autofill:feature_flags", "//ios/chrome/browser/ui/settings/autofill:feature_flags",
......
...@@ -380,6 +380,10 @@ id<GREYMatcher> SettingsProfileMatcher(); ...@@ -380,6 +380,10 @@ id<GREYMatcher> SettingsProfileMatcher();
// Returns a matcher for the credit card settings collection view. // Returns a matcher for the credit card settings collection view.
id<GREYMatcher> SettingsCreditCardMatcher(); id<GREYMatcher> SettingsCreditCardMatcher();
// Returns a matcher for the delete button at the bottom of settings collection
// views.
id<GREYMatcher> SettingsBottomToolbarDeleteButton();
// Returns a matcher for an autofill suggestion view. // Returns a matcher for an autofill suggestion view.
id<GREYMatcher> AutofillSuggestionViewMatcher(); id<GREYMatcher> AutofillSuggestionViewMatcher();
......
...@@ -475,6 +475,10 @@ id<GREYMatcher> SettingsCreditCardMatcher() { ...@@ -475,6 +475,10 @@ id<GREYMatcher> SettingsCreditCardMatcher() {
return [ChromeMatchersAppInterface settingsCreditCardMatcher]; return [ChromeMatchersAppInterface settingsCreditCardMatcher];
} }
id<GREYMatcher> SettingsBottomToolbarDeleteButton() {
return [ChromeMatchersAppInterface settingsBottomToolbarDeleteButton];
}
id<GREYMatcher> AutofillSuggestionViewMatcher() { id<GREYMatcher> AutofillSuggestionViewMatcher() {
return [ChromeMatchersAppInterface autofillSuggestionViewMatcher]; return [ChromeMatchersAppInterface autofillSuggestionViewMatcher];
} }
......
...@@ -385,6 +385,10 @@ ...@@ -385,6 +385,10 @@
// Returns a matcher for the credit card settings collection view. // Returns a matcher for the credit card settings collection view.
+ (id<GREYMatcher>)settingsCreditCardMatcher; + (id<GREYMatcher>)settingsCreditCardMatcher;
// Returns a matcher for the delete button at the bottom of settings collection
// views.
+ (id<GREYMatcher>)settingsBottomToolbarDeleteButton;
// Returns a matcher for an autofill suggestion view. // Returns a matcher for an autofill suggestion view.
+ (id<GREYMatcher>)autofillSuggestionViewMatcher; + (id<GREYMatcher>)autofillSuggestionViewMatcher;
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h" #import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/password/passwords_table_view_controller.h" #import "ios/chrome/browser/ui/settings/password/passwords_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/privacy_table_view_controller.h" #import "ios/chrome/browser/ui/settings/privacy_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_table_view_controller.h" #import "ios/chrome/browser/ui/settings/settings_table_view_controller.h"
#import "ios/chrome/browser/ui/static_content/static_html_view_controller.h" #import "ios/chrome/browser/ui/static_content/static_html_view_controller.h"
#import "ios/chrome/browser/ui/tab_grid/grid/grid_constants.h" #import "ios/chrome/browser/ui/tab_grid/grid/grid_constants.h"
...@@ -760,6 +761,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -760,6 +761,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kFormSuggestionLabelAccessibilityIdentifier); return grey_accessibilityID(kFormSuggestionLabelAccessibilityIdentifier);
} }
+ (id<GREYMatcher>)settingsBottomToolbarDeleteButton {
return grey_accessibilityID(kSettingsToolbarDeleteButtonId);
}
#pragma mark - Manual Fallback #pragma mark - Manual Fallback
+ (id<GREYMatcher>)manualFallbackFormSuggestionViewMatcher { + (id<GREYMatcher>)manualFallbackFormSuggestionViewMatcher {
......
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