OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 TEST_F(ThumbnailDatabaseTest, GetFaviconAfterMigrationToTopSites) { | 113 TEST_F(ThumbnailDatabaseTest, GetFaviconAfterMigrationToTopSites) { |
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<RefCountedBytes> favicon(new RefCountedBytes(data)); | 119 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
120 | 120 |
121 GURL url("http://google.com"); | 121 GURL url("http://google.com"); |
122 FavIconID id = db.AddFavIcon(url, FAV_ICON); | 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.SetFavicon(id, favicon, time); |
125 EXPECT_TRUE(db.RenameAndDropThumbnails(file_name_, new_file_name_)); | 125 EXPECT_TRUE(db.RenameAndDropThumbnails(file_name_, new_file_name_)); |
126 | 126 |
127 base::Time time_out; | 127 base::Time time_out; |
128 std::vector<unsigned char> favicon_out; | 128 std::vector<unsigned char> favicon_out; |
129 GURL url_out; | 129 GURL url_out; |
130 EXPECT_TRUE(db.GetFavicon(id, &time_out, &favicon_out, &url_out)); | 130 EXPECT_TRUE(db.GetFavicon(id, &time_out, &favicon_out, &url_out)); |
131 EXPECT_EQ(url, url_out); | 131 EXPECT_EQ(url, url_out); |
132 EXPECT_EQ(time.ToTimeT(), time_out.ToTimeT()); | 132 EXPECT_EQ(time.ToTimeT(), time_out.ToTimeT()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 197 |
198 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 198 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
199 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 199 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
200 | 200 |
201 GURL url("http://google.com"); | 201 GURL url("http://google.com"); |
202 FavIconID id = db.AddFavIcon(url, TOUCH_ICON); | 202 FavIconID id = db.AddFavIcon(url, TOUCH_ICON); |
203 base::Time time = base::Time::Now(); | 203 base::Time time = base::Time::Now(); |
204 db.SetFavicon(id, favicon, time); | 204 db.SetFavicon(id, favicon, time); |
205 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); | 205 EXPECT_TRUE(0 < db.AddIconMapping(url, id)); |
206 | 206 |
207 FavIconID id2 = db.AddFavIcon(url, FAV_ICON); | 207 FavIconID id2 = db.AddFavIcon(url, FAVICON); |
208 db.SetFavicon(id2, favicon, time); | 208 db.SetFavicon(id2, favicon, time); |
209 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); | 209 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); |
210 ASSERT_NE(id, id2); | 210 ASSERT_NE(id, id2); |
211 | 211 |
212 std::vector<IconMapping> icon_mapping; | 212 std::vector<IconMapping> icon_mapping; |
213 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 213 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
214 ASSERT_EQ(2u, icon_mapping.size()); | 214 ASSERT_EQ(2u, icon_mapping.size()); |
215 EXPECT_EQ(icon_mapping.front().icon_type, TOUCH_ICON); | 215 EXPECT_EQ(icon_mapping.front().icon_type, TOUCH_ICON); |
216 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAV_ICON, NULL)); | 216 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAVICON, NULL)); |
217 | 217 |
218 db.DeleteIconMappings(url); | 218 db.DeleteIconMappings(url); |
219 | 219 |
220 EXPECT_FALSE(db.GetIconMappingsForPageURL(url, NULL)); | 220 EXPECT_FALSE(db.GetIconMappingsForPageURL(url, NULL)); |
221 EXPECT_FALSE(db.GetIconMappingForPageURL(url, FAV_ICON, NULL)); | 221 EXPECT_FALSE(db.GetIconMappingForPageURL(url, FAVICON, NULL)); |
222 } | 222 } |
223 | 223 |
224 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURL) { | 224 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURL) { |
225 ThumbnailDatabase db; | 225 ThumbnailDatabase db; |
226 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 226 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
227 db.BeginTransaction(); | 227 db.BeginTransaction(); |
228 | 228 |
229 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 229 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
230 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 230 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
231 | 231 |
232 GURL url("http://google.com"); | 232 GURL url("http://google.com"); |
233 | 233 |
234 FavIconID id1 = db.AddFavIcon(url, TOUCH_ICON); | 234 FavIconID id1 = db.AddFavIcon(url, TOUCH_ICON); |
235 base::Time time = base::Time::Now(); | 235 base::Time time = base::Time::Now(); |
236 db.SetFavicon(id1, favicon, time); | 236 db.SetFavicon(id1, favicon, time); |
237 EXPECT_TRUE(0 < db.AddIconMapping(url, id1)); | 237 EXPECT_TRUE(0 < db.AddIconMapping(url, id1)); |
238 | 238 |
239 FavIconID id2 = db.AddFavIcon(url, FAV_ICON); | 239 FavIconID id2 = db.AddFavIcon(url, FAVICON); |
240 EXPECT_NE(id1, id2); | 240 EXPECT_NE(id1, id2); |
241 db.SetFavicon(id2, favicon, time); | 241 db.SetFavicon(id2, favicon, time); |
242 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); | 242 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); |
243 | 243 |
244 std::vector<IconMapping> icon_mapping; | 244 std::vector<IconMapping> icon_mapping; |
245 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 245 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
246 ASSERT_EQ(2u, icon_mapping.size()); | 246 ASSERT_EQ(2u, icon_mapping.size()); |
247 EXPECT_NE(icon_mapping[0].icon_id, icon_mapping[1].icon_id); | 247 EXPECT_NE(icon_mapping[0].icon_id, icon_mapping[1].icon_id); |
248 EXPECT_TRUE(icon_mapping[0].icon_id == id1 && icon_mapping[1].icon_id == id2); | 248 EXPECT_TRUE(icon_mapping[0].icon_id == id1 && icon_mapping[1].icon_id == id2); |
249 } | 249 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 292 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
293 | 293 |
294 db.BeginTransaction(); | 294 db.BeginTransaction(); |
295 | 295 |
296 EXPECT_TRUE(db.InitTemporaryIconMappingTable()); | 296 EXPECT_TRUE(db.InitTemporaryIconMappingTable()); |
297 | 297 |
298 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 298 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
299 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 299 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
300 | 300 |
301 GURL url("http://google.com"); | 301 GURL url("http://google.com"); |
302 FavIconID id = db.AddFavIcon(url, FAV_ICON); | 302 FavIconID id = db.AddFavIcon(url, FAVICON); |
303 base::Time time = base::Time::Now(); | 303 base::Time time = base::Time::Now(); |
304 db.SetFavicon(id, favicon, time); | 304 db.SetFavicon(id, favicon, time); |
305 | 305 |
306 db.AddToTemporaryIconMappingTable(url, id); | 306 db.AddToTemporaryIconMappingTable(url, id); |
307 db.CommitTemporaryIconMappingTable(); | 307 db.CommitTemporaryIconMappingTable(); |
308 IconMapping icon_mapping; | 308 IconMapping icon_mapping; |
309 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAV_ICON, &icon_mapping)); | 309 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAVICON, &icon_mapping)); |
310 EXPECT_EQ(id, icon_mapping.icon_id); | 310 EXPECT_EQ(id, icon_mapping.icon_id); |
311 EXPECT_EQ(url, icon_mapping.page_url); | 311 EXPECT_EQ(url, icon_mapping.page_url); |
312 } | 312 } |
313 | 313 |
314 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLForReturnOrder) { | 314 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLForReturnOrder) { |
315 ThumbnailDatabase db; | 315 ThumbnailDatabase db; |
316 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 316 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
317 db.BeginTransaction(); | 317 db.BeginTransaction(); |
318 | 318 |
319 // Add a favicon | 319 // Add a favicon |
320 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 320 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
321 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 321 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
322 | 322 |
323 GURL url("http://google.com"); | 323 GURL url("http://google.com"); |
324 FavIconID id = db.AddFavIcon(url, FAV_ICON); | 324 FavIconID id = db.AddFavIcon(url, FAVICON); |
325 base::Time time = base::Time::Now(); | 325 base::Time time = base::Time::Now(); |
326 db.SetFavicon(id, favicon, time); | 326 db.SetFavicon(id, favicon, time); |
327 | 327 |
328 EXPECT_NE(0, db.AddIconMapping(url, id)); | 328 EXPECT_NE(0, db.AddIconMapping(url, id)); |
329 std::vector<IconMapping> icon_mapping; | 329 std::vector<IconMapping> icon_mapping; |
330 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 330 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
331 | 331 |
332 EXPECT_EQ(url, icon_mapping.front().page_url); | 332 EXPECT_EQ(url, icon_mapping.front().page_url); |
333 EXPECT_EQ(id, icon_mapping.front().icon_id); | 333 EXPECT_EQ(id, icon_mapping.front().icon_id); |
334 EXPECT_EQ(FAV_ICON, icon_mapping.front().icon_type); | 334 EXPECT_EQ(FAVICON, icon_mapping.front().icon_type); |
335 | 335 |
336 // Add a touch icon | 336 // Add a touch icon |
337 std::vector<unsigned char> data2(blob2, blob2 + sizeof(blob2)); | 337 std::vector<unsigned char> data2(blob2, blob2 + sizeof(blob2)); |
338 scoped_refptr<RefCountedBytes> favicon2(new RefCountedBytes(data)); | 338 scoped_refptr<RefCountedBytes> favicon2(new RefCountedBytes(data)); |
339 | 339 |
340 FavIconID id2 = db.AddFavIcon(url, TOUCH_ICON); | 340 FavIconID id2 = db.AddFavIcon(url, TOUCH_ICON); |
341 db.SetFavicon(id2, favicon2, time); | 341 db.SetFavicon(id2, favicon2, time); |
342 EXPECT_NE(0, db.AddIconMapping(url, id2)); | 342 EXPECT_NE(0, db.AddIconMapping(url, id2)); |
343 | 343 |
344 icon_mapping.clear(); | 344 icon_mapping.clear(); |
(...skipping 20 matching lines...) Expand all Loading... |
365 | 365 |
366 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { | 366 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { |
367 ThumbnailDatabase db; | 367 ThumbnailDatabase db; |
368 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 368 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
369 db.BeginTransaction(); | 369 db.BeginTransaction(); |
370 | 370 |
371 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 371 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
372 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); | 372 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data)); |
373 | 373 |
374 // Add a favicon which will have icon_mappings | 374 // Add a favicon which will have icon_mappings |
375 FavIconID id1 = db.AddFavIcon(GURL("http://google.com"), FAV_ICON); | 375 FavIconID id1 = db.AddFavIcon(GURL("http://google.com"), FAVICON); |
376 EXPECT_NE(id1, 0); | 376 EXPECT_NE(id1, 0); |
377 base::Time time = base::Time::Now(); | 377 base::Time time = base::Time::Now(); |
378 db.SetFavicon(id1, favicon, time); | 378 db.SetFavicon(id1, favicon, time); |
379 | 379 |
380 // Add another type of favicon | 380 // Add another type of favicon |
381 FavIconID id2 = db.AddFavIcon(GURL("http://www.google.com/icon"), TOUCH_ICON); | 381 FavIconID id2 = db.AddFavIcon(GURL("http://www.google.com/icon"), TOUCH_ICON); |
382 EXPECT_NE(id2, 0); | 382 EXPECT_NE(id2, 0); |
383 time = base::Time::Now(); | 383 time = base::Time::Now(); |
384 db.SetFavicon(id2, favicon, time); | 384 db.SetFavicon(id2, favicon, time); |
385 | 385 |
(...skipping 30 matching lines...) Expand all Loading... |
416 ThumbnailDatabase db; | 416 ThumbnailDatabase db; |
417 ASSERT_EQ(sql::INIT_OK, db.Init(thumbnail_db_name_, NULL, &history_db)); | 417 ASSERT_EQ(sql::INIT_OK, db.Init(thumbnail_db_name_, NULL, &history_db)); |
418 db.BeginTransaction(); | 418 db.BeginTransaction(); |
419 | 419 |
420 // Migration should be done. | 420 // Migration should be done. |
421 // Test one icon_mapping. | 421 // Test one icon_mapping. |
422 GURL page_url1 = GURL("http://google.com/"); | 422 GURL page_url1 = GURL("http://google.com/"); |
423 std::vector<IconMapping> icon_mappings; | 423 std::vector<IconMapping> icon_mappings; |
424 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url1, &icon_mappings)); | 424 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url1, &icon_mappings)); |
425 ASSERT_EQ(1u, icon_mappings.size()); | 425 ASSERT_EQ(1u, icon_mappings.size()); |
426 EXPECT_EQ(FAV_ICON, icon_mappings[0].icon_type); | 426 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); |
427 EXPECT_EQ(page_url1, icon_mappings[0].page_url); | 427 EXPECT_EQ(page_url1, icon_mappings[0].page_url); |
428 EXPECT_EQ(1, icon_mappings[0].icon_id); | 428 EXPECT_EQ(1, icon_mappings[0].icon_id); |
429 base::Time time; | 429 base::Time time; |
430 std::vector<unsigned char> out_data; | 430 std::vector<unsigned char> out_data; |
431 GURL out_icon_url; | 431 GURL out_icon_url; |
432 ASSERT_TRUE(db.GetFavicon( | 432 ASSERT_TRUE(db.GetFavicon( |
433 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url)); | 433 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url)); |
434 EXPECT_EQ(icon1, out_icon_url); | 434 EXPECT_EQ(icon1, out_icon_url); |
435 | 435 |
436 // Test a page which has the same icon. | 436 // Test a page which has the same icon. |
437 GURL page_url3 = GURL("http://www.google.com/"); | 437 GURL page_url3 = GURL("http://www.google.com/"); |
438 icon_mappings.clear(); | 438 icon_mappings.clear(); |
439 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url3, &icon_mappings)); | 439 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url3, &icon_mappings)); |
440 ASSERT_EQ(1u, icon_mappings.size()); | 440 ASSERT_EQ(1u, icon_mappings.size()); |
441 EXPECT_EQ(FAV_ICON, icon_mappings[0].icon_type); | 441 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); |
442 EXPECT_EQ(page_url3, icon_mappings[0].page_url); | 442 EXPECT_EQ(page_url3, icon_mappings[0].page_url); |
443 EXPECT_EQ(1, icon_mappings[0].icon_id); | 443 EXPECT_EQ(1, icon_mappings[0].icon_id); |
444 | 444 |
445 // Test a icon_mapping with different IconID. | 445 // Test a icon_mapping with different IconID. |
446 GURL page_url2 = GURL("http://yahoo.com/"); | 446 GURL page_url2 = GURL("http://yahoo.com/"); |
447 icon_mappings.clear(); | 447 icon_mappings.clear(); |
448 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url2, &icon_mappings)); | 448 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url2, &icon_mappings)); |
449 ASSERT_EQ(1u, icon_mappings.size()); | 449 ASSERT_EQ(1u, icon_mappings.size()); |
450 EXPECT_EQ(FAV_ICON, icon_mappings[0].icon_type); | 450 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); |
451 EXPECT_EQ(page_url2, icon_mappings[0].page_url); | 451 EXPECT_EQ(page_url2, icon_mappings[0].page_url); |
452 EXPECT_EQ(2, icon_mappings[0].icon_id); | 452 EXPECT_EQ(2, icon_mappings[0].icon_id); |
453 ASSERT_TRUE(db.GetFavicon( | 453 ASSERT_TRUE(db.GetFavicon( |
454 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url)); | 454 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url)); |
455 EXPECT_EQ(icon2, out_icon_url); | 455 EXPECT_EQ(icon2, out_icon_url); |
456 | 456 |
457 // Test a page without icon | 457 // Test a page without icon |
458 GURL page_url4 = GURL("http://www.google.com/blank.html"); | 458 GURL page_url4 = GURL("http://www.google.com/blank.html"); |
459 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL)); | 459 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL)); |
460 } | 460 } |
461 | 461 |
462 } // namespace history | 462 } // namespace history |
OLD | NEW |