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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 ThumbnailDatabase db; | 114 ThumbnailDatabase db; |
115 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 115 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
116 db.BeginTransaction(); | 116 db.BeginTransaction(); |
117 | 117 |
118 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 118 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
119 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 119 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
120 | 120 |
121 GURL url("http://google.com"); | 121 GURL url("http://google.com"); |
122 FaviconID id = db.AddFavicon(url, FAVICON); | 122 FaviconID id = db.AddFavicon(url, FAVICON); |
123 base::Time time = base::Time::Now(); | 123 base::Time time = base::Time::Now(); |
124 db.SetFavicon(id, favicon, time); | 124 db.AddFaviconFrame(id, favicon, time); |
125 EXPECT_TRUE(db.RenameAndDropThumbnails(file_name_, new_file_name_)); | 125 EXPECT_TRUE(db.RenameAndDropThumbnails(file_name_, new_file_name_)); |
126 EXPECT_TRUE(db.IsLatestVersion()); | 126 EXPECT_TRUE(db.IsLatestVersion()); |
127 | 127 |
128 base::Time time_out; | 128 base::Time time_out; |
129 std::vector<unsigned char> favicon_out; | 129 std::vector<unsigned char> favicon_out; |
130 GURL url_out; | 130 GURL url_out; |
131 IconType icon_type_out; | 131 IconType icon_type_out; |
132 EXPECT_TRUE(db.GetFavicon(id, &time_out, &favicon_out, &url_out, | 132 EXPECT_TRUE(db.GetFavicon(id, &time_out, &favicon_out, &url_out, |
133 &icon_type_out)); | 133 &icon_type_out)); |
134 EXPECT_EQ(url, url_out); | 134 EXPECT_EQ(url, url_out); |
(...skipping 10 matching lines...) Expand all Loading... | |
145 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 145 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
146 db.BeginTransaction(); | 146 db.BeginTransaction(); |
147 | 147 |
148 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 148 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
149 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 149 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
150 | 150 |
151 GURL url("http://google.com"); | 151 GURL url("http://google.com"); |
152 FaviconID id = db.AddFavicon(url, TOUCH_ICON); | 152 FaviconID id = db.AddFavicon(url, TOUCH_ICON); |
153 EXPECT_NE(0, id); | 153 EXPECT_NE(0, id); |
154 base::Time time = base::Time::Now(); | 154 base::Time time = base::Time::Now(); |
155 db.SetFavicon(id, favicon, time); | 155 db.AddFaviconFrame(id, favicon, time); |
156 | 156 |
157 EXPECT_NE(0, db.AddIconMapping(url, id)); | 157 EXPECT_NE(0, db.AddIconMapping(url, id)); |
158 std::vector<IconMapping> icon_mapping; | 158 std::vector<IconMapping> icon_mapping; |
159 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 159 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
160 EXPECT_EQ(1u, icon_mapping.size()); | 160 EXPECT_EQ(1u, icon_mapping.size()); |
161 EXPECT_EQ(url, icon_mapping.front().page_url); | 161 EXPECT_EQ(url, icon_mapping.front().page_url); |
162 EXPECT_EQ(id, icon_mapping.front().icon_id); | 162 EXPECT_EQ(id, icon_mapping.front().icon_id); |
163 } | 163 } |
164 | 164 |
165 TEST_F(ThumbnailDatabaseTest, UpdateIconMapping) { | 165 TEST_F(ThumbnailDatabaseTest, UpdateIconMapping) { |
166 ThumbnailDatabase db; | 166 ThumbnailDatabase db; |
167 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 167 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
168 db.BeginTransaction(); | 168 db.BeginTransaction(); |
169 | 169 |
170 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 170 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
171 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 171 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
172 | 172 |
173 GURL url("http://google.com"); | 173 GURL url("http://google.com"); |
174 FaviconID id = db.AddFavicon(url, TOUCH_ICON); | 174 FaviconID id = db.AddFavicon(url, TOUCH_ICON); |
175 base::Time time = base::Time::Now(); | 175 base::Time time = base::Time::Now(); |
176 db.SetFavicon(id, favicon, time); | 176 db.AddFaviconFrame(id, favicon, time); |
177 | 177 |
178 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); | 178 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); |
179 std::vector<IconMapping> icon_mapping; | 179 std::vector<IconMapping> icon_mapping; |
180 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 180 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
181 ASSERT_EQ(1u, icon_mapping.size()); | 181 ASSERT_EQ(1u, icon_mapping.size()); |
182 EXPECT_EQ(url, icon_mapping.front().page_url); | 182 EXPECT_EQ(url, icon_mapping.front().page_url); |
183 EXPECT_EQ(id, icon_mapping.front().icon_id); | 183 EXPECT_EQ(id, icon_mapping.front().icon_id); |
184 | 184 |
185 GURL url1("http://www.google.com/"); | 185 GURL url1("http://www.google.com/"); |
186 FaviconID new_id = db.AddFavicon(url1, TOUCH_ICON); | 186 FaviconID new_id = db.AddFavicon(url1, TOUCH_ICON); |
(...skipping 11 matching lines...) Expand all Loading... | |
198 ThumbnailDatabase db; | 198 ThumbnailDatabase db; |
199 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 199 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
200 db.BeginTransaction(); | 200 db.BeginTransaction(); |
201 | 201 |
202 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 202 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
203 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 203 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
204 | 204 |
205 GURL url("http://google.com"); | 205 GURL url("http://google.com"); |
206 FaviconID id = db.AddFavicon(url, TOUCH_ICON); | 206 FaviconID id = db.AddFavicon(url, TOUCH_ICON); |
207 base::Time time = base::Time::Now(); | 207 base::Time time = base::Time::Now(); |
208 db.SetFavicon(id, favicon, time); | 208 db.AddFaviconFrame(id, favicon, time); |
209 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); | 209 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); |
210 | 210 |
211 FaviconID id2 = db.AddFavicon(url, FAVICON); | 211 FaviconID id2 = db.AddFavicon(url, FAVICON); |
212 db.SetFavicon(id2, favicon, time); | 212 db.AddFaviconFrame(id2, favicon, time); |
213 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); | 213 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); |
214 ASSERT_NE(id, id2); | 214 ASSERT_NE(id, id2); |
215 | 215 |
216 std::vector<IconMapping> icon_mapping; | 216 std::vector<IconMapping> icon_mapping; |
217 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 217 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
218 ASSERT_EQ(2u, icon_mapping.size()); | 218 ASSERT_EQ(2u, icon_mapping.size()); |
219 EXPECT_EQ(icon_mapping.front().icon_type, TOUCH_ICON); | 219 EXPECT_EQ(icon_mapping.front().icon_type, TOUCH_ICON); |
220 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAVICON, NULL)); | 220 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAVICON, NULL)); |
221 | 221 |
222 db.DeleteIconMappings(url); | 222 db.DeleteIconMappings(url); |
223 | 223 |
224 EXPECT_FALSE(db.GetIconMappingsForPageURL(url, NULL)); | 224 EXPECT_FALSE(db.GetIconMappingsForPageURL(url, NULL)); |
225 EXPECT_FALSE(db.GetIconMappingForPageURL(url, FAVICON, NULL)); | 225 EXPECT_FALSE(db.GetIconMappingForPageURL(url, FAVICON, NULL)); |
226 } | 226 } |
227 | 227 |
228 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURL) { | 228 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURL) { |
229 ThumbnailDatabase db; | 229 ThumbnailDatabase db; |
230 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 230 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
231 db.BeginTransaction(); | 231 db.BeginTransaction(); |
232 | 232 |
233 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 233 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
234 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 234 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
235 | 235 |
236 GURL url("http://google.com"); | 236 GURL url("http://google.com"); |
237 | 237 |
238 FaviconID id1 = db.AddFavicon(url, TOUCH_ICON); | 238 FaviconID id1 = db.AddFavicon(url, TOUCH_ICON); |
239 base::Time time = base::Time::Now(); | 239 base::Time time = base::Time::Now(); |
240 db.SetFavicon(id1, favicon, time); | 240 db.AddFaviconFrame(id1, favicon, time); |
241 EXPECT_TRUE(0 < db.AddIconMapping(url, id1)); | 241 EXPECT_TRUE(0 < db.AddIconMapping(url, id1)); |
242 | 242 |
243 FaviconID id2 = db.AddFavicon(url, FAVICON); | 243 FaviconID id2 = db.AddFavicon(url, FAVICON); |
244 EXPECT_NE(id1, id2); | 244 EXPECT_NE(id1, id2); |
245 db.SetFavicon(id2, favicon, time); | 245 db.AddFaviconFrame(id2, favicon, time); |
246 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); | 246 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); |
247 | 247 |
248 std::vector<IconMapping> icon_mapping; | 248 std::vector<IconMapping> icon_mapping; |
249 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 249 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
250 ASSERT_EQ(2u, icon_mapping.size()); | 250 ASSERT_EQ(2u, icon_mapping.size()); |
251 EXPECT_NE(icon_mapping[0].icon_id, icon_mapping[1].icon_id); | 251 EXPECT_NE(icon_mapping[0].icon_id, icon_mapping[1].icon_id); |
252 EXPECT_TRUE(icon_mapping[0].icon_id == id1 && icon_mapping[1].icon_id == id2); | 252 EXPECT_TRUE(icon_mapping[0].icon_id == id1 && icon_mapping[1].icon_id == id2); |
253 } | 253 } |
254 | 254 |
255 TEST_F(ThumbnailDatabaseTest, UpgradeToVersion4) { | 255 TEST_F(ThumbnailDatabaseTest, UpgradeToVersion4) { |
(...skipping 12 matching lines...) Expand all Loading... | |
268 sql.append(name); | 268 sql.append(name); |
269 sql.append("(" | 269 sql.append("(" |
270 "id INTEGER PRIMARY KEY," | 270 "id INTEGER PRIMARY KEY," |
271 "url LONGVARCHAR NOT NULL," | 271 "url LONGVARCHAR NOT NULL," |
272 "last_updated INTEGER DEFAULT 0," | 272 "last_updated INTEGER DEFAULT 0," |
273 "image_data BLOB)"); | 273 "image_data BLOB)"); |
274 EXPECT_TRUE(db.db_.Execute(sql.c_str())); | 274 EXPECT_TRUE(db.db_.Execute(sql.c_str())); |
275 | 275 |
276 EXPECT_TRUE(db.UpgradeToVersion4()); | 276 EXPECT_TRUE(db.UpgradeToVersion4()); |
277 | 277 |
278 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 278 GURL url("http://google.com"); |
279 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | |
280 | 279 |
281 GURL url("http://google.com"); | 280 sql::Statement statement; |
282 FaviconID id = db.AddFavicon(url, TOUCH_ICON); | 281 statement.Assign(db.db_.GetCachedStatement(SQL_FROM_HERE, |
283 base::Time time = base::Time::Now(); | 282 "INSERT INTO favicons (url, icon_type) VALUES (?, ?)")); |
284 db.SetFavicon(id, favicon, time); | 283 statement.BindString(0, URLDatabase::GURLToDatabaseURL(url)); |
284 statement.BindInt(1, TOUCH_ICON); | |
285 EXPECT_TRUE(statement.Run()); | |
285 | 286 |
286 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); | 287 statement.Assign(db.db_.GetCachedStatement(SQL_FROM_HERE, |
287 IconMapping icon_mapping; | 288 "SELECT icon_type FROM favicons")); |
288 EXPECT_TRUE(db.GetIconMappingForPageURL(url, TOUCH_ICON, &icon_mapping)); | 289 EXPECT_TRUE(statement.Step()); |
289 EXPECT_EQ(url, icon_mapping.page_url); | 290 |
290 EXPECT_EQ(id, icon_mapping.icon_id); | 291 EXPECT_EQ(TOUCH_ICON, static_cast<IconType>(statement.ColumnInt(0))); |
291 } | 292 } |
292 | 293 |
293 TEST_F(ThumbnailDatabaseTest, UpgradeToVersion5) { | 294 TEST_F(ThumbnailDatabaseTest, UpgradeToVersion5) { |
294 ThumbnailDatabase db; | 295 ThumbnailDatabase db; |
295 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 296 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
296 db.BeginTransaction(); | 297 db.BeginTransaction(); |
297 | 298 |
298 const char* name = "favicons"; | 299 const char* name = "favicons"; |
299 std::string sql; | 300 std::string sql; |
300 sql.append("DROP TABLE IF EXISTS "); | 301 sql.append("DROP TABLE IF EXISTS "); |
(...skipping 10 matching lines...) Expand all Loading... | |
311 "image_data BLOB," | 312 "image_data BLOB," |
312 "icon_type INTEGER DEFAULT 1)"); | 313 "icon_type INTEGER DEFAULT 1)"); |
313 ASSERT_TRUE(db.db_.Execute(sql.c_str())); | 314 ASSERT_TRUE(db.db_.Execute(sql.c_str())); |
314 | 315 |
315 ASSERT_TRUE(db.UpgradeToVersion5()); | 316 ASSERT_TRUE(db.UpgradeToVersion5()); |
316 | 317 |
317 sql = "SELECT sizes FROM favicons"; | 318 sql = "SELECT sizes FROM favicons"; |
318 EXPECT_TRUE(db.db_.Execute(sql.c_str())); | 319 EXPECT_TRUE(db.db_.Execute(sql.c_str())); |
319 } | 320 } |
320 | 321 |
322 TEST_F(ThumbnailDatabaseTest, UpgradeToVersion6) { | |
323 ThumbnailDatabase db; | |
324 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | |
325 db.BeginTransaction(); | |
326 | |
327 const char* name = "favicons"; | |
328 std::string sql; | |
329 sql.append("DROP TABLE IF EXISTS "); | |
330 sql.append(name); | |
331 EXPECT_TRUE(db.db_.Execute(sql.c_str())); | |
332 | |
333 sql.resize(0); | |
334 sql.append("CREATE TABLE "); | |
335 sql.append(name); | |
336 sql.append("(" | |
337 "id INTEGER PRIMARY KEY," | |
338 "url LONGVARCHAR NOT NULL," | |
339 "last_updated INTEGER DEFAULT 0," | |
340 "image_data BLOB," | |
341 "icon_type INTEGER DEFAULT 1," | |
342 "sizes LONGVARCHAR)"); | |
343 EXPECT_TRUE(db.db_.Execute(sql.c_str())); | |
344 | |
345 int favicon_id = 1; | |
346 GURL url("http://google.com"); | |
347 time_t last_updated = Time::Now().ToTimeT(); | |
348 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | |
349 scoped_refptr<base::RefCountedBytes> bitmap_data( | |
350 new base::RefCountedBytes(data)); | |
351 | |
352 sql::Statement statement; | |
353 statement.Assign(db.db_.GetCachedStatement(SQL_FROM_HERE, | |
354 "INSERT INTO favicons (id, url, last_updated, image_data, icon_type, " | |
355 "sizes) VALUES (?, ?, ?, ?, ?, ?)")); | |
356 statement.BindInt(0, favicon_id); | |
357 statement.BindString(1, URLDatabase::GURLToDatabaseURL(url)); | |
358 statement.BindInt64(2, last_updated); | |
359 statement.BindBlob(3, bitmap_data->front(), | |
360 static_cast<int>(bitmap_data->size())); | |
361 statement.BindInt(4, TOUCH_ICON); | |
362 statement.BindCString(5, "Data which happened to be there"); | |
363 EXPECT_TRUE(statement.Run()); | |
364 | |
365 EXPECT_TRUE(db.UpgradeToVersion6()); | |
366 | |
367 statement.Assign(db.db_.GetCachedStatement(SQL_FROM_HERE, | |
368 "SELECT id, url, icon_type, sizes FROM favicons")); | |
369 EXPECT_TRUE(statement.Step()); | |
370 EXPECT_EQ(favicon_id, statement.ColumnInt(0)); | |
371 EXPECT_EQ(url, GURL(statement.ColumnString(1))); | |
372 EXPECT_EQ(TOUCH_ICON, statement.ColumnInt(2)); | |
373 // sizes should not be copied to new version of database. | |
374 EXPECT_EQ(std::string(""), statement.ColumnString(3)); | |
sky
2012/08/02 19:57:01
no ""
| |
375 | |
376 // Query width and height to ensure that the columns exist. | |
sky
2012/08/02 19:57:01
Can you also verify the size is set to 16x16 in th
| |
377 statement.Assign(db.db_.GetCachedStatement(SQL_FROM_HERE, | |
378 "SELECT icon_id, last_updated, image_data, width, height " | |
379 "FROM favicon_frames")); | |
380 EXPECT_TRUE(statement.Step()); | |
381 EXPECT_EQ(favicon_id, statement.ColumnInt(0)); | |
382 EXPECT_EQ(last_updated, statement.ColumnInt64(1)); | |
383 EXPECT_EQ(static_cast<int>(bitmap_data->size()), | |
384 statement.ColumnByteLength(2)); | |
385 } | |
386 | |
321 TEST_F(ThumbnailDatabaseTest, TemporayIconMapping) { | 387 TEST_F(ThumbnailDatabaseTest, TemporayIconMapping) { |
322 ThumbnailDatabase db; | 388 ThumbnailDatabase db; |
323 | 389 |
324 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 390 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
325 | 391 |
326 db.BeginTransaction(); | 392 db.BeginTransaction(); |
327 | 393 |
328 EXPECT_TRUE(db.InitTemporaryIconMappingTable()); | 394 EXPECT_TRUE(db.InitTemporaryIconMappingTable()); |
329 | 395 |
330 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 396 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
331 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 397 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
332 | 398 |
333 GURL url("http://google.com"); | 399 GURL url("http://google.com"); |
334 FaviconID id = db.AddFavicon(url, FAVICON); | 400 FaviconID id = db.AddFavicon(url, FAVICON); |
335 base::Time time = base::Time::Now(); | 401 base::Time time = base::Time::Now(); |
336 db.SetFavicon(id, favicon, time); | 402 db.AddFaviconFrame(id, favicon, time); |
337 | 403 |
338 db.AddToTemporaryIconMappingTable(url, id); | 404 db.AddToTemporaryIconMappingTable(url, id); |
339 db.CommitTemporaryIconMappingTable(); | 405 db.CommitTemporaryIconMappingTable(); |
340 IconMapping icon_mapping; | 406 IconMapping icon_mapping; |
341 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAVICON, &icon_mapping)); | 407 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAVICON, &icon_mapping)); |
342 EXPECT_EQ(id, icon_mapping.icon_id); | 408 EXPECT_EQ(id, icon_mapping.icon_id); |
343 EXPECT_EQ(url, icon_mapping.page_url); | 409 EXPECT_EQ(url, icon_mapping.page_url); |
344 } | 410 } |
345 | 411 |
412 TEST_F(ThumbnailDatabaseTest, DeleteFavicon) { | |
413 ThumbnailDatabase db; | |
414 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | |
415 db.BeginTransaction(); | |
416 | |
417 std::vector<unsigned char> data1(blob1, blob1 + sizeof(blob1)); | |
418 scoped_refptr<base::RefCountedBytes> favicon1( | |
419 new base::RefCountedBytes(data1)); | |
420 std::vector<unsigned char> data2(blob2, blob2 + sizeof(blob2)); | |
421 scoped_refptr<base::RefCountedBytes> favicon2( | |
422 new base::RefCountedBytes(data2)); | |
423 | |
424 GURL url("http://google.com"); | |
425 FaviconID id = db.AddFavicon(url, FAVICON); | |
426 base::Time last_updated = base::Time::Now(); | |
427 db.AddFaviconFrame(id, favicon1, last_updated); | |
428 db.AddFaviconFrame(id, favicon2, last_updated); | |
429 | |
430 std::vector<unsigned char> result_data; | |
431 EXPECT_TRUE(db.GetFaviconFrame(id, NULL, &result_data)); | |
432 | |
433 EXPECT_TRUE(db.DeleteFavicon(id)); | |
434 EXPECT_FALSE(db.GetFaviconFrame(id, NULL, &result_data)); | |
435 } | |
436 | |
346 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLForReturnOrder) { | 437 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLForReturnOrder) { |
347 ThumbnailDatabase db; | 438 ThumbnailDatabase db; |
348 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 439 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
349 db.BeginTransaction(); | 440 db.BeginTransaction(); |
350 | 441 |
351 // Add a favicon | 442 // Add a favicon |
352 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 443 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
353 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 444 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
354 | 445 |
355 GURL url("http://google.com"); | 446 GURL url("http://google.com"); |
356 FaviconID id = db.AddFavicon(url, FAVICON); | 447 FaviconID id = db.AddFavicon(url, FAVICON); |
357 base::Time time = base::Time::Now(); | 448 base::Time time = base::Time::Now(); |
358 db.SetFavicon(id, favicon, time); | 449 db.AddFaviconFrame(id, favicon, time); |
359 | 450 |
360 EXPECT_NE(0, db.AddIconMapping(url, id)); | 451 EXPECT_NE(0, db.AddIconMapping(url, id)); |
361 std::vector<IconMapping> icon_mapping; | 452 std::vector<IconMapping> icon_mapping; |
362 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 453 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
363 | 454 |
364 EXPECT_EQ(url, icon_mapping.front().page_url); | 455 EXPECT_EQ(url, icon_mapping.front().page_url); |
365 EXPECT_EQ(id, icon_mapping.front().icon_id); | 456 EXPECT_EQ(id, icon_mapping.front().icon_id); |
366 EXPECT_EQ(FAVICON, icon_mapping.front().icon_type); | 457 EXPECT_EQ(FAVICON, icon_mapping.front().icon_type); |
367 | 458 |
368 // Add a touch icon | 459 // Add a touch icon |
369 std::vector<unsigned char> data2(blob2, blob2 + sizeof(blob2)); | 460 std::vector<unsigned char> data2(blob2, blob2 + sizeof(blob2)); |
370 scoped_refptr<base::RefCountedBytes> favicon2 = | 461 scoped_refptr<base::RefCountedBytes> favicon2 = |
371 new base::RefCountedBytes(data); | 462 new base::RefCountedBytes(data); |
372 | 463 |
373 FaviconID id2 = db.AddFavicon(url, TOUCH_ICON); | 464 FaviconID id2 = db.AddFavicon(url, TOUCH_ICON); |
374 db.SetFavicon(id2, favicon2, time); | 465 db.AddFaviconFrame(id2, favicon2, time); |
375 EXPECT_NE(0, db.AddIconMapping(url, id2)); | 466 EXPECT_NE(0, db.AddIconMapping(url, id2)); |
376 | 467 |
377 icon_mapping.clear(); | 468 icon_mapping.clear(); |
378 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 469 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
379 | 470 |
380 EXPECT_EQ(url, icon_mapping.front().page_url); | 471 EXPECT_EQ(url, icon_mapping.front().page_url); |
381 EXPECT_EQ(id2, icon_mapping.front().icon_id); | 472 EXPECT_EQ(id2, icon_mapping.front().icon_id); |
382 EXPECT_EQ(TOUCH_ICON, icon_mapping.front().icon_type); | 473 EXPECT_EQ(TOUCH_ICON, icon_mapping.front().icon_type); |
383 | 474 |
384 // Add a touch precomposed icon | 475 // Add a touch precomposed icon |
385 scoped_refptr<base::RefCountedBytes> favicon3 = | 476 scoped_refptr<base::RefCountedBytes> favicon3 = |
386 new base::RefCountedBytes(data2); | 477 new base::RefCountedBytes(data2); |
387 | 478 |
388 FaviconID id3 = db.AddFavicon(url, TOUCH_PRECOMPOSED_ICON); | 479 FaviconID id3 = db.AddFavicon(url, TOUCH_PRECOMPOSED_ICON); |
389 db.SetFavicon(id3, favicon3, time); | 480 db.AddFaviconFrame(id3, favicon3, time); |
390 EXPECT_NE(0, db.AddIconMapping(url, id3)); | 481 EXPECT_NE(0, db.AddIconMapping(url, id3)); |
391 | 482 |
392 icon_mapping.clear(); | 483 icon_mapping.clear(); |
393 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 484 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
394 | 485 |
395 EXPECT_EQ(url, icon_mapping.front().page_url); | 486 EXPECT_EQ(url, icon_mapping.front().page_url); |
396 EXPECT_EQ(id3, icon_mapping.front().icon_id); | 487 EXPECT_EQ(id3, icon_mapping.front().icon_id); |
397 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mapping.front().icon_type); | 488 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mapping.front().icon_type); |
398 } | 489 } |
399 | 490 |
400 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { | 491 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { |
401 ThumbnailDatabase db; | 492 ThumbnailDatabase db; |
402 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 493 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
403 db.BeginTransaction(); | 494 db.BeginTransaction(); |
404 | 495 |
405 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 496 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
406 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 497 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
407 | 498 |
408 // Add a favicon which will have icon_mappings | 499 // Add a favicon which will have icon_mappings |
409 FaviconID id1 = db.AddFavicon(GURL("http://google.com"), FAVICON); | 500 FaviconID id1 = db.AddFavicon(GURL("http://google.com"), FAVICON); |
410 EXPECT_NE(id1, 0); | 501 EXPECT_NE(id1, 0); |
411 base::Time time = base::Time::Now(); | 502 base::Time time = base::Time::Now(); |
412 db.SetFavicon(id1, favicon, time); | 503 db.AddFaviconFrame(id1, favicon, time); |
413 | 504 |
414 // Add another type of favicon | 505 // Add another type of favicon |
415 FaviconID id2 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON); | 506 FaviconID id2 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON); |
416 EXPECT_NE(id2, 0); | 507 EXPECT_NE(id2, 0); |
417 time = base::Time::Now(); | 508 time = base::Time::Now(); |
418 db.SetFavicon(id2, favicon, time); | 509 db.AddFaviconFrame(id2, favicon, time); |
419 | 510 |
420 // Add 3rd favicon | 511 // Add 3rd favicon |
421 FaviconID id3 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON); | 512 FaviconID id3 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON); |
422 EXPECT_NE(id3, 0); | 513 EXPECT_NE(id3, 0); |
423 time = base::Time::Now(); | 514 time = base::Time::Now(); |
424 db.SetFavicon(id3, favicon, time); | 515 db.AddFaviconFrame(id3, favicon, time); |
425 | 516 |
426 // Add 2 icon mapping | 517 // Add 2 icon mapping |
427 GURL page_url("http://www.google.com"); | 518 GURL page_url("http://www.google.com"); |
428 EXPECT_TRUE(db.AddIconMapping(page_url, id1)); | 519 EXPECT_TRUE(db.AddIconMapping(page_url, id1)); |
429 EXPECT_TRUE(db.AddIconMapping(page_url, id2)); | 520 EXPECT_TRUE(db.AddIconMapping(page_url, id2)); |
430 | 521 |
431 EXPECT_TRUE(db.HasMappingFor(id1)); | 522 EXPECT_TRUE(db.HasMappingFor(id1)); |
432 EXPECT_TRUE(db.HasMappingFor(id2)); | 523 EXPECT_TRUE(db.HasMappingFor(id2)); |
433 EXPECT_FALSE(db.HasMappingFor(id3)); | 524 EXPECT_FALSE(db.HasMappingFor(id3)); |
434 | 525 |
435 // Remove all mappings | 526 // Remove all mappings |
436 db.DeleteIconMappings(page_url); | 527 db.DeleteIconMappings(page_url); |
437 EXPECT_FALSE(db.HasMappingFor(id1)); | 528 EXPECT_FALSE(db.HasMappingFor(id1)); |
438 EXPECT_FALSE(db.HasMappingFor(id2)); | 529 EXPECT_FALSE(db.HasMappingFor(id2)); |
439 EXPECT_FALSE(db.HasMappingFor(id3)); | 530 EXPECT_FALSE(db.HasMappingFor(id3)); |
440 } | 531 } |
441 | 532 |
442 TEST_F(ThumbnailDatabaseTest, CloneIconMapping) { | 533 TEST_F(ThumbnailDatabaseTest, CloneIconMapping) { |
443 ThumbnailDatabase db; | 534 ThumbnailDatabase db; |
444 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 535 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
445 db.BeginTransaction(); | 536 db.BeginTransaction(); |
446 | 537 |
447 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 538 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
448 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 539 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
449 | 540 |
450 // Add a favicon which will have icon_mappings | 541 // Add a favicon which will have icon_mappings |
451 FaviconID id1 = db.AddFavicon(GURL("http://google.com"), FAVICON); | 542 FaviconID id1 = db.AddFavicon(GURL("http://google.com"), FAVICON); |
452 EXPECT_NE(0, id1); | 543 EXPECT_NE(0, id1); |
453 base::Time time = base::Time::Now(); | 544 base::Time time = base::Time::Now(); |
454 db.SetFavicon(id1, favicon, time); | 545 db.AddFaviconFrame(id1, favicon, time); |
455 | 546 |
456 // Add another type of favicon | 547 // Add another type of favicon |
457 FaviconID id2 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON); | 548 FaviconID id2 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON); |
458 EXPECT_NE(0, id2); | 549 EXPECT_NE(0, id2); |
459 time = base::Time::Now(); | 550 time = base::Time::Now(); |
460 db.SetFavicon(id2, favicon, time); | 551 db.AddFaviconFrame(id2, favicon, time); |
461 | 552 |
462 // Add 3rd favicon | 553 // Add 3rd favicon |
463 FaviconID id3 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON); | 554 FaviconID id3 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON); |
464 EXPECT_NE(0, id3); | 555 EXPECT_NE(0, id3); |
465 time = base::Time::Now(); | 556 time = base::Time::Now(); |
466 db.SetFavicon(id3, favicon, time); | 557 db.AddFaviconFrame(id3, favicon, time); |
467 | 558 |
468 GURL page1_url("http://page1.com"); | 559 GURL page1_url("http://page1.com"); |
469 EXPECT_TRUE(db.AddIconMapping(page1_url, id1)); | 560 EXPECT_TRUE(db.AddIconMapping(page1_url, id1)); |
470 EXPECT_TRUE(db.AddIconMapping(page1_url, id2)); | 561 EXPECT_TRUE(db.AddIconMapping(page1_url, id2)); |
471 | 562 |
472 GURL page2_url("http://page2.com"); | 563 GURL page2_url("http://page2.com"); |
473 EXPECT_TRUE(db.AddIconMapping(page2_url, id3)); | 564 EXPECT_TRUE(db.AddIconMapping(page2_url, id3)); |
474 | 565 |
475 // Test we do nothing with existing mappings. | 566 // Test we do nothing with existing mappings. |
476 std::vector<IconMapping> icon_mapping; | 567 std::vector<IconMapping> icon_mapping; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 ThumbnailDatabase db; | 650 ThumbnailDatabase db; |
560 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 651 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
561 db.BeginTransaction(); | 652 db.BeginTransaction(); |
562 | 653 |
563 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 654 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
564 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 655 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
565 | 656 |
566 GURL url("http://google.com"); | 657 GURL url("http://google.com"); |
567 FaviconID touch_icon_id1 = db.AddFavicon(url, TOUCH_ICON); | 658 FaviconID touch_icon_id1 = db.AddFavicon(url, TOUCH_ICON); |
568 ASSERT_NE(0, touch_icon_id1); | 659 ASSERT_NE(0, touch_icon_id1); |
569 ASSERT_TRUE(db.SetFavicon(touch_icon_id1, favicon, base::Time::Now())); | 660 ASSERT_TRUE(db.AddFaviconFrame(touch_icon_id1, favicon, base::Time::Now())); |
570 IconMappingID touch_mapping_id1 = db.AddIconMapping(url, touch_icon_id1); | 661 IconMappingID touch_mapping_id1 = db.AddIconMapping(url, touch_icon_id1); |
571 ASSERT_NE(0, touch_mapping_id1); | 662 ASSERT_NE(0, touch_mapping_id1); |
572 | 663 |
573 FaviconID favicon_id1 = db.AddFavicon(url, FAVICON); | 664 FaviconID favicon_id1 = db.AddFavicon(url, FAVICON); |
574 ASSERT_NE(0, favicon_id1); | 665 ASSERT_NE(0, favicon_id1); |
575 ASSERT_TRUE(db.SetFavicon(favicon_id1, favicon, base::Time::Now())); | 666 ASSERT_TRUE(db.AddFaviconFrame(favicon_id1, favicon, base::Time::Now())); |
576 IconMappingID favicon_mapping_id1 = db.AddIconMapping(url, favicon_id1); | 667 IconMappingID favicon_mapping_id1 = db.AddIconMapping(url, favicon_id1); |
577 ASSERT_NE(0, favicon_mapping_id1); | 668 ASSERT_NE(0, favicon_mapping_id1); |
578 | 669 |
579 GURL url2("http://chromium.org"); | 670 GURL url2("http://chromium.org"); |
580 FaviconID favicon_id2 = db.AddFavicon(url2, FAVICON); | 671 FaviconID favicon_id2 = db.AddFavicon(url2, FAVICON); |
581 ASSERT_NE(0, favicon_id2); | 672 ASSERT_NE(0, favicon_id2); |
582 ASSERT_TRUE(db.SetFavicon(favicon_id2, favicon, base::Time::Now())); | 673 ASSERT_TRUE(db.AddFaviconFrame(favicon_id2, favicon, base::Time::Now())); |
583 IconMappingID favicon_mapping_id2 = db.AddIconMapping(url2, favicon_id2); | 674 IconMappingID favicon_mapping_id2 = db.AddIconMapping(url2, favicon_id2); |
584 ASSERT_NE(0, favicon_mapping_id2); | 675 ASSERT_NE(0, favicon_mapping_id2); |
585 | 676 |
586 IconMapping icon_mapping; | 677 IconMapping icon_mapping; |
587 ThumbnailDatabase::IconMappingEnumerator enumerator1; | 678 ThumbnailDatabase::IconMappingEnumerator enumerator1; |
588 ASSERT_TRUE(db.InitIconMappingEnumerator(FAVICON, &enumerator1)); | 679 ASSERT_TRUE(db.InitIconMappingEnumerator(FAVICON, &enumerator1)); |
589 // There are 2 favicon mappings. | 680 // There are 2 favicon mappings. |
590 bool has_favicon_mapping1 = false; | 681 bool has_favicon_mapping1 = false; |
591 bool has_favicon_mapping2 = false; | 682 bool has_favicon_mapping2 = false; |
592 int mapping_count = 0; | 683 int mapping_count = 0; |
(...skipping 20 matching lines...) Expand all Loading... | |
613 ASSERT_TRUE(enumerator2.GetNextIconMapping(&icon_mapping)); | 704 ASSERT_TRUE(enumerator2.GetNextIconMapping(&icon_mapping)); |
614 EXPECT_EQ(touch_mapping_id1, icon_mapping.mapping_id); | 705 EXPECT_EQ(touch_mapping_id1, icon_mapping.mapping_id); |
615 EXPECT_EQ(url, icon_mapping.page_url); | 706 EXPECT_EQ(url, icon_mapping.page_url); |
616 EXPECT_EQ(touch_icon_id1, icon_mapping.icon_id); | 707 EXPECT_EQ(touch_icon_id1, icon_mapping.icon_id); |
617 EXPECT_EQ(TOUCH_ICON, icon_mapping.icon_type); | 708 EXPECT_EQ(TOUCH_ICON, icon_mapping.icon_type); |
618 | 709 |
619 EXPECT_FALSE(enumerator2.GetNextIconMapping(&icon_mapping)); | 710 EXPECT_FALSE(enumerator2.GetNextIconMapping(&icon_mapping)); |
620 } | 711 } |
621 | 712 |
622 } // namespace history | 713 } // namespace history |
OLD | NEW |