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/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 base::Int64ToString(Time::Now().ToTimeT()) + | 33 base::Int64ToString(Time::Now().ToTimeT()) + |
34 ".db"; | 34 ".db"; |
35 file_ = file_.AppendASCII(test_db); | 35 file_ = file_.AppendASCII(test_db); |
36 file_util::Delete(file_, false); | 36 file_util::Delete(file_, false); |
37 } | 37 } |
38 | 38 |
39 virtual void TearDown() { | 39 virtual void TearDown() { |
40 file_util::Delete(file_, false); | 40 file_util::Delete(file_, false); |
41 } | 41 } |
42 | 42 |
43 static void SetID(int64 new_id, TemplateURL* url) { | |
44 url->set_id(new_id); | |
45 } | |
46 | |
47 FilePath file_; | 43 FilePath file_; |
48 | 44 |
49 private: | 45 private: |
50 DISALLOW_COPY_AND_ASSIGN(KeywordTableTest); | 46 DISALLOW_COPY_AND_ASSIGN(KeywordTableTest); |
51 }; | 47 }; |
52 | 48 |
53 | 49 |
54 TEST_F(KeywordTableTest, Keywords) { | 50 TEST_F(KeywordTableTest, Keywords) { |
55 WebDatabase db; | 51 WebDatabase db; |
56 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 52 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
57 KeywordTable* keyword_table = db.GetKeywordTable(); | 53 KeywordTable* keyword_table = db.GetKeywordTable(); |
58 | 54 |
59 TemplateURL keyword; | 55 TemplateURLData keyword; |
60 keyword.set_short_name(ASCIIToUTF16("short_name")); | 56 keyword.short_name = ASCIIToUTF16("short_name"); |
61 keyword.set_originating_url(GURL("http://google.com/")); | 57 keyword.SetKeyword(ASCIIToUTF16("keyword")); |
62 keyword.set_keyword(ASCIIToUTF16("keyword")); | |
63 keyword.set_show_in_default_list(true); | |
64 keyword.set_safe_for_autoreplace(true); | |
65 keyword.add_input_encoding("UTF-8"); | |
66 keyword.add_input_encoding("UTF-16"); | |
67 SetID(1, &keyword); | |
68 keyword.set_date_created(Time::Now()); | |
69 keyword.set_last_modified( | |
70 keyword.date_created() + TimeDelta::FromSeconds(10)); | |
71 keyword.set_created_by_policy(true); | |
72 keyword.set_usage_count(32); | |
73 keyword.SetPrepopulateId(10); | |
74 keyword.SetURL("http://url/"); | 58 keyword.SetURL("http://url/"); |
75 keyword.SetInstantURL("http://instant/"); | 59 keyword.instant_url = "http://instant/"; |
76 keyword.set_favicon_url(GURL("http://favicon.url/")); | 60 keyword.favicon_url = GURL("http://favicon.url/"); |
77 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); | 61 keyword.originating_url = GURL("http://google.com/"); |
| 62 keyword.show_in_default_list = true; |
| 63 keyword.safe_for_autoreplace = true; |
| 64 keyword.input_encodings.push_back("UTF-8"); |
| 65 keyword.input_encodings.push_back("UTF-16"); |
| 66 keyword.id = 1; |
| 67 keyword.date_created = Time::Now(); |
| 68 keyword.last_modified = keyword.date_created + TimeDelta::FromSeconds(10); |
| 69 keyword.created_by_policy = true; |
| 70 keyword.usage_count = 32; |
| 71 keyword.prepopulate_id = 10; |
| 72 TemplateURL url(keyword); |
| 73 EXPECT_TRUE(keyword_table->AddKeyword(url)); |
78 | 74 |
79 KeywordTable::Keywords keywords; | 75 KeywordTable::Keywords keywords; |
80 EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); | 76 EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); |
81 EXPECT_EQ(1U, keywords.size()); | 77 EXPECT_EQ(1U, keywords.size()); |
82 const TemplateURL* restored_keyword = keywords.front(); | 78 const TemplateURLData& restored_keyword = keywords.front(); |
83 | 79 |
84 EXPECT_EQ(keyword.short_name(), restored_keyword->short_name()); | 80 EXPECT_EQ(keyword.short_name, restored_keyword.short_name); |
85 EXPECT_EQ(keyword.originating_url(), restored_keyword->originating_url()); | 81 EXPECT_EQ(url.keyword(), TemplateURL(restored_keyword).keyword()); |
86 EXPECT_EQ(keyword.autogenerate_keyword(), | 82 EXPECT_EQ(keyword.autogenerate_keyword(), |
87 restored_keyword->autogenerate_keyword()); | 83 restored_keyword.autogenerate_keyword()); |
88 EXPECT_EQ(keyword.keyword(), restored_keyword->keyword()); | 84 EXPECT_EQ(keyword.url(), restored_keyword.url()); |
89 EXPECT_EQ(keyword.show_in_default_list(), | 85 EXPECT_EQ(keyword.instant_url, restored_keyword.instant_url); |
90 restored_keyword->show_in_default_list()); | 86 EXPECT_EQ(keyword.favicon_url, restored_keyword.favicon_url); |
91 EXPECT_EQ(keyword.safe_for_autoreplace(), | 87 EXPECT_EQ(keyword.originating_url, restored_keyword.originating_url); |
92 restored_keyword->safe_for_autoreplace()); | 88 EXPECT_EQ(keyword.show_in_default_list, |
93 EXPECT_EQ(keyword.input_encodings(), restored_keyword->input_encodings()); | 89 restored_keyword.show_in_default_list); |
94 EXPECT_EQ(keyword.id(), restored_keyword->id()); | 90 EXPECT_EQ(keyword.safe_for_autoreplace, |
| 91 restored_keyword.safe_for_autoreplace); |
| 92 EXPECT_EQ(keyword.input_encodings, restored_keyword.input_encodings); |
| 93 EXPECT_EQ(keyword.id, restored_keyword.id); |
95 // The database stores time only at the resolution of a second. | 94 // The database stores time only at the resolution of a second. |
96 EXPECT_EQ(keyword.date_created().ToTimeT(), | 95 EXPECT_EQ(keyword.date_created.ToTimeT(), |
97 restored_keyword->date_created().ToTimeT()); | 96 restored_keyword.date_created.ToTimeT()); |
98 EXPECT_EQ(keyword.last_modified().ToTimeT(), | 97 EXPECT_EQ(keyword.last_modified.ToTimeT(), |
99 restored_keyword->last_modified().ToTimeT()); | 98 restored_keyword.last_modified.ToTimeT()); |
100 EXPECT_EQ(keyword.created_by_policy(), restored_keyword->created_by_policy()); | 99 EXPECT_EQ(keyword.created_by_policy, restored_keyword.created_by_policy); |
101 EXPECT_EQ(keyword.usage_count(), restored_keyword->usage_count()); | 100 EXPECT_EQ(keyword.usage_count, restored_keyword.usage_count); |
102 EXPECT_EQ(keyword.prepopulate_id(), restored_keyword->prepopulate_id()); | 101 EXPECT_EQ(keyword.prepopulate_id, restored_keyword.prepopulate_id); |
103 EXPECT_EQ(keyword.url(), restored_keyword->url()); | |
104 EXPECT_EQ(keyword.instant_url(), restored_keyword->instant_url()); | |
105 EXPECT_EQ(keyword.favicon_url(), restored_keyword->favicon_url()); | |
106 | 102 |
107 EXPECT_TRUE(keyword_table->RemoveKeyword(restored_keyword->id())); | 103 EXPECT_TRUE(keyword_table->RemoveKeyword(restored_keyword.id)); |
108 STLDeleteElements(&keywords); | |
109 | 104 |
110 KeywordTable::Keywords empty_keywords; | 105 KeywordTable::Keywords empty_keywords; |
111 EXPECT_TRUE(keyword_table->GetKeywords(&empty_keywords)); | 106 EXPECT_TRUE(keyword_table->GetKeywords(&empty_keywords)); |
112 EXPECT_EQ(0U, empty_keywords.size()); | 107 EXPECT_EQ(0U, empty_keywords.size()); |
113 STLDeleteElements(&empty_keywords); | |
114 } | 108 } |
115 | 109 |
116 TEST_F(KeywordTableTest, KeywordMisc) { | 110 TEST_F(KeywordTableTest, KeywordMisc) { |
117 WebDatabase db; | 111 WebDatabase db; |
118 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 112 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
119 KeywordTable* keyword_table = db.GetKeywordTable(); | 113 KeywordTable* keyword_table = db.GetKeywordTable(); |
120 | 114 |
121 ASSERT_EQ(kInvalidTemplateURLID, keyword_table->GetDefaultSearchProviderID()); | 115 ASSERT_EQ(kInvalidTemplateURLID, keyword_table->GetDefaultSearchProviderID()); |
122 ASSERT_EQ(0, keyword_table->GetBuiltinKeywordVersion()); | 116 ASSERT_EQ(0, keyword_table->GetBuiltinKeywordVersion()); |
123 | 117 |
124 TemplateURL keyword; | 118 TemplateURLData keyword; |
125 keyword.set_short_name(ASCIIToUTF16("short_name")); | 119 keyword.short_name = ASCIIToUTF16("short_name"); |
126 keyword.set_originating_url(GURL("http://google.com/")); | 120 keyword.SetKeyword(ASCIIToUTF16("keyword")); |
127 keyword.set_keyword(ASCIIToUTF16("keyword")); | |
128 keyword.set_show_in_default_list(true); | |
129 keyword.set_safe_for_autoreplace(true); | |
130 keyword.add_input_encoding("UTF-8"); | |
131 keyword.add_input_encoding("UTF-16"); | |
132 SetID(10, &keyword); | |
133 keyword.set_date_created(Time::Now()); | |
134 keyword.set_last_modified( | |
135 keyword.date_created() + TimeDelta::FromSeconds(10)); | |
136 keyword.set_created_by_policy(true); | |
137 keyword.set_usage_count(32); | |
138 keyword.SetPrepopulateId(10); | |
139 keyword.SetURL("http://url/"); | 121 keyword.SetURL("http://url/"); |
140 keyword.SetInstantURL("http://instant/"); | 122 keyword.instant_url = "http://instant/"; |
141 keyword.set_favicon_url(GURL("http://favicon.url/")); | 123 keyword.favicon_url = GURL("http://favicon.url/"); |
142 ASSERT_TRUE(keyword_table->AddKeyword(keyword)); | 124 keyword.originating_url = GURL("http://google.com/"); |
| 125 keyword.show_in_default_list = true; |
| 126 keyword.safe_for_autoreplace = true; |
| 127 keyword.input_encodings.push_back("UTF-8"); |
| 128 keyword.input_encodings.push_back("UTF-16"); |
| 129 keyword.id = 10; |
| 130 keyword.date_created = Time::Now(); |
| 131 keyword.last_modified = keyword.date_created + TimeDelta::FromSeconds(10); |
| 132 keyword.created_by_policy = true; |
| 133 keyword.usage_count = 32; |
| 134 keyword.prepopulate_id = 10; |
| 135 TemplateURL url(keyword); |
| 136 ASSERT_TRUE(keyword_table->AddKeyword(url)); |
143 | 137 |
144 ASSERT_TRUE(keyword_table->SetDefaultSearchProviderID(10)); | 138 ASSERT_TRUE(keyword_table->SetDefaultSearchProviderID(10)); |
145 ASSERT_TRUE(keyword_table->SetBuiltinKeywordVersion(11)); | 139 ASSERT_TRUE(keyword_table->SetBuiltinKeywordVersion(11)); |
146 | 140 |
147 ASSERT_EQ(10, keyword_table->GetDefaultSearchProviderID()); | 141 ASSERT_EQ(10, keyword_table->GetDefaultSearchProviderID()); |
148 ASSERT_EQ(11, keyword_table->GetBuiltinKeywordVersion()); | 142 ASSERT_EQ(11, keyword_table->GetBuiltinKeywordVersion()); |
149 } | 143 } |
150 | 144 |
151 TEST_F(KeywordTableTest, DefaultSearchProviderBackup) { | 145 TEST_F(KeywordTableTest, DefaultSearchProviderBackup) { |
152 // TODO(ivankr): suppress keyword_table.cc ERROR logs. | 146 // TODO(ivankr): suppress keyword_table.cc ERROR logs. |
153 WebDatabase db; | 147 WebDatabase db; |
154 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 148 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
155 KeywordTable* keyword_table = db.GetKeywordTable(); | 149 KeywordTable* keyword_table = db.GetKeywordTable(); |
156 | 150 |
157 EXPECT_EQ(kInvalidTemplateURLID, keyword_table->GetDefaultSearchProviderID()); | 151 EXPECT_EQ(kInvalidTemplateURLID, keyword_table->GetDefaultSearchProviderID()); |
158 | 152 |
159 TemplateURL keyword; | 153 TemplateURLData keyword; |
160 keyword.set_short_name(ASCIIToUTF16("short_name")); | 154 keyword.short_name = ASCIIToUTF16("short_name"); |
161 keyword.set_keyword(ASCIIToUTF16("keyword")); | 155 keyword.SetKeyword(ASCIIToUTF16("keyword")); |
162 keyword.set_show_in_default_list(true); | |
163 keyword.set_safe_for_autoreplace(true); | |
164 SetID(1, &keyword); | |
165 keyword.SetSuggestionsURL("url2"); | |
166 keyword.SetURL("http://url/"); | 156 keyword.SetURL("http://url/"); |
167 keyword.set_favicon_url(GURL("http://favicon.url/")); | 157 keyword.suggestions_url = "url2"; |
168 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); | 158 keyword.favicon_url = GURL("http://favicon.url/"); |
| 159 keyword.show_in_default_list = true; |
| 160 keyword.safe_for_autoreplace = true; |
| 161 keyword.id = 1; |
| 162 TemplateURL url(keyword); |
| 163 EXPECT_TRUE(keyword_table->AddKeyword(url)); |
169 | 164 |
170 ASSERT_TRUE(keyword_table->SetDefaultSearchProviderID(1)); | 165 ASSERT_TRUE(keyword_table->SetDefaultSearchProviderID(1)); |
171 EXPECT_TRUE(keyword_table->IsBackupSignatureValid()); | 166 EXPECT_TRUE(keyword_table->IsBackupSignatureValid()); |
172 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); | 167 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); |
173 | 168 |
174 scoped_ptr<TemplateURL> backup_url( | 169 TemplateURLData backup; |
175 keyword_table->GetDefaultSearchProviderBackup()); | 170 EXPECT_TRUE(keyword_table->GetDefaultSearchProviderBackup(&backup)); |
176 // Backup URL should have an invalid ID. | 171 // Backup URL should have an invalid ID. |
177 EXPECT_EQ(kInvalidTemplateURLID, backup_url->id()); | 172 EXPECT_EQ(kInvalidTemplateURLID, backup.id); |
178 EXPECT_EQ(keyword.short_name(), backup_url->short_name()); | 173 EXPECT_EQ(keyword.short_name, backup.short_name); |
179 EXPECT_EQ(keyword.keyword(), backup_url->keyword()); | 174 EXPECT_EQ(url.keyword(), TemplateURL(backup).keyword()); |
180 EXPECT_EQ(keyword.favicon_url(), backup_url->favicon_url()); | 175 EXPECT_EQ(keyword.url(), backup.url()); |
181 EXPECT_EQ(keyword.url(), backup_url->url()); | 176 EXPECT_EQ(keyword.favicon_url, backup.favicon_url); |
182 EXPECT_EQ(keyword.safe_for_autoreplace(), backup_url->safe_for_autoreplace()); | 177 EXPECT_EQ(keyword.suggestions_url, backup.suggestions_url); |
183 EXPECT_EQ(keyword.show_in_default_list(), backup_url->show_in_default_list()); | 178 EXPECT_EQ(keyword.show_in_default_list, backup.show_in_default_list); |
184 EXPECT_EQ(keyword.suggestions_url(), backup_url->suggestions_url()); | 179 EXPECT_EQ(keyword.safe_for_autoreplace, backup.safe_for_autoreplace); |
185 EXPECT_FALSE(keyword_table->DidDefaultSearchProviderChange()); | 180 EXPECT_FALSE(keyword_table->DidDefaultSearchProviderChange()); |
186 | 181 |
187 // Change the actual setting. | 182 // Change the actual setting. |
188 ASSERT_TRUE(keyword_table->meta_table_->SetValue( | 183 ASSERT_TRUE(keyword_table->meta_table_->SetValue( |
189 KeywordTable::kDefaultSearchProviderKey, 2)); | 184 KeywordTable::kDefaultSearchProviderKey, 2)); |
190 EXPECT_TRUE(keyword_table->IsBackupSignatureValid()); | 185 EXPECT_TRUE(keyword_table->IsBackupSignatureValid()); |
191 EXPECT_EQ(2, keyword_table->GetDefaultSearchProviderID()); | 186 EXPECT_EQ(2, keyword_table->GetDefaultSearchProviderID()); |
192 | 187 |
193 backup_url.reset(keyword_table->GetDefaultSearchProviderBackup()); | 188 EXPECT_TRUE(keyword_table->GetDefaultSearchProviderBackup(&backup)); |
194 EXPECT_EQ(kInvalidTemplateURLID, backup_url->id()); | 189 EXPECT_EQ(kInvalidTemplateURLID, backup.id); |
195 EXPECT_EQ(keyword.short_name(), backup_url->short_name()); | 190 EXPECT_EQ(keyword.short_name, backup.short_name); |
196 EXPECT_EQ(keyword.keyword(), backup_url->keyword()); | 191 EXPECT_EQ(url.keyword(), TemplateURL(backup).keyword()); |
197 EXPECT_EQ(keyword.favicon_url(), backup_url->favicon_url()); | 192 EXPECT_EQ(keyword.url(), backup.url()); |
198 EXPECT_EQ(keyword.url(), backup_url->url()); | 193 EXPECT_EQ(keyword.favicon_url, backup.favicon_url); |
199 EXPECT_EQ(keyword.safe_for_autoreplace(), backup_url->safe_for_autoreplace()); | 194 EXPECT_EQ(keyword.suggestions_url, backup.suggestions_url); |
200 EXPECT_EQ(keyword.show_in_default_list(), backup_url->show_in_default_list()); | 195 EXPECT_EQ(keyword.show_in_default_list, backup.show_in_default_list); |
201 EXPECT_EQ(keyword.suggestions_url(), backup_url->suggestions_url()); | 196 EXPECT_EQ(keyword.safe_for_autoreplace, backup.safe_for_autoreplace); |
202 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); | 197 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); |
203 | 198 |
204 // Change the backup. | 199 // Change the backup. |
205 ASSERT_TRUE(keyword_table->meta_table_->SetValue( | 200 ASSERT_TRUE(keyword_table->meta_table_->SetValue( |
206 KeywordTable::kDefaultSearchProviderKey, 1)); | 201 KeywordTable::kDefaultSearchProviderKey, 1)); |
207 ASSERT_TRUE(keyword_table->meta_table_->SetValue( | 202 ASSERT_TRUE(keyword_table->meta_table_->SetValue( |
208 KeywordTable::kDefaultSearchIDBackupKey, 2)); | 203 KeywordTable::kDefaultSearchIDBackupKey, 2)); |
209 EXPECT_FALSE(keyword_table->IsBackupSignatureValid()); | 204 EXPECT_FALSE(keyword_table->IsBackupSignatureValid()); |
210 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); | 205 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); |
211 EXPECT_EQ(NULL, keyword_table->GetDefaultSearchProviderBackup()); | 206 EXPECT_FALSE(keyword_table->GetDefaultSearchProviderBackup(&backup)); |
212 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); | 207 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); |
213 | 208 |
214 // Change the signature. | 209 // Change the signature. |
215 ASSERT_TRUE(keyword_table->meta_table_->SetValue( | 210 ASSERT_TRUE(keyword_table->meta_table_->SetValue( |
216 KeywordTable::kDefaultSearchIDBackupKey, 1)); | 211 KeywordTable::kDefaultSearchIDBackupKey, 1)); |
217 ASSERT_TRUE(keyword_table->meta_table_->SetValue( | 212 ASSERT_TRUE(keyword_table->meta_table_->SetValue( |
218 KeywordTable::kBackupSignatureKey, std::string())); | 213 KeywordTable::kBackupSignatureKey, std::string())); |
219 EXPECT_FALSE(keyword_table->IsBackupSignatureValid()); | 214 EXPECT_FALSE(keyword_table->IsBackupSignatureValid()); |
220 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); | 215 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); |
221 EXPECT_EQ(NULL, keyword_table->GetDefaultSearchProviderBackup()); | 216 EXPECT_FALSE(keyword_table->GetDefaultSearchProviderBackup(&backup)); |
222 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); | 217 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); |
223 | 218 |
224 // Change keywords. | 219 // Change keywords. |
225 ASSERT_TRUE(keyword_table->UpdateBackupSignature()); | 220 ASSERT_TRUE(keyword_table->UpdateBackupSignature()); |
226 sql::Statement remove_keyword(keyword_table->db_->GetUniqueStatement( | 221 sql::Statement remove_keyword(keyword_table->db_->GetUniqueStatement( |
227 "DELETE FROM keywords WHERE id=1")); | 222 "DELETE FROM keywords WHERE id=1")); |
228 ASSERT_TRUE(remove_keyword.Run()); | 223 ASSERT_TRUE(remove_keyword.Run()); |
229 EXPECT_TRUE(keyword_table->IsBackupSignatureValid()); | 224 EXPECT_TRUE(keyword_table->IsBackupSignatureValid()); |
230 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); | 225 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); |
231 | 226 |
232 backup_url.reset(keyword_table->GetDefaultSearchProviderBackup()); | 227 EXPECT_TRUE(keyword_table->GetDefaultSearchProviderBackup(&backup)); |
233 EXPECT_EQ(kInvalidTemplateURLID, backup_url->id()); | 228 EXPECT_EQ(kInvalidTemplateURLID, backup.id); |
234 EXPECT_EQ(keyword.short_name(), backup_url->short_name()); | 229 EXPECT_EQ(keyword.short_name, backup.short_name); |
235 EXPECT_EQ(keyword.keyword(), backup_url->keyword()); | 230 EXPECT_EQ(url.keyword(), TemplateURL(backup).keyword()); |
236 EXPECT_EQ(keyword.favicon_url(), backup_url->favicon_url()); | 231 EXPECT_EQ(keyword.url(), backup.url()); |
237 EXPECT_EQ(keyword.url(), backup_url->url()); | 232 EXPECT_EQ(keyword.suggestions_url, backup.suggestions_url); |
238 EXPECT_EQ(keyword.safe_for_autoreplace(), backup_url->safe_for_autoreplace()); | 233 EXPECT_EQ(keyword.favicon_url, backup.favicon_url); |
239 EXPECT_EQ(keyword.show_in_default_list(), backup_url->show_in_default_list()); | 234 EXPECT_EQ(keyword.show_in_default_list, backup.show_in_default_list); |
240 EXPECT_EQ(keyword.suggestions_url(), backup_url->suggestions_url()); | 235 EXPECT_EQ(keyword.safe_for_autoreplace, backup.safe_for_autoreplace); |
241 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); | 236 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); |
242 | 237 |
243 // Change keywords backup. | 238 // Change keywords backup. |
244 sql::Statement remove_keyword_backup(keyword_table->db_->GetUniqueStatement( | 239 sql::Statement remove_keyword_backup(keyword_table->db_->GetUniqueStatement( |
245 "DELETE FROM keywords_backup WHERE id=1")); | 240 "DELETE FROM keywords_backup WHERE id=1")); |
246 ASSERT_TRUE(remove_keyword_backup.Run()); | 241 ASSERT_TRUE(remove_keyword_backup.Run()); |
247 EXPECT_FALSE(keyword_table->IsBackupSignatureValid()); | 242 EXPECT_FALSE(keyword_table->IsBackupSignatureValid()); |
248 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); | 243 EXPECT_EQ(1, keyword_table->GetDefaultSearchProviderID()); |
249 EXPECT_EQ(NULL, keyword_table->GetDefaultSearchProviderBackup()); | 244 EXPECT_FALSE(keyword_table->GetDefaultSearchProviderBackup(&backup)); |
250 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); | 245 EXPECT_TRUE(keyword_table->DidDefaultSearchProviderChange()); |
251 } | 246 } |
252 | 247 |
253 TEST_F(KeywordTableTest, GetTableContents) { | 248 TEST_F(KeywordTableTest, GetTableContents) { |
254 WebDatabase db; | 249 WebDatabase db; |
255 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 250 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
256 KeywordTable* keyword_table = db.GetKeywordTable(); | 251 KeywordTable* keyword_table = db.GetKeywordTable(); |
257 | 252 |
258 TemplateURL keyword; | 253 TemplateURLData keyword; |
259 keyword.set_short_name(ASCIIToUTF16("short_name")); | 254 keyword.short_name = ASCIIToUTF16("short_name"); |
260 keyword.set_keyword(ASCIIToUTF16("keyword")); | 255 keyword.SetKeyword(ASCIIToUTF16("keyword")); |
261 keyword.set_show_in_default_list(true); | |
262 keyword.set_safe_for_autoreplace(true); | |
263 SetID(1, &keyword); | |
264 keyword.set_date_created(base::Time::UnixEpoch()); | |
265 keyword.set_last_modified(base::Time::UnixEpoch()); | |
266 keyword.set_sync_guid("1234-5678-90AB-CDEF"); | |
267 keyword.SetSuggestionsURL("url2"); | |
268 keyword.SetURL("http://url/"); | 256 keyword.SetURL("http://url/"); |
269 keyword.set_favicon_url(GURL("http://favicon.url/")); | 257 keyword.suggestions_url = "url2"; |
270 ASSERT_TRUE(keyword_table->AddKeyword(keyword)); | 258 keyword.favicon_url = GURL("http://favicon.url/"); |
| 259 keyword.show_in_default_list = true; |
| 260 keyword.safe_for_autoreplace = true; |
| 261 keyword.id = 1; |
| 262 keyword.date_created = base::Time::UnixEpoch(); |
| 263 keyword.last_modified = base::Time::UnixEpoch(); |
| 264 keyword.sync_guid = "1234-5678-90AB-CDEF"; |
| 265 TemplateURL url(keyword); |
| 266 EXPECT_TRUE(keyword_table->AddKeyword(url)); |
271 | 267 |
272 keyword.set_originating_url(GURL("http://originating.url/")); | 268 keyword.SetAutogenerateKeyword(true); |
273 keyword.set_autogenerate_keyword(true); | 269 keyword.instant_url = "http://instant2/"; |
274 EXPECT_EQ(ASCIIToUTF16("url"), keyword.keyword()); | 270 keyword.originating_url = GURL("http://originating.url/"); |
275 keyword.add_input_encoding("Shift_JIS"); | 271 keyword.input_encodings.push_back("Shift_JIS"); |
276 SetID(2, &keyword); | 272 keyword.id = 2; |
277 keyword.SetPrepopulateId(5); | 273 keyword.prepopulate_id = 5; |
278 keyword.set_sync_guid("FEDC-BA09-8765-4321"); | 274 keyword.sync_guid = "FEDC-BA09-8765-4321"; |
279 keyword.SetInstantURL("http://instant2/"); | 275 TemplateURL url2(keyword); |
280 ASSERT_TRUE(keyword_table->AddKeyword(keyword)); | 276 EXPECT_TRUE(keyword_table->AddKeyword(url2)); |
281 | 277 |
282 const char kTestContents[] = "1short_namekeywordhttp://favicon.url/" | 278 const char kTestContents[] = "1short_namekeywordhttp://favicon.url/" |
283 "http://url/1001url2000001234-5678-90AB-CDEF2short_nameurl" | 279 "http://url/1001url2000001234-5678-90AB-CDEF2short_nameurl" |
284 "http://favicon.url/http://url/1http://originating.url/00Shift_JIS1url251" | 280 "http://favicon.url/http://url/1http://originating.url/00Shift_JIS1url251" |
285 "00http://instant2/0FEDC-BA09-8765-4321"; | 281 "00http://instant2/0FEDC-BA09-8765-4321"; |
286 | 282 |
287 std::string contents; | 283 std::string contents; |
288 ASSERT_TRUE(keyword_table->GetTableContents("keywords", &contents)); | 284 ASSERT_TRUE(keyword_table->GetTableContents("keywords", &contents)); |
289 EXPECT_EQ(kTestContents, contents); | 285 EXPECT_EQ(kTestContents, contents); |
290 | 286 |
291 ASSERT_TRUE(keyword_table->GetTableContents("keywords_backup", &contents)); | 287 ASSERT_TRUE(keyword_table->GetTableContents("keywords_backup", &contents)); |
292 EXPECT_EQ(kTestContents, contents); | 288 EXPECT_EQ(kTestContents, contents); |
293 } | 289 } |
294 | 290 |
295 TEST_F(KeywordTableTest, GetTableContentsOrdering) { | 291 TEST_F(KeywordTableTest, GetTableContentsOrdering) { |
296 WebDatabase db; | 292 WebDatabase db; |
297 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 293 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
298 KeywordTable* keyword_table = db.GetKeywordTable(); | 294 KeywordTable* keyword_table = db.GetKeywordTable(); |
299 | 295 |
300 TemplateURL keyword; | 296 TemplateURLData keyword; |
301 keyword.set_short_name(ASCIIToUTF16("short_name")); | 297 keyword.short_name = ASCIIToUTF16("short_name"); |
302 keyword.set_keyword(ASCIIToUTF16("keyword")); | 298 keyword.SetKeyword(ASCIIToUTF16("keyword")); |
303 keyword.set_show_in_default_list(true); | |
304 keyword.set_safe_for_autoreplace(true); | |
305 SetID(2, &keyword); | |
306 keyword.set_date_created(base::Time::UnixEpoch()); | |
307 keyword.set_last_modified(base::Time::UnixEpoch()); | |
308 keyword.set_sync_guid("1234-5678-90AB-CDEF"); | |
309 keyword.SetSuggestionsURL("url2"); | |
310 keyword.SetURL("http://url/"); | 299 keyword.SetURL("http://url/"); |
311 keyword.set_favicon_url(GURL("http://favicon.url/")); | 300 keyword.suggestions_url = "url2"; |
312 ASSERT_TRUE(keyword_table->AddKeyword(keyword)); | 301 keyword.favicon_url = GURL("http://favicon.url/"); |
| 302 keyword.show_in_default_list = true; |
| 303 keyword.safe_for_autoreplace = true; |
| 304 keyword.id = 2; |
| 305 keyword.date_created = base::Time::UnixEpoch(); |
| 306 keyword.last_modified = base::Time::UnixEpoch(); |
| 307 keyword.sync_guid = "1234-5678-90AB-CDEF"; |
| 308 TemplateURL url(keyword); |
| 309 EXPECT_TRUE(keyword_table->AddKeyword(url)); |
313 | 310 |
314 keyword.set_originating_url(GURL("http://originating.url/")); | 311 keyword.SetAutogenerateKeyword(true); |
315 keyword.set_autogenerate_keyword(true); | 312 keyword.instant_url = "http://instant2/"; |
316 EXPECT_EQ(ASCIIToUTF16("url"), keyword.keyword()); | 313 keyword.originating_url = GURL("http://originating.url/"); |
317 keyword.add_input_encoding("Shift_JIS"); | 314 keyword.input_encodings.push_back("Shift_JIS"); |
318 SetID(1, &keyword); | 315 keyword.id = 1; |
319 keyword.SetPrepopulateId(5); | 316 keyword.prepopulate_id = 5; |
320 keyword.set_sync_guid("FEDC-BA09-8765-4321"); | 317 keyword.sync_guid = "FEDC-BA09-8765-4321"; |
321 keyword.SetInstantURL("http://instant2/"); | 318 TemplateURL url2(keyword); |
322 ASSERT_TRUE(keyword_table->AddKeyword(keyword)); | 319 EXPECT_TRUE(keyword_table->AddKeyword(url2)); |
323 | 320 |
324 const char kTestContents[] = "1short_nameurlhttp://favicon.url/http://url/1" | 321 const char kTestContents[] = "1short_nameurlhttp://favicon.url/http://url/1" |
325 "http://originating.url/00Shift_JIS1url25100http://instant2/0" | 322 "http://originating.url/00Shift_JIS1url25100http://instant2/0" |
326 "FEDC-BA09-8765-43212short_namekeywordhttp://favicon.url/http://url/1001" | 323 "FEDC-BA09-8765-43212short_namekeywordhttp://favicon.url/http://url/1001" |
327 "url2000001234-5678-90AB-CDEF"; | 324 "url2000001234-5678-90AB-CDEF"; |
328 | 325 |
329 std::string contents; | 326 std::string contents; |
330 ASSERT_TRUE(keyword_table->GetTableContents("keywords", &contents)); | 327 ASSERT_TRUE(keyword_table->GetTableContents("keywords", &contents)); |
331 EXPECT_EQ(kTestContents, contents); | 328 EXPECT_EQ(kTestContents, contents); |
332 | 329 |
333 ASSERT_TRUE(keyword_table->GetTableContents("keywords_backup", &contents)); | 330 ASSERT_TRUE(keyword_table->GetTableContents("keywords_backup", &contents)); |
334 EXPECT_EQ(kTestContents, contents); | 331 EXPECT_EQ(kTestContents, contents); |
335 } | 332 } |
336 | 333 |
337 TEST_F(KeywordTableTest, UpdateKeyword) { | 334 TEST_F(KeywordTableTest, UpdateKeyword) { |
338 WebDatabase db; | 335 WebDatabase db; |
339 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 336 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
340 KeywordTable* keyword_table = db.GetKeywordTable(); | 337 KeywordTable* keyword_table = db.GetKeywordTable(); |
341 | 338 |
342 TemplateURL keyword; | 339 TemplateURLData keyword; |
343 keyword.set_short_name(ASCIIToUTF16("short_name")); | 340 keyword.short_name = ASCIIToUTF16("short_name"); |
344 keyword.set_keyword(ASCIIToUTF16("keyword")); | 341 keyword.SetKeyword(ASCIIToUTF16("keyword")); |
345 keyword.set_show_in_default_list(true); | |
346 keyword.set_safe_for_autoreplace(true); | |
347 SetID(1, &keyword); | |
348 keyword.SetSuggestionsURL("url2"); | |
349 keyword.SetURL("http://url/"); | 342 keyword.SetURL("http://url/"); |
350 keyword.set_favicon_url(GURL("http://favicon.url/")); | 343 keyword.suggestions_url = "url2"; |
351 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); | 344 keyword.favicon_url = GURL("http://favicon.url/"); |
| 345 keyword.show_in_default_list = true; |
| 346 keyword.safe_for_autoreplace = true; |
| 347 keyword.id = 1; |
| 348 TemplateURL url(keyword); |
| 349 EXPECT_TRUE(keyword_table->AddKeyword(url)); |
352 | 350 |
353 keyword.set_originating_url(GURL("http://originating.url/")); | 351 keyword.originating_url = GURL("http://originating.url/"); |
354 keyword.set_autogenerate_keyword(true); | 352 keyword.SetAutogenerateKeyword(true); |
355 EXPECT_EQ(ASCIIToUTF16("url"), keyword.keyword()); | 353 keyword.instant_url = "http://instant2/"; |
356 keyword.add_input_encoding("Shift_JIS"); | 354 keyword.input_encodings.push_back("Shift_JIS"); |
357 keyword.SetPrepopulateId(5); | 355 keyword.prepopulate_id = 5; |
358 keyword.SetInstantURL("http://instant2/"); | 356 TemplateURL url2(keyword); |
359 EXPECT_TRUE(keyword_table->UpdateKeyword(keyword)); | 357 EXPECT_TRUE(keyword_table->UpdateKeyword(url2)); |
360 | 358 |
361 KeywordTable::Keywords keywords; | 359 KeywordTable::Keywords keywords; |
362 EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); | 360 EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); |
363 EXPECT_EQ(1U, keywords.size()); | 361 EXPECT_EQ(1U, keywords.size()); |
364 const TemplateURL* restored_keyword = keywords.front(); | 362 const TemplateURLData& restored_keyword = keywords.front(); |
365 | 363 |
366 EXPECT_EQ(keyword.short_name(), restored_keyword->short_name()); | 364 EXPECT_EQ(keyword.short_name, restored_keyword.short_name); |
367 EXPECT_EQ(keyword.originating_url(), restored_keyword->originating_url()); | 365 EXPECT_EQ(url2.keyword(), TemplateURL(restored_keyword).keyword()); |
368 EXPECT_EQ(keyword.keyword(), restored_keyword->keyword()); | |
369 EXPECT_EQ(keyword.autogenerate_keyword(), | 366 EXPECT_EQ(keyword.autogenerate_keyword(), |
370 restored_keyword->autogenerate_keyword()); | 367 restored_keyword.autogenerate_keyword()); |
371 EXPECT_EQ(keyword.show_in_default_list(), | 368 EXPECT_EQ(keyword.suggestions_url, restored_keyword.suggestions_url); |
372 restored_keyword->show_in_default_list()); | 369 EXPECT_EQ(keyword.instant_url, restored_keyword.instant_url); |
373 EXPECT_EQ(keyword.safe_for_autoreplace(), | 370 EXPECT_EQ(keyword.favicon_url, restored_keyword.favicon_url); |
374 restored_keyword->safe_for_autoreplace()); | 371 EXPECT_EQ(keyword.originating_url, restored_keyword.originating_url); |
375 EXPECT_EQ(keyword.input_encodings(), restored_keyword->input_encodings()); | 372 EXPECT_EQ(keyword.show_in_default_list, |
376 EXPECT_EQ(keyword.id(), restored_keyword->id()); | 373 restored_keyword.show_in_default_list); |
377 EXPECT_EQ(keyword.prepopulate_id(), restored_keyword->prepopulate_id()); | 374 EXPECT_EQ(keyword.safe_for_autoreplace, |
378 EXPECT_EQ(keyword.suggestions_url(), restored_keyword->suggestions_url()); | 375 restored_keyword.safe_for_autoreplace); |
379 EXPECT_EQ(keyword.favicon_url(), restored_keyword->favicon_url()); | 376 EXPECT_EQ(keyword.input_encodings, restored_keyword.input_encodings); |
380 EXPECT_EQ(keyword.instant_url(), restored_keyword->instant_url()); | 377 EXPECT_EQ(keyword.id, restored_keyword.id); |
381 | 378 EXPECT_EQ(keyword.prepopulate_id, restored_keyword.prepopulate_id); |
382 STLDeleteElements(&keywords); | |
383 } | 379 } |
384 | 380 |
385 TEST_F(KeywordTableTest, KeywordWithNoFavicon) { | 381 TEST_F(KeywordTableTest, KeywordWithNoFavicon) { |
386 WebDatabase db; | 382 WebDatabase db; |
387 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 383 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
388 KeywordTable* keyword_table = db.GetKeywordTable(); | 384 KeywordTable* keyword_table = db.GetKeywordTable(); |
389 | 385 |
390 TemplateURL keyword; | 386 TemplateURLData keyword; |
391 keyword.set_short_name(ASCIIToUTF16("short_name")); | 387 keyword.short_name = ASCIIToUTF16("short_name"); |
392 keyword.set_keyword(ASCIIToUTF16("keyword")); | 388 keyword.SetKeyword(ASCIIToUTF16("keyword")); |
393 keyword.set_safe_for_autoreplace(true); | |
394 SetID(-100, &keyword); | |
395 keyword.SetURL("http://url/"); | 389 keyword.SetURL("http://url/"); |
396 EXPECT_TRUE(keyword_table->AddKeyword(keyword)); | 390 keyword.safe_for_autoreplace = true; |
| 391 keyword.id = -100; |
| 392 TemplateURL url(keyword); |
| 393 EXPECT_TRUE(keyword_table->AddKeyword(url)); |
397 | 394 |
398 KeywordTable::Keywords keywords; | 395 KeywordTable::Keywords keywords; |
399 EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); | 396 EXPECT_TRUE(keyword_table->GetKeywords(&keywords)); |
400 EXPECT_EQ(1U, keywords.size()); | 397 EXPECT_EQ(1U, keywords.size()); |
401 const TemplateURL* restored_keyword = keywords.front(); | 398 const TemplateURLData& restored_keyword = keywords.front(); |
402 | 399 |
403 EXPECT_EQ(keyword.short_name(), restored_keyword->short_name()); | 400 EXPECT_EQ(keyword.short_name, restored_keyword.short_name); |
404 EXPECT_EQ(keyword.keyword(), restored_keyword->keyword()); | 401 EXPECT_EQ(url.keyword(), TemplateURL(restored_keyword).keyword()); |
405 EXPECT_EQ(keyword.safe_for_autoreplace(), | 402 EXPECT_EQ(keyword.favicon_url, restored_keyword.favicon_url); |
406 restored_keyword->safe_for_autoreplace()); | 403 EXPECT_EQ(keyword.safe_for_autoreplace, |
407 EXPECT_EQ(keyword.id(), restored_keyword->id()); | 404 restored_keyword.safe_for_autoreplace); |
408 EXPECT_EQ(keyword.favicon_url(), restored_keyword->favicon_url()); | 405 EXPECT_EQ(keyword.id, restored_keyword.id); |
409 | |
410 STLDeleteElements(&keywords); | |
411 } | 406 } |
OLD | NEW |