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") {
":eg_test_support+eg2",
":test_resources",
"//base",
"//components/autofill/core/common",
"//components/password_manager/core/common",
"//components/policy:generated",
"//components/policy/core/common:common_constants",
......@@ -179,6 +180,7 @@ source_set("eg2_tests") {
"//ios/chrome/browser/translate:eg_test_support+eg2",
"//ios/chrome/browser/ui/popup_menu: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/password:password_constants",
"//ios/chrome/browser/ui/table_view/cells:cells_constants",
......
......@@ -6,6 +6,7 @@
#include "base/json/json_string_value_serializer.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/policy/policy_constants.h"
#include "components/strings/grit/components_strings.h"
......@@ -14,6 +15,7 @@
#include "ios/chrome/browser/pref_names.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/settings/autofill/autofill_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/settings_table_view_controller_constants.h"
......@@ -101,21 +103,26 @@ id<GREYMatcher> ToolsMenuTranslateButton() {
// Verifies that a managed setting item is shown and react properly.
void VerifyManagedSettingItem(NSString* accessibilityID,
NSString* accessibilityValue,
id<GREYMatcher> goBackMatcher) {
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(accessibilityID)]
NSString* containerViewAccessibilityID) {
// Check if the managed item is shown in the corresponding table view.
[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(accessibilityID)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)
onElementWithMatcher:grey_accessibilityID(containerViewAccessibilityID)]
assertWithMatcher:grey_sufficientlyVisible()];
// Click the info button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityValue(accessibilityValue)]
performAction:grey_tap()];
[ChromeEarlGreyUI tapSettingsMenuButton:grey_accessibilityID(
kTableViewCellInfoButtonViewId)];
// Check if the contextual bubble is shown.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kEnterpriseInfoBubbleViewId)]
assertWithMatcher:grey_sufficientlyVisible()];
// 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.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
......@@ -162,10 +169,8 @@ void VerifyManagedSettingItem(NSString* accessibilityID,
// Open settings menu.
[ChromeEarlGreyUI openSettingsMenu];
VerifyManagedSettingItem(
kSettingsManagedSearchEngineCellId,
l10n_util::GetNSString(IDS_IOS_SEARCH_ENGINE_SETTING_DISABLED_STATUS),
chrome_test_util::SettingsDoneButton());
VerifyManagedSettingItem(kSettingsManagedSearchEngineCellId,
kSettingsTableViewId);
}
// Tests for the PasswordManagerEnabled policy.
......@@ -184,15 +189,44 @@ void VerifyManagedSettingItem(NSString* accessibilityID,
@"Preference was unexpectedly true");
// Open settings menu and tap password settings.
[ChromeEarlGreyUI openSettingsMenu];
[[[EarlGrey
selectElementWithMatcher:grey_accessibilityID(kSettingsPasswordsCellId)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)
onElementWithMatcher:grey_accessibilityID(kSettingsTableViewId)]
performAction:grey_tap()];
[ChromeEarlGreyUI
tapSettingsMenuButton:chrome_test_util::SettingsMenuPasswordsButton()];
VerifyManagedSettingItem(kSavePasswordManagedTableViewId,
l10n_util::GetNSString(IDS_IOS_SETTING_OFF),
chrome_test_util::SettingsMenuBackButton());
kPasswordsTableViewId);
}
// 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.
......
......@@ -9,8 +9,10 @@
extern NSString* const kAutofillProfileEditTableViewId;
extern NSString* const kAutofillProfileTableViewID;
extern NSString* const kAutofillPaymentMethodsToolbarId;
extern NSString* const kAutofillAddressSwitchViewId;
extern NSString* const kAutofillAddressManagedViewId;
extern NSString* const kAutofillCreditCardTableViewId;
extern NSString* const kAutofillCreditCardSwitchViewId;
extern NSString* const kAutofillCreditCardManagedViewId;
......
......@@ -11,10 +11,16 @@
NSString* const kAutofillProfileEditTableViewId =
@"kAutofillProfileEditTableViewId";
NSString* const kAutofillProfileTableViewID = @"kAutofillProfileTableViewID";
NSString* const kAutofillAddressSwitchViewId = @"kAutofillAddressSwitchViewId";
NSString* const kAutofillAddressManagedViewId =
@"kAutofillAddressManagedViewId";
NSString* const kAutofillCreditCardTableViewId = @"kAutofillTableViewId";
NSString* const kAutofillCreditCardSwitchViewId = @"cardItem_switch";
NSString* const kAutofillCreditCardManagedViewId = @"cardItem_managed";
NSString* const kAutofillCreditCardTableViewId =
@"kAutofillCreditCardTableViewId";
NSString* const kAutofillCreditCardSwitchViewId =
@"kAutofillCreditCardSwitchViewId";
NSString* const kAutofillCreditCardManagedViewId =
@"kAutofillCreditCardManagedViewId";
NSString* const kAutofillPaymentMethodsToolbarId =
@"kAutofillPaymentMethodsToolbarId";
NSString* const kSettingsAddPaymentMethodButtonId =
......
......@@ -110,13 +110,8 @@ id<GREYMatcher> NavigationBarEditButton() {
// Helper to open the settings page for Autofill profiles.
- (void)openAutofillProfilesSettings {
[ChromeEarlGreyUI openSettingsMenu];
id<GREYMatcher> addressesButton =
ButtonWithAccessibilityLabelId(IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE);
[[[EarlGrey selectElementWithMatcher:addressesButton]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)
onElementWithMatcher:grey_allOf(grey_kindOfClassName(@"UITableView"),
grey_sufficientlyVisible(), nil)]
performAction:grey_tap()];
[ChromeEarlGreyUI
tapSettingsMenuButton:chrome_test_util::AddressesAndMoreButton()];
}
// Helper to open the settings page for the Autofill profile with |label|.
......@@ -248,8 +243,10 @@ id<GREYMatcher> NavigationBarEditButton() {
performAction:grey_tap()];
// Check the Autofill profile switch is disabled.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
@"addressItem_switch", YES, NO)]
[[EarlGrey
selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
kAutofillAddressSwitchViewId,
/*is_toggled_on=*/YES, /*is_enabled=*/NO)]
assertWithMatcher:grey_notNil()];
[self exitSettingsMenu];
......@@ -262,8 +259,10 @@ id<GREYMatcher> NavigationBarEditButton() {
[self openAutofillProfilesSettings];
// Toggle the Autofill profiles switch off.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
@"addressItem_switch", YES, YES)]
[[EarlGrey
selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
kAutofillAddressSwitchViewId,
/*is_toggled_on=*/YES, /*is_enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(NO)];
// Expect Autofill profiles to remain visible.
......@@ -271,8 +270,10 @@ id<GREYMatcher> NavigationBarEditButton() {
assertWithMatcher:grey_notNil()];
// Toggle the Autofill profiles switch back on.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
@"addressItem_switch", NO, YES)]
[[EarlGrey
selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
kAutofillAddressSwitchViewId,
/*is_toggled_on=*/NO, /*is_enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(YES)];
// Expect Autofill profiles to remain visible.
......
......@@ -162,7 +162,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
switchItem.text =
l10n_util::GetNSString(IDS_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL);
switchItem.on = [self isAutofillProfileEnabled];
switchItem.accessibilityIdentifier = @"addressItem_switch";
switchItem.accessibilityIdentifier = kAutofillAddressSwitchViewId;
return switchItem;
}
......@@ -175,7 +175,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
managedAddressItem.statusText = l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
managedAddressItem.accessibilityHint =
l10n_util::GetNSString(IDS_IOS_TOGGLE_SETTING_MANAGED_ACCESSIBILITY_HINT);
managedAddressItem.accessibilityIdentifier = @"addressItem_managed";
managedAddressItem.accessibilityIdentifier = kAutofillAddressManagedViewId;
return managedAddressItem;
}
......
......@@ -182,6 +182,9 @@ id<GREYMatcher> SyncSettingsConfirmButton();
// settings menu.
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.
id<GREYMatcher> PaymentMethodsButton();
......
......@@ -231,6 +231,10 @@ id<GREYMatcher> AutofillCreditCardTableView() {
return [ChromeMatchersAppInterface autofillCreditCardTableView];
}
id<GREYMatcher> AddressesAndMoreButton() {
return [ChromeMatchersAppInterface addressesAndMoreButton];
}
id<GREYMatcher> PaymentMethodsButton() {
return [ChromeMatchersAppInterface paymentMethodsButton];
}
......
......@@ -186,6 +186,9 @@
// settings menu.
+ (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.
+ (id<GREYMatcher>)paymentMethodsButton;
......
......@@ -466,6 +466,11 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kSyncSettingsConfirmButtonId);
}
+ (id<GREYMatcher>)addressesAndMoreButton {
return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:(IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE)];
}
+ (id<GREYMatcher>)paymentMethodsButton {
return [ChromeMatchersAppInterface
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