Index: chrome/browser/webdata/keyword_table_unittest.cc |
diff --git a/chrome/browser/webdata/keyword_table_unittest.cc b/chrome/browser/webdata/keyword_table_unittest.cc |
index b8483020e7bd0fbe0b5f991e60a59c373efa7743..3af911b68ddf38c05f5626cb72ba171c373b4e0c 100644 |
--- a/chrome/browser/webdata/keyword_table_unittest.cc |
+++ b/chrome/browser/webdata/keyword_table_unittest.cc |
@@ -31,10 +31,17 @@ class KeywordTableTest : public testing::Test { |
virtual void SetUp() { |
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
file_ = temp_dir_.path().AppendASCII("TestWebDatabase"); |
+ |
+ table_.reset(new KeywordTable); |
+ db_.reset(new WebDatabase); |
+ db_->AddTable(table_.get()); |
+ ASSERT_EQ(sql::INIT_OK, db_->Init(file_, std::string())); |
} |
base::FilePath file_; |
base::ScopedTempDir temp_dir_; |
+ scoped_ptr<KeywordTable> table_; |
+ scoped_ptr<WebDatabase> db_; |
private: |
DISALLOW_COPY_AND_ASSIGN(KeywordTableTest); |
@@ -42,10 +49,6 @@ class KeywordTableTest : public testing::Test { |
TEST_F(KeywordTableTest, Keywords) { |
- WebDatabase db; |
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); |
- KeywordTable* keyword_table = db.GetKeywordTable(); |
- |
TemplateURLData keyword; |
keyword.short_name = ASCIIToUTF16("short_name"); |
keyword.SetKeyword(ASCIIToUTF16("keyword")); |
@@ -63,10 +66,10 @@ TEST_F(KeywordTableTest, Keywords) { |
keyword.created_by_policy = true; |
keyword.usage_count = 32; |
keyword.prepopulate_id = 10; |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
KeywordTable::Keywords keywords; |
- EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); |
+ EXPECT_TRUE(table_->GetKeywords(&keywords)); |
EXPECT_EQ(1U, keywords.size()); |
const TemplateURLData& restored_keyword = keywords.front(); |
@@ -92,20 +95,16 @@ TEST_F(KeywordTableTest, Keywords) { |
EXPECT_EQ(keyword.usage_count, restored_keyword.usage_count); |
EXPECT_EQ(keyword.prepopulate_id, restored_keyword.prepopulate_id); |
- EXPECT_TRUE(keyword_table->RemoveKeyword(restored_keyword.id)); |
+ EXPECT_TRUE(table_->RemoveKeyword(restored_keyword.id)); |
KeywordTable::Keywords empty_keywords; |
- EXPECT_TRUE(keyword_table->GetKeywords(&empty_keywords)); |
+ EXPECT_TRUE(table_->GetKeywords(&empty_keywords)); |
EXPECT_EQ(0U, empty_keywords.size()); |
} |
TEST_F(KeywordTableTest, KeywordMisc) { |
- WebDatabase db; |
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); |
- KeywordTable* keyword_table = db.GetKeywordTable(); |
- |
- EXPECT_EQ(kInvalidTemplateURLID, keyword_table->GetDefaultSearchProviderID()); |
- EXPECT_EQ(0, keyword_table->GetBuiltinKeywordVersion()); |
+ EXPECT_EQ(kInvalidTemplateURLID, table_->GetDefaultSearchProviderID()); |
+ EXPECT_EQ(0, table_->GetBuiltinKeywordVersion()); |
TemplateURLData keyword; |
keyword.short_name = ASCIIToUTF16("short_name"); |
@@ -124,20 +123,16 @@ TEST_F(KeywordTableTest, KeywordMisc) { |
keyword.created_by_policy = true; |
keyword.usage_count = 32; |
keyword.prepopulate_id = 10; |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
- EXPECT_TRUE(keyword_table->SetDefaultSearchProviderID(10)); |
- EXPECT_TRUE(keyword_table->SetBuiltinKeywordVersion(11)); |
+ EXPECT_TRUE(table_->SetDefaultSearchProviderID(10)); |
+ EXPECT_TRUE(table_->SetBuiltinKeywordVersion(11)); |
- EXPECT_EQ(10, keyword_table->GetDefaultSearchProviderID()); |
- EXPECT_EQ(11, keyword_table->GetBuiltinKeywordVersion()); |
+ EXPECT_EQ(10, table_->GetDefaultSearchProviderID()); |
+ EXPECT_EQ(11, table_->GetBuiltinKeywordVersion()); |
} |
TEST_F(KeywordTableTest, GetTableContents) { |
- WebDatabase db; |
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); |
- KeywordTable* keyword_table = db.GetKeywordTable(); |
- |
TemplateURLData keyword; |
keyword.short_name = ASCIIToUTF16("short_name"); |
keyword.SetKeyword(ASCIIToUTF16("keyword")); |
@@ -153,7 +148,7 @@ TEST_F(KeywordTableTest, GetTableContents) { |
keyword.alternate_urls.push_back("a_url1"); |
keyword.alternate_urls.push_back("a_url2"); |
keyword.search_terms_replacement_key = "espv"; |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
keyword.SetKeyword(ASCIIToUTF16("url")); |
keyword.instant_url = "http://instant2/"; |
@@ -164,7 +159,7 @@ TEST_F(KeywordTableTest, GetTableContents) { |
keyword.sync_guid = "FEDC-BA09-8765-4321"; |
keyword.alternate_urls.clear(); |
keyword.search_terms_replacement_key.clear(); |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
const char kTestContents[] = "1short_namekeywordhttp://favicon.url/" |
"http://url/1001url20001234-5678-90AB-CDEF[\"a_url1\",\"a_url2\"]espv" |
@@ -172,16 +167,12 @@ TEST_F(KeywordTableTest, GetTableContents) { |
"Shift_JIS1url250http://instant2/0FEDC-BA09-8765-4321[]"; |
std::string contents; |
- EXPECT_TRUE(keyword_table->GetTableContents("keywords", |
+ EXPECT_TRUE(table_->GetTableContents("keywords", |
WebDatabase::kCurrentVersionNumber, &contents)); |
EXPECT_EQ(kTestContents, contents); |
} |
TEST_F(KeywordTableTest, GetTableContentsOrdering) { |
- WebDatabase db; |
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); |
- KeywordTable* keyword_table = db.GetKeywordTable(); |
- |
TemplateURLData keyword; |
keyword.short_name = ASCIIToUTF16("short_name"); |
keyword.SetKeyword(ASCIIToUTF16("keyword")); |
@@ -197,7 +188,7 @@ TEST_F(KeywordTableTest, GetTableContentsOrdering) { |
keyword.alternate_urls.push_back("a_url1"); |
keyword.alternate_urls.push_back("a_url2"); |
keyword.search_terms_replacement_key = "espv"; |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
keyword.SetKeyword(ASCIIToUTF16("url")); |
keyword.instant_url = "http://instant2/"; |
@@ -208,7 +199,7 @@ TEST_F(KeywordTableTest, GetTableContentsOrdering) { |
keyword.sync_guid = "FEDC-BA09-8765-4321"; |
keyword.alternate_urls.clear(); |
keyword.search_terms_replacement_key.clear(); |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
const char kTestContents[] = "1short_nameurlhttp://favicon.url/http://url/1" |
"http://originating.url/00Shift_JIS1url250http://instant2/0" |
@@ -217,16 +208,12 @@ TEST_F(KeywordTableTest, GetTableContentsOrdering) { |
"url20001234-5678-90AB-CDEF[\"a_url1\",\"a_url2\"]espv"; |
std::string contents; |
- EXPECT_TRUE(keyword_table->GetTableContents("keywords", |
+ EXPECT_TRUE(table_->GetTableContents("keywords", |
WebDatabase::kCurrentVersionNumber, &contents)); |
EXPECT_EQ(kTestContents, contents); |
} |
TEST_F(KeywordTableTest, UpdateKeyword) { |
- WebDatabase db; |
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); |
- KeywordTable* keyword_table = db.GetKeywordTable(); |
- |
TemplateURLData keyword; |
keyword.short_name = ASCIIToUTF16("short_name"); |
keyword.SetKeyword(ASCIIToUTF16("keyword")); |
@@ -236,17 +223,17 @@ TEST_F(KeywordTableTest, UpdateKeyword) { |
keyword.show_in_default_list = true; |
keyword.safe_for_autoreplace = true; |
keyword.id = 1; |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
keyword.SetKeyword(ASCIIToUTF16("url")); |
keyword.instant_url = "http://instant2/"; |
keyword.originating_url = GURL("http://originating.url/"); |
keyword.input_encodings.push_back("Shift_JIS"); |
keyword.prepopulate_id = 5; |
- EXPECT_TRUE(keyword_table->UpdateKeyword(keyword)); |
+ EXPECT_TRUE(table_->UpdateKeyword(keyword)); |
KeywordTable::Keywords keywords; |
- EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); |
+ EXPECT_TRUE(table_->GetKeywords(&keywords)); |
EXPECT_EQ(1U, keywords.size()); |
const TemplateURLData& restored_keyword = keywords.front(); |
@@ -266,20 +253,16 @@ TEST_F(KeywordTableTest, UpdateKeyword) { |
} |
TEST_F(KeywordTableTest, KeywordWithNoFavicon) { |
- WebDatabase db; |
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); |
- KeywordTable* keyword_table = db.GetKeywordTable(); |
- |
TemplateURLData keyword; |
keyword.short_name = ASCIIToUTF16("short_name"); |
keyword.SetKeyword(ASCIIToUTF16("keyword")); |
keyword.SetURL("http://url/"); |
keyword.safe_for_autoreplace = true; |
keyword.id = -100; |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
KeywordTable::Keywords keywords; |
- EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); |
+ EXPECT_TRUE(table_->GetKeywords(&keywords)); |
EXPECT_EQ(1U, keywords.size()); |
const TemplateURLData& restored_keyword = keywords.front(); |
@@ -292,36 +275,32 @@ TEST_F(KeywordTableTest, KeywordWithNoFavicon) { |
} |
TEST_F(KeywordTableTest, SanitizeURLs) { |
- WebDatabase db; |
- ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string())); |
- KeywordTable* keyword_table = db.GetKeywordTable(); |
- |
TemplateURLData keyword; |
keyword.short_name = ASCIIToUTF16("legit"); |
keyword.SetKeyword(ASCIIToUTF16("legit")); |
keyword.SetURL("http://url/"); |
keyword.id = 1000; |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
keyword.short_name = ASCIIToUTF16("bogus"); |
keyword.SetKeyword(ASCIIToUTF16("bogus")); |
keyword.id = 2000; |
- EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
+ EXPECT_TRUE(table_->AddKeyword(keyword)); |
KeywordTable::Keywords keywords; |
- EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); |
+ EXPECT_TRUE(table_->GetKeywords(&keywords)); |
EXPECT_EQ(2U, keywords.size()); |
keywords.clear(); |
// Erase the URL field for the second keyword to simulate having bogus data |
// previously saved into the database. |
- sql::Statement s(keyword_table->db_->GetUniqueStatement( |
+ sql::Statement s(table_->db_->GetUniqueStatement( |
"UPDATE keywords SET url=? WHERE id=?")); |
s.BindString16(0, string16()); |
s.BindInt64(1, 2000); |
EXPECT_TRUE(s.Run()); |
// GetKeywords() should erase the entry with the empty URL field. |
- EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); |
+ EXPECT_TRUE(table_->GetKeywords(&keywords)); |
EXPECT_EQ(1U, keywords.size()); |
} |