Commit 78b9bb38 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Convert TranslateCollectionVC to UITableView

Also fixes bugs with the SwitchItem and adding test for the
ChromeTableViewControllerTest platform test helper.

Bug: 894791
Change-Id: Ib2d4631ac65ce380dbe18d43603a34e74baec66c
Reviewed-on: https://chromium-review.googlesource.com/c/1297977
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603121}
parent bfae0f8b
......@@ -99,8 +99,8 @@ source_set("settings") {
"table_cell_catalog_view_controller.mm",
"time_range_selector_collection_view_controller.h",
"time_range_selector_collection_view_controller.mm",
"translate_collection_view_controller.h",
"translate_collection_view_controller.mm",
"translate_table_view_controller.h",
"translate_table_view_controller.mm",
"voicesearch_collection_view_controller.h",
"voicesearch_collection_view_controller.mm",
]
......@@ -293,7 +293,7 @@ source_set("unit_tests") {
"sync_encryption_passphrase_collection_view_controller_unittest.mm",
"sync_settings_collection_view_controller_unittest.mm",
"time_range_selector_collection_view_controller_unittest.mm",
"translate_collection_view_controller_unittest.mm",
"translate_table_view_controller_unittest.mm",
"voicesearch_collection_view_controller_unittest.mm",
]
deps = [
......
......@@ -5,7 +5,12 @@
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SETTINGS_CELLS_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SETTINGS_CELLS_CONSTANTS_H_
#import <UIKit/UIKit.h>
// The color of the detail text for the settings cells.
extern const int kSettingsCellsDetailTextColor;
// Default height for the settings cells.
extern const CGFloat kSettingsCellDefaultHeight;
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SETTINGS_CELLS_CONSTANTS_H_
......@@ -9,3 +9,5 @@
#endif
const int kSettingsCellsDetailTextColor = 0x767676;
const CGFloat kSettingsCellDefaultHeight = 70;
......@@ -153,9 +153,7 @@ const CGFloat kIconImageSize = 28;
constant:-kTableViewHorizontalSpacing],
[_iconImageView.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],
[_textLabel.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],
constraintEqualToAnchor:_textLabel.centerYAnchor],
_iconHiddenConstraint,
]];
......
......@@ -22,7 +22,7 @@
#import "ios/chrome/browser/ui/settings/cells/legacy/legacy_settings_detail_item.h"
#import "ios/chrome/browser/ui/settings/compose_email_handler_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/chrome/browser/ui/settings/translate_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/translate_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h"
#import "ios/chrome/browser/web/mailto_handler_manager.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -225,8 +225,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
break;
}
case ItemTypeSettingsTranslate: {
TranslateCollectionViewController* controller =
[[TranslateCollectionViewController alloc]
TranslateTableViewController* controller =
[[TranslateTableViewController alloc]
initWithPrefs:browserState_->GetPrefs()];
controller.dispatcher = self.dispatcher;
[self.navigationController pushViewController:controller animated:YES];
......
......@@ -8,6 +8,7 @@
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/material_components/utils.h"
#import "ios/chrome/browser/ui/settings/cells/settings_cells_constants.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
......@@ -26,6 +27,10 @@
self.styler.tableViewSectionHeaderBlurEffect = nil;
[super viewDidLoad];
self.styler.cellBackgroundColor = [UIColor whiteColor];
self.styler.cellTitleColor = [UIColor blackColor];
self.tableView.estimatedRowHeight = kSettingsCellDefaultHeight;
// Do not set the estimated height of the footer/header as if there is no
// header/footer, there is an empty space.
}
- (void)viewWillAppear:(BOOL)animated {
......
......@@ -2,24 +2,24 @@
// 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_TRANSLATE_COLLECTION_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_TRANSLATE_COLLECTION_VIEW_CONTROLLER_H_
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_TRANSLATE_TABLE_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_TRANSLATE_TABLE_VIEW_CONTROLLER_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 PrefService;
// Controller for the UI that allows the user to control Translate settings.
@interface TranslateCollectionViewController
: SettingsRootCollectionViewController
@interface TranslateTableViewController : SettingsRootTableViewController
// |prefs| must not be nil.
- (instancetype)initWithPrefs:(PrefService*)prefs NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithLayout:(UICollectionViewLayout*)layout
style:(CollectionViewControllerStyle)style
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_TRANSLATE_COLLECTION_VIEW_CONTROLLER_H_
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_TRANSLATE_TABLE_VIEW_CONTROLLER_H_
......@@ -2,7 +2,7 @@
// 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/translate_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/translate_table_view_controller.h"
#import <Foundation/Foundation.h>
#include <memory>
......@@ -15,19 +15,17 @@
#include "components/translate/core/browser/translate_prefs.h"
#include "ios/chrome/browser/application_context.h"
#import "ios/chrome/browser/translate/chrome_ios_translate_client.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.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_cells_constants.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h"
#import "ios/chrome/browser/ui/settings/settings_utils.h"
#import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_detail_text_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "ios/chrome/browser/ui/util/uikit_ui_util.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/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Snackbar/src/MaterialSnackbar.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
......@@ -39,7 +37,6 @@ namespace {
typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierTranslate = kSectionIdentifierEnumZero,
SectionIdentifierFooter,
};
typedef NS_ENUM(NSInteger, ItemType) {
......@@ -54,89 +51,88 @@ NSString* const kTranslateSettingsCategory = @"ChromeTranslateSettings";
} // namespace
@interface TranslateCollectionViewController ()<BooleanObserver> {
@interface TranslateTableViewController ()<BooleanObserver> {
// Profile preferences.
PrefService* _prefs; // weak
PrefBackedBoolean* _translationEnabled;
// The item related to the switch for the translation setting.
LegacySettingsSwitchItem* _translationItem;
SettingsSwitchItem* _translationItem;
}
@end
@implementation TranslateCollectionViewController
@implementation TranslateTableViewController
#pragma mark - Initialization
- (instancetype)initWithPrefs:(PrefService*)prefs {
DCHECK(prefs);
UICollectionViewLayout* layout = [[MDCCollectionViewFlowLayout alloc] init];
self =
[super initWithLayout:layout style:CollectionViewControllerStyleAppBar];
[super initWithTableViewStyle:UITableViewStyleGrouped
appBarStyle:ChromeTableViewControllerStyleWithAppBar];
if (self) {
self.title = l10n_util::GetNSString(IDS_IOS_TRANSLATE_SETTING);
self.collectionViewAccessibilityIdentifier =
@"translate_settings_view_controller";
_prefs = prefs;
_translationEnabled = [[PrefBackedBoolean alloc]
initWithPrefService:_prefs
prefName:prefs::kOfferTranslateEnabled];
[_translationEnabled setObserver:self];
// 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
- (void)viewDidLoad {
[super viewDidLoad];
self.title = l10n_util::GetNSString(IDS_IOS_TRANSLATE_SETTING);
self.tableView.accessibilityIdentifier =
@"translate_settings_view_controller";
[self loadModel];
self.tableView.estimatedSectionFooterHeight = kSettingsCellDefaultHeight;
}
#pragma mark - SettingsRootTableViewController
- (void)loadModel {
[super loadModel];
CollectionViewModel* model = self.collectionViewModel;
TableViewModel<TableViewItem*>* model = self.tableViewModel;
// Translate Section
[model addSectionWithIdentifier:SectionIdentifierTranslate];
_translationItem =
[[LegacySettingsSwitchItem alloc] initWithType:ItemTypeTranslate];
[[SettingsSwitchItem alloc] initWithType:ItemTypeTranslate];
_translationItem.text = l10n_util::GetNSString(IDS_IOS_TRANSLATE_SETTING);
_translationItem.on = [_translationEnabled value];
[model addItem:_translationItem
toSectionWithIdentifier:SectionIdentifierTranslate];
SettingsTextItem* resetTranslate =
[[SettingsTextItem alloc] initWithType:ItemTypeResetTranslate];
TableViewDetailTextItem* resetTranslate =
[[TableViewDetailTextItem alloc] initWithType:ItemTypeResetTranslate];
resetTranslate.text = l10n_util::GetNSString(IDS_IOS_TRANSLATE_SETTING_RESET);
resetTranslate.accessibilityTraits |= UIAccessibilityTraitButton;
[model addItem:resetTranslate
toSectionWithIdentifier:SectionIdentifierTranslate];
// Footer Section
[model addSectionWithIdentifier:SectionIdentifierFooter];
CollectionViewFooterItem* footer =
[[CollectionViewFooterItem alloc] initWithType:ItemTypeFooter];
footer.cellStyle = CollectionViewCellStyle::kUIKit;
TableViewLinkHeaderFooterItem* footer =
[[TableViewLinkHeaderFooterItem alloc] initWithType:ItemTypeFooter];
footer.text = l10n_util::GetNSString(IDS_IOS_TRANSLATE_SETTING_DESCRIPTION);
footer.linkURL = google_util::AppendGoogleLocaleParam(
GURL(kTranslateLearnMoreUrl),
GetApplicationContext()->GetApplicationLocale());
footer.linkDelegate = self;
[model addItem:footer toSectionWithIdentifier:SectionIdentifierFooter];
[model setFooter:footer forSectionWithIdentifier:SectionIdentifierTranslate];
}
#pragma mark UICollectionViewDataSource
#pragma mark - UITableViewDataSource
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
cellForItemAtIndexPath:(NSIndexPath*)indexPath {
UICollectionViewCell* cell =
[super collectionView:collectionView cellForItemAtIndexPath:indexPath];
NSInteger itemType =
[self.collectionViewModel itemTypeForIndexPath:indexPath];
- (UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UITableViewCell* cell =
[super tableView:tableView cellForRowAtIndexPath:indexPath];
NSInteger itemType = [self.tableViewModel itemTypeForIndexPath:indexPath];
switch (itemType) {
case ItemTypeTranslate: {
LegacySettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<LegacySettingsSwitchCell>(cell);
cell.selectionStyle = UITableViewCellSelectionStyleNone;
SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
[switchCell.switchView addTarget:self
action:@selector(translateToggled:)
forControlEvents:UIControlEventValueChanged];
......@@ -149,13 +145,24 @@ NSString* const kTranslateSettingsCategory = @"ChromeTranslateSettings";
return cell;
}
#pragma mark UICollectionViewDelegate
- (void)collectionView:(UICollectionView*)collectionView
didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
[super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
#pragma mark - UITableViewDelegate
- (UIView*)tableView:(UITableView*)tableView
viewForFooterInSection:(NSInteger)section {
UIView* footerView =
[super tableView:tableView viewForFooterInSection:section];
if (SectionIdentifierTranslate ==
[self.tableViewModel sectionIdentifierForSection:section]) {
TableViewLinkHeaderFooterView* footer =
base::mac::ObjCCastStrict<TableViewLinkHeaderFooterView>(footerView);
footer.delegate = self;
}
return footerView;
}
NSInteger itemType =
[self.collectionViewModel itemTypeForIndexPath:indexPath];
- (void)tableView:(UITableView*)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
NSInteger itemType = [self.tableViewModel itemTypeForIndexPath:indexPath];
if (itemType == ItemTypeResetTranslate) {
std::unique_ptr<translate::TranslatePrefs> translatePrefs(
......@@ -169,56 +176,7 @@ NSString* const kTranslateSettingsCategory = @"ChromeTranslateSettings";
message.category = kTranslateSettingsCategory;
[MDCSnackbarManager showMessage:message];
}
}
#pragma mark MDCCollectionViewStylingDelegate
- (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView
cellStyleForSection:(NSInteger)section {
NSInteger sectionIdentifier =
[self.collectionViewModel sectionIdentifierForSection:section];
if (sectionIdentifier == SectionIdentifierFooter) {
return MDCCollectionViewCellStyleDefault;
}
return self.styler.cellStyle;
}
- (BOOL)collectionView:(UICollectionView*)collectionView
shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath {
NSInteger sectionIdentifier =
[self.collectionViewModel sectionIdentifierForSection:indexPath.section];
if (sectionIdentifier == SectionIdentifierFooter) {
return YES;
}
return NO;
}
- (CGFloat)collectionView:(UICollectionView*)collectionView
cellHeightAtIndexPath:(NSIndexPath*)indexPath {
CollectionViewItem* item =
[self.collectionViewModel itemAtIndexPath:indexPath];
if (item.type == ItemTypeFooter)
return [MDCCollectionViewCell
cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
forItem:item];
return MDCCellDefaultOneLineHeight;
}
- (BOOL)collectionView:(UICollectionView*)collectionView
hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
switch (type) {
case ItemTypeFooter:
case ItemTypeTranslate:
return YES;
default:
return NO;
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark - BooleanObserver
......@@ -236,16 +194,16 @@ NSString* const kTranslateSettingsCategory = @"ChromeTranslateSettings";
#pragma mark - Actions
- (void)translateToggled:(id)sender {
NSIndexPath* switchPath = [self.collectionViewModel
indexPathForItemType:ItemTypeTranslate
sectionIdentifier:SectionIdentifierTranslate];
LegacySettingsSwitchItem* switchItem =
base::mac::ObjCCastStrict<LegacySettingsSwitchItem>(
[self.collectionViewModel itemAtIndexPath:switchPath]);
LegacySettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<LegacySettingsSwitchCell>(
[self.collectionView cellForItemAtIndexPath:switchPath]);
NSIndexPath* switchPath =
[self.tableViewModel indexPathForItemType:ItemTypeTranslate
sectionIdentifier:SectionIdentifierTranslate];
SettingsSwitchItem* switchItem =
base::mac::ObjCCastStrict<SettingsSwitchItem>(
[self.tableViewModel itemAtIndexPath:switchPath]);
SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(
[self.tableView cellForRowAtIndexPath:switchPath]);
DCHECK_EQ(switchCell.switchView, sender);
BOOL isOn = switchCell.switchView.isOn;
......
......@@ -2,7 +2,7 @@
// 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/translate_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/translate_table_view_controller.h"
#include <memory>
......@@ -19,7 +19,7 @@
#include "components/translate/core/browser/translate_prefs.h"
#include "ios/chrome/browser/pref_names.h"
#import "ios/chrome/browser/translate/chrome_ios_translate_client.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller_test.h"
#include "ios/chrome/grit/ios_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
......@@ -39,20 +39,19 @@ const char kBlacklistedSite[] = "http://blacklistedsite.com";
const char kLanguage1[] = "klingon";
const char kLanguage2[] = "pirate";
class TranslateCollectionViewControllerTest
: public CollectionViewControllerTest {
class TranslateTableViewControllerTest : public ChromeTableViewControllerTest {
protected:
TranslateCollectionViewControllerTest()
TranslateTableViewControllerTest()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
void SetUp() override {
CollectionViewControllerTest::SetUp();
ChromeTableViewControllerTest::SetUp();
pref_service_ = CreateLocalState();
}
CollectionViewController* InstantiateController() override {
return [[TranslateCollectionViewController alloc]
ChromeTableViewController* InstantiateController() override {
return [[TranslateTableViewController alloc]
initWithPrefs:pref_service_.get()];
}
......@@ -64,7 +63,7 @@ class TranslateCollectionViewControllerTest
registry->RegisterStringPref(
prefs::kAcceptLanguages,
l10n_util::GetStringUTF8(IDS_ACCEPT_LANGUAGES));
base::FilePath path("TranslateCollectionViewControllerTest.pref");
base::FilePath path("TranslateTableViewControllerTest.pref");
sync_preferences::PrefServiceMockFactory factory;
factory.SetUserPrefsFile(path, base::ThreadTaskRunnerHandle::Get().get());
return factory.Create(registry.get());
......@@ -74,27 +73,27 @@ class TranslateCollectionViewControllerTest
std::unique_ptr<PrefService> pref_service_;
};
TEST_F(TranslateCollectionViewControllerTest, TestModelTranslateOff) {
TEST_F(TranslateTableViewControllerTest, TestModelTranslateOff) {
CreateController();
CheckController();
EXPECT_EQ(2, NumberOfSections());
EXPECT_EQ(1, NumberOfSections());
EXPECT_EQ(2, NumberOfItemsInSection(0));
CheckSwitchCellStateAndTitleWithId(NO, IDS_IOS_TRANSLATE_SETTING, 0, 0);
CheckTextCellTitleWithId(IDS_IOS_TRANSLATE_SETTING_RESET, 0, 1);
CheckSwitchCellStateAndTextWithId(NO, IDS_IOS_TRANSLATE_SETTING, 0, 0);
CheckTextCellTextWithId(IDS_IOS_TRANSLATE_SETTING_RESET, 0, 1);
}
TEST_F(TranslateCollectionViewControllerTest, TestModelTranslateOn) {
TEST_F(TranslateTableViewControllerTest, TestModelTranslateOn) {
BooleanPrefMember translateEnabled;
translateEnabled.Init(prefs::kOfferTranslateEnabled, pref_service_.get());
translateEnabled.SetValue(true);
CreateController();
EXPECT_EQ(2, NumberOfSections());
EXPECT_EQ(1, NumberOfSections());
EXPECT_EQ(2, NumberOfItemsInSection(0));
CheckSwitchCellStateAndTitleWithId(YES, IDS_IOS_TRANSLATE_SETTING, 0, 0);
CheckTextCellTitleWithId(IDS_IOS_TRANSLATE_SETTING_RESET, 0, 1);
CheckSwitchCellStateAndTextWithId(YES, IDS_IOS_TRANSLATE_SETTING, 0, 0);
CheckTextCellTextWithId(IDS_IOS_TRANSLATE_SETTING_RESET, 0, 1);
}
TEST_F(TranslateCollectionViewControllerTest, TestClearPreferences) {
TEST_F(TranslateTableViewControllerTest, TestClearPreferences) {
// Set some preferences.
std::unique_ptr<translate::TranslatePrefs> translate_prefs(
ChromeIOSTranslateClient::CreateTranslatePrefs(pref_service_.get()));
......@@ -107,11 +106,11 @@ TEST_F(TranslateCollectionViewControllerTest, TestClearPreferences) {
translate_prefs->IsLanguagePairWhitelisted(kLanguage1, kLanguage2));
// Reset the preferences through the UI.
CreateController();
TranslateCollectionViewController* controller =
static_cast<TranslateCollectionViewController*>(this->controller());
TranslateTableViewController* controller =
static_cast<TranslateTableViewController*>(this->controller());
// Simulate a tap on the "reset" item.
[controller collectionView:[controller collectionView]
didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0]];
[controller tableView:controller.tableView
didSelectRowAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0]];
// Check that preferences are gone.
EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(kBlacklistedSite));
EXPECT_FALSE(translate_prefs->IsBlockedLanguage(kLanguage1));
......
......@@ -83,20 +83,21 @@ class ChromeTableViewControllerTest : public BlockCleanupTest {
int section_id,
int item_id);
// Verifies that the switch cell at |item| in |section| has a title which
// matches |expected_title| and is currently in |state|.
void CheckSwitchCellStateAndTitle(BOOL expected_state,
NSString* expected_title,
int section,
int item);
// Verifies that the switch cell at |item| in |section| has a title which
// matches the l10n string for |expected_title_id| and is currently in
// |state|.
void CheckSwitchCellStateAndTitleWithId(BOOL expected_state,
int expected_title_id,
int section,
int item);
// Verifies that the switch cell at |item| in |section| has a text property
// which matches |expected_title| and a isOn method which matches
// |expected_state|.
void CheckSwitchCellStateAndText(BOOL expected_state,
NSString* expected_title,
int section,
int item);
// Verifies that the switch cell at |item| in |section| has a text property
// which matches the l10n string for |expected_title_id| and a isOn method
// which matches |expected_state|.
void CheckSwitchCellStateAndTextWithId(BOOL expected_state,
int expected_title_id,
int section,
int item);
// Verifies that the cell at |item| in |section| has the given
// |accessory_type|.
......
......@@ -140,21 +140,24 @@ void ChromeTableViewControllerTest::CheckDetailItemTextWithIds(
[item detailText]);
}
void ChromeTableViewControllerTest::CheckSwitchCellStateAndTitle(
void ChromeTableViewControllerTest::CheckSwitchCellStateAndText(
BOOL expected_state,
NSString* expected_title,
int section,
int item) {
// TODO(crbug.com/894791): Implement this.
NOTREACHED();
id switch_item = GetTableViewItem(section, item);
EXPECT_TRUE([switch_item respondsToSelector:@selector(text)]);
EXPECT_NSEQ(expected_title, [switch_item text]);
EXPECT_TRUE([switch_item respondsToSelector:@selector(isOn)]);
EXPECT_EQ(expected_state, [switch_item isOn]);
}
void ChromeTableViewControllerTest::CheckSwitchCellStateAndTitleWithId(
void ChromeTableViewControllerTest::CheckSwitchCellStateAndTextWithId(
BOOL expected_state,
int expected_title_id,
int section,
int item) {
CheckSwitchCellStateAndTitle(
CheckSwitchCellStateAndText(
expected_state, l10n_util::GetNSString(expected_title_id), section, item);
}
......
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