Commit 17f29310 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[ios] Add EG test to save password settings UI

1. Encapsulated the test logic of checking click action of
TableViewInfoButtonItem.
2. Added EG test to save password settings UI.
3. Added the accessibility IDs of save password switch item and managed
item to constants file.

Bug: 1131052
Change-Id: Ice93cde0f2db4917d66293188faa063e16869e08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436690
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812264}
parent e29a5552
......@@ -171,12 +171,14 @@ source_set("eg2_tests") {
"//components/policy:generated",
"//components/policy/core/common:common_constants",
"//components/strings",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser:pref_names",
"//ios/chrome/browser:utils",
"//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/elements:constants",
"//ios/chrome/browser/ui/settings/password:password_constants",
"//ios/chrome/browser/ui/table_view/cells:cells_constants",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
......
......@@ -15,8 +15,10 @@
#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/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"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#include "ios/chrome/grit/ios_strings.h"
#include "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_matchers.h"
......@@ -97,6 +99,30 @@ id<GREYMatcher> ToolsMenuTranslateButton() {
grey_interactable(), nil);
}
// 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)]
assertWithMatcher:grey_sufficientlyVisible()];
// Click the info button.
[[EarlGrey
selectElementWithMatcher:grey_accessibilityValue(accessibilityValue)]
performAction:grey_tap()];
// 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()];
// Check if the contextual bubble is hidden.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kEnterpriseInfoBubbleViewId)]
assertWithMatcher:grey_notVisible()];
}
} // namespace
// Test case to verify that enterprise policies are set and respected.
......@@ -133,25 +159,13 @@ id<GREYMatcher> ToolsMenuTranslateButton() {
[ChromeEarlGrey loadURL:GURL("chrome://policy")];
[EarlGrey dismissKeyboardWithError:nil];
// Open settings menu and check if the settings UI is a managed UI.
// Open settings menu.
[ChromeEarlGreyUI openSettingsMenu];
// Click on the info button of the managed item.
[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:chrome_test_util::SettingsDoneButton()]
performAction:grey_tap()];
// Check if the contextual bubble is hidden.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kEnterpriseInfoBubbleViewId)]
assertWithMatcher:grey_notVisible()];
VerifyManagedSettingItem(
kSettingsManagedSearchEngineCellId,
l10n_util::GetNSString(IDS_IOS_SEARCH_ENGINE_SETTING_DISABLED_STATUS),
chrome_test_util::SettingsDoneButton());
}
// Tests for the PasswordManagerEnabled policy.
......@@ -160,6 +174,27 @@ id<GREYMatcher> ToolsMenuTranslateButton() {
password_manager::prefs::kCredentialsEnableService);
}
// Tests for the PasswordManagerEnabled policy Settings UI.
- (void)testPasswordManagerEnabledSettingsUI {
// Force the preference off via policy.
SetPolicy(false, policy::key::kPasswordManagerEnabled);
GREYAssertFalse(
[ChromeEarlGrey
userBooleanPref:password_manager::prefs::kCredentialsEnableService],
@"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()];
VerifyManagedSettingItem(kSavePasswordManagedTableViewId,
l10n_util::GetNSString(IDS_IOS_SETTING_OFF),
chrome_test_util::SettingsMenuBackButton());
}
// Tests for the SavingBrowserHistoryDisabled policy.
- (void)testSavingBrowserHistoryDisabled {
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
......
......@@ -724,8 +724,8 @@ void TapEdit() {
// Check that the "Save Passwords" switch is disabled.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
@"savePasswordsItem_switch", YES, NO)]
assertWithMatcher:grey_notNil()];
kSavePasswordSwitchTableViewId, YES,
NO)] assertWithMatcher:grey_notNil()];
[GetInteractionForPasswordEntry(@"example.com, concrete username")
performAction:grey_tap()];
......@@ -1122,14 +1122,14 @@ void TapEdit() {
for (BOOL expected_state : kExpectedState) {
// Toggle the switch. It is located near the top, so if not interactable,
// try scrolling up.
[GetInteractionForListItem(chrome_test_util::SettingsSwitchCell(
@"savePasswordsItem_switch", expected_state),
kGREYDirectionUp)
performAction:TurnSettingsSwitchOn(!expected_state)];
[GetInteractionForListItem(
chrome_test_util::SettingsSwitchCell(kSavePasswordSwitchTableViewId,
expected_state),
kGREYDirectionUp) performAction:TurnSettingsSwitchOn(!expected_state)];
// Check that the switch has been modified.
[GetInteractionForListItem(
chrome_test_util::SettingsSwitchCell(@"savePasswordsItem_switch",
chrome_test_util::SettingsSwitchCell(kSavePasswordSwitchTableViewId,
!expected_state),
kGREYDirectionUp) assertWithMatcher:grey_sufficientlyVisible()];
......@@ -1156,7 +1156,7 @@ void TapEdit() {
constexpr BOOL kExpectedState[] = {YES, NO};
for (BOOL expected_initial_state : kExpectedState) {
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
@"savePasswordsItem_switch",
kSavePasswordSwitchTableViewId,
expected_initial_state)]
performAction:TurnSettingsSwitchOn(!expected_initial_state)];
const bool expected_final_state = !expected_initial_state;
......@@ -1458,7 +1458,7 @@ void TapEdit() {
// Check that the "Save Passwords" switch is hidden.
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
@"savePasswordsItem_switch", YES)]
kSavePasswordSwitchTableViewId, YES)]
assertWithMatcher:grey_nil()];
[GetInteractionForPasswordEntry(@"example11.com, user1")
......
......@@ -17,4 +17,8 @@ extern NSString* const kPasswordsScrimViewId;
extern NSString* const kPasswordDetailsTableViewId;
extern NSString* const kPasswordDetailsDeletionAlertViewId;
// The accessibility identifier of the save password item.
extern NSString* const kSavePasswordSwitchTableViewId;
extern NSString* const kSavePasswordManagedTableViewId;
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_PASSWORD_PASSWORDS_TABLE_VIEW_CONSTANTS_H_
......@@ -16,3 +16,8 @@ NSString* const kPasswordsScrimViewId = @"PasswordsScrimViewId";
NSString* const kPasswordDetailsTableViewId = @"PasswordDetailsTableViewId";
NSString* const kPasswordDetailsDeletionAlertViewId =
@"PasswordDetailsDeletionAlertViewId";
NSString* const kSavePasswordSwitchTableViewId =
@"kSavePasswordSwitchTableViewId";
NSString* const kSavePasswordManagedTableViewId =
@"kSavePasswordSwitchTableViewId";
......@@ -524,7 +524,7 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
[[SettingsSwitchItem alloc] initWithType:ItemTypeSavePasswordsSwitch];
savePasswordsItem.text = l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS);
savePasswordsItem.on = [_passwordManagerEnabled value];
savePasswordsItem.accessibilityIdentifier = @"savePasswordsItem_switch";
savePasswordsItem.accessibilityIdentifier = kSavePasswordSwitchTableViewId;
return savePasswordsItem;
}
......@@ -540,7 +540,7 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
managedSavePasswordItem.accessibilityHint =
l10n_util::GetNSString(IDS_IOS_TOGGLE_SETTING_MANAGED_ACCESSIBILITY_HINT);
managedSavePasswordItem.accessibilityIdentifier =
@"savePasswordsItem_managed";
kSavePasswordManagedTableViewId;
return managedSavePasswordItem;
}
......
......@@ -196,6 +196,7 @@ source_set("eg2_tests") {
"//ios/chrome/app/strings",
"//ios/chrome/browser:pref_names",
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/settings/password:password_constants",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
......
......@@ -6,6 +6,7 @@
#import <UIKit/UIKit.h>
#include "ios/chrome/browser/pref_names.h"
#import "ios/chrome/browser/ui/settings/password/passwords_table_view_constants.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -65,10 +66,10 @@
// Toggle the passwords switch off and on.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
@"savePasswordsItem_switch")]
kSavePasswordSwitchTableViewId)]
performAction:chrome_test_util::TurnSettingsSwitchOn(NO)];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
@"savePasswordsItem_switch")]
kSavePasswordSwitchTableViewId)]
performAction:chrome_test_util::TurnSettingsSwitchOn(YES)];
// Close the settings menu.
......
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