Commit ac43b757 authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Add test coverage for Settings table view controller.

Adds a simple test to ensure that Sync settings is on when Sync is
enabled in the sign-in flow.

Bug: 1145188
Change-Id: I3f705030a5b2af9b0a31734a372bed7f2de20f58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2517463
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824071}
parent d6c67df9
......@@ -210,6 +210,7 @@ source_set("constants") {
"settings_table_view_controller_constants.mm",
]
frameworks = [ "Foundation.framework" ]
deps = [ "//ios/chrome/browser/ui/list_model" ]
}
source_set("test_support") {
......@@ -270,6 +271,7 @@ source_set("unit_tests") {
"search_engine_table_view_controller_unittest.mm",
"settings_navigation_controller_unittest.mm",
"settings_root_table_view_controller_unittest.mm",
"settings_table_view_controller_unittest.mm",
"translate_table_view_controller_unittest.mm",
"voice_search_table_view_controller_unittest.mm",
]
......@@ -289,6 +291,7 @@ source_set("unit_tests") {
"//components/prefs:test_support",
"//components/search_engines",
"//components/strings",
"//components/sync/driver:test_support",
"//components/sync_preferences",
"//components/sync_preferences:test_support",
"//components/translate/core/browser",
......@@ -311,9 +314,12 @@ source_set("unit_tests") {
"//ios/chrome/browser/signin",
"//ios/chrome/browser/signin:test_support",
"//ios/chrome/browser/sync",
"//ios/chrome/browser/sync:test_support",
"//ios/chrome/browser/translate",
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/icons",
"//ios/chrome/browser/ui/settings:constants",
"//ios/chrome/browser/ui/settings/cells",
"//ios/chrome/browser/ui/table_view",
"//ios/chrome/browser/ui/table_view:test_support",
......@@ -324,6 +330,7 @@ source_set("unit_tests") {
"//ios/chrome/test:test_support",
"//ios/chrome/test/app:test_support",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/signin:fake_chrome_identity",
"//ios/public/provider/chrome/browser/voice",
"//ios/web/public/test",
"//net",
......
......@@ -136,43 +136,6 @@ NSString* const kSettingsArticleSuggestionsImageName =
@"settings_article_suggestions";
NSString* const kDefaultBrowserWorldImageName = @"default_browser_world";
typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierSignIn = kSectionIdentifierEnumZero,
SectionIdentifierAccount,
SectionIdentifierBasics,
SectionIdentifierAdvanced,
SectionIdentifierInfo,
SectionIdentifierDebug,
SectionIdentifierDefaults,
};
typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeSignInButton = kItemTypeEnumZero,
ItemTypeSigninPromo,
ItemTypeAccount,
ItemTypeSyncAndGoogleServices,
ItemTypeGoogleSync,
ItemTypeGoogleServices,
ItemTypeHeader,
ItemTypeSearchEngine,
ItemTypeManagedDefaultSearchEngine,
ItemTypePasswords,
ItemTypeAutofillCreditCard,
ItemTypeAutofillProfile,
ItemTypeVoiceSearch,
ItemTypePrivacy,
ItemTypeLanguageSettings,
ItemTypeContentSettings,
ItemTypeBandwidth,
ItemTypeAboutChrome,
ItemTypeMemoryDebugging,
ItemTypeViewSource,
ItemTypeTableCellCatalog,
ItemTypeArticlesForYou,
ItemTypeSafetyCheck,
ItemTypeDefaultBrowser,
};
#if BUILDFLAG(CHROMIUM_BRANDING) && !defined(NDEBUG)
NSString* kDevViewSourceKey = @"DevViewSource";
#endif // BUILDFLAG(CHROMIUM_BRANDING) && !defined(NDEBUG)
......@@ -406,7 +369,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
AuthenticationServiceFactory::GetForBrowserState(_browserState);
if (!authService->IsAuthenticated()) {
// Sign in section
[model addSectionWithIdentifier:SectionIdentifierSignIn];
[model addSectionWithIdentifier:SettingsSectionIdentifierSignIn];
if ([SigninPromoViewMediator
shouldDisplaySigninPromoViewWithAccessPoint:
signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS
......@@ -424,113 +387,114 @@ NSString* kDevViewSourceKey = @"DevViewSource";
_signinPromoViewMediator = nil;
}
[model addItem:[self signInTextItem]
toSectionWithIdentifier:SectionIdentifierSignIn];
toSectionWithIdentifier:SettingsSectionIdentifierSignIn];
} else {
// Account section
[model addSectionWithIdentifier:SectionIdentifierAccount];
[model addSectionWithIdentifier:SettingsSectionIdentifierAccount];
_hasRecordedSigninImpression = NO;
[_signinPromoViewMediator signinPromoViewIsRemoved];
_signinPromoViewMediator = nil;
[model addItem:[self accountCellItem]
toSectionWithIdentifier:SectionIdentifierAccount];
toSectionWithIdentifier:SettingsSectionIdentifierAccount];
}
if (![model hasSectionForSectionIdentifier:SectionIdentifierAccount]) {
if (![model
hasSectionForSectionIdentifier:SettingsSectionIdentifierAccount]) {
// Add the Account section for the Sync & Google services cell, if the user
// is signed-out.
[model addSectionWithIdentifier:SectionIdentifierAccount];
[model addSectionWithIdentifier:SettingsSectionIdentifierAccount];
}
// Adds experimental Google Services item separate from Sync.
if (base::FeatureList::IsEnabled(signin::kMobileIdentityConsistency)) {
if (authService->IsAuthenticated()) {
[model addItem:[self googleSyncCellItem]
toSectionWithIdentifier:SectionIdentifierAccount];
toSectionWithIdentifier:SettingsSectionIdentifierAccount];
}
[model addItem:[self googleServicesCellItem]
toSectionWithIdentifier:SectionIdentifierAccount];
toSectionWithIdentifier:SettingsSectionIdentifierAccount];
} else {
[model addItem:[self syncAndGoogleServicesCellItem]
toSectionWithIdentifier:SectionIdentifierAccount];
toSectionWithIdentifier:SettingsSectionIdentifierAccount];
}
// Defaults section.
if (@available(iOS 14, *)) {
if (base::FeatureList::IsEnabled(kDefaultBrowserSettings)) {
[model addSectionWithIdentifier:SectionIdentifierDefaults];
[model addSectionWithIdentifier:SettingsSectionIdentifierDefaults];
[model addItem:[self defaultBrowserCellItem]
toSectionWithIdentifier:SectionIdentifierDefaults];
toSectionWithIdentifier:SettingsSectionIdentifierDefaults];
}
}
// Basics section
[model addSectionWithIdentifier:SectionIdentifierBasics];
[model addSectionWithIdentifier:SettingsSectionIdentifierBasics];
// Show managed UI if default search engine is managed by policy.
if (base::FeatureList::IsEnabled(kEnableIOSManagedSettingsUI) &&
[self isDefaultSearchEngineManagedByPolicy]) {
[model addItem:[self managedSearchEngineItem]
toSectionWithIdentifier:SectionIdentifierBasics];
toSectionWithIdentifier:SettingsSectionIdentifierBasics];
} else {
if (@available(iOS 14, *)) {
if (base::FeatureList::IsEnabled(kDefaultBrowserSettings)) {
[model addItem:[self searchEngineDetailItem]
toSectionWithIdentifier:SectionIdentifierDefaults];
toSectionWithIdentifier:SettingsSectionIdentifierDefaults];
} else {
[model addItem:[self searchEngineDetailItem]
toSectionWithIdentifier:SectionIdentifierBasics];
toSectionWithIdentifier:SettingsSectionIdentifierBasics];
}
} else {
[model addItem:[self searchEngineDetailItem]
toSectionWithIdentifier:SectionIdentifierBasics];
toSectionWithIdentifier:SettingsSectionIdentifierBasics];
}
}
[model addItem:[self passwordsDetailItem]
toSectionWithIdentifier:SectionIdentifierBasics];
toSectionWithIdentifier:SettingsSectionIdentifierBasics];
[model addItem:[self autoFillCreditCardDetailItem]
toSectionWithIdentifier:SectionIdentifierBasics];
toSectionWithIdentifier:SettingsSectionIdentifierBasics];
[model addItem:[self autoFillProfileDetailItem]
toSectionWithIdentifier:SectionIdentifierBasics];
toSectionWithIdentifier:SettingsSectionIdentifierBasics];
// Advanced Section
[model addSectionWithIdentifier:SectionIdentifierAdvanced];
[model addSectionWithIdentifier:SettingsSectionIdentifierAdvanced];
[model addItem:[self voiceSearchDetailItem]
toSectionWithIdentifier:SectionIdentifierAdvanced];
toSectionWithIdentifier:SettingsSectionIdentifierAdvanced];
if (base::FeatureList::IsEnabled(kSafetyCheckIOS)) {
[model addItem:[self safetyCheckDetailItem]
toSectionWithIdentifier:SectionIdentifierAdvanced];
toSectionWithIdentifier:SettingsSectionIdentifierAdvanced];
}
[model addItem:[self privacyDetailItem]
toSectionWithIdentifier:SectionIdentifierAdvanced];
toSectionWithIdentifier:SettingsSectionIdentifierAdvanced];
_articlesForYouItem = [self articlesForYouSwitchItem];
[model addItem:_articlesForYouItem
toSectionWithIdentifier:SectionIdentifierAdvanced];
toSectionWithIdentifier:SettingsSectionIdentifierAdvanced];
[model addItem:[self languageSettingsDetailItem]
toSectionWithIdentifier:SectionIdentifierAdvanced];
toSectionWithIdentifier:SettingsSectionIdentifierAdvanced];
[model addItem:[self contentSettingsDetailItem]
toSectionWithIdentifier:SectionIdentifierAdvanced];
toSectionWithIdentifier:SettingsSectionIdentifierAdvanced];
[model addItem:[self bandwidthManagementDetailItem]
toSectionWithIdentifier:SectionIdentifierAdvanced];
toSectionWithIdentifier:SettingsSectionIdentifierAdvanced];
// Info Section
[model addSectionWithIdentifier:SectionIdentifierInfo];
[model addSectionWithIdentifier:SettingsSectionIdentifierInfo];
[model addItem:[self aboutChromeDetailItem]
toSectionWithIdentifier:SectionIdentifierInfo];
toSectionWithIdentifier:SettingsSectionIdentifierInfo];
// Debug Section
if ([self hasDebugSection]) {
[model addSectionWithIdentifier:SectionIdentifierDebug];
[model addSectionWithIdentifier:SettingsSectionIdentifierDebug];
}
if (experimental_flags::IsMemoryDebuggingEnabled()) {
_showMemoryDebugToolsItem = [self showMemoryDebugSwitchItem];
[model addItem:_showMemoryDebugToolsItem
toSectionWithIdentifier:SectionIdentifierDebug];
toSectionWithIdentifier:SettingsSectionIdentifierDebug];
}
#if BUILDFLAG(CHROMIUM_BRANDING) && !defined(NDEBUG)
[model addItem:[self viewSourceSwitchItem]
toSectionWithIdentifier:SectionIdentifierDebug];
toSectionWithIdentifier:SettingsSectionIdentifierDebug];
[model addItem:[self tableViewCatalogDetailItem]
toSectionWithIdentifier:SectionIdentifierDebug];
toSectionWithIdentifier:SettingsSectionIdentifierDebug];
#endif // BUILDFLAG(CHROMIUM_BRANDING) && !defined(NDEBUG)
}
......@@ -539,7 +503,8 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (TableViewItem*)signInTextItem {
if (_signinPromoViewMediator) {
TableViewSigninPromoItem* signinPromoItem =
[[TableViewSigninPromoItem alloc] initWithType:ItemTypeSigninPromo];
[[TableViewSigninPromoItem alloc]
initWithType:SettingsItemTypeSigninPromo];
signinPromoItem.text =
l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_SETTINGS_WITH_UNITY);
signinPromoItem.configurator =
......@@ -556,7 +521,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
_hasRecordedSigninImpression = YES;
}
AccountSignInItem* signInTextItem =
[[AccountSignInItem alloc] initWithType:ItemTypeSignInButton];
[[AccountSignInItem alloc] initWithType:SettingsItemTypeSignInButton];
signInTextItem.accessibilityIdentifier = kSettingsSignInCellId;
signInTextItem.detailText =
l10n_util::GetNSString(IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SUBTITLE);
......@@ -566,7 +531,8 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (TableViewItem*)googleServicesCellItem {
SettingsImageDetailTextItem* googleServicesItem =
[[SettingsImageDetailTextItem alloc] initWithType:ItemTypeGoogleServices];
[[SettingsImageDetailTextItem alloc]
initWithType:SettingsItemTypeGoogleServices];
googleServicesItem.accessoryType =
UITableViewCellAccessoryDisclosureIndicator;
googleServicesItem.text =
......@@ -581,7 +547,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
// TODO(crbug.com/805214): This branded icon image needs to come from
// BrandedImageProvider.
TableViewDetailIconItem* googleSyncCellItem =
[self detailItemWithType:ItemTypeGoogleSync
[self detailItemWithType:SettingsItemTypeGoogleSync
text:l10n_util::GetNSString(
IDS_IOS_GOOGLE_SYNC_SETTINGS_TITLE)
detailText:l10n_util::GetNSString(IDS_IOS_SETTING_ON)
......@@ -596,7 +562,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
// BrandedImageProvider.
SettingsImageDetailTextItem* googleServicesItem =
[[SettingsImageDetailTextItem alloc]
initWithType:ItemTypeSyncAndGoogleServices];
initWithType:SettingsItemTypeSyncAndGoogleServices];
googleServicesItem.accessoryType =
UITableViewCellAccessoryDisclosureIndicator;
googleServicesItem.text =
......@@ -608,8 +574,8 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
- (TableViewItem*)defaultBrowserCellItem {
TableViewDetailIconItem* defaultBrowser =
[[TableViewDetailIconItem alloc] initWithType:ItemTypeDefaultBrowser];
TableViewDetailIconItem* defaultBrowser = [[TableViewDetailIconItem alloc]
initWithType:SettingsItemTypeDefaultBrowser];
defaultBrowser.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
defaultBrowser.text =
l10n_util::GetNSString(IDS_IOS_SETTINGS_SET_DEFAULT_BROWSER);
......@@ -620,7 +586,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (TableViewItem*)accountCellItem {
TableViewAccountItem* identityAccountItem =
[[TableViewAccountItem alloc] initWithType:ItemTypeAccount];
[[TableViewAccountItem alloc] initWithType:SettingsItemTypeAccount];
identityAccountItem.accessoryType =
UITableViewCellAccessoryDisclosureIndicator;
identityAccountItem.accessibilityIdentifier = kSettingsAccountCellId;
......@@ -634,7 +600,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
ios::TemplateURLServiceFactory::GetForBrowserState(_browserState)));
_defaultSearchEngineItem =
[self detailItemWithType:ItemTypeSearchEngine
[self detailItemWithType:SettingsItemTypeSearchEngine
text:l10n_util::GetNSString(
IDS_IOS_SEARCH_ENGINE_SETTING_TITLE)
detailText:defaultSearchEngineName
......@@ -646,7 +612,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (TableViewInfoButtonItem*)managedSearchEngineItem {
TableViewInfoButtonItem* managedDefaultSearchEngineItem =
[[TableViewInfoButtonItem alloc]
initWithType:ItemTypeManagedDefaultSearchEngine];
initWithType:SettingsItemTypeManagedDefaultSearchEngine];
managedDefaultSearchEngineItem.text =
l10n_util::GetNSString(IDS_IOS_SEARCH_ENGINE_SETTING_TITLE);
managedDefaultSearchEngineItem.iconImageName = kSettingsSearchEngineImageName;
......@@ -679,7 +645,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
: l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
_passwordsDetailItem =
[self detailItemWithType:ItemTypePasswords
[self detailItemWithType:SettingsItemTypePasswords
text:l10n_util::GetNSString(IDS_IOS_PASSWORDS)
detailText:passwordsDetail
iconImageName:kSettingsPasswordsImageName
......@@ -695,7 +661,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
: l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
_autoFillCreditCardDetailItem =
[self detailItemWithType:ItemTypeAutofillCreditCard
[self detailItemWithType:SettingsItemTypeAutofillCreditCard
text:l10n_util::GetNSString(
IDS_AUTOFILL_PAYMENT_METHODS)
detailText:detailText
......@@ -712,7 +678,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
: l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
_autoFillProfileDetailItem =
[self detailItemWithType:ItemTypeAutofillProfile
[self detailItemWithType:SettingsItemTypeAutofillProfile
text:l10n_util::GetNSString(
IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE)
detailText:detailText
......@@ -731,7 +697,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
: localeConfig->GetDefaultLocale();
NSString* languageName = base::SysUTF16ToNSString(locale.display_name);
_voiceSearchDetailItem =
[self detailItemWithType:ItemTypeVoiceSearch
[self detailItemWithType:SettingsItemTypeVoiceSearch
text:l10n_util::GetNSString(
IDS_IOS_VOICE_SEARCH_SETTING_TITLE)
detailText:languageName
......@@ -744,7 +710,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
NSString* safetyCheckTitle =
l10n_util::GetNSString(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SAFETY_CHECK);
_safetyCheckItem =
[[SettingsCheckItem alloc] initWithType:ItemTypeSafetyCheck];
[[SettingsCheckItem alloc] initWithType:SettingsItemTypeSafetyCheck];
_safetyCheckItem.text = safetyCheckTitle;
_safetyCheckItem.enabled = YES;
_safetyCheckItem.indicatorHidden = YES;
......@@ -767,7 +733,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (TableViewItem*)privacyDetailItem {
return [self
detailItemWithType:ItemTypePrivacy
detailItemWithType:SettingsItemTypePrivacy
text:l10n_util::GetNSString(
IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY)
detailText:nil
......@@ -776,7 +742,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
- (TableViewItem*)languageSettingsDetailItem {
return [self detailItemWithType:ItemTypeLanguageSettings
return [self detailItemWithType:SettingsItemTypeLanguageSettings
text:l10n_util::GetNSString(
IDS_IOS_LANGUAGE_SETTINGS_TITLE)
detailText:nil
......@@ -785,7 +751,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
- (TableViewItem*)contentSettingsDetailItem {
return [self detailItemWithType:ItemTypeContentSettings
return [self detailItemWithType:SettingsItemTypeContentSettings
text:l10n_util::GetNSString(
IDS_IOS_CONTENT_SETTINGS_TITLE)
detailText:nil
......@@ -794,7 +760,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
- (TableViewItem*)bandwidthManagementDetailItem {
return [self detailItemWithType:ItemTypeBandwidth
return [self detailItemWithType:SettingsItemTypeBandwidth
text:l10n_util::GetNSString(
IDS_IOS_BANDWIDTH_MANAGEMENT_SETTINGS)
detailText:nil
......@@ -803,7 +769,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
- (TableViewItem*)aboutChromeDetailItem {
return [self detailItemWithType:ItemTypeAboutChrome
return [self detailItemWithType:SettingsItemTypeAboutChrome
text:l10n_util::GetNSString(IDS_IOS_PRODUCT_NAME)
detailText:nil
iconImageName:kSettingsAboutChromeImageName
......@@ -812,7 +778,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (SettingsSwitchItem*)showMemoryDebugSwitchItem {
SettingsSwitchItem* showMemoryDebugSwitchItem =
[self switchItemWithType:ItemTypeMemoryDebugging
[self switchItemWithType:SettingsItemTypeMemoryDebugging
title:@"Show memory debug tools"
iconImageName:kSettingsDebugImageName
withDefaultsKey:nil
......@@ -829,7 +795,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
: l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_SETTING_TITLE);
SettingsSwitchItem* articlesForYouSwitchItem =
[self switchItemWithType:ItemTypeArticlesForYou
[self switchItemWithType:SettingsItemTypeArticlesForYou
title:settingTitle
iconImageName:kSettingsArticleSuggestionsImageName
withDefaultsKey:nil
......@@ -841,7 +807,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
#if BUILDFLAG(CHROMIUM_BRANDING) && !defined(NDEBUG)
- (SettingsSwitchItem*)viewSourceSwitchItem {
return [self switchItemWithType:ItemTypeViewSource
return [self switchItemWithType:SettingsItemTypeViewSource
title:@"View source menu"
iconImageName:kSettingsDebugImageName
withDefaultsKey:kDevViewSourceKey
......@@ -849,7 +815,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
- (TableViewDetailIconItem*)tableViewCatalogDetailItem {
return [self detailItemWithType:ItemTypeTableCellCatalog
return [self detailItemWithType:SettingsItemTypeTableCellCatalog
text:@"TableView Cell Catalog"
detailText:nil
iconImageName:kSettingsDebugImageName
......@@ -907,7 +873,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
if ([cell isKindOfClass:[TableViewDetailIconCell class]]) {
TableViewDetailIconCell* detailCell =
base::mac::ObjCCastStrict<TableViewDetailIconCell>(cell);
if (itemType == ItemTypePasswords) {
if (itemType == SettingsItemTypePasswords) {
scoped_refptr<password_manager::PasswordStore> passwordStore =
IOSChromePasswordStoreFactory::GetForBrowserState(
_browserState, ServiceAccessType::EXPLICIT_ACCESS);
......@@ -928,7 +894,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
switch (itemType) {
case ItemTypeMemoryDebugging: {
case SettingsItemTypeMemoryDebugging: {
SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
[switchCell.switchView addTarget:self
......@@ -936,7 +902,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
forControlEvents:UIControlEventValueChanged];
break;
}
case ItemTypeArticlesForYou: {
case SettingsItemTypeArticlesForYou: {
SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
[switchCell.switchView addTarget:self
......@@ -944,7 +910,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
forControlEvents:UIControlEventValueChanged];
break;
}
case ItemTypeViewSource: {
case SettingsItemTypeViewSource: {
#if BUILDFLAG(CHROMIUM_BRANDING) && !defined(NDEBUG)
SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
......@@ -956,7 +922,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
#endif // BUILDFLAG(CHROMIUM_BRANDING) && !defined(NDEBUG)
break;
}
case ItemTypeManagedDefaultSearchEngine: {
case SettingsItemTypeManagedDefaultSearchEngine: {
TableViewInfoButtonCell* managedCell =
base::mac::ObjCCastStrict<TableViewInfoButtonCell>(cell);
[managedCell.trailingButton
......@@ -988,7 +954,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
UIViewController<SettingsRootViewControlling>* controller;
switch (itemType) {
case ItemTypeSignInButton:
case SettingsItemTypeSignInButton:
signin_metrics::RecordSigninUserActionForAccessPoint(
signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS,
signin_metrics::PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO);
......@@ -997,58 +963,58 @@ NSString* kDevViewSourceKey = @"DevViewSource";
PROMO_ACTION_NO_SIGNIN_PROMO
completion:nil];
break;
case ItemTypeAccount:
case SettingsItemTypeAccount:
base::RecordAction(base::UserMetricsAction("Settings.MyAccount"));
controller = [[AccountsTableViewController alloc] initWithBrowser:_browser
closeSettingsOnAddAccount:NO];
break;
case ItemTypeSyncAndGoogleServices:
case ItemTypeGoogleServices:
case SettingsItemTypeSyncAndGoogleServices:
case SettingsItemTypeGoogleServices:
base::RecordAction(base::UserMetricsAction("Settings.GoogleServices"));
[self showGoogleServices];
break;
case ItemTypeGoogleSync:
case SettingsItemTypeGoogleSync:
base::RecordAction(base::UserMetricsAction("Settings.Sync"));
[self showGoogleSync];
break;
case ItemTypeDefaultBrowser:
case SettingsItemTypeDefaultBrowser:
base::RecordAction(
base::UserMetricsAction("Settings.ShowDefaultBrowser"));
controller = [[DefaultBrowserSettingsTableViewController alloc] init];
break;
case ItemTypeSearchEngine:
case SettingsItemTypeSearchEngine:
base::RecordAction(base::UserMetricsAction("EditSearchEngines"));
controller = [[SearchEngineTableViewController alloc]
initWithBrowserState:_browserState];
break;
case ItemTypePasswords:
case SettingsItemTypePasswords:
base::RecordAction(
base::UserMetricsAction("Options_ShowPasswordManager"));
[self showPasswords];
break;
case ItemTypeAutofillCreditCard:
case SettingsItemTypeAutofillCreditCard:
base::RecordAction(base::UserMetricsAction("AutofillCreditCardsViewed"));
controller = [[AutofillCreditCardTableViewController alloc]
initWithBrowser:_browser];
break;
case ItemTypeAutofillProfile:
case SettingsItemTypeAutofillProfile:
base::RecordAction(base::UserMetricsAction("AutofillAddressesViewed"));
controller = [[AutofillProfileTableViewController alloc]
initWithBrowserState:_browserState];
break;
case ItemTypeVoiceSearch:
case SettingsItemTypeVoiceSearch:
base::RecordAction(base::UserMetricsAction("Settings.VoiceSearch"));
controller = [[VoiceSearchTableViewController alloc]
initWithPrefs:_browserState->GetPrefs()];
break;
case ItemTypeSafetyCheck:
case SettingsItemTypeSafetyCheck:
[self showSafetyCheck];
break;
case ItemTypePrivacy:
case SettingsItemTypePrivacy:
base::RecordAction(base::UserMetricsAction("Settings.Privacy"));
[self showPrivacy];
break;
case ItemTypeLanguageSettings: {
case SettingsItemTypeLanguageSettings: {
base::RecordAction(base::UserMetricsAction("Settings.Language"));
LanguageSettingsMediator* mediator =
[[LanguageSettingsMediator alloc] initWithBrowserState:_browserState];
......@@ -1060,26 +1026,26 @@ NSString* kDevViewSourceKey = @"DevViewSource";
controller = languageSettingsTableViewController;
break;
}
case ItemTypeContentSettings:
case SettingsItemTypeContentSettings:
base::RecordAction(base::UserMetricsAction("Settings.ContentSettings"));
controller = [[ContentSettingsTableViewController alloc]
initWithBrowserState:_browserState];
break;
case ItemTypeBandwidth:
case SettingsItemTypeBandwidth:
base::RecordAction(base::UserMetricsAction("Settings.Bandwidth"));
controller = [[BandwidthManagementTableViewController alloc]
initWithBrowserState:_browserState];
break;
case ItemTypeAboutChrome:
case SettingsItemTypeAboutChrome:
base::RecordAction(base::UserMetricsAction("AboutChrome"));
controller = [[AboutChromeTableViewController alloc] init];
break;
case ItemTypeMemoryDebugging:
case ItemTypeViewSource:
case SettingsItemTypeMemoryDebugging:
case SettingsItemTypeViewSource:
// Taps on these don't do anything. They have a switch as accessory view
// and only the switch is tappable.
break;
case ItemTypeTableCellCatalog:
case SettingsItemTypeTableCellCatalog:
[self.navigationController
pushViewController:[[TableCellCatalogViewController alloc] init]
animated:YES];
......@@ -1124,8 +1090,8 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (void)memorySwitchToggled:(UISwitch*)sender {
NSIndexPath* switchPath =
[self.tableViewModel indexPathForItemType:ItemTypeMemoryDebugging
sectionIdentifier:SectionIdentifierDebug];
[self.tableViewModel indexPathForItemType:SettingsItemTypeMemoryDebugging
sectionIdentifier:SettingsSectionIdentifierDebug];
SettingsSwitchItem* switchItem =
base::mac::ObjCCastStrict<SettingsSwitchItem>(
......@@ -1137,9 +1103,9 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
- (void)articlesForYouSwitchToggled:(UISwitch*)sender {
NSIndexPath* switchPath =
[self.tableViewModel indexPathForItemType:ItemTypeArticlesForYou
sectionIdentifier:SectionIdentifierAdvanced];
NSIndexPath* switchPath = [self.tableViewModel
indexPathForItemType:SettingsItemTypeArticlesForYou
sectionIdentifier:SettingsSectionIdentifierAdvanced];
SettingsSwitchItem* switchItem =
base::mac::ObjCCastStrict<SettingsSwitchItem>(
......@@ -1153,8 +1119,8 @@ NSString* kDevViewSourceKey = @"DevViewSource";
#if BUILDFLAG(CHROMIUM_BRANDING) && !defined(NDEBUG)
- (void)viewSourceSwitchToggled:(UISwitch*)sender {
NSIndexPath* switchPath =
[self.tableViewModel indexPathForItemType:ItemTypeViewSource
sectionIdentifier:SectionIdentifierDebug];
[self.tableViewModel indexPathForItemType:SettingsItemTypeViewSource
sectionIdentifier:SettingsSectionIdentifierDebug];
SettingsSwitchItem* switchItem =
base::mac::ObjCCastStrict<SettingsSwitchItem>(
......@@ -1276,13 +1242,14 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
- (void)reloadAccountCell {
if (![self.tableViewModel hasItemForItemType:ItemTypeAccount
sectionIdentifier:SectionIdentifierAccount]) {
if (![self.tableViewModel
hasItemForItemType:SettingsItemTypeAccount
sectionIdentifier:SettingsSectionIdentifierAccount]) {
return;
}
NSIndexPath* accountCellIndexPath =
[self.tableViewModel indexPathForItemType:ItemTypeAccount
sectionIdentifier:SectionIdentifierAccount];
NSIndexPath* accountCellIndexPath = [self.tableViewModel
indexPathForItemType:SettingsItemTypeAccount
sectionIdentifier:SettingsSectionIdentifierAccount];
TableViewAccountItem* identityAccountItem =
base::mac::ObjCCast<TableViewAccountItem>(
[self.tableViewModel itemAtIndexPath:accountCellIndexPath]);
......@@ -1368,19 +1335,19 @@ NSString* kDevViewSourceKey = @"DevViewSource";
// Updates and reloads the Google service cell.
- (void)reloadSyncAndGoogleServicesCell {
if (base::FeatureList::IsEnabled(signin::kMobileIdentityConsistency)) {
bool googleSyncCellInitialized =
[self.tableViewModel hasItemForItemType:ItemTypeGoogleSync
sectionIdentifier:SectionIdentifierAccount];
bool googleSyncCellInitialized = [self.tableViewModel
hasItemForItemType:SettingsItemTypeGoogleSync
sectionIdentifier:SettingsSectionIdentifierAccount];
AuthenticationService* authService =
AuthenticationServiceFactory::GetForBrowserState(_browserState);
if (authService->IsAuthenticated()) {
if (!googleSyncCellInitialized) {
[self.tableViewModel addItem:[self googleSyncCellItem]
toSectionWithIdentifier:SectionIdentifierAccount];
toSectionWithIdentifier:SettingsSectionIdentifierAccount];
} else {
NSIndexPath* syncCellIndexPath =
[self.tableViewModel indexPathForItemType:ItemTypeGoogleSync
sectionIdentifier:SectionIdentifierAccount];
NSIndexPath* syncCellIndexPath = [self.tableViewModel
indexPathForItemType:SettingsItemTypeGoogleSync
sectionIdentifier:SettingsSectionIdentifierAccount];
TableViewDetailIconItem* detailIconItem =
base::mac::ObjCCast<TableViewDetailIconItem>(
[self.tableViewModel itemAtIndexPath:syncCellIndexPath]);
......@@ -1389,14 +1356,15 @@ NSString* kDevViewSourceKey = @"DevViewSource";
}
} else {
if (googleSyncCellInitialized) {
[self.tableViewModel removeItemWithType:ItemTypeGoogleSync
fromSectionWithIdentifier:SectionIdentifierAccount];
[self.tableViewModel
removeItemWithType:SettingsItemTypeGoogleSync
fromSectionWithIdentifier:SettingsSectionIdentifierAccount];
}
}
} else {
NSIndexPath* googleServicesCellIndexPath =
[self.tableViewModel indexPathForItemType:ItemTypeSyncAndGoogleServices
sectionIdentifier:SectionIdentifierAccount];
NSIndexPath* googleServicesCellIndexPath = [self.tableViewModel
indexPathForItemType:SettingsItemTypeSyncAndGoogleServices
sectionIdentifier:SettingsSectionIdentifierAccount];
SettingsImageDetailTextItem* googleServicesItem =
base::mac::ObjCCast<SettingsImageDetailTextItem>(
[self.tableViewModel itemAtIndexPath:googleServicesCellIndexPath]);
......@@ -1633,13 +1601,14 @@ NSString* kDevViewSourceKey = @"DevViewSource";
(SigninPromoViewConfigurator*)configurator
identityChanged:(BOOL)identityChanged {
DCHECK(!self.isSigninInProgress);
if (![self.tableViewModel hasItemForItemType:ItemTypeSigninPromo
sectionIdentifier:SectionIdentifierSignIn]) {
if (![self.tableViewModel
hasItemForItemType:SettingsItemTypeSigninPromo
sectionIdentifier:SettingsSectionIdentifierSignIn]) {
return;
}
NSIndexPath* signinPromoCellIndexPath =
[self.tableViewModel indexPathForItemType:ItemTypeSigninPromo
sectionIdentifier:SectionIdentifierSignIn];
NSIndexPath* signinPromoCellIndexPath = [self.tableViewModel
indexPathForItemType:SettingsItemTypeSigninPromo
sectionIdentifier:SettingsSectionIdentifierSignIn];
DCHECK(signinPromoCellIndexPath.item != NSNotFound);
TableViewSigninPromoItem* signinPromoItem =
base::mac::ObjCCast<TableViewSigninPromoItem>(
......
......@@ -7,6 +7,47 @@
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/ui/list_model/list_model.h"
// Sections used in Settings page.
typedef NS_ENUM(NSInteger, SettingsSectionIdentifier) {
SettingsSectionIdentifierSignIn = kSectionIdentifierEnumZero,
SettingsSectionIdentifierAccount,
SettingsSectionIdentifierBasics,
SettingsSectionIdentifierAdvanced,
SettingsSectionIdentifierInfo,
SettingsSectionIdentifierDebug,
SettingsSectionIdentifierDefaults,
};
// Item types used per Setting section.
typedef NS_ENUM(NSInteger, SettingsItemType) {
SettingsItemTypeSignInButton = kItemTypeEnumZero,
SettingsItemTypeSigninPromo,
SettingsItemTypeAccount,
SettingsItemTypeSyncAndGoogleServices,
SettingsItemTypeGoogleSync,
SettingsItemTypeGoogleServices,
SettingsItemTypeHeader,
SettingsItemTypeSearchEngine,
SettingsItemTypeManagedDefaultSearchEngine,
SettingsItemTypePasswords,
SettingsItemTypeAutofillCreditCard,
SettingsItemTypeAutofillProfile,
SettingsItemTypeVoiceSearch,
SettingsItemTypePrivacy,
SettingsItemTypeLanguageSettings,
SettingsItemTypeContentSettings,
SettingsItemTypeBandwidth,
SettingsItemTypeAboutChrome,
SettingsItemTypeMemoryDebugging,
SettingsItemTypeViewSource,
SettingsItemTypeTableCellCatalog,
SettingsItemTypeArticlesForYou,
SettingsItemTypeSafetyCheck,
SettingsItemTypeDefaultBrowser,
};
// The accessibility identifier of the settings TableView.
extern NSString* const kSettingsTableViewId;
......
// Copyright 2020 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/settings_table_view_controller.h"
#import "base/test/task_environment.h"
#import "components/sync/driver/mock_sync_service.h"
#import "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#import "ios/chrome/browser/main/test_browser.h"
#import "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service_fake.h"
#import "ios/chrome/browser/sync/profile_sync_service_factory.h"
#import "ios/chrome/browser/sync/sync_setup_service_factory.h"
#import "ios/chrome/browser/sync/sync_setup_service_mock.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/settings/cells/settings_image_detail_text_item.h"
#import "ios/chrome/browser/ui/settings/settings_table_view_controller_constants.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller_test.h"
#import "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/ios_chrome_scoped_testing_local_state.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/web/public/test/web_task_environment.h"
#import "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
#import "third_party/ocmock/OCMock/OCMock.h"
#import "third_party/ocmock/gtest_support.h"
#import "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using ::testing::NiceMock;
using ::testing::Return;
namespace {
std::unique_ptr<KeyedService> CreateMockSyncService(
web::BrowserState* context) {
return std::make_unique<NiceMock<syncer::MockSyncService>>();
}
std::unique_ptr<KeyedService> CreateMockSyncSetupService(
web::BrowserState* context) {
ChromeBrowserState* browser_state =
ChromeBrowserState::FromBrowserState(context);
return std::make_unique<SyncSetupServiceMock>(
ProfileSyncServiceFactory::GetForBrowserState(browser_state));
}
} // namespace
class SettingsTableViewControllerTest : public ChromeTableViewControllerTest {
public:
void SetUp() override {
ChromeTableViewControllerTest::SetUp();
TestChromeBrowserState::Builder builder;
builder.AddTestingFactory(ProfileSyncServiceFactory::GetInstance(),
base::BindRepeating(&CreateMockSyncService));
builder.AddTestingFactory(SyncSetupServiceFactory::GetInstance(),
base::BindRepeating(&CreateMockSyncSetupService));
builder.AddTestingFactory(
ios::TemplateURLServiceFactory::GetInstance(),
ios::TemplateURLServiceFactory::GetDefaultFactory());
builder.AddTestingFactory(
AuthenticationServiceFactory::GetInstance(),
base::BindRepeating(
&AuthenticationServiceFake::CreateAuthenticationService));
chrome_browser_state_ = builder.Build();
WebStateList* web_state_list = nullptr;
browser_ = std::make_unique<TestBrowser>(chrome_browser_state_.get(),
web_state_list);
sync_setup_service_mock_ = static_cast<SyncSetupServiceMock*>(
SyncSetupServiceFactory::GetForBrowserState(
chrome_browser_state_.get()));
sync_service_mock_ = static_cast<syncer::MockSyncService*>(
ProfileSyncServiceFactory::GetForBrowserState(
chrome_browser_state_.get()));
auth_service_ = static_cast<AuthenticationServiceFake*>(
AuthenticationServiceFactory::GetInstance()->GetForBrowserState(
chrome_browser_state_.get()));
fake_identity_ = [FakeChromeIdentity identityWithEmail:@"foo1@gmail.com"
gaiaID:@"foo1ID"
name:@"Fake Foo 1"];
}
void TearDown() override {
[static_cast<SettingsTableViewController*>(controller())
settingsWillBeDismissed];
ChromeTableViewControllerTest::TearDown();
}
ChromeTableViewController* InstantiateController() override {
return [[SettingsTableViewController alloc]
initWithBrowser:browser_.get()
dispatcher:static_cast<id<ApplicationCommands, BrowserCommands,
BrowsingDataCommands>>(
browser_->GetCommandDispatcher())];
}
void SetupSyncServiceEnabledExpectations() {
ON_CALL(*sync_setup_service_mock_, IsSyncEnabled())
.WillByDefault(Return(true));
ON_CALL(*sync_setup_service_mock_, IsSyncingAllDataTypes())
.WillByDefault(Return(true));
ON_CALL(*sync_setup_service_mock_, HasFinishedInitialSetup())
.WillByDefault(Return(true));
ON_CALL(*sync_service_mock_, GetTransportState())
.WillByDefault(Return(syncer::SyncService::TransportState::ACTIVE));
ON_CALL(*sync_service_mock_->GetMockUserSettings(), IsFirstSetupComplete())
.WillByDefault(Return(true));
}
protected:
// Needed for test browser state created by TestChromeBrowserState().
web::WebTaskEnvironment task_environment_;
IOSChromeScopedTestingLocalState local_state_;
FakeChromeIdentity* fake_identity_ = nullptr;
AuthenticationServiceFake* auth_service_ = nullptr;
syncer::MockSyncService* sync_service_mock_ = nullptr;
SyncSetupServiceMock* sync_setup_service_mock_ = nullptr;
std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
std::unique_ptr<TestBrowser> browser_;
SettingsTableViewController* controller_ = nullptr;
};
// Verifies that the Sync & Google Services icon displays Sync on state when
// the user has turned on sync during sign-in.
TEST_F(SettingsTableViewControllerTest, SyncOn) {
SetupSyncServiceEnabledExpectations();
ON_CALL(*sync_setup_service_mock_, GetSyncServiceState())
.WillByDefault(Return(SyncSetupService::kNoSyncServiceError));
auth_service_->SignIn(fake_identity_);
CreateController();
CheckController();
NSArray* account_items = [controller().tableViewModel
itemsInSectionWithIdentifier:SettingsSectionIdentifier::
SettingsSectionIdentifierAccount];
ASSERT_EQ(2U, account_items.count);
SettingsImageDetailTextItem* sync_item =
static_cast<SettingsImageDetailTextItem*>(account_items[1]);
ASSERT_NSEQ(sync_item.text, l10n_util::GetNSString(
IDS_IOS_GOOGLE_SERVICES_SYNC_SETTINGS_TITLE));
ASSERT_NSEQ(
sync_item.detailText,
l10n_util::GetNSString(IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SYNC_ON));
}
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