Commit 38797b5c authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Convert ImportData to UITableView

This CL converts ImportDataCollectionViewController to use UITableView
instead of MDCCollectionViewController.

Bug: 894791
Change-Id: I38a99ae849ef2b30d90820b197f4ba56edadabba
Reviewed-on: https://chromium-review.googlesource.com/c/1352156
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612205}
parent 1854accc
......@@ -30,7 +30,7 @@
#include "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/authentication/authentication_ui_util.h"
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h"
#import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -396,7 +396,7 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10;
#pragma mark - ImportDataControllerDelegate
- (void)didChooseClearDataPolicy:(ImportDataCollectionViewController*)controller
- (void)didChooseClearDataPolicy:(ImportDataTableViewController*)controller
shouldClearData:(ShouldClearData)shouldClearData {
DCHECK_NE(SHOULD_CLEAR_DATA_USER_CHOICE, shouldClearData);
if (shouldClearData == SHOULD_CLEAR_DATA_CLEAR_DATA) {
......
......@@ -58,8 +58,8 @@ source_set("settings") {
"google_services_settings_view_controller_model_delegate.h",
"handoff_table_view_controller.h",
"handoff_table_view_controller.mm",
"import_data_collection_view_controller.h",
"import_data_collection_view_controller.mm",
"import_data_table_view_controller.h",
"import_data_table_view_controller.mm",
"legacy_autofill_edit_collection_view_controller+protected.h",
"legacy_autofill_edit_collection_view_controller.h",
"legacy_autofill_edit_collection_view_controller.mm",
......@@ -281,7 +281,7 @@ source_set("unit_tests") {
"compose_email_handler_collection_view_controller_unittest.mm",
"content_settings_table_view_controller_unittest.mm",
"dataplan_usage_table_view_controller_unittest.mm",
"import_data_collection_view_controller_unittest.mm",
"import_data_table_view_controller_unittest.mm",
"password_details_table_view_controller_unittest.mm",
"password_exporter_unittest.mm",
"privacy_table_view_controller_unittest.mm",
......
......@@ -7,15 +7,14 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
// ImportDataMultilineDetailItem is a model class that uses
// ImportDataMultilineDetailCell.
@interface ImportDataMultilineDetailItem : CollectionViewItem
@interface ImportDataMultilineDetailItem : TableViewItem
// The accessory type to display on the trailing edge of the cell.
@property(nonatomic) MDCCollectionViewCellAccessoryType accessoryType;
@property(nonatomic) UITableViewCellAccessoryType accessoryType;
// The main text string.
@property(nonatomic, copy) NSString* text;
......@@ -25,12 +24,12 @@
@end
// ImportDataMultilineDetailCell implements an MDCCollectionViewCell
// ImportDataMultilineDetailCell implements an UITableViewCell
// subclass containing two text labels: a "main" label and a "detail" label.
// The two labels are laid out on top of each other. The detail text can span
// multiple lines.
// This is to be used with a ImportDataMultilineDetailItem.
@interface ImportDataMultilineDetailCell : MDCCollectionViewCell
@interface ImportDataMultilineDetailCell : UITableViewCell
// UILabels corresponding to |text| and |detailText| from the item.
@property(nonatomic, readonly, strong) UILabel* textLabel;
......
......@@ -4,25 +4,15 @@
#import "ios/chrome/browser/ui/settings/cells/import_data_multiline_detail_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#include "ios/chrome/browser/ui/collection_view/cells/collection_view_cell_constants.h"
#import "ios/chrome/browser/ui/settings/cells/settings_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Padding used on the leading and trailing edges of the cell.
const CGFloat kHorizontalPadding = 16;
// Padding used on the top and bottom edges of the cell.
const CGFloat kVerticalPadding = 16;
} // namespace
@implementation ImportDataMultilineDetailItem
@synthesize accessoryType = _accessoryType;
......@@ -39,9 +29,10 @@ const CGFloat kVerticalPadding = 16;
#pragma mark CollectionViewItem
- (void)configureCell:(ImportDataMultilineDetailCell*)cell {
[super configureCell:cell];
[cell cr_setAccessoryType:self.accessoryType];
- (void)configureCell:(ImportDataMultilineDetailCell*)cell
withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:cell withStyler:styler];
cell.accessoryType = self.accessoryType;
cell.textLabel.text = self.text;
cell.detailTextLabel.text = self.detailText;
}
......@@ -53,34 +44,37 @@ const CGFloat kVerticalPadding = 16;
@synthesize textLabel = _textLabel;
@synthesize detailTextLabel = _detailTextLabel;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.isAccessibilityElement = YES;
UIView* contentView = self.contentView;
_textLabel = [[UILabel alloc] init];
_textLabel.translatesAutoresizingMaskIntoConstraints = NO;
_textLabel.font = [UIFont systemFontOfSize:kUIKitMainFontSize];
_textLabel.textColor = UIColorFromRGB(kUIKitMainTextColor);
_textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
_textLabel.adjustsFontForContentSizeCategory = YES;
_textLabel.textColor = UIColor.blackColor;
[contentView addSubview:_textLabel];
_detailTextLabel = [[UILabel alloc] init];
_detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO;
_detailTextLabel.numberOfLines = 0;
_detailTextLabel.font =
[UIFont systemFontOfSize:kUIKitMultilineDetailFontSize];
_detailTextLabel.textColor = UIColorFromRGB(kUIKitMultilineDetailTextColor);
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
_detailTextLabel.adjustsFontForContentSizeCategory = YES;
_detailTextLabel.textColor = UIColorFromRGB(kSettingsCellsDetailTextColor);
[contentView addSubview:_detailTextLabel];
// Set up the constraints.
[NSLayoutConstraint activateConstraints:@[
[_textLabel.leadingAnchor
constraintEqualToAnchor:contentView.leadingAnchor
constant:kHorizontalPadding],
constant:kTableViewHorizontalSpacing],
[_textLabel.trailingAnchor
constraintEqualToAnchor:contentView.trailingAnchor
constant:-kHorizontalPadding],
constant:-kTableViewHorizontalSpacing],
[_detailTextLabel.leadingAnchor
constraintEqualToAnchor:_textLabel.leadingAnchor],
[_detailTextLabel.trailingAnchor
......@@ -89,41 +83,11 @@ const CGFloat kVerticalPadding = 16;
constraintEqualToAnchor:_detailTextLabel.topAnchor],
]];
AddOptionalVerticalPadding(contentView, _textLabel, _detailTextLabel,
kVerticalPadding);
kTableViewLargeVerticalSpacing);
}
return self;
}
- (void)layoutSubviews {
// When the accessory type is None, the content view of the cell (and thus)
// the labels inside it span larger than when there is a Checkmark accessory
// type. That means that toggling the accessory type can induce a rewrapping
// of the detail text, which is not visually pleasing. To alleviate that
// issue, always lay out the cell as if there was a Checkmark accessory type.
//
// Force the accessory type to Checkmark for the duration of layout.
MDCCollectionViewCellAccessoryType realAccessoryType = self.accessoryType;
self.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
// Implement -layoutSubviews as per instructions in documentation for
// +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:].
[super layoutSubviews];
// Adjust the text label preferredMaxLayoutWidth when the parent's width
// changes, for instance on screen rotation.
CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds);
self.textLabel.preferredMaxLayoutWidth = parentWidth - 2 * kHorizontalPadding;
self.detailTextLabel.preferredMaxLayoutWidth =
parentWidth - 2 * kHorizontalPadding;
// Re-layout with the new preferred width to allow the label to adjust its
// height.
[super layoutSubviews];
// Restore the real accessory type at the end of the layout.
self.accessoryType = realAccessoryType;
}
#pragma mark Accessibility
- (NSString*)accessibilityLabel {
......
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/settings/cells/import_data_multiline_detail_item.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
......@@ -38,7 +39,7 @@ TEST_F(ImportDataMultilineDetailItemTest, ConfigureCell) {
EXPECT_FALSE(multilineDetailCell.textLabel.text);
EXPECT_FALSE(multilineDetailCell.detailTextLabel.text);
[item configureCell:cell];
[item configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]];
EXPECT_NSEQ(text, multilineDetailCell.textLabel.text);
EXPECT_NSEQ(detailText, multilineDetailCell.detailTextLabel.text);
}
......
......@@ -2,13 +2,13 @@
// 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_IMPORT_DATA_COLLECTION_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_IMPORT_DATA_COLLECTION_VIEW_CONTROLLER_H_
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_IMPORT_DATA_TABLE_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_IMPORT_DATA_TABLE_VIEW_CONTROLLER_H_
#import "ios/chrome/browser/signin/constants.h"
#import "ios/chrome/browser/ui/settings/settings_root_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h"
@class ImportDataCollectionViewController;
@class ImportDataTableViewController;
// The accessibility identifier of the Import Data cell.
extern NSString* const kImportDataImportCellId;
......@@ -17,19 +17,18 @@ extern NSString* const kImportDataImportCellId;
extern NSString* const kImportDataKeepSeparateCellId;
// Notifies of the user action on the corresponding
// ImportDataCollectionViewController.
// ImportDataTableViewController.
@protocol ImportDataControllerDelegate
// Indicates that the user chose the clear data policy to be |shouldClearData|
// when presented with |controller|.
- (void)didChooseClearDataPolicy:(ImportDataCollectionViewController*)controller
- (void)didChooseClearDataPolicy:(ImportDataTableViewController*)controller
shouldClearData:(ShouldClearData)shouldClearData;
@end
// Collection View that handles how to import data during account switching.
@interface ImportDataCollectionViewController
: SettingsRootCollectionViewController
// Table View that handles how to import data during account switching.
@interface ImportDataTableViewController : SettingsRootTableViewController
// |fromEmail| is the email of the previously signed in account.
// |toIdentity| is the email of the account switched to.
......@@ -41,10 +40,11 @@ extern NSString* const kImportDataKeepSeparateCellId;
toEmail:(NSString*)toEmail
isSignedIn:(BOOL)isSignedIn NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithLayout:(UICollectionViewLayout*)layout
style:(CollectionViewControllerStyle)style
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_IMPORT_DATA_COLLECTION_VIEW_CONTROLLER_H_
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_IMPORT_DATA_TABLE_VIEW_CONTROLLER_H_
......@@ -2,20 +2,16 @@
// 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/import_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h"
#include "base/logging.h"
#import "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/settings/cells/card_multiline_item.h"
#import "ios/chrome/browser/ui/settings/cells/import_data_multiline_detail_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
#import "ios/third_party/material_components_ios/src/components/Collections/src/MaterialCollections.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -43,7 +39,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
} // namespace
@implementation ImportDataCollectionViewController {
@implementation ImportDataTableViewController {
__weak id<ImportDataControllerDelegate> _delegate;
NSString* _fromEmail;
NSString* _toEmail;
......@@ -53,7 +49,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ImportDataMultilineDetailItem* _keepDataSeparateItem;
}
#pragma mark Initialization
#pragma mark - Initialization
- (instancetype)initWithDelegate:(id<ImportDataControllerDelegate>)delegate
fromEmail:(NSString*)fromEmail
......@@ -61,9 +57,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
isSignedIn:(BOOL)isSignedIn {
DCHECK(fromEmail);
DCHECK(toEmail);
UICollectionViewLayout* layout = [[MDCCollectionViewFlowLayout alloc] init];
self =
[super initWithLayout:layout style:CollectionViewControllerStyleAppBar];
[super initWithTableViewStyle:UITableViewStyleGrouped
appBarStyle:ChromeTableViewControllerStyleWithAppBar];
if (self) {
_delegate = delegate;
_fromEmail = [fromEmail copy];
......@@ -76,24 +72,29 @@ typedef NS_ENUM(NSInteger, ItemType) {
? l10n_util::GetNSString(IDS_IOS_OPTIONS_IMPORT_DATA_TITLE_SWITCH)
: l10n_util::GetNSString(IDS_IOS_OPTIONS_IMPORT_DATA_TITLE_SIGNIN);
[self setShouldHideDoneButton:YES];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setShouldHideDoneButton:YES];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:l10n_util::GetNSString(
IDS_IOS_OPTIONS_IMPORT_DATA_CONTINUE_BUTTON)
style:UIBarButtonItemStyleDone
target:self
action:@selector(didTapContinue)];
// 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;
}
#pragma mark SettingsRootCollectionViewController
#pragma mark - SettingsRootTableViewController
- (void)loadModel {
[super loadModel];
CollectionViewModel* model = self.collectionViewModel;
TableViewModel* model = self.tableViewModel;
[model addSectionWithIdentifier:SectionIdentifierDisclaimer];
[model addItem:[self descriptionItem]
......@@ -115,13 +116,14 @@ typedef NS_ENUM(NSInteger, ItemType) {
}
}
#pragma mark Items
#pragma mark - Items
- (CollectionViewItem*)descriptionItem {
CardMultilineItem* item =
[[CardMultilineItem alloc] initWithType:ItemTypeFooter];
- (TableViewItem*)descriptionItem {
TableViewTextItem* item =
[[TableViewTextItem alloc] initWithType:ItemTypeFooter];
item.text = l10n_util::GetNSStringF(IDS_IOS_OPTIONS_IMPORT_DATA_HEADER,
base::SysNSStringToUTF16(_fromEmail));
item.textColor = UIColor.blackColor;
return item;
}
......@@ -132,8 +134,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
item.detailText =
l10n_util::GetNSStringF(IDS_IOS_OPTIONS_IMPORT_DATA_IMPORT_SUBTITLE,
base::SysNSStringToUTF16(_toEmail));
item.accessoryType = _isSignedIn ? MDCCollectionViewCellAccessoryNone
: MDCCollectionViewCellAccessoryCheckmark;
item.accessoryType = _isSignedIn ? UITableViewCellAccessoryNone
: UITableViewCellAccessoryCheckmark;
item.accessibilityIdentifier = kImportDataImportCellId;
return item;
}
......@@ -150,54 +152,52 @@ typedef NS_ENUM(NSInteger, ItemType) {
item.detailText = l10n_util::GetNSString(
IDS_IOS_OPTIONS_IMPORT_DATA_KEEP_SUBTITLE_SIGNIN);
}
item.accessoryType = _isSignedIn ? MDCCollectionViewCellAccessoryCheckmark
: MDCCollectionViewCellAccessoryNone;
item.accessoryType = _isSignedIn ? UITableViewCellAccessoryCheckmark
: UITableViewCellAccessoryNone;
item.accessibilityIdentifier = kImportDataKeepSeparateCellId;
return item;
}
#pragma mark MDCCollectionViewStylingDelegate
#pragma mark - UITableViewDelegate
- (CGFloat)collectionView:(UICollectionView*)collectionView
cellHeightAtIndexPath:(NSIndexPath*)indexPath {
CollectionViewItem* item =
[self.collectionViewModel itemAtIndexPath:indexPath];
CGFloat cardWidth = CGRectGetWidth(collectionView.bounds) -
2 * MDCCollectionViewCellStyleCardSectionInset;
return
[MDCCollectionViewCell cr_preferredHeightForWidth:cardWidth forItem:item];
- (BOOL)tableView:(UITableView*)tableView
shouldHighlightRowAtIndexPath:(NSIndexPath*)indexPath {
NSInteger sectionIdentifier =
[self.tableViewModel sectionIdentifierForSection:indexPath.section];
if (sectionIdentifier != SectionIdentifierOptions)
return NO;
return YES;
}
#pragma mark UICollectionViewDelegate
- (void)collectionView:(UICollectionView*)collectionView
didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
[super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
- (void)tableView:(UITableView*)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
NSInteger sectionIdentifier =
[self.collectionViewModel sectionIdentifierForSection:indexPath.section];
[self.tableViewModel sectionIdentifierForSection:indexPath.section];
if (sectionIdentifier == SectionIdentifierOptions) {
// Store the user choice.
NSInteger itemType =
[self.collectionViewModel itemTypeForIndexPath:indexPath];
NSInteger itemType = [self.tableViewModel itemTypeForIndexPath:indexPath];
_shouldClearData = (itemType == ItemTypeOptionImportData)
? SHOULD_CLEAR_DATA_MERGE_DATA
: SHOULD_CLEAR_DATA_CLEAR_DATA;
[self updateUI];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark Private methods
#pragma mark - Private
// Updates the UI based on the value of |_shouldClearData|.
- (void)updateUI {
BOOL importDataSelected = _shouldClearData == SHOULD_CLEAR_DATA_MERGE_DATA;
_importDataItem.accessoryType = importDataSelected
? MDCCollectionViewCellAccessoryCheckmark
: MDCCollectionViewCellAccessoryNone;
_keepDataSeparateItem.accessoryType =
importDataSelected ? MDCCollectionViewCellAccessoryNone
: MDCCollectionViewCellAccessoryCheckmark;
? UITableViewCellAccessoryCheckmark
: UITableViewCellAccessoryNone;
_keepDataSeparateItem.accessoryType = importDataSelected
? UITableViewCellAccessoryNone
: UITableViewCellAccessoryCheckmark;
[self reconfigureCellsForItems:@[ _importDataItem, _keepDataSeparateItem ]];
}
......
......@@ -2,14 +2,14 @@
// 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/import_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/settings/cells/card_multiline_item.h"
#import "ios/chrome/browser/ui/settings/cells/import_data_multiline_detail_item.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller_test.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "ios/chrome/grit/ios_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
......@@ -21,7 +21,7 @@
#endif
@interface ImportDataControllerTestDelegate
: NSObject<ImportDataControllerDelegate>
: NSObject <ImportDataControllerDelegate>
@property(nonatomic, readonly) BOOL didChooseClearDataPolicyCalled;
@property(nonatomic, readonly) ShouldClearData shouldClearData;
@end
......@@ -31,7 +31,7 @@
@synthesize didChooseClearDataPolicyCalled = _didChooseClearDataPolicyCalled;
@synthesize shouldClearData = _shouldClearData;
- (void)didChooseClearDataPolicy:(ImportDataCollectionViewController*)controller
- (void)didChooseClearDataPolicy:(ImportDataTableViewController*)controller
shouldClearData:(ShouldClearData)shouldClearData {
_didChooseClearDataPolicyCalled = YES;
_shouldClearData = shouldClearData;
......@@ -41,20 +41,19 @@
namespace {
class ImportDataCollectionViewControllerTest
: public CollectionViewControllerTest {
class ImportDataTableViewControllerTest : public ChromeTableViewControllerTest {
public:
ImportDataControllerTestDelegate* delegate() { return delegate_; }
protected:
void SetUp() override {
CollectionViewControllerTest::SetUp();
ChromeTableViewControllerTest::SetUp();
is_signed_in_ = true;
}
CollectionViewController* InstantiateController() override {
ChromeTableViewController* InstantiateController() override {
delegate_ = [[ImportDataControllerTestDelegate alloc] init];
return [[ImportDataCollectionViewController alloc]
return [[ImportDataTableViewController alloc]
initWithDelegate:delegate_
fromEmail:@"fromEmail@gmail.com"
toEmail:@"toEmail@gmail.com"
......@@ -67,91 +66,89 @@ class ImportDataCollectionViewControllerTest
ImportDataControllerTestDelegate* delegate_;
};
TEST_F(ImportDataCollectionViewControllerTest, TestModelSignedIn) {
TEST_F(ImportDataTableViewControllerTest, TestModelSignedIn) {
CreateController();
CheckController();
ASSERT_EQ(2, NumberOfSections());
EXPECT_EQ(1, NumberOfItemsInSection(0));
CardMultilineItem* item = GetCollectionViewItem(0, 0);
CardMultilineItem* item = GetTableViewItem(0, 0);
EXPECT_NSEQ(
l10n_util::GetNSStringF(IDS_IOS_OPTIONS_IMPORT_DATA_HEADER,
base::SysNSStringToUTF16(@"fromEmail@gmail.com")),
item.text);
EXPECT_EQ(2, NumberOfItemsInSection(1));
CheckTextCellTitleAndSubtitle(
CheckTextCellTextAndDetailText(
l10n_util::GetNSString(IDS_IOS_OPTIONS_IMPORT_DATA_KEEP_TITLE),
l10n_util::GetNSStringF(IDS_IOS_OPTIONS_IMPORT_DATA_KEEP_SUBTITLE_SWITCH,
base::SysNSStringToUTF16(@"fromEmail@gmail.com")),
1, 0);
CheckAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 1, 0);
CheckTextCellTitleAndSubtitle(
CheckAccessoryType(UITableViewCellAccessoryCheckmark, 1, 0);
CheckTextCellTextAndDetailText(
l10n_util::GetNSString(IDS_IOS_OPTIONS_IMPORT_DATA_IMPORT_TITLE),
l10n_util::GetNSStringF(IDS_IOS_OPTIONS_IMPORT_DATA_IMPORT_SUBTITLE,
base::SysNSStringToUTF16(@"toEmail@gmail.com")),
1, 1);
CheckAccessoryType(MDCCollectionViewCellAccessoryNone, 1, 1);
CheckAccessoryType(UITableViewCellAccessoryNone, 1, 1);
}
TEST_F(ImportDataCollectionViewControllerTest, TestModelSignedOut) {
TEST_F(ImportDataTableViewControllerTest, TestModelSignedOut) {
set_is_signed_in(false);
CreateController();
CheckController();
ASSERT_EQ(2, NumberOfSections());
EXPECT_EQ(1, NumberOfItemsInSection(0));
CardMultilineItem* item = GetCollectionViewItem(0, 0);
CardMultilineItem* item = GetTableViewItem(0, 0);
EXPECT_NSEQ(
l10n_util::GetNSStringF(IDS_IOS_OPTIONS_IMPORT_DATA_HEADER,
base::SysNSStringToUTF16(@"fromEmail@gmail.com")),
item.text);
EXPECT_EQ(2, NumberOfItemsInSection(1));
CheckTextCellTitleAndSubtitle(
CheckTextCellTextAndDetailText(
l10n_util::GetNSString(IDS_IOS_OPTIONS_IMPORT_DATA_IMPORT_TITLE),
l10n_util::GetNSStringF(IDS_IOS_OPTIONS_IMPORT_DATA_IMPORT_SUBTITLE,
base::SysNSStringToUTF16(@"toEmail@gmail.com")),
1, 0);
CheckAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 1, 0);
CheckTextCellTitleAndSubtitle(
CheckAccessoryType(UITableViewCellAccessoryCheckmark, 1, 0);
CheckTextCellTextAndDetailText(
l10n_util::GetNSString(IDS_IOS_OPTIONS_IMPORT_DATA_KEEP_TITLE),
l10n_util::GetNSString(IDS_IOS_OPTIONS_IMPORT_DATA_KEEP_SUBTITLE_SIGNIN),
1, 1);
CheckAccessoryType(MDCCollectionViewCellAccessoryNone, 1, 1);
CheckAccessoryType(UITableViewCellAccessoryNone, 1, 1);
}
// Tests that checking a checkbox correctly uncheck the other one.
TEST_F(ImportDataCollectionViewControllerTest, TestUniqueBoxChecked) {
TEST_F(ImportDataTableViewControllerTest, TestUniqueBoxChecked) {
CreateController();
ImportDataCollectionViewController* import_data_controller =
base::mac::ObjCCastStrict<ImportDataCollectionViewController>(
controller());
ImportDataTableViewController* import_data_controller =
base::mac::ObjCCastStrict<ImportDataTableViewController>(controller());
NSIndexPath* importIndexPath = [NSIndexPath indexPathForItem:0 inSection:1];
NSIndexPath* keepSeparateIndexPath =
[NSIndexPath indexPathForItem:1 inSection:1];
NSIndexPath* keepSeparateIndexPath = [NSIndexPath indexPathForItem:1
inSection:1];
ImportDataMultilineDetailItem* importItem =
base::mac::ObjCCastStrict<ImportDataMultilineDetailItem>(
[import_data_controller.collectionViewModel
[import_data_controller.tableViewModel
itemAtIndexPath:importIndexPath]);
ImportDataMultilineDetailItem* keepSeparateItem =
base::mac::ObjCCastStrict<ImportDataMultilineDetailItem>(
[import_data_controller.collectionViewModel
[import_data_controller.tableViewModel
itemAtIndexPath:keepSeparateIndexPath]);
[import_data_controller collectionView:[import_data_controller collectionView]
didSelectItemAtIndexPath:importIndexPath];
EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark, importItem.accessoryType);
EXPECT_EQ(MDCCollectionViewCellAccessoryNone, keepSeparateItem.accessoryType);
[import_data_controller tableView:[import_data_controller tableView]
didSelectRowAtIndexPath:importIndexPath];
EXPECT_EQ(UITableViewCellAccessoryCheckmark, importItem.accessoryType);
EXPECT_EQ(UITableViewCellAccessoryNone, keepSeparateItem.accessoryType);
[import_data_controller collectionView:[import_data_controller collectionView]
didSelectItemAtIndexPath:keepSeparateIndexPath];
EXPECT_EQ(MDCCollectionViewCellAccessoryNone, importItem.accessoryType);
EXPECT_EQ(MDCCollectionViewCellAccessoryCheckmark,
keepSeparateItem.accessoryType);
[import_data_controller tableView:[import_data_controller tableView]
didSelectRowAtIndexPath:keepSeparateIndexPath];
EXPECT_EQ(UITableViewCellAccessoryNone, importItem.accessoryType);
EXPECT_EQ(UITableViewCellAccessoryCheckmark, keepSeparateItem.accessoryType);
}
// Tests that the default choice when the user is signed in is Clear Data and
// that tapping continue will correctly select it. Regression test for
// crbug.com/649533
TEST_F(ImportDataCollectionViewControllerTest, TestDefaultChoiceSignedIn) {
TEST_F(ImportDataTableViewControllerTest, TestDefaultChoiceSignedIn) {
CreateController();
EXPECT_FALSE(delegate().didChooseClearDataPolicyCalled);
......@@ -169,7 +166,7 @@ TEST_F(ImportDataCollectionViewControllerTest, TestDefaultChoiceSignedIn) {
// Tests that the default choice when the user is signed out is Merge Data and
// that tapping continue will correctly select it. Regression test for
// crbug.com/649533
TEST_F(ImportDataCollectionViewControllerTest, TestDefaultChoiceSignedOut) {
TEST_F(ImportDataTableViewControllerTest, TestDefaultChoiceSignedOut) {
set_is_signed_in(false);
CreateController();
......
......@@ -94,7 +94,7 @@ newUserFeedbackController:(ios::ChromeBrowserState*)browserState
delegate:(id<SettingsNavigationControllerDelegate>)delegate
feedbackDataSource:(id<UserFeedbackDataSource>)dataSource;
// Creates and displays a new ImportDataCollectionViewController. |browserState|
// Creates and displays a new ImportDataTableViewController. |browserState|
// should not be nil.
+ (SettingsNavigationController*)
newImportDataController:(ios::ChromeBrowserState*)browserState
......
......@@ -18,7 +18,7 @@
#import "ios/chrome/browser/ui/settings/autofill_profile_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_coordinator.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_view_controller.h"
#import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_root_collection_view_controller.h"
......@@ -221,8 +221,8 @@ newImportDataController:(ios::ChromeBrowserState*)browserState
fromEmail:(NSString*)fromEmail
toEmail:(NSString*)toEmail
isSignedIn:(BOOL)isSignedIn {
UIViewController* controller = [[ImportDataCollectionViewController alloc]
initWithDelegate:importDataDelegate
UIViewController* controller =
[[ImportDataTableViewController alloc] initWithDelegate:importDataDelegate
fromEmail:fromEmail
toEmail:toEmail
isSignedIn:isSignedIn];
......
......@@ -30,7 +30,7 @@
#import "ios/chrome/browser/ui/settings/cells/sync_switch_item.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data_ui_constants.h"
#import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/sync_settings_collection_view_controller.h"
#import "ios/chrome/browser/ui/static_content/static_html_view_controller.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