Commit 4ebdece0 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[ios] Add EG tests for autofill address & credit card settings UI

1. Added EG tests for the managed items and click actions.
2. Added constants to autofill_constants and formatted the existing ones.
3. Improved the helper api by:
- adding scroll action to avoid issue while testing on small screens.
- simplify the parameters.

Bug: 131052
Change-Id: Ibe507443a07b1fe7e5c2374bf8b5a1436b43461b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441191Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813917}
parent 157b9af0
...@@ -169,6 +169,7 @@ source_set("eg2_tests") { ...@@ -169,6 +169,7 @@ source_set("eg2_tests") {
":eg_test_support+eg2", ":eg_test_support+eg2",
":test_resources", ":test_resources",
"//base", "//base",
"//components/autofill/core/common",
"//components/password_manager/core/common", "//components/password_manager/core/common",
"//components/policy:generated", "//components/policy:generated",
"//components/policy/core/common:common_constants", "//components/policy/core/common:common_constants",
...@@ -179,6 +180,7 @@ source_set("eg2_tests") { ...@@ -179,6 +180,7 @@ source_set("eg2_tests") {
"//ios/chrome/browser/translate:eg_test_support+eg2", "//ios/chrome/browser/translate:eg_test_support+eg2",
"//ios/chrome/browser/ui/popup_menu:constants", "//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/settings:constants", "//ios/chrome/browser/ui/settings:constants",
"//ios/chrome/browser/ui/settings/autofill:constants",
"//ios/chrome/browser/ui/settings/elements:constants", "//ios/chrome/browser/ui/settings/elements:constants",
"//ios/chrome/browser/ui/settings/password:password_constants", "//ios/chrome/browser/ui/settings/password:password_constants",
"//ios/chrome/browser/ui/table_view/cells:cells_constants", "//ios/chrome/browser/ui/table_view/cells:cells_constants",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/json/json_string_value_serializer.h" #include "base/json/json_string_value_serializer.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/password_manager/core/common/password_manager_pref_names.h" #include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#import "ios/chrome/browser/translate/translate_app_interface.h" #import "ios/chrome/browser/translate/translate_app_interface.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h" #import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_constants.h"
#import "ios/chrome/browser/ui/settings/elements/elements_constants.h" #import "ios/chrome/browser/ui/settings/elements/elements_constants.h"
#import "ios/chrome/browser/ui/settings/password/passwords_table_view_constants.h" #import "ios/chrome/browser/ui/settings/password/passwords_table_view_constants.h"
#import "ios/chrome/browser/ui/settings/settings_table_view_controller_constants.h" #import "ios/chrome/browser/ui/settings/settings_table_view_controller_constants.h"
...@@ -101,21 +103,26 @@ id<GREYMatcher> ToolsMenuTranslateButton() { ...@@ -101,21 +103,26 @@ id<GREYMatcher> ToolsMenuTranslateButton() {
// Verifies that a managed setting item is shown and react properly. // Verifies that a managed setting item is shown and react properly.
void VerifyManagedSettingItem(NSString* accessibilityID, void VerifyManagedSettingItem(NSString* accessibilityID,
NSString* accessibilityValue, NSString* containerViewAccessibilityID) {
id<GREYMatcher> goBackMatcher) { // Check if the managed item is shown in the corresponding table view.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(accessibilityID)] [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(accessibilityID)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)
onElementWithMatcher:grey_accessibilityID(containerViewAccessibilityID)]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
// Click the info button. // Click the info button.
[[EarlGrey [ChromeEarlGreyUI tapSettingsMenuButton:grey_accessibilityID(
selectElementWithMatcher:grey_accessibilityValue(accessibilityValue)] kTableViewCellInfoButtonViewId)];
performAction:grey_tap()];
// Check if the contextual bubble is shown. // Check if the contextual bubble is shown.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID( [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kEnterpriseInfoBubbleViewId)] kEnterpriseInfoBubbleViewId)]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
// Tap outside of the bubble. // Tap outside of the bubble.
[[EarlGrey selectElementWithMatcher:goBackMatcher] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kTableViewCellInfoButtonViewId)]
performAction:grey_tap()];
// Check if the contextual bubble is hidden. // Check if the contextual bubble is hidden.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID( [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
...@@ -162,10 +169,8 @@ void VerifyManagedSettingItem(NSString* accessibilityID, ...@@ -162,10 +169,8 @@ void VerifyManagedSettingItem(NSString* accessibilityID,
// Open settings menu. // Open settings menu.
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
VerifyManagedSettingItem( VerifyManagedSettingItem(kSettingsManagedSearchEngineCellId,
kSettingsManagedSearchEngineCellId, kSettingsTableViewId);
l10n_util::GetNSString(IDS_IOS_SEARCH_ENGINE_SETTING_DISABLED_STATUS),
chrome_test_util::SettingsDoneButton());
} }
// Tests for the PasswordManagerEnabled policy. // Tests for the PasswordManagerEnabled policy.
...@@ -184,15 +189,44 @@ void VerifyManagedSettingItem(NSString* accessibilityID, ...@@ -184,15 +189,44 @@ void VerifyManagedSettingItem(NSString* accessibilityID,
@"Preference was unexpectedly true"); @"Preference was unexpectedly true");
// Open settings menu and tap password settings. // Open settings menu and tap password settings.
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[[[EarlGrey [ChromeEarlGreyUI
selectElementWithMatcher:grey_accessibilityID(kSettingsPasswordsCellId)] tapSettingsMenuButton:chrome_test_util::SettingsMenuPasswordsButton()];
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)
onElementWithMatcher:grey_accessibilityID(kSettingsTableViewId)]
performAction:grey_tap()];
VerifyManagedSettingItem(kSavePasswordManagedTableViewId, VerifyManagedSettingItem(kSavePasswordManagedTableViewId,
l10n_util::GetNSString(IDS_IOS_SETTING_OFF), kPasswordsTableViewId);
chrome_test_util::SettingsMenuBackButton()); }
// Tests for the AutofillAddressEnabled policy Settings UI.
- (void)testAutofillAddressSettingsUI {
// Force the preference off via policy.
SetPolicy(false, policy::key::kAutofillAddressEnabled);
GREYAssertFalse(
[ChromeEarlGrey userBooleanPref:autofill::prefs::kAutofillProfileEnabled],
@"Preference was unexpectedly true");
// Open settings menu and tap Address and More settings.
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI
tapSettingsMenuButton:chrome_test_util::AddressesAndMoreButton()];
VerifyManagedSettingItem(kAutofillAddressManagedViewId,
kAutofillProfileTableViewID);
}
// Tests for the AutofillCreditCardEnabled policy Settings UI.
- (void)testAutofillCreditCardSettingsUI {
// Force the preference off via policy.
SetPolicy(false, policy::key::kAutofillCreditCardEnabled);
GREYAssertFalse(
[ChromeEarlGrey
userBooleanPref:autofill::prefs::kAutofillCreditCardEnabled],
@"Preference was unexpectedly true");
// Open settings menu and tap Payment Method settings.
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI
tapSettingsMenuButton:chrome_test_util::PaymentMethodsButton()];
VerifyManagedSettingItem(kAutofillCreditCardManagedViewId,
kAutofillCreditCardTableViewId);
} }
// Tests for the SavingBrowserHistoryDisabled policy. // Tests for the SavingBrowserHistoryDisabled policy.
......
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
extern NSString* const kAutofillProfileEditTableViewId; extern NSString* const kAutofillProfileEditTableViewId;
extern NSString* const kAutofillProfileTableViewID; extern NSString* const kAutofillProfileTableViewID;
extern NSString* const kAutofillPaymentMethodsToolbarId; extern NSString* const kAutofillPaymentMethodsToolbarId;
extern NSString* const kAutofillAddressSwitchViewId;
extern NSString* const kAutofillAddressManagedViewId;
extern NSString* const kAutofillCreditCardTableViewId; extern NSString* const kAutofillCreditCardTableViewId;
extern NSString* const kAutofillCreditCardSwitchViewId; extern NSString* const kAutofillCreditCardSwitchViewId;
extern NSString* const kAutofillCreditCardManagedViewId; extern NSString* const kAutofillCreditCardManagedViewId;
......
...@@ -11,10 +11,16 @@ ...@@ -11,10 +11,16 @@
NSString* const kAutofillProfileEditTableViewId = NSString* const kAutofillProfileEditTableViewId =
@"kAutofillProfileEditTableViewId"; @"kAutofillProfileEditTableViewId";
NSString* const kAutofillProfileTableViewID = @"kAutofillProfileTableViewID"; NSString* const kAutofillProfileTableViewID = @"kAutofillProfileTableViewID";
NSString* const kAutofillAddressSwitchViewId = @"kAutofillAddressSwitchViewId";
NSString* const kAutofillAddressManagedViewId =
@"kAutofillAddressManagedViewId";
NSString* const kAutofillCreditCardTableViewId = @"kAutofillTableViewId"; NSString* const kAutofillCreditCardTableViewId =
NSString* const kAutofillCreditCardSwitchViewId = @"cardItem_switch"; @"kAutofillCreditCardTableViewId";
NSString* const kAutofillCreditCardManagedViewId = @"cardItem_managed"; NSString* const kAutofillCreditCardSwitchViewId =
@"kAutofillCreditCardSwitchViewId";
NSString* const kAutofillCreditCardManagedViewId =
@"kAutofillCreditCardManagedViewId";
NSString* const kAutofillPaymentMethodsToolbarId = NSString* const kAutofillPaymentMethodsToolbarId =
@"kAutofillPaymentMethodsToolbarId"; @"kAutofillPaymentMethodsToolbarId";
NSString* const kSettingsAddPaymentMethodButtonId = NSString* const kSettingsAddPaymentMethodButtonId =
......
...@@ -110,13 +110,8 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -110,13 +110,8 @@ id<GREYMatcher> NavigationBarEditButton() {
// Helper to open the settings page for Autofill profiles. // Helper to open the settings page for Autofill profiles.
- (void)openAutofillProfilesSettings { - (void)openAutofillProfilesSettings {
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
id<GREYMatcher> addressesButton = [ChromeEarlGreyUI
ButtonWithAccessibilityLabelId(IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE); tapSettingsMenuButton:chrome_test_util::AddressesAndMoreButton()];
[[[EarlGrey selectElementWithMatcher:addressesButton]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)
onElementWithMatcher:grey_allOf(grey_kindOfClassName(@"UITableView"),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
} }
// Helper to open the settings page for the Autofill profile with |label|. // Helper to open the settings page for the Autofill profile with |label|.
...@@ -248,8 +243,10 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -248,8 +243,10 @@ id<GREYMatcher> NavigationBarEditButton() {
performAction:grey_tap()]; performAction:grey_tap()];
// Check the Autofill profile switch is disabled. // Check the Autofill profile switch is disabled.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsSwitchCell( [[EarlGrey
@"addressItem_switch", YES, NO)] selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
kAutofillAddressSwitchViewId,
/*is_toggled_on=*/YES, /*is_enabled=*/NO)]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
[self exitSettingsMenu]; [self exitSettingsMenu];
...@@ -262,8 +259,10 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -262,8 +259,10 @@ id<GREYMatcher> NavigationBarEditButton() {
[self openAutofillProfilesSettings]; [self openAutofillProfilesSettings];
// Toggle the Autofill profiles switch off. // Toggle the Autofill profiles switch off.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsSwitchCell( [[EarlGrey
@"addressItem_switch", YES, YES)] selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
kAutofillAddressSwitchViewId,
/*is_toggled_on=*/YES, /*is_enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(NO)]; performAction:chrome_test_util::TurnSettingsSwitchOn(NO)];
// Expect Autofill profiles to remain visible. // Expect Autofill profiles to remain visible.
...@@ -271,8 +270,10 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -271,8 +270,10 @@ id<GREYMatcher> NavigationBarEditButton() {
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
// Toggle the Autofill profiles switch back on. // Toggle the Autofill profiles switch back on.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsSwitchCell( [[EarlGrey
@"addressItem_switch", NO, YES)] selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
kAutofillAddressSwitchViewId,
/*is_toggled_on=*/NO, /*is_enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(YES)]; performAction:chrome_test_util::TurnSettingsSwitchOn(YES)];
// Expect Autofill profiles to remain visible. // Expect Autofill profiles to remain visible.
......
...@@ -162,7 +162,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -162,7 +162,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
switchItem.text = switchItem.text =
l10n_util::GetNSString(IDS_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL); l10n_util::GetNSString(IDS_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL);
switchItem.on = [self isAutofillProfileEnabled]; switchItem.on = [self isAutofillProfileEnabled];
switchItem.accessibilityIdentifier = @"addressItem_switch"; switchItem.accessibilityIdentifier = kAutofillAddressSwitchViewId;
return switchItem; return switchItem;
} }
...@@ -175,7 +175,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -175,7 +175,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
managedAddressItem.statusText = l10n_util::GetNSString(IDS_IOS_SETTING_OFF); managedAddressItem.statusText = l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
managedAddressItem.accessibilityHint = managedAddressItem.accessibilityHint =
l10n_util::GetNSString(IDS_IOS_TOGGLE_SETTING_MANAGED_ACCESSIBILITY_HINT); l10n_util::GetNSString(IDS_IOS_TOGGLE_SETTING_MANAGED_ACCESSIBILITY_HINT);
managedAddressItem.accessibilityIdentifier = @"addressItem_managed"; managedAddressItem.accessibilityIdentifier = kAutofillAddressManagedViewId;
return managedAddressItem; return managedAddressItem;
} }
......
...@@ -182,6 +182,9 @@ id<GREYMatcher> SyncSettingsConfirmButton(); ...@@ -182,6 +182,9 @@ id<GREYMatcher> SyncSettingsConfirmButton();
// settings menu. // settings menu.
id<GREYMatcher> AutofillCreditCardTableView(); id<GREYMatcher> AutofillCreditCardTableView();
// Returns matcher for the "Addresses and More" button in the settings menu.
id<GREYMatcher> AddressesAndMoreButton();
// Returns matcher for the "Payment Methods" button in the settings menu. // Returns matcher for the "Payment Methods" button in the settings menu.
id<GREYMatcher> PaymentMethodsButton(); id<GREYMatcher> PaymentMethodsButton();
......
...@@ -231,6 +231,10 @@ id<GREYMatcher> AutofillCreditCardTableView() { ...@@ -231,6 +231,10 @@ id<GREYMatcher> AutofillCreditCardTableView() {
return [ChromeMatchersAppInterface autofillCreditCardTableView]; return [ChromeMatchersAppInterface autofillCreditCardTableView];
} }
id<GREYMatcher> AddressesAndMoreButton() {
return [ChromeMatchersAppInterface addressesAndMoreButton];
}
id<GREYMatcher> PaymentMethodsButton() { id<GREYMatcher> PaymentMethodsButton() {
return [ChromeMatchersAppInterface paymentMethodsButton]; return [ChromeMatchersAppInterface paymentMethodsButton];
} }
......
...@@ -186,6 +186,9 @@ ...@@ -186,6 +186,9 @@
// settings menu. // settings menu.
+ (id<GREYMatcher>)autofillCreditCardTableView; + (id<GREYMatcher>)autofillCreditCardTableView;
// Returns matcher for the "Addresses and More" button in the settings menu.
+ (id<GREYMatcher>)addressesAndMoreButton;
// Returns matcher for the "Payment Methods" button in the settings menu. // Returns matcher for the "Payment Methods" button in the settings menu.
+ (id<GREYMatcher>)paymentMethodsButton; + (id<GREYMatcher>)paymentMethodsButton;
......
...@@ -466,6 +466,11 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -466,6 +466,11 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kSyncSettingsConfirmButtonId); return grey_accessibilityID(kSyncSettingsConfirmButtonId);
} }
+ (id<GREYMatcher>)addressesAndMoreButton {
return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:(IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE)];
}
+ (id<GREYMatcher>)paymentMethodsButton { + (id<GREYMatcher>)paymentMethodsButton {
return [ChromeMatchersAppInterface return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:(IDS_AUTOFILL_PAYMENT_METHODS)]; buttonWithAccessibilityLabelID:(IDS_AUTOFILL_PAYMENT_METHODS)];
......
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