Commit 5226a554 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

[EG2] Convert autofill_profile_settings_egtest

Bug: 987646
Tbr: eugenebut
Change-Id: Id2af6bb88a61567a113b82e33eddb2645a3ee4c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1890039
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711250}
parent ccd149af
......@@ -133,7 +133,15 @@ void ClearPasswordStore() {
// Saves an example profile in the store.
void AddAutofillProfile(autofill::PersonalDataManager* personalDataManager) {
autofill::AutofillProfile profile = autofill::test::GetFullProfile();
// If the test profile is already in the store, adding it will be a no-op.
// In that case, early return.
for (autofill::AutofillProfile* p : personalDataManager->GetProfiles()) {
if (p->Compare(profile) == 0) {
return;
}
}
size_t profileCount = personalDataManager->GetProfiles().size();
personalDataManager->AddProfile(profile);
ConditionBlock conditionBlock = ^bool {
......
......@@ -307,6 +307,7 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/settings",
"//ios/chrome/browser/ui/settings/autofill",
"//ios/chrome/browser/ui/settings/autofill:constants",
"//ios/chrome/test:eg_test_support",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
......
......@@ -13,6 +13,7 @@
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/ui/autofill/card_unmask_prompt_view_bridge.h"
#import "ios/chrome/browser/ui/payments/payment_request_egtest_base.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_constants.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_profile_table_view_controller.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
......
......@@ -26,6 +26,7 @@ source_set("autofill") {
"autofill_profile_table_view_controller.mm",
]
deps = [
":constants",
":feature_flags",
"//components/autofill/core/browser",
"//components/autofill/core/common",
......@@ -58,6 +59,14 @@ source_set("autofill") {
]
}
source_set("constants") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"autofill_constants.h",
"autofill_constants.mm",
]
}
source_set("feature_flags") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
......@@ -107,12 +116,14 @@ source_set("eg_tests") {
]
deps = [
":autofill",
":constants",
":feature_flags",
"//components/autofill/core/browser",
"//components/autofill/core/browser:test_support",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser/autofill",
"//ios/chrome/browser/ui/autofill:test_support",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/testing/earl_grey:earl_grey_support",
......@@ -129,12 +140,16 @@ source_set("eg2_tests") {
testonly = true
sources = [
"autofill_add_credit_card_egtest.mm",
"autofill_profile_settings_egtest.mm",
]
deps = [
":constants",
":feature_flags",
"//base",
"//components/strings:components_strings_grit",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/autofill:eg_test_support+eg2",
"//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",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_AUTOFILL_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_AUTOFILL_CONSTANTS_H_
#import <Foundation/Foundation.h>
extern NSString* const kAutofillProfileEditTableViewId;
extern NSString* const kAutofillProfileTableViewID;
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_AUTOFILL_CONSTANTS_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/settings/autofill/autofill_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
NSString* const kAutofillProfileEditTableViewId =
@"kAutofillProfileEditTableViewId";
NSString* const kAutofillProfileTableViewID = @"kAutofillProfileTableViewID";
......@@ -12,8 +12,6 @@ class AutofillProfile;
class PersonalDataManager;
} // namespace autofill
extern NSString* const kAutofillProfileEditTableViewId;
// The table view for the Autofill profile edit settings.
@interface AutofillProfileEditTableViewController
: AutofillEditTableViewController
......
......@@ -18,6 +18,7 @@
#import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h"
#include "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_constants.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -28,8 +29,6 @@
#error "This file requires ARC support."
#endif
NSString* const kAutofillProfileEditTableViewId =
@"kAutofillProfileEditTableViewId";
namespace {
using ::AutofillTypeFromAutofillUIType;
......
......@@ -2,24 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h>
#include "base/ios/ios_util.h"
#import "base/test/ios/wait_util.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_profile_edit_table_view_controller.h"
#import "ios/chrome/browser/ui/autofill/autofill_app_interface.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_constants.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_earl_grey.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_test_case.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -98,43 +94,18 @@ id<GREYMatcher> NavigationBarEditButton() {
@interface AutofillProfileSettingsTestCase : ChromeTestCase
@end
@implementation AutofillProfileSettingsTestCase {
// The PersonalDataManager instance for the current browser state.
autofill::PersonalDataManager* _personalDataManager;
}
@implementation AutofillProfileSettingsTestCase
- (void)setUp {
[super setUp];
_personalDataManager =
autofill::PersonalDataManagerFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
_personalDataManager->SetSyncingForTest(true);
[AutofillAppInterface clearProfilesStore];
}
- (void)tearDown {
// Clear existing profiles.
for (const auto* profile : _personalDataManager->GetProfiles()) {
_personalDataManager->RemoveByGUID(profile->guid());
}
[AutofillAppInterface clearProfilesStore];
[super tearDown];
}
- (autofill::AutofillProfile)addAutofillProfile {
autofill::AutofillProfile profile = autofill::test::GetFullProfile();
size_t profileCount = _personalDataManager->GetProfiles().size();
_personalDataManager->AddProfile(profile);
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForActionTimeout,
^bool() {
return profileCount <
_personalDataManager->GetProfiles().size();
}),
@"Failed to add profile.");
return profile;
}
// Helper to open the settings page for Autofill profiles.
- (void)openAutofillProfilesSettings {
[ChromeEarlGreyUI openSettingsMenu];
......@@ -142,7 +113,7 @@ id<GREYMatcher> NavigationBarEditButton() {
ButtonWithAccessibilityLabelId(IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE);
[[[EarlGrey selectElementWithMatcher:addressesButton]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)
onElementWithMatcher:grey_kindOfClass([UITableView class])]
onElementWithMatcher:grey_kindOfClassName(@"UITableView")]
performAction:grey_tap()];
}
......@@ -167,7 +138,7 @@ id<GREYMatcher> NavigationBarEditButton() {
// Test that the page for viewing Autofill profile details is as expected.
// TODO(crbug.com/922117): Reenable test.
- (void)FLAKY_testAutofillProfileViewPage {
autofill::AutofillProfile profile = [self addAutofillProfile];
[AutofillAppInterface saveExampleProfile];
[self openEditProfile:kProfileLabel];
// Check that all fields and values match the expectations.
......@@ -199,7 +170,8 @@ id<GREYMatcher> NavigationBarEditButton() {
if (base::ios::IsRunningOnOrLater(12, 2, 0)) {
EARL_GREY_TEST_DISABLED(@"Disabled on iOS 12,2.");
}
autofill::AutofillProfile profile = [self addAutofillProfile];
[AutofillAppInterface saveExampleProfile];
[self openEditProfile:kProfileLabel];
// Keep editing the Country field and verify that validation works.
......@@ -209,8 +181,11 @@ id<GREYMatcher> NavigationBarEditButton() {
performAction:grey_tap()];
// Replace the text field with the user-version of the country.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID(
IDS_IOS_AUTOFILL_COUNTRY))]
[[EarlGrey
selectElementWithMatcher:grey_allOf(
grey_accessibilityID(GetTextFieldForID(
IDS_IOS_AUTOFILL_COUNTRY)),
grey_kindOfClassName(@"UITextField"), nil)]
performAction:grey_replaceText(expectation.user_typed_country)];
// Switch off edit mode.
......@@ -236,7 +211,7 @@ id<GREYMatcher> NavigationBarEditButton() {
// Test that the page for viewing Autofill profile details is accessible.
- (void)testAccessibilityOnAutofillProfileViewPage {
autofill::AutofillProfile profile = [self addAutofillProfile];
[AutofillAppInterface saveExampleProfile];
[self openEditProfile:kProfileLabel];
[ChromeEarlGrey verifyAccessibilityForCurrentScreen];
......@@ -250,7 +225,7 @@ id<GREYMatcher> NavigationBarEditButton() {
// Test that the page for editing Autofill profile details is accessible.
- (void)testAccessibilityOnAutofillProfileEditPage {
autofill::AutofillProfile profile = [self addAutofillProfile];
[AutofillAppInterface saveExampleProfile];
[self openEditProfile:kProfileLabel];
// Switch on edit mode.
......@@ -268,7 +243,7 @@ id<GREYMatcher> NavigationBarEditButton() {
// Checks that the Autofill profiles list view is in edit mode and the Autofill
// profiles switch is disabled.
- (void)testListViewEditMode {
autofill::AutofillProfile profile = [self addAutofillProfile];
[AutofillAppInterface saveExampleProfile];
[self openAutofillProfilesSettings];
......@@ -287,7 +262,7 @@ id<GREYMatcher> NavigationBarEditButton() {
// Checks that the Autofill profile switch can be toggled on/off and the list of
// Autofill profiles is not affected by it.
- (void)testToggleAutofillProfileSwitch {
autofill::AutofillProfile profile = [self addAutofillProfile];
[AutofillAppInterface saveExampleProfile];
[self openAutofillProfilesSettings];
// Toggle the Autofill profiles switch off.
......
......@@ -11,8 +11,6 @@ namespace ios {
class ChromeBrowserState;
} // namespace ios
extern NSString* const kAutofillProfileTableViewID;
// The TableView for the Autofill settings.
@interface AutofillProfileTableViewController : SettingsRootTableViewController
......
......@@ -15,6 +15,7 @@
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_constants.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_profile_edit_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/cells/autofill_data_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_cell.h"
......@@ -34,8 +35,6 @@
#error "This file requires ARC support."
#endif
NSString* const kAutofillProfileTableViewID = @"kAutofillProfileTableViewID";
namespace {
typedef NS_ENUM(NSInteger, SectionIdentifier) {
......
......@@ -261,6 +261,7 @@ source_set("test_support") {
"//ios/chrome/browser/ui/safe_mode:test_support",
"//ios/chrome/browser/ui/settings:settings",
"//ios/chrome/browser/ui/settings/autofill",
"//ios/chrome/browser/ui/settings/autofill:constants",
"//ios/chrome/browser/ui/settings/autofill:feature_flags",
"//ios/chrome/browser/ui/settings/cells",
"//ios/chrome/browser/ui/settings/clear_browsing_data",
......@@ -390,6 +391,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/settings:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings:settings",
"//ios/chrome/browser/ui/settings/autofill",
"//ios/chrome/browser/ui/settings/autofill:constants",
"//ios/chrome/browser/ui/settings/autofill:feature_flags",
"//ios/chrome/browser/ui/settings/cells",
"//ios/chrome/browser/ui/settings/clear_browsing_data",
......
......@@ -32,6 +32,7 @@
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_constants.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_add_credit_card_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_constants.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_profile_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/cells/clear_browsing_data_constants.h"
......
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