Commit 2b549d86 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Add custom search engines list in Search Engine Settings.

This CL changes how search engines are displayed in Search Engine Settings.

Previous(1 list):
  1. search engines that are prepopulated or created by policy.

Current(2 lists):
  1. Search engines that are prepopulated or created by policy, and possibly
     one custom search engine at the end if it's selected as default search
     engine;
  2. All remaining search engines.

Unittests are also updated.

Bug: 433824
Change-Id: Ib70a18f0544101760c331bb349ee9818956ed231
Reviewed-on: https://chromium-review.googlesource.com/c/1323509Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606776}
parent 6105631e
......@@ -1313,6 +1313,9 @@ Handoff must also be enabled in the General section of Settings, and your device
<message name="IDS_IOS_SEARCH_ENGINE_SETTING_TITLE" desc="The title for Search Engine selection setting [iOS only]">
Search Engine
</message>
<message name="IDS_IOS_SEARCH_ENGINE_SETTING_CUSTOM_SECTION_HEADER" desc="The header for custom search engines section in Search Engine selection setting [iOS only]">
Recently Visited
</message>
<message name="IDS_IOS_SETTINGS_SITE_COPY_BUTTON" desc="Button that the user can press to copy the site to clipboard. [Length: 12em]">
Copy
</message>
......
......@@ -17,6 +17,7 @@
#import "ios/chrome/browser/ui/settings/cells/settings_text_item.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/Palettes/src/MaterialPalettes.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -26,13 +27,19 @@
namespace {
typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierSearchEngines = kSectionIdentifierEnumZero,
SectionIdentifierPriorSearchEngines = kSectionIdentifierEnumZero,
SectionIdentifierCustomSearchEngines,
};
typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeSearchEnginesEngine = kItemTypeEnumZero,
ItemTypePriorSearchEnginesEngine = kItemTypeEnumZero,
ItemTypeCustomSearchEnginesEngineHeader,
ItemTypeCustomSearchEnginesEngine,
};
constexpr base::TimeDelta kMaxVisitAge = base::TimeDelta::FromDays(2);
const size_t kMaxcustomSearchEngines = 3;
} // namespace
@interface SearchEngineSettingsCollectionViewController ()<
......@@ -40,10 +47,17 @@ typedef NS_ENUM(NSInteger, ItemType) {
@end
@implementation SearchEngineSettingsCollectionViewController {
TemplateURLService* templateURLService_; // weak
std::unique_ptr<SearchEngineObserverBridge> observer_;
TemplateURLService* _templateURLService; // weak
std::unique_ptr<SearchEngineObserverBridge> _observer;
// Prevent unnecessary notifications when we write to the setting.
BOOL updatingBackend_;
BOOL _updatingBackend;
// The first list in the page which contains prepopulted search engines and
// search engines that are created by policy, and possibly one custom search
// engine if it's selected as default search engine.
std::vector<TemplateURL*> _priorSearchEngines;
// The second list in the page which contains all remaining custom search
// engines.
std::vector<TemplateURL*> _customSearchEngines;
}
#pragma mark Initialization
......@@ -54,11 +68,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
self =
[super initWithLayout:layout style:CollectionViewControllerStyleAppBar];
if (self) {
templateURLService_ =
_templateURLService =
ios::TemplateURLServiceFactory::GetForBrowserState(browserState);
observer_ =
std::make_unique<SearchEngineObserverBridge>(self, templateURLService_);
templateURLService_->Load();
_observer =
std::make_unique<SearchEngineObserverBridge>(self, _templateURLService);
_templateURLService->Load();
[self setTitle:l10n_util::GetNSString(IDS_IOS_SEARCH_ENGINE_SETTING_TITLE)];
[self setCollectionViewAccessibilityIdentifier:@"Search Engine"];
// TODO(crbug.com/764578): -loadModel should not be called from
......@@ -71,26 +85,46 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)loadModel {
[super loadModel];
CollectionViewModel* model = self.collectionViewModel;
NSArray* values = [self allValues];
[self loadSearchEngines];
// Do not add any sections if there are no search engines.
if (![values count]) {
return;
// Add prior search engines.
if (_priorSearchEngines.size() > 0) {
[model addSectionWithIdentifier:SectionIdentifierPriorSearchEngines];
for (TemplateURL* url : _priorSearchEngines) {
SettingsTextItem* engine = [[SettingsTextItem alloc]
initWithType:ItemTypePriorSearchEnginesEngine];
[engine setText:base::SysUTF16ToNSString(url->short_name())];
if (url == _templateURLService->GetDefaultSearchProvider()) {
[engine setAccessoryType:MDCCollectionViewCellAccessoryCheckmark];
}
[model addItem:engine
toSectionWithIdentifier:SectionIdentifierPriorSearchEngines];
}
}
[model addSectionWithIdentifier:SectionIdentifierSearchEngines];
for (NSUInteger i = 0; i < values.count; i++) {
NSString* value = values[i];
BOOL checked = [value isEqualToString:[self currentValue]];
// Add custom search engines.
if (_customSearchEngines.size() > 0) {
[model addSectionWithIdentifier:SectionIdentifierCustomSearchEngines];
SettingsTextItem* engine =
[[SettingsTextItem alloc] initWithType:ItemTypeSearchEnginesEngine];
[engine setText:value];
if (checked) {
[engine setAccessoryType:MDCCollectionViewCellAccessoryCheckmark];
SettingsTextItem* header = [[SettingsTextItem alloc]
initWithType:ItemTypeCustomSearchEnginesEngineHeader];
header.text = l10n_util::GetNSString(
IDS_IOS_SEARCH_ENGINE_SETTING_CUSTOM_SECTION_HEADER);
header.textColor = [[MDCPalette greyPalette] tint500];
[model setHeader:header
forSectionWithIdentifier:SectionIdentifierCustomSearchEngines];
for (TemplateURL* url : _customSearchEngines) {
SettingsTextItem* engine = [[SettingsTextItem alloc]
initWithType:ItemTypeCustomSearchEnginesEngine];
[engine setText:base::SysUTF16ToNSString(url->short_name())];
if (url == _templateURLService->GetDefaultSearchProvider()) {
[engine setAccessoryType:MDCCollectionViewCellAccessoryCheckmark];
}
[model addItem:engine
toSectionWithIdentifier:SectionIdentifierCustomSearchEngines];
}
[model addItem:engine
toSectionWithIdentifier:SectionIdentifierSearchEngines];
}
}
......@@ -103,7 +137,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
// Only handle taps on search engine items.
CollectionViewItem* selectedItem = [model itemAtIndexPath:indexPath];
if (selectedItem.type != ItemTypeSearchEnginesEngine) {
if (selectedItem.type != ItemTypePriorSearchEnginesEngine &&
selectedItem.type != ItemTypeCustomSearchEnginesEngine) {
return;
}
......@@ -115,19 +150,39 @@ typedef NS_ENUM(NSInteger, ItemType) {
return;
}
// Iterate through the engines and remove the checkmark from any that have it.
NSMutableArray* modifiedItems = [NSMutableArray array];
for (CollectionViewItem* item in
[model itemsInSectionWithIdentifier:SectionIdentifierSearchEngines]) {
if (item.type != ItemTypeSearchEnginesEngine) {
continue;
}
SettingsTextItem* textItem =
base::mac::ObjCCastStrict<SettingsTextItem>(item);
if (textItem.accessoryType == MDCCollectionViewCellAccessoryCheckmark) {
textItem.accessoryType = MDCCollectionViewCellAccessoryNone;
[modifiedItems addObject:textItem];
// Iterate through the engines and remove the checkmark from any that have it.
if ([model
hasSectionForSectionIdentifier:SectionIdentifierPriorSearchEngines]) {
for (CollectionViewItem* item in
[model itemsInSectionWithIdentifier:
SectionIdentifierPriorSearchEngines]) {
if (item.type != ItemTypePriorSearchEnginesEngine) {
continue;
}
SettingsTextItem* textItem =
base::mac::ObjCCastStrict<SettingsTextItem>(item);
if (textItem.accessoryType == MDCCollectionViewCellAccessoryCheckmark) {
textItem.accessoryType = MDCCollectionViewCellAccessoryNone;
[modifiedItems addObject:textItem];
}
}
}
if ([model hasSectionForSectionIdentifier:
SectionIdentifierCustomSearchEngines]) {
for (CollectionViewItem* item in
[model itemsInSectionWithIdentifier:
SectionIdentifierCustomSearchEngines]) {
if (item.type != ItemTypeCustomSearchEnginesEngine) {
continue;
}
SettingsTextItem* textItem =
base::mac::ObjCCastStrict<SettingsTextItem>(item);
if (textItem.accessoryType == MDCCollectionViewCellAccessoryCheckmark) {
textItem.accessoryType = MDCCollectionViewCellAccessoryNone;
[modifiedItems addObject:textItem];
}
}
}
......@@ -139,39 +194,89 @@ typedef NS_ENUM(NSInteger, ItemType) {
[modifiedItems addObject:newDefaultEngine];
// Set the new engine as the default.
[self setValueFromIndex:[model indexInItemTypeForIndexPath:indexPath]];
if (selectedItem.type == ItemTypePriorSearchEnginesEngine)
[self setDefaultToPriorSearchEngineAtIndex:
[model indexInItemTypeForIndexPath:indexPath]];
else
[self setDefaultToCustomSearchEngineAtIndex:
[model indexInItemTypeForIndexPath:indexPath]];
[self reconfigureCellsForItems:modifiedItems];
}
#pragma mark Internal methods
- (NSArray*)allValues {
std::vector<TemplateURL*> urls = templateURLService_->GetTemplateURLs();
NSMutableArray* items = [NSMutableArray arrayWithCapacity:urls.size()];
for (std::vector<TemplateURL*>::const_iterator iter = urls.begin();
iter != urls.end(); ++iter) {
[items addObject:base::SysUTF16ToNSString((*iter)->short_name())];
// Loads all TemplateURLs from TemplateURLService and classifies them into
// |_priorSearchEngines| and |_customSearchEngines|. If a TemplateURL is
// prepopulated, created by policy or the default search engine, it will get
// into the first list, otherwise the second list.
- (void)loadSearchEngines {
std::vector<TemplateURL*> urls = _templateURLService->GetTemplateURLs();
_priorSearchEngines.clear();
_priorSearchEngines.reserve(urls.size());
_customSearchEngines.clear();
_customSearchEngines.reserve(urls.size());
// Classify TemplateURLs.
for (TemplateURL* url : urls) {
if (_templateURLService->IsPrepopulatedOrCreatedByPolicy(url) ||
url == _templateURLService->GetDefaultSearchProvider())
_priorSearchEngines.push_back(url);
else
_customSearchEngines.push_back(url);
}
return items;
// Sort |fixedCutomeSearchEngines_| by TemplateURL's prepopulate_id. If
// prepopulated_id == 0, it's a custom search engine and should be put in the
// end of the list.
std::sort(_priorSearchEngines.begin(), _priorSearchEngines.end(),
[](const TemplateURL* lhs, const TemplateURL* rhs) {
if (lhs->prepopulate_id() == 0)
return false;
if (rhs->prepopulate_id() == 0)
return true;
return lhs->prepopulate_id() < rhs->prepopulate_id();
});
// Partially sort |_customSearchEngines| by TemplateURL's last_visited time.
auto begin = _customSearchEngines.begin();
auto end = _customSearchEngines.end();
auto pivot =
begin + std::min(kMaxcustomSearchEngines, _customSearchEngines.size());
std::partial_sort(begin, pivot, end,
[](const TemplateURL* lhs, const TemplateURL* rhs) {
return lhs->last_visited() > rhs->last_visited();
});
// Keep the search engines visited within |kMaxVisitAge| and erase others.
const base::Time cutoff = base::Time::Now() - kMaxVisitAge;
auto cutBegin = std::find_if(begin, pivot, [cutoff](const TemplateURL* url) {
return url->last_visited() < cutoff;
});
_customSearchEngines.erase(cutBegin, end);
}
- (NSString*)currentValue {
return base::SysUTF16ToNSString(
templateURLService_->GetDefaultSearchProvider()->short_name());
// Sets the search engine at |index| in prior section as default search engine.
- (void)setDefaultToPriorSearchEngineAtIndex:(NSUInteger)index {
DCHECK_GE(index, 0U);
DCHECK_LT(index, _priorSearchEngines.size());
_updatingBackend = YES;
_templateURLService->SetUserSelectedDefaultSearchProvider(
_priorSearchEngines[index]);
_updatingBackend = NO;
}
- (void)setValueFromIndex:(NSUInteger)index {
std::vector<TemplateURL*> urls = templateURLService_->GetTemplateURLs();
// Sets the search engine at |index| in custom section as default search engine.
- (void)setDefaultToCustomSearchEngineAtIndex:(NSUInteger)index {
DCHECK_GE(index, 0U);
DCHECK_LT(index, urls.size());
updatingBackend_ = YES;
templateURLService_->SetUserSelectedDefaultSearchProvider(urls[index]);
updatingBackend_ = NO;
DCHECK_LT(index, _customSearchEngines.size());
_updatingBackend = YES;
_templateURLService->SetUserSelectedDefaultSearchProvider(
_customSearchEngines[index]);
_updatingBackend = NO;
}
- (void)searchEngineChanged {
if (!updatingBackend_)
if (!_updatingBackend)
[self reloadData];
}
......
......@@ -48,38 +48,44 @@ class SearchEngineSettingsCollectionViewControllerTest
initWithBrowserState:chrome_browser_state_.get()];
}
std::unique_ptr<TemplateURL> NewTemplateUrl(const std::string& shortName) {
// Adds a prepopulated search engine to TemplateURLService.
TemplateURL* AddPriorSearchEngine(const std::string& short_name,
int prepopulate_id,
bool set_default) {
TemplateURLData data;
data.SetShortName(base::ASCIIToUTF16(shortName));
return std::unique_ptr<TemplateURL>(new TemplateURL(data));
data.SetShortName(base::ASCIIToUTF16(short_name));
data.SetURL("https://chromium.test/index.php?q={searchTerms}");
data.prepopulate_id = prepopulate_id;
TemplateURL* url =
template_url_service_->Add(std::make_unique<TemplateURL>(data));
if (set_default)
template_url_service_->SetUserSelectedDefaultSearchProvider(url);
return url;
}
void FillTemplateUrlService() {
TemplateURL* defaultProvider =
template_url_service_->Add(NewTemplateUrl("first_url"));
template_url_service_->SetUserSelectedDefaultSearchProvider(
defaultProvider);
template_url_service_->Add(NewTemplateUrl("second_url"));
template_url_service_->Add(NewTemplateUrl("third_url"));
// Adds a custom search engine to TemplateURLService.
TemplateURL* AddCustomSearchEngine(const std::string& short_name,
base::Time last_visited_time,
bool set_default) {
TemplateURLData data;
data.SetShortName(base::ASCIIToUTF16(short_name));
data.SetURL("https://chromium.test/index.php?q={searchTerms}");
data.last_visited = last_visited_time;
TemplateURL* url =
template_url_service_->Add(std::make_unique<TemplateURL>(data));
if (set_default)
template_url_service_->SetUserSelectedDefaultSearchProvider(url);
return url;
}
void CheckModelMatchesTemplateURLs() {
TemplateURLService::TemplateURLVector urls =
template_url_service_->GetTemplateURLs();
EXPECT_EQ(1, NumberOfSections());
ASSERT_EQ(urls.size(),
static_cast<unsigned int>(NumberOfItemsInSection(0)));
for (unsigned int i = 0; i < urls.size(); ++i) {
BOOL isDefault =
template_url_service_->GetDefaultSearchProvider() == urls[i];
CheckTextCellTitle(base::SysUTF16ToNSString(urls[i]->short_name()), 0, i);
SettingsTextItem* textItem = base::mac::ObjCCastStrict<SettingsTextItem>(
GetCollectionViewItem(0, i));
EXPECT_EQ(isDefault ? MDCCollectionViewCellAccessoryCheckmark
: MDCCollectionViewCellAccessoryNone,
textItem.accessoryType);
}
// Checks if a text cell in the CollectionView has a check mark.
void CheckTextCellChecked(bool expect_checked, int section, int item) {
SettingsTextItem* text_item = base::mac::ObjCCastStrict<SettingsTextItem>(
GetCollectionViewItem(section, item));
ASSERT_TRUE(text_item);
EXPECT_EQ(expect_checked ? MDCCollectionViewCellAccessoryCheckmark
: MDCCollectionViewCellAccessoryNone,
text_item.accessoryType);
}
web::TestWebThreadBundle thread_bundle_;
......@@ -87,60 +93,170 @@ class SearchEngineSettingsCollectionViewControllerTest
TemplateURLService* template_url_service_; // weak
};
// Tests that no items are shown if TemplateURLService is empty.
TEST_F(SearchEngineSettingsCollectionViewControllerTest, TestNoUrl) {
CreateController();
CheckController();
EXPECT_EQ(0, NumberOfSections());
}
TEST_F(SearchEngineSettingsCollectionViewControllerTest, TestWithUrlsLoaded) {
FillTemplateUrlService();
// Tests that items are displayed correctly when TemplateURLService is filled
// and a prepopulated search engine is selected as default.
TEST_F(SearchEngineSettingsCollectionViewControllerTest,
TestUrlsLoadedWithPrepopulatedSearchEngineAsDefault) {
AddPriorSearchEngine("prepopulated-3", 3, false);
AddPriorSearchEngine("prepopulated-1", 1, false);
AddPriorSearchEngine("prepopulated-2", 2, true);
AddCustomSearchEngine(
"custom-4", base::Time::Now() - base::TimeDelta::FromDays(10), false);
AddCustomSearchEngine(
"custom-1", base::Time::Now() - base::TimeDelta::FromSeconds(10), false);
AddCustomSearchEngine(
"custom-3", base::Time::Now() - base::TimeDelta::FromHours(10), false);
AddCustomSearchEngine(
"custom-2", base::Time::Now() - base::TimeDelta::FromMinutes(10), false);
CreateController();
CheckController();
ASSERT_EQ(2, NumberOfSections());
ASSERT_EQ(3, NumberOfItemsInSection(0));
CheckTextCellTitle(@"prepopulated-1", 0, 0);
CheckTextCellChecked(false, 0, 0);
CheckTextCellTitle(@"prepopulated-2", 0, 1);
CheckTextCellChecked(true, 0, 1);
CheckTextCellTitle(@"prepopulated-3", 0, 2);
CheckTextCellChecked(false, 0, 2);
ASSERT_EQ(3, NumberOfItemsInSection(1));
CheckTextCellTitle(@"custom-1", 1, 0);
CheckTextCellChecked(false, 1, 0);
CheckTextCellTitle(@"custom-2", 1, 1);
CheckTextCellChecked(false, 1, 1);
CheckTextCellTitle(@"custom-3", 1, 2);
CheckTextCellChecked(false, 1, 2);
}
// Tests that items are displayed correctly when TemplateURLService is filled
// and a custom search engine is selected as default.
TEST_F(SearchEngineSettingsCollectionViewControllerTest,
TestUrlsLoadedWithCustomSearchEngineAsDefault) {
AddPriorSearchEngine("prepopulated-3", 3, false);
AddPriorSearchEngine("prepopulated-1", 1, false);
AddPriorSearchEngine("prepopulated-2", 2, false);
AddCustomSearchEngine(
"custom-4", base::Time::Now() - base::TimeDelta::FromDays(10), false);
AddCustomSearchEngine(
"custom-1", base::Time::Now() - base::TimeDelta::FromSeconds(10), false);
AddCustomSearchEngine(
"custom-3", base::Time::Now() - base::TimeDelta::FromHours(10), false);
AddCustomSearchEngine(
"custom-2", base::Time::Now() - base::TimeDelta::FromMinutes(10), true);
CreateController();
CheckModelMatchesTemplateURLs();
CheckController();
ASSERT_EQ(2, NumberOfSections());
ASSERT_EQ(4, NumberOfItemsInSection(0));
CheckTextCellTitle(@"prepopulated-1", 0, 0);
CheckTextCellChecked(false, 0, 0);
CheckTextCellTitle(@"prepopulated-2", 0, 1);
CheckTextCellChecked(false, 0, 1);
CheckTextCellTitle(@"prepopulated-3", 0, 2);
CheckTextCellChecked(false, 0, 2);
CheckTextCellTitle(@"custom-2", 0, 3);
CheckTextCellChecked(true, 0, 3);
ASSERT_EQ(2, NumberOfItemsInSection(1));
CheckTextCellTitle(@"custom-1", 1, 0);
CheckTextCellChecked(false, 1, 0);
CheckTextCellTitle(@"custom-3", 1, 1);
CheckTextCellChecked(false, 1, 1);
}
TEST_F(SearchEngineSettingsCollectionViewControllerTest, TestWithAddedUrl) {
FillTemplateUrlService();
// Tests that when TemplateURLService add or remove TemplateURLs, or update
// default search engine, the controller will update the displayed items.
TEST_F(SearchEngineSettingsCollectionViewControllerTest,
TestUrlModifiedByService) {
TemplateURL* url_1 = AddPriorSearchEngine("prepopulated-1", 1, true);
CreateController();
CheckController();
ASSERT_EQ(1, NumberOfSections());
ASSERT_EQ(1, NumberOfItemsInSection(0));
CheckTextCellTitle(@"prepopulated-1", 0, 0);
CheckTextCellChecked(true, 0, 0);
TemplateURL* url_2 = AddPriorSearchEngine("prepopulated-2", 2, false);
TemplateURL* newUrl = template_url_service_->Add(NewTemplateUrl("new_url"));
CheckModelMatchesTemplateURLs();
ASSERT_EQ(1, NumberOfSections());
ASSERT_EQ(2, NumberOfItemsInSection(0));
CheckTextCellTitle(@"prepopulated-1", 0, 0);
CheckTextCellChecked(true, 0, 0);
CheckTextCellTitle(@"prepopulated-2", 0, 1);
CheckTextCellChecked(false, 0, 1);
template_url_service_->SetUserSelectedDefaultSearchProvider(newUrl);
CheckModelMatchesTemplateURLs();
template_url_service_->SetUserSelectedDefaultSearchProvider(url_2);
DCHECK(newUrl != template_url_service_->GetTemplateURLs()[0]);
template_url_service_->SetUserSelectedDefaultSearchProvider(
template_url_service_->GetTemplateURLs()[0]);
template_url_service_->Remove(newUrl);
CheckModelMatchesTemplateURLs();
ASSERT_EQ(1, NumberOfSections());
ASSERT_EQ(2, NumberOfItemsInSection(0));
CheckTextCellTitle(@"prepopulated-1", 0, 0);
CheckTextCellChecked(false, 0, 0);
CheckTextCellTitle(@"prepopulated-2", 0, 1);
CheckTextCellChecked(true, 0, 1);
template_url_service_->SetUserSelectedDefaultSearchProvider(url_1);
template_url_service_->Remove(url_2);
ASSERT_EQ(1, NumberOfSections());
ASSERT_EQ(1, NumberOfItemsInSection(0));
CheckTextCellTitle(@"prepopulated-1", 0, 0);
CheckTextCellChecked(true, 0, 0);
}
// Tests that when user change default search engine, all items can be displayed
// correctly and the change can be synced to the prefs.
TEST_F(SearchEngineSettingsCollectionViewControllerTest, TestChangeProvider) {
FillTemplateUrlService();
TemplateURL* url_1 = AddPriorSearchEngine("prepopulated-1", 1, false);
TemplateURL* url_2 = AddPriorSearchEngine("prepopulated-2", 2, true);
CreateController();
CheckController();
[controller() collectionView:[controller() collectionView]
didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
EXPECT_EQ(template_url_service_->GetTemplateURLs()[0],
template_url_service_->GetDefaultSearchProvider());
CheckModelMatchesTemplateURLs();
ASSERT_EQ(1, NumberOfSections());
ASSERT_EQ(2, NumberOfItemsInSection(0));
CheckTextCellTitle(@"prepopulated-1", 0, 0);
CheckTextCellChecked(true, 0, 0);
CheckTextCellTitle(@"prepopulated-2", 0, 1);
CheckTextCellChecked(false, 0, 1);
EXPECT_EQ(url_1, template_url_service_->GetDefaultSearchProvider());
[controller() collectionView:[controller() collectionView]
didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
TemplateURL* url = template_url_service_->GetTemplateURLs()[1];
EXPECT_EQ(url, template_url_service_->GetDefaultSearchProvider());
ASSERT_EQ(1, NumberOfSections());
ASSERT_EQ(2, NumberOfItemsInSection(0));
CheckTextCellTitle(@"prepopulated-1", 0, 0);
CheckTextCellChecked(false, 0, 0);
CheckTextCellTitle(@"prepopulated-2", 0, 1);
CheckTextCellChecked(true, 0, 1);
EXPECT_EQ(url_2, template_url_service_->GetDefaultSearchProvider());
// Check that the selection was written back to the prefs.
const base::DictionaryValue* searchProviderDict =
chrome_browser_state_->GetTestingPrefService()->GetDictionary(
DefaultSearchManager::kDefaultSearchProviderDataPrefName);
EXPECT_TRUE(searchProviderDict);
base::string16 shortName;
ASSERT_TRUE(searchProviderDict);
base::string16 short_name;
EXPECT_TRUE(searchProviderDict->GetString(DefaultSearchManager::kShortName,
&shortName));
EXPECT_EQ(url->short_name(), shortName);
CheckModelMatchesTemplateURLs();
&short_name));
EXPECT_EQ(url_2->short_name(), short_name);
}
} // namespace
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