Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 keyword.suggestions_url = "url2"; | 145 keyword.suggestions_url = "url2"; |
| 146 keyword.favicon_url = GURL("http://favicon.url/"); | 146 keyword.favicon_url = GURL("http://favicon.url/"); |
| 147 keyword.show_in_default_list = true; | 147 keyword.show_in_default_list = true; |
| 148 keyword.safe_for_autoreplace = true; | 148 keyword.safe_for_autoreplace = true; |
| 149 keyword.id = 1; | 149 keyword.id = 1; |
| 150 keyword.date_created = base::Time::UnixEpoch(); | 150 keyword.date_created = base::Time::UnixEpoch(); |
| 151 keyword.last_modified = base::Time::UnixEpoch(); | 151 keyword.last_modified = base::Time::UnixEpoch(); |
| 152 keyword.sync_guid = "1234-5678-90AB-CDEF"; | 152 keyword.sync_guid = "1234-5678-90AB-CDEF"; |
| 153 keyword.alternate_urls.push_back("a_url1"); | 153 keyword.alternate_urls.push_back("a_url1"); |
| 154 keyword.alternate_urls.push_back("a_url2"); | 154 keyword.alternate_urls.push_back("a_url2"); |
| 155 keyword.search_terms_replacement_key = "espv"; | |
| 155 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); | 156 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
| 156 | 157 |
| 157 keyword.SetKeyword(ASCIIToUTF16("url")); | 158 keyword.SetKeyword(ASCIIToUTF16("url")); |
| 158 keyword.instant_url = "http://instant2/"; | 159 keyword.instant_url = "http://instant2/"; |
| 159 keyword.originating_url = GURL("http://originating.url/"); | 160 keyword.originating_url = GURL("http://originating.url/"); |
| 160 keyword.input_encodings.push_back("Shift_JIS"); | 161 keyword.input_encodings.push_back("Shift_JIS"); |
| 161 keyword.id = 2; | 162 keyword.id = 2; |
| 162 keyword.prepopulate_id = 5; | 163 keyword.prepopulate_id = 5; |
| 163 keyword.sync_guid = "FEDC-BA09-8765-4321"; | 164 keyword.sync_guid = "FEDC-BA09-8765-4321"; |
| 164 keyword.alternate_urls.clear(); | 165 keyword.alternate_urls.clear(); |
| 166 keyword.search_terms_replacement_key = ""; | |
|
Peter Kasting
2012/12/18 01:54:43
Nit: .clear() (2 places)
beaudoin
2012/12/20 04:23:29
Done.
| |
| 165 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); | 167 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
| 166 | 168 |
| 167 const char kTestContents[] = "1short_namekeywordhttp://favicon.url/" | 169 const char kTestContents[] = "1short_namekeywordhttp://favicon.url/" |
| 168 "http://url/1001url20001234-5678-90AB-CDEF[\"a_url1\",\"a_url2\"]" | 170 "http://url/1001url20001234-5678-90AB-CDEF[\"a_url1\",\"a_url2\"]espv" |
| 169 "2short_nameurlhttp://favicon.url/http://url/1http://originating.url/00" | 171 "2short_nameurlhttp://favicon.url/http://url/1http://originating.url/00" |
| 170 "Shift_JIS1url250http://instant2/0FEDC-BA09-8765-4321[]"; | 172 "Shift_JIS1url250http://instant2/0FEDC-BA09-8765-4321[]"; |
| 171 | 173 |
| 172 std::string contents; | 174 std::string contents; |
| 173 EXPECT_TRUE(keyword_table->GetTableContents("keywords", | 175 EXPECT_TRUE(keyword_table->GetTableContents("keywords", |
| 174 WebDatabase::kCurrentVersionNumber, &contents)); | 176 WebDatabase::kCurrentVersionNumber, &contents)); |
| 175 EXPECT_EQ(kTestContents, contents); | 177 EXPECT_EQ(kTestContents, contents); |
| 176 } | 178 } |
| 177 | 179 |
| 178 TEST_F(KeywordTableTest, GetTableContentsOrdering) { | 180 TEST_F(KeywordTableTest, GetTableContentsOrdering) { |
| 179 WebDatabase db; | 181 WebDatabase db; |
| 180 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 182 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| 181 KeywordTable* keyword_table = db.GetKeywordTable(); | 183 KeywordTable* keyword_table = db.GetKeywordTable(); |
| 182 | 184 |
| 183 TemplateURLData keyword; | 185 TemplateURLData keyword; |
| 184 keyword.short_name = ASCIIToUTF16("short_name"); | 186 keyword.short_name = ASCIIToUTF16("short_name"); |
| 185 keyword.SetKeyword(ASCIIToUTF16("keyword")); | 187 keyword.SetKeyword(ASCIIToUTF16("keyword")); |
| 186 keyword.SetURL("http://url/"); | 188 keyword.SetURL("http://url/"); |
| 187 keyword.suggestions_url = "url2"; | 189 keyword.suggestions_url = "url2"; |
| 188 keyword.favicon_url = GURL("http://favicon.url/"); | 190 keyword.favicon_url = GURL("http://favicon.url/"); |
| 189 keyword.show_in_default_list = true; | 191 keyword.show_in_default_list = true; |
| 190 keyword.safe_for_autoreplace = true; | 192 keyword.safe_for_autoreplace = true; |
| 191 keyword.id = 2; | 193 keyword.id = 2; |
| 192 keyword.date_created = base::Time::UnixEpoch(); | 194 keyword.date_created = base::Time::UnixEpoch(); |
| 193 keyword.last_modified = base::Time::UnixEpoch(); | 195 keyword.last_modified = base::Time::UnixEpoch(); |
| 194 keyword.sync_guid = "1234-5678-90AB-CDEF"; | 196 keyword.sync_guid = "1234-5678-90AB-CDEF"; |
| 195 keyword.alternate_urls.push_back("a_url1"); | 197 keyword.alternate_urls.push_back("a_url1"); |
| 196 keyword.alternate_urls.push_back("a_url2"); | 198 keyword.alternate_urls.push_back("a_url2"); |
| 199 keyword.search_terms_replacement_key = "espv"; | |
| 197 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); | 200 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
| 198 | 201 |
| 199 keyword.SetKeyword(ASCIIToUTF16("url")); | 202 keyword.SetKeyword(ASCIIToUTF16("url")); |
| 200 keyword.instant_url = "http://instant2/"; | 203 keyword.instant_url = "http://instant2/"; |
| 201 keyword.originating_url = GURL("http://originating.url/"); | 204 keyword.originating_url = GURL("http://originating.url/"); |
| 202 keyword.input_encodings.push_back("Shift_JIS"); | 205 keyword.input_encodings.push_back("Shift_JIS"); |
| 203 keyword.id = 1; | 206 keyword.id = 1; |
| 204 keyword.prepopulate_id = 5; | 207 keyword.prepopulate_id = 5; |
| 205 keyword.sync_guid = "FEDC-BA09-8765-4321"; | 208 keyword.sync_guid = "FEDC-BA09-8765-4321"; |
| 206 keyword.alternate_urls.clear(); | 209 keyword.alternate_urls.clear(); |
| 210 keyword.search_terms_replacement_key = ""; | |
| 207 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); | 211 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); |
| 208 | 212 |
| 209 const char kTestContents[] = "1short_nameurlhttp://favicon.url/http://url/1" | 213 const char kTestContents[] = "1short_nameurlhttp://favicon.url/http://url/1" |
| 210 "http://originating.url/00Shift_JIS1url250http://instant2/0" | 214 "http://originating.url/00Shift_JIS1url250http://instant2/0" |
| 211 "FEDC-BA09-8765-4321[]" | 215 "FEDC-BA09-8765-4321[]" |
| 212 "2short_namekeywordhttp://favicon.url/http://url/1001" | 216 "2short_namekeywordhttp://favicon.url/http://url/1001" |
| 213 "url20001234-5678-90AB-CDEF[\"a_url1\",\"a_url2\"]"; | 217 "url20001234-5678-90AB-CDEF[\"a_url1\",\"a_url2\"]espv"; |
| 214 | 218 |
| 215 std::string contents; | 219 std::string contents; |
| 216 EXPECT_TRUE(keyword_table->GetTableContents("keywords", | 220 EXPECT_TRUE(keyword_table->GetTableContents("keywords", |
| 217 WebDatabase::kCurrentVersionNumber, &contents)); | 221 WebDatabase::kCurrentVersionNumber, &contents)); |
| 218 EXPECT_EQ(kTestContents, contents); | 222 EXPECT_EQ(kTestContents, contents); |
| 219 } | 223 } |
| 220 | 224 |
| 221 TEST_F(KeywordTableTest, UpdateKeyword) { | 225 TEST_F(KeywordTableTest, UpdateKeyword) { |
| 222 WebDatabase db; | 226 WebDatabase db; |
| 223 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 227 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 sql::Statement s(keyword_table->db_->GetUniqueStatement( | 318 sql::Statement s(keyword_table->db_->GetUniqueStatement( |
| 315 "UPDATE keywords SET url=? WHERE id=?")); | 319 "UPDATE keywords SET url=? WHERE id=?")); |
| 316 s.BindString16(0, string16()); | 320 s.BindString16(0, string16()); |
| 317 s.BindInt64(1, 2000); | 321 s.BindInt64(1, 2000); |
| 318 EXPECT_TRUE(s.Run()); | 322 EXPECT_TRUE(s.Run()); |
| 319 | 323 |
| 320 // GetKeywords() should erase the entry with the empty URL field. | 324 // GetKeywords() should erase the entry with the empty URL field. |
| 321 EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); | 325 EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); |
| 322 EXPECT_EQ(1U, keywords.size()); | 326 EXPECT_EQ(1U, keywords.size()); |
| 323 } | 327 } |
| OLD | NEW |