This source file includes following definitions.
- CreatePrepopulateTemplateURL
- TEST
#include "base/memory/scoped_vector.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
TemplateURL* CreatePrepopulateTemplateURL(int prepopulate_id,
const std::string& keyword,
TemplateURLID id) {
TemplateURLData data;
data.prepopulate_id = prepopulate_id;
data.SetKeyword(base::ASCIIToUTF16(keyword));
data.id = id;
return new TemplateURL(NULL, data);
}
};
TEST(TemplateURLServiceUtilTest, RemoveDuplicatePrepopulateIDs) {
ScopedVector<TemplateURL> prepopulated_turls;
TemplateURLService::TemplateURLVector local_turls;
STLElementDeleter<TemplateURLService::TemplateURLVector> local_turls_deleter(
&local_turls);
prepopulated_turls.push_back(CreatePrepopulateTemplateURL(1, "winner4", 1));
prepopulated_turls.push_back(CreatePrepopulateTemplateURL(2, "xxx", 2));
prepopulated_turls.push_back(CreatePrepopulateTemplateURL(3, "yyy", 3));
local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner1", 4));
local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner2", 5));
local_turls.push_back(CreatePrepopulateTemplateURL(0, "winner3", 6));
size_t num_non_prepopulated_urls = local_turls.size();
local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser1", 7));
local_turls.push_back(CreatePrepopulateTemplateURL(1, "loser2", 8));
local_turls.push_back(CreatePrepopulateTemplateURL(1, "winner4", 9));
local_turls.push_back(CreatePrepopulateTemplateURL(2, "loser3", 10));
local_turls.push_back(CreatePrepopulateTemplateURL(2, "xxx", 11));
TemplateURL* default_turl = CreatePrepopulateTemplateURL(2, "winner5", 12);
local_turls.push_back(default_turl);
local_turls.push_back(CreatePrepopulateTemplateURL(3, "winner6", 13));
local_turls.push_back(CreatePrepopulateTemplateURL(3, "loser5", 14));
local_turls.push_back(CreatePrepopulateTemplateURL(3, "loser6", 15));
RemoveDuplicatePrepopulateIDs(NULL, prepopulated_turls, default_turl,
&local_turls, NULL);
EXPECT_EQ(local_turls.size(),
prepopulated_turls.size() + num_non_prepopulated_urls);
for (TemplateURLService::TemplateURLVector::const_iterator itr =
local_turls.begin(); itr != local_turls.end(); ++itr) {
EXPECT_TRUE(
StartsWith((*itr)->keyword(), base::ASCIIToUTF16("winner"), true));
}
}