Commit 7b1085b3 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Convert AutofillProfileEditCollectionVC to UITableView

This CL converts the ViewController, keeping the same features.

Bug: 894791
Change-Id: I8cd336a878d42d6a69bed10e3b22c56d842e5c0d
Reviewed-on: https://chromium-review.googlesource.com/c/1345974
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611661}
parent 386c1169
...@@ -20,8 +20,8 @@ source_set("settings") { ...@@ -20,8 +20,8 @@ source_set("settings") {
"autofill_edit_table_view_controller.mm", "autofill_edit_table_view_controller.mm",
"autofill_profile_collection_view_controller.h", "autofill_profile_collection_view_controller.h",
"autofill_profile_collection_view_controller.mm", "autofill_profile_collection_view_controller.mm",
"autofill_profile_edit_collection_view_controller.h", "autofill_profile_edit_table_view_controller.h",
"autofill_profile_edit_collection_view_controller.mm", "autofill_profile_edit_table_view_controller.mm",
"bandwidth_management_table_view_controller.h", "bandwidth_management_table_view_controller.h",
"bandwidth_management_table_view_controller.mm", "bandwidth_management_table_view_controller.mm",
"bar_button_activity_indicator.h", "bar_button_activity_indicator.h",
...@@ -273,7 +273,7 @@ source_set("unit_tests") { ...@@ -273,7 +273,7 @@ source_set("unit_tests") {
"about_chrome_table_view_controller_unittest.mm", "about_chrome_table_view_controller_unittest.mm",
"autofill_credit_card_collection_view_controller_unittest.mm", "autofill_credit_card_collection_view_controller_unittest.mm",
"autofill_profile_collection_view_controller_unittest.mm", "autofill_profile_collection_view_controller_unittest.mm",
"autofill_profile_edit_collection_view_controller_unittest.mm", "autofill_profile_edit_table_view_controller_unittest.mm",
"bandwidth_management_table_view_controller_unittest.mm", "bandwidth_management_table_view_controller_unittest.mm",
"block_popups_table_view_controller_unittest.mm", "block_popups_table_view_controller_unittest.mm",
"clear_browsing_data_collection_view_controller_unittest.mm", "clear_browsing_data_collection_view_controller_unittest.mm",
......
...@@ -31,9 +31,13 @@ ...@@ -31,9 +31,13 @@
} }
_accessoryView = [[AutofillEditAccessoryView alloc] initWithDelegate:self]; _accessoryView = [[AutofillEditAccessoryView alloc] initWithDelegate:self];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setShouldHideDoneButton:YES]; [self setShouldHideDoneButton:YES];
[self updateEditButton]; [self updateEditButton];
return self;
} }
- (void)viewDidAppear:(BOOL)animated { - (void)viewDidAppear:(BOOL)animated {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "ios/chrome/browser/ui/collection_view/cells/collection_view_cell_constants.h" #include "ios/chrome/browser/ui/collection_view/cells/collection_view_cell_constants.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h" #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h" #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/settings/autofill_profile_edit_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/autofill_profile_edit_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/cells/autofill_data_item.h" #import "ios/chrome/browser/ui/settings/cells/autofill_data_item.h"
#import "ios/chrome/browser/ui/settings/cells/legacy/legacy_settings_switch_item.h" #import "ios/chrome/browser/ui/settings/cells/legacy/legacy_settings_switch_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_text_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_text_item.h"
...@@ -319,8 +319,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -319,8 +319,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
const std::vector<autofill::AutofillProfile*> autofillProfiles = const std::vector<autofill::AutofillProfile*> autofillProfiles =
_personalDataManager->GetProfiles(); _personalDataManager->GetProfiles();
AutofillProfileEditCollectionViewController* controller = AutofillProfileEditTableViewController* controller =
[AutofillProfileEditCollectionViewController [AutofillProfileEditTableViewController
controllerWithProfile:*autofillProfiles[indexPath.item] controllerWithProfile:*autofillProfiles[indexPath.item]
personalDataManager:_personalDataManager]; personalDataManager:_personalDataManager];
controller.dispatcher = self.dispatcher; controller.dispatcher = self.dispatcher;
......
...@@ -2,31 +2,32 @@ ...@@ -2,31 +2,32 @@
// 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.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_PROFILE_EDIT_COLLECTION_VIEW_CONTROLLER_H_ #ifndef IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_PROFILE_EDIT_TABLE_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_PROFILE_EDIT_COLLECTION_VIEW_CONTROLLER_H_ #define IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_PROFILE_EDIT_TABLE_VIEW_CONTROLLER_H_
#import "ios/chrome/browser/ui/settings/legacy_autofill_edit_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/autofill_edit_table_view_controller.h"
namespace autofill { namespace autofill {
class AutofillProfile; class AutofillProfile;
class PersonalDataManager; class PersonalDataManager;
} // namespace autofill } // namespace autofill
extern NSString* const kAutofillProfileEditCollectionViewId; extern NSString* const kAutofillProfileEditTableViewId;
// The collection view for the Autofill settings. // The table view for the Autofill profile edit settings.
@interface AutofillProfileEditCollectionViewController @interface AutofillProfileEditTableViewController
: LegacyAutofillEditCollectionViewController : AutofillEditTableViewController
// Creates a controller for |profile| and |dataManager| that cannot be null. // Creates a controller for |profile| and |dataManager| that cannot be null.
+ (instancetype)controllerWithProfile:(const autofill::AutofillProfile&)profile + (instancetype)controllerWithProfile:(const autofill::AutofillProfile&)profile
personalDataManager: personalDataManager:
(autofill::PersonalDataManager*)dataManager; (autofill::PersonalDataManager*)dataManager;
- (instancetype)initWithLayout:(UICollectionViewLayout*)layout - (instancetype)initWithTableViewStyle:(UITableViewStyle)style
style:(CollectionViewControllerStyle)style appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
NS_UNAVAILABLE; NS_UNAVAILABLE;
@end @end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_PROFILE_EDIT_COLLECTION_VIEW_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_PROFILE_EDIT_TABLE_VIEW_CONTROLLER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// 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 "ios/chrome/browser/ui/settings/autofill_profile_edit_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/autofill_profile_edit_table_view_controller.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h"
#import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h"
#import "ios/chrome/browser/ui/autofill/cells/legacy_autofill_edit_item.h" #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#include "ios/chrome/browser/ui/commands/application_commands.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/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kAutofillProfileEditCollectionViewId = NSString* const kAutofillProfileEditTableViewId =
@"kAutofillProfileEditCollectionViewId"; @"kAutofillProfileEditTableViewId";
namespace { namespace {
using ::AutofillTypeFromAutofillUIType; using ::AutofillTypeFromAutofillUIType;
...@@ -73,9 +73,9 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = { ...@@ -73,9 +73,9 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = {
} // namespace } // namespace
@interface AutofillProfileEditCollectionViewController () @interface AutofillProfileEditTableViewController ()
// Initializes a AutofillProfileEditCollectionViewController with |profile| and // Initializes a AutofillProfileEditTableViewController with |profile| and
// |dataManager|. // |dataManager|.
- (instancetype)initWithProfile:(const autofill::AutofillProfile&)profile - (instancetype)initWithProfile:(const autofill::AutofillProfile&)profile
personalDataManager:(autofill::PersonalDataManager*)dataManager personalDataManager:(autofill::PersonalDataManager*)dataManager
...@@ -83,7 +83,7 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = { ...@@ -83,7 +83,7 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = {
@end @end
@implementation AutofillProfileEditCollectionViewController { @implementation AutofillProfileEditTableViewController {
autofill::PersonalDataManager* _personalDataManager; // weak autofill::PersonalDataManager* _personalDataManager; // weak
autofill::AutofillProfile _autofillProfile; autofill::AutofillProfile _autofillProfile;
} }
...@@ -94,19 +94,14 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = { ...@@ -94,19 +94,14 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = {
personalDataManager:(autofill::PersonalDataManager*)dataManager { personalDataManager:(autofill::PersonalDataManager*)dataManager {
DCHECK(dataManager); DCHECK(dataManager);
UICollectionViewLayout* layout = [[MDCCollectionViewFlowLayout alloc] init];
self = self =
[super initWithLayout:layout style:CollectionViewControllerStyleAppBar]; [super initWithTableViewStyle:UITableViewStyleGrouped
appBarStyle:ChromeTableViewControllerStyleWithAppBar];
if (self) { if (self) {
_personalDataManager = dataManager; _personalDataManager = dataManager;
_autofillProfile = profile; _autofillProfile = profile;
[self setCollectionViewAccessibilityIdentifier:
kAutofillProfileEditCollectionViewId];
[self setTitle:l10n_util::GetNSString(IDS_IOS_AUTOFILL_EDIT_ADDRESS)]; [self setTitle:l10n_util::GetNSString(IDS_IOS_AUTOFILL_EDIT_ADDRESS)];
// TODO(crbug.com/764578): -loadModel should not be called from
// initializer. A possible fix is to move this call to -viewDidLoad.
[self loadModel];
} }
return self; return self;
...@@ -118,7 +113,15 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = { ...@@ -118,7 +113,15 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = {
return [[self alloc] initWithProfile:profile personalDataManager:dataManager]; return [[self alloc] initWithProfile:profile personalDataManager:dataManager];
} }
#pragma mark - SettingsRootCollectionViewController - (void)viewDidLoad {
[super viewDidLoad];
self.tableView.allowsSelectionDuringEditing = YES;
self.tableView.accessibilityIdentifier = kAutofillProfileEditTableViewId;
[self loadModel];
}
#pragma mark - SettingsRootTableViewController
- (void)editButtonPressed { - (void)editButtonPressed {
// In the case of server profiles, open the Payments editing page instead. // In the case of server profiles, open the Payments editing page instead.
...@@ -136,8 +139,8 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = { ...@@ -136,8 +139,8 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = {
[super editButtonPressed]; [super editButtonPressed];
if (!self.editor.editing) { if (!self.tableView.editing) {
CollectionViewModel* model = self.collectionViewModel; TableViewModel* model = self.tableViewModel;
NSInteger itemCount = NSInteger itemCount =
[model numberOfItemsInSection: [model numberOfItemsInSection:
[model sectionForSectionIdentifier:SectionIdentifierFields]]; [model sectionForSectionIdentifier:SectionIdentifierFields]];
...@@ -147,11 +150,10 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = { ...@@ -147,11 +150,10 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = {
NSInteger section = NSInteger section =
[model sectionForSectionIdentifier:SectionIdentifierFields]; [model sectionForSectionIdentifier:SectionIdentifierFields];
for (NSInteger itemIndex = 0; itemIndex < itemCount; ++itemIndex) { for (NSInteger itemIndex = 0; itemIndex < itemCount; ++itemIndex) {
NSIndexPath* path = NSIndexPath* path = [NSIndexPath indexPathForItem:itemIndex
[NSIndexPath indexPathForItem:itemIndex inSection:section]; inSection:section];
LegacyAutofillEditItem* item = AutofillEditItem* item = base::mac::ObjCCastStrict<AutofillEditItem>(
base::mac::ObjCCastStrict<LegacyAutofillEditItem>( [model itemAtIndexPath:path]);
[model itemAtIndexPath:path]);
autofill::ServerFieldType serverFieldType = autofill::ServerFieldType serverFieldType =
AutofillTypeFromAutofillUIType(item.autofillUIType); AutofillTypeFromAutofillUIType(item.autofillUIType);
if (item.autofillUIType == AutofillUITypeProfileHomeAddressCountry) { if (item.autofillUIType == AutofillUITypeProfileHomeAddressCountry) {
...@@ -172,26 +174,25 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = { ...@@ -172,26 +174,25 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = {
[self loadModel]; [self loadModel];
// Update the cells. // Update the cells.
[self reconfigureCellsForItems: [self reconfigureCellsForItems:
[self.collectionViewModel [self.tableViewModel
itemsInSectionWithIdentifier:SectionIdentifierFields]]; itemsInSectionWithIdentifier:SectionIdentifierFields]];
} }
- (void)loadModel { - (void)loadModel {
[super loadModel]; [super loadModel];
CollectionViewModel* model = self.collectionViewModel; TableViewModel* model = self.tableViewModel;
std::string locale = GetApplicationContext()->GetApplicationLocale(); std::string locale = GetApplicationContext()->GetApplicationLocale();
[model addSectionWithIdentifier:SectionIdentifierFields]; [model addSectionWithIdentifier:SectionIdentifierFields];
for (size_t i = 0; i < base::size(kFieldsToDisplay); ++i) { for (size_t i = 0; i < base::size(kFieldsToDisplay); ++i) {
const AutofillFieldDisplayInfo& field = kFieldsToDisplay[i]; const AutofillFieldDisplayInfo& field = kFieldsToDisplay[i];
LegacyAutofillEditItem* item = AutofillEditItem* item =
[[LegacyAutofillEditItem alloc] initWithType:ItemTypeField]; [[AutofillEditItem alloc] initWithType:ItemTypeField];
item.cellStyle = CollectionViewCellStyle::kUIKit;
item.textFieldName = l10n_util::GetNSString(field.displayStringID); item.textFieldName = l10n_util::GetNSString(field.displayStringID);
item.textFieldValue = base::SysUTF16ToNSString(_autofillProfile.GetInfo( item.textFieldValue = base::SysUTF16ToNSString(_autofillProfile.GetInfo(
autofill::AutofillType(field.autofillType), locale)); autofill::AutofillType(field.autofillType), locale));
item.autofillUIType = AutofillUITypeFromAutofillType(field.autofillType); item.autofillUIType = AutofillUITypeFromAutofillType(field.autofillType);
item.textFieldEnabled = self.editor.editing; item.textFieldEnabled = self.tableView.editing;
item.autoCapitalizationType = field.autoCapitalizationType; item.autoCapitalizationType = field.autoCapitalizationType;
item.returnKeyType = field.returnKeyType; item.returnKeyType = field.returnKeyType;
item.keyboardType = field.keyboardType; item.keyboardType = field.keyboardType;
...@@ -199,48 +200,37 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = { ...@@ -199,48 +200,37 @@ static const AutofillFieldDisplayInfo kFieldsToDisplay[] = {
} }
} }
#pragma mark - MDCCollectionViewEditingDelegate #pragma mark - UITableViewDataSource
- (BOOL)collectionViewAllowsEditing:(UICollectionView*)collectionView { - (UITableViewCell*)tableView:(UITableView*)tableView
// The collection view needs to allow editing in order to respond to the Edit cellForRowAtIndexPath:(NSIndexPath*)indexPath {
// button. UITableViewCell* cell = [super tableView:tableView
return YES; cellForRowAtIndexPath:indexPath];
}
- (BOOL)collectionView:(UICollectionView*)collectionView cell.selectionStyle = UITableViewCellSelectionStyleNone;
canEditItemAtIndexPath:(NSIndexPath*)indexPath {
// Items in this collection view are not deletable, so should not be seen
// as editable by the collection view.
return NO;
}
#pragma mark - UICollectionViewDataSource AutofillEditCell* textFieldCell =
base::mac::ObjCCastStrict<AutofillEditCell>(cell);
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
cellForItemAtIndexPath:(NSIndexPath*)indexPath {
UICollectionViewCell* cell =
[super collectionView:collectionView cellForItemAtIndexPath:indexPath];
LegacyAutofillEditCell* textFieldCell =
base::mac::ObjCCastStrict<LegacyAutofillEditCell>(cell);
textFieldCell.accessibilityIdentifier = textFieldCell.textLabel.text; textFieldCell.accessibilityIdentifier = textFieldCell.textLabel.text;
textFieldCell.textField.delegate = self; textFieldCell.textField.delegate = self;
return textFieldCell; return textFieldCell;
} }
#pragma mark - UICollectionViewDelegate - (void)tableView:(UITableView*)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
- (BOOL)collectionView:(UICollectionView*)collectionView if (self.tableView.editing) {
shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (self.editor.editing) { AutofillEditCell* textFieldCell =
UICollectionViewCell* cell = base::mac::ObjCCastStrict<AutofillEditCell>(cell);
[self.collectionView cellForItemAtIndexPath:indexPath];
LegacyAutofillEditCell* textFieldCell =
base::mac::ObjCCastStrict<LegacyAutofillEditCell>(cell);
[textFieldCell.textField becomeFirstResponder]; [textFieldCell.textField becomeFirstResponder];
} }
return [super collectionView:collectionView }
shouldSelectItemAtIndexPath:indexPath];
- (BOOL)tableView:(UITableView*)tableView
canEditRowAtIndexPath:(NSIndexPath*)indexPath {
// Items in this collection view are not deletable, so should not be seen
// as editable by the table view.
return NO;
} }
@end @end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// 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 "ios/chrome/browser/ui/settings/autofill_profile_edit_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/autofill_profile_edit_table_view_controller.h"
#include <memory> #include <memory>
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#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/test_chrome_browser_state.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#include "ios/chrome/browser/ui/settings/personal_data_manager_data_changed_observer.h" #include "ios/chrome/browser/ui/settings/personal_data_manager_data_changed_observer.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "ios/web/public/test/test_web_thread_bundle.h" #include "ios/web/public/test/test_web_thread_bundle.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
...@@ -46,9 +46,9 @@ static NSArray* FindTextFieldDescendants(UIView* root) { ...@@ -46,9 +46,9 @@ static NSArray* FindTextFieldDescendants(UIView* root) {
return textFields; return textFields;
} }
class AutofillProfileEditCollectionViewControllerTest : public PlatformTest { class AutofillProfileEditTableViewControllerTest : public PlatformTest {
protected: protected:
AutofillProfileEditCollectionViewControllerTest() { AutofillProfileEditTableViewControllerTest() {
TestChromeBrowserState::Builder test_cbs_builder; TestChromeBrowserState::Builder test_cbs_builder;
chrome_browser_state_ = test_cbs_builder.Build(); chrome_browser_state_ = test_cbs_builder.Build();
chrome_browser_state_->CreateWebDataService(); chrome_browser_state_->CreateWebDataService();
...@@ -70,44 +70,40 @@ class AutofillProfileEditCollectionViewControllerTest : public PlatformTest { ...@@ -70,44 +70,40 @@ class AutofillProfileEditCollectionViewControllerTest : public PlatformTest {
personal_data_manager_->SaveImportedProfile(autofill_profile); personal_data_manager_->SaveImportedProfile(autofill_profile);
observer.Wait(); // Wait for the completion of the asynchronous operation. observer.Wait(); // Wait for the completion of the asynchronous operation.
autofill_profile_edit_controller_ = autofill_profile_edit_controller_ = [AutofillProfileEditTableViewController
[AutofillProfileEditCollectionViewController controllerWithProfile:autofill_profile
controllerWithProfile:autofill_profile personalDataManager:personal_data_manager_];
personalDataManager:personal_data_manager_];
// Load the view to force the loading of the model.
[autofill_profile_edit_controller_ loadViewIfNeeded];
} }
web::TestWebThreadBundle thread_bundle_; web::TestWebThreadBundle thread_bundle_;
std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
autofill::PersonalDataManager* personal_data_manager_; autofill::PersonalDataManager* personal_data_manager_;
AutofillProfileEditCollectionViewController* AutofillProfileEditTableViewController* autofill_profile_edit_controller_;
autofill_profile_edit_controller_;
}; };
// Default test case of no addresses or credit cards. // Default test case of no addresses or credit cards.
TEST_F(AutofillProfileEditCollectionViewControllerTest, TestInitialization) { TEST_F(AutofillProfileEditTableViewControllerTest, TestInitialization) {
CollectionViewModel* model = TableViewModel* model = [autofill_profile_edit_controller_ tableViewModel];
[autofill_profile_edit_controller_ collectionViewModel];
EXPECT_EQ(1, [model numberOfSections]); EXPECT_EQ(1, [model numberOfSections]);
EXPECT_EQ(10, [model numberOfItemsInSection:0]); EXPECT_EQ(10, [model numberOfItemsInSection:0]);
} }
// Adding a single address results in an address section. // Adding a single address results in an address section.
TEST_F(AutofillProfileEditCollectionViewControllerTest, TestOneProfile) { TEST_F(AutofillProfileEditTableViewControllerTest, TestOneProfile) {
CollectionViewModel* model = TableViewModel* model = [autofill_profile_edit_controller_ tableViewModel];
[autofill_profile_edit_controller_ collectionViewModel]; UITableView* tableView = [autofill_profile_edit_controller_ tableView];
UICollectionView* collectionView =
[autofill_profile_edit_controller_ collectionView];
EXPECT_EQ(1, [model numberOfSections]); EXPECT_EQ(1, [model numberOfSections]);
EXPECT_EQ(10, [model numberOfItemsInSection:0]); EXPECT_EQ(10, [model numberOfItemsInSection:0]);
NSIndexPath* path = [NSIndexPath indexPathForRow:0 inSection:0]; NSIndexPath* path = [NSIndexPath indexPathForRow:0 inSection:0];
UIView* cell = UIView* cell = [autofill_profile_edit_controller_ tableView:tableView
[autofill_profile_edit_controller_ collectionView:collectionView cellForRowAtIndexPath:path];
cellForItemAtIndexPath:path];
EXPECT_TRUE([cell isKindOfClass:[MDCCollectionViewCell class]]);
NSArray* textFields = FindTextFieldDescendants(cell); NSArray* textFields = FindTextFieldDescendants(cell);
EXPECT_TRUE([textFields count] > 0); EXPECT_TRUE([textFields count] > 0);
...@@ -117,9 +113,8 @@ TEST_F(AutofillProfileEditCollectionViewControllerTest, TestOneProfile) { ...@@ -117,9 +113,8 @@ TEST_F(AutofillProfileEditCollectionViewControllerTest, TestOneProfile) {
[[field text] isEqualToString:base::SysUTF8ToNSString(kTestFullName)]); [[field text] isEqualToString:base::SysUTF8ToNSString(kTestFullName)]);
path = [NSIndexPath indexPathForRow:2 inSection:0]; path = [NSIndexPath indexPathForRow:2 inSection:0];
cell = [autofill_profile_edit_controller_ collectionView:collectionView cell = [autofill_profile_edit_controller_ tableView:tableView
cellForItemAtIndexPath:path]; cellForRowAtIndexPath:path];
EXPECT_TRUE([cell isKindOfClass:[MDCCollectionViewCell class]]);
textFields = FindTextFieldDescendants(cell); textFields = FindTextFieldDescendants(cell);
EXPECT_TRUE([textFields count] > 0); EXPECT_TRUE([textFields count] > 0);
field = [textFields objectAtIndex:0]; field = [textFields objectAtIndex:0];
......
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