Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: components/history/core/browser/thumbnail_database_unittest.cc

Issue 2823093002: Make FaviconService::GetRawFaviconForPageURL() select the best candidate among all the icon types (Closed)
Patch Set: Merge branch 'master' into icon_type Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 23 matching lines...) Expand all
34 "goiwuegrqrcomizqyzkjalitbahxfjytrqvpqeroicxmnlkhlzunacxaneviawrtxcywhgef"; 34 "goiwuegrqrcomizqyzkjalitbahxfjytrqvpqeroicxmnlkhlzunacxaneviawrtxcywhgef";
35 35
36 // Page and icon urls shared by tests. Present in golden database 36 // Page and icon urls shared by tests. Present in golden database
37 // files (see VersionN tests). 37 // files (see VersionN tests).
38 const GURL kPageUrl1 = GURL("http://google.com/"); 38 const GURL kPageUrl1 = GURL("http://google.com/");
39 const GURL kPageUrl2 = GURL("http://yahoo.com/"); 39 const GURL kPageUrl2 = GURL("http://yahoo.com/");
40 const GURL kPageUrl3 = GURL("http://www.google.com/"); 40 const GURL kPageUrl3 = GURL("http://www.google.com/");
41 const GURL kPageUrl4 = GURL("http://www.google.com/blank.html"); 41 const GURL kPageUrl4 = GURL("http://www.google.com/blank.html");
42 const GURL kPageUrl5 = GURL("http://www.bing.com/"); 42 const GURL kPageUrl5 = GURL("http://www.bing.com/");
43 43
44 const GURL kIconUrl1 = GURL("http://www.google.com/favicon.ico"); 44 const GURL kIconUrl1 = GURL("http://www.bing.com/favicon.ico");
45 const GURL kIconUrl2 = GURL("http://www.yahoo.com/favicon.ico"); 45 const GURL kIconUrl2 = GURL("http://www.duckduckgo.com/favicon.ico");
46 const GURL kIconUrl3 = GURL("http://www.google.com/touch.ico"); 46 const GURL kIconUrl3 = GURL("http://www.google.com/favicon.ico");
47 const GURL kIconUrl5 = GURL("http://www.bing.com/favicon.ico"); 47 const GURL kIconUrl4 = GURL("http://www.google.com/touch.ico");
48 const GURL kIconUrl5 = GURL("http://www.yahoo.com/favicon.ico");
48 49
49 const gfx::Size kSmallSize = gfx::Size(16, 16); 50 const gfx::Size kSmallSize = gfx::Size(16, 16);
50 const gfx::Size kLargeSize = gfx::Size(32, 32); 51 const gfx::Size kLargeSize = gfx::Size(32, 32);
51 52
52 // Verify that the up-to-date database has the expected tables and 53 // Verify that the up-to-date database has the expected tables and
53 // columns. Functional tests only check whether the things which 54 // columns. Functional tests only check whether the things which
54 // should be there are, but do not check if extraneous items are 55 // should be there are, but do not check if extraneous items are
55 // present. Any extraneous items have the potential to interact 56 // present. Any extraneous items have the potential to interact
56 // negatively with future schema changes. 57 // negatively with future schema changes.
57 void VerifyTablesAndColumns(sql::Connection* db) { 58 void VerifyTablesAndColumns(sql::Connection* db) {
(...skipping 11 matching lines...) Expand all
69 EXPECT_EQ(3u, sql::test::CountTableColumns(db, "favicons")); 70 EXPECT_EQ(3u, sql::test::CountTableColumns(db, "favicons"));
70 71
71 // [id], [icon_id], [last_updated], [image_data], [width], [height] and 72 // [id], [icon_id], [last_updated], [image_data], [width], [height] and
72 // [last_requested]. 73 // [last_requested].
73 EXPECT_EQ(7u, sql::test::CountTableColumns(db, "favicon_bitmaps")); 74 EXPECT_EQ(7u, sql::test::CountTableColumns(db, "favicon_bitmaps"));
74 75
75 // [id], [page_url], and [icon_id]. 76 // [id], [page_url], and [icon_id].
76 EXPECT_EQ(3u, sql::test::CountTableColumns(db, "icon_mapping")); 77 EXPECT_EQ(3u, sql::test::CountTableColumns(db, "icon_mapping"));
77 } 78 }
78 79
80 // Adds a favicon at |icon_url| with |icon_type| with default bitmap data and
81 // maps |page_url| to |icon_url|.
82 void AddFaviconAndMapSimple(ThumbnailDatabase* db,
83 const GURL& page_url,
84 const GURL& icon_url,
85 favicon_base::IconType icon_type) {
86 scoped_refptr<base::RefCountedStaticMemory> data(
87 new base::RefCountedStaticMemory(kBlob1, sizeof(kBlob1)));
88 favicon_base::FaviconID favicon_id =
89 db->AddFavicon(icon_url, icon_type, data, base::Time::Now(), gfx::Size());
90 db->AddIconMapping(page_url, favicon_id);
91 }
92
79 void VerifyDatabaseEmpty(sql::Connection* db) { 93 void VerifyDatabaseEmpty(sql::Connection* db) {
80 size_t rows = 0; 94 size_t rows = 0;
81 EXPECT_TRUE(sql::test::CountTableRows(db, "favicons", &rows)); 95 EXPECT_TRUE(sql::test::CountTableRows(db, "favicons", &rows));
82 EXPECT_EQ(0u, rows); 96 EXPECT_EQ(0u, rows);
83 EXPECT_TRUE(sql::test::CountTableRows(db, "favicon_bitmaps", &rows)); 97 EXPECT_TRUE(sql::test::CountTableRows(db, "favicon_bitmaps", &rows));
84 EXPECT_EQ(0u, rows); 98 EXPECT_EQ(0u, rows);
85 EXPECT_TRUE(sql::test::CountTableRows(db, "icon_mapping", &rows)); 99 EXPECT_TRUE(sql::test::CountTableRows(db, "icon_mapping", &rows));
86 EXPECT_EQ(0u, rows); 100 EXPECT_EQ(0u, rows);
87 } 101 }
88 102
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 154 }
141 155
142 if (memcmp(favicon_bitmaps[0].bitmap_data->front(), 156 if (memcmp(favicon_bitmaps[0].bitmap_data->front(),
143 expected_icon_contents, expected_icon_contents_size)) { 157 expected_icon_contents, expected_icon_contents_size)) {
144 ADD_FAILURE() << "failed to match |expected_icon_contents|"; 158 ADD_FAILURE() << "failed to match |expected_icon_contents|";
145 return false; 159 return false;
146 } 160 }
147 return true; 161 return true;
148 } 162 }
149 163
164 bool CompareIconMappingIconUrl(const IconMapping& a, const IconMapping& b) {
165 return a.icon_url < b.icon_url;
166 }
167
168 void SortMappingsByIconUrl(std::vector<IconMapping>* mappings) {
169 std::sort(mappings->begin(), mappings->end(), &CompareIconMappingIconUrl);
170 }
171
150 } // namespace 172 } // namespace
151 173
152 class ThumbnailDatabaseTest : public testing::Test { 174 class ThumbnailDatabaseTest : public testing::Test {
153 public: 175 public:
154 ThumbnailDatabaseTest() {} 176 ThumbnailDatabaseTest() {}
155 ~ThumbnailDatabaseTest() override {} 177 ~ThumbnailDatabaseTest() override {}
156 178
157 // Initialize a thumbnail database instance from the SQL file at 179 // Initialize a thumbnail database instance from the SQL file at
158 // |golden_path| in the "History/" subdirectory of test data. 180 // |golden_path| in the "History/" subdirectory of test data.
159 std::unique_ptr<ThumbnailDatabase> LoadFromGolden(const char* golden_path) { 181 std::unique_ptr<ThumbnailDatabase> LoadFromGolden(const char* golden_path) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 kBlob1)); 384 kBlob1));
363 EXPECT_TRUE(CheckPageHasIcon(&db, 385 EXPECT_TRUE(CheckPageHasIcon(&db,
364 kPageUrl5, 386 kPageUrl5,
365 favicon_base::FAVICON, 387 favicon_base::FAVICON,
366 kIconUrl5, 388 kIconUrl5,
367 kLargeSize, 389 kLargeSize,
368 sizeof(kBlob2), 390 sizeof(kBlob2),
369 kBlob2)); 391 kBlob2));
370 392
371 // The ones not retained should be missing. 393 // The ones not retained should be missing.
372 EXPECT_FALSE(db.GetFaviconIDForFaviconURL(kPageUrl2, false, NULL)); 394 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, nullptr));
373 EXPECT_FALSE(db.GetFaviconIDForFaviconURL(kPageUrl4, false, NULL)); 395 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl4, nullptr));
374 396
375 // Schema should be the same. 397 // Schema should be the same.
376 EXPECT_EQ(original_schema, db.db_.GetSchema()); 398 EXPECT_EQ(original_schema, db.db_.GetSchema());
377 } 399 }
378 400
379 // Test that RetainDataForPageUrls() expires retained favicons. 401 // Test that RetainDataForPageUrls() expires retained favicons.
380 TEST_F(ThumbnailDatabaseTest, RetainDataForPageUrlsExpiresRetainedFavicons) { 402 TEST_F(ThumbnailDatabaseTest, RetainDataForPageUrlsExpiresRetainedFavicons) {
381 ThumbnailDatabase db(NULL); 403 ThumbnailDatabase db(NULL);
382 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 404 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
383 db.BeginTransaction(); 405 db.BeginTransaction();
384 406
385 scoped_refptr<base::RefCountedStaticMemory> favicon1( 407 scoped_refptr<base::RefCountedStaticMemory> favicon1(
386 new base::RefCountedStaticMemory(kBlob1, sizeof(kBlob1))); 408 new base::RefCountedStaticMemory(kBlob1, sizeof(kBlob1)));
387 favicon_base::FaviconID kept_id = db.AddFavicon( 409 favicon_base::FaviconID kept_id = db.AddFavicon(
388 kIconUrl1, favicon_base::FAVICON, favicon1, base::Time::Now(), 410 kIconUrl1, favicon_base::FAVICON, favicon1, base::Time::Now(),
389 gfx::Size()); 411 gfx::Size());
390 db.AddIconMapping(kPageUrl1, kept_id); 412 db.AddIconMapping(kPageUrl1, kept_id);
391 413
392 EXPECT_TRUE(db.RetainDataForPageUrls(std::vector<GURL>(1u, kPageUrl1))); 414 EXPECT_TRUE(db.RetainDataForPageUrls(std::vector<GURL>(1u, kPageUrl1)));
393 415
394 favicon_base::FaviconID new_favicon_id = db.GetFaviconIDForFaviconURL( 416 favicon_base::FaviconID new_favicon_id =
395 kIconUrl1, favicon_base::FAVICON, nullptr); 417 db.GetFaviconIDForFaviconURL(kIconUrl1, favicon_base::FAVICON);
396 ASSERT_NE(0, new_favicon_id); 418 ASSERT_NE(0, new_favicon_id);
397 std::vector<FaviconBitmap> new_favicon_bitmaps; 419 std::vector<FaviconBitmap> new_favicon_bitmaps;
398 db.GetFaviconBitmaps(new_favicon_id, &new_favicon_bitmaps); 420 db.GetFaviconBitmaps(new_favicon_id, &new_favicon_bitmaps);
399 421
400 ASSERT_EQ(1u, new_favicon_bitmaps.size()); 422 ASSERT_EQ(1u, new_favicon_bitmaps.size());
401 EXPECT_EQ(0, new_favicon_bitmaps[0].last_updated.ToInternalValue()); 423 EXPECT_EQ(0, new_favicon_bitmaps[0].last_updated.ToInternalValue());
402 } 424 }
403 425
404 // Tests that deleting a favicon deletes the favicon row and favicon bitmap 426 // Tests that deleting a favicon deletes the favicon row and favicon bitmap
405 // rows from the database. 427 // rows from the database.
(...skipping 14 matching lines...) Expand all
420 base::Time last_updated = base::Time::Now(); 442 base::Time last_updated = base::Time::Now();
421 db.AddFaviconBitmap(id, favicon1, last_updated, kSmallSize); 443 db.AddFaviconBitmap(id, favicon1, last_updated, kSmallSize);
422 db.AddFaviconBitmap(id, favicon2, last_updated, kLargeSize); 444 db.AddFaviconBitmap(id, favicon2, last_updated, kLargeSize);
423 445
424 EXPECT_TRUE(db.GetFaviconBitmaps(id, NULL)); 446 EXPECT_TRUE(db.GetFaviconBitmaps(id, NULL));
425 447
426 EXPECT_TRUE(db.DeleteFavicon(id)); 448 EXPECT_TRUE(db.DeleteFavicon(id));
427 EXPECT_FALSE(db.GetFaviconBitmaps(id, NULL)); 449 EXPECT_FALSE(db.GetFaviconBitmaps(id, NULL));
428 } 450 }
429 451
430 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLForReturnOrder) { 452 // Test that when multiple icon types are passed to GetIconMappingsForPageURL()
453 // that the results are filtered according to the passed in types.
454 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLWithIconTypes) {
431 ThumbnailDatabase db(NULL); 455 ThumbnailDatabase db(NULL);
432 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 456 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
433 db.BeginTransaction(); 457 db.BeginTransaction();
434 458
435 // Add a favicon 459 GURL page_url("http://www.google.com");
436 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); 460 AddFaviconAndMapSimple(&db, page_url, kIconUrl1, favicon_base::FAVICON);
437 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); 461 AddFaviconAndMapSimple(&db, page_url, kIconUrl2, favicon_base::TOUCH_ICON);
462 AddFaviconAndMapSimple(&db, page_url, kIconUrl3, favicon_base::TOUCH_ICON);
463 AddFaviconAndMapSimple(&db, page_url, kIconUrl4,
464 favicon_base::TOUCH_PRECOMPOSED_ICON);
438 465
439 GURL page_url("http://google.com"); 466 // Only the mappings for FAVICON and TOUCH_ICON should be returned.
440 GURL icon_url("http://google.com/favicon.ico");
441 base::Time time = base::Time::Now();
442
443 favicon_base::FaviconID id = db.AddFavicon(
444 icon_url, favicon_base::FAVICON, favicon, time, gfx::Size());
445 EXPECT_NE(0, db.AddIconMapping(page_url, id));
446 std::vector<IconMapping> icon_mappings;
447 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings));
448
449 EXPECT_EQ(page_url, icon_mappings.front().page_url);
450 EXPECT_EQ(id, icon_mappings.front().icon_id);
451 EXPECT_EQ(favicon_base::FAVICON, icon_mappings.front().icon_type);
452 EXPECT_EQ(icon_url, icon_mappings.front().icon_url);
453
454 // Add a touch icon
455 std::vector<unsigned char> data2(kBlob2, kBlob2 + sizeof(kBlob2));
456 scoped_refptr<base::RefCountedBytes> favicon2 =
457 new base::RefCountedBytes(data);
458
459 favicon_base::FaviconID id2 = db.AddFavicon(
460 icon_url, favicon_base::TOUCH_ICON, favicon2, time, gfx::Size());
461 EXPECT_NE(0, db.AddIconMapping(page_url, id2));
462
463 icon_mappings.clear();
464 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings));
465
466 EXPECT_EQ(page_url, icon_mappings.front().page_url);
467 EXPECT_EQ(id2, icon_mappings.front().icon_id);
468 EXPECT_EQ(favicon_base::TOUCH_ICON, icon_mappings.front().icon_type);
469 EXPECT_EQ(icon_url, icon_mappings.front().icon_url);
470
471 // Add a touch precomposed icon
472 scoped_refptr<base::RefCountedBytes> favicon3 =
473 new base::RefCountedBytes(data2);
474
475 favicon_base::FaviconID id3 =
476 db.AddFavicon(icon_url,
477 favicon_base::TOUCH_PRECOMPOSED_ICON,
478 favicon3,
479 time,
480 gfx::Size());
481 EXPECT_NE(0, db.AddIconMapping(page_url, id3));
482
483 icon_mappings.clear();
484 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings));
485
486 EXPECT_EQ(page_url, icon_mappings.front().page_url);
487 EXPECT_EQ(id3, icon_mappings.front().icon_id);
488 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON,
489 icon_mappings.front().icon_type);
490 EXPECT_EQ(icon_url, icon_mappings.front().icon_url);
491 }
492
493 // Test result of GetIconMappingsForPageURL when an icon type is passed in.
494 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLWithIconType) {
495 ThumbnailDatabase db(NULL);
496 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
497 db.BeginTransaction();
498
499 GURL url("http://google.com");
500 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
501 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
502 base::Time time = base::Time::Now();
503
504 favicon_base::FaviconID id1 =
505 db.AddFavicon(url, favicon_base::FAVICON, favicon, time, gfx::Size());
506 EXPECT_NE(0, db.AddIconMapping(url, id1));
507
508 favicon_base::FaviconID id2 =
509 db.AddFavicon(url, favicon_base::TOUCH_ICON, favicon, time, gfx::Size());
510 EXPECT_NE(0, db.AddIconMapping(url, id2));
511
512 favicon_base::FaviconID id3 =
513 db.AddFavicon(url, favicon_base::TOUCH_ICON, favicon, time, gfx::Size());
514 EXPECT_NE(0, db.AddIconMapping(url, id3));
515
516 // Only the mappings for favicons of type TOUCH_ICON should be returned as
517 // TOUCH_ICON is a larger icon type than FAVICON.
518 std::vector<IconMapping> icon_mappings; 467 std::vector<IconMapping> icon_mappings;
519 EXPECT_TRUE(db.GetIconMappingsForPageURL( 468 EXPECT_TRUE(db.GetIconMappingsForPageURL(
520 url, 469 page_url, favicon_base::FAVICON | favicon_base::TOUCH_ICON,
521 favicon_base::FAVICON | favicon_base::TOUCH_ICON |
522 favicon_base::TOUCH_PRECOMPOSED_ICON,
523 &icon_mappings)); 470 &icon_mappings));
471 SortMappingsByIconUrl(&icon_mappings);
524 472
525 EXPECT_EQ(2u, icon_mappings.size()); 473 EXPECT_EQ(3u, icon_mappings.size());
526 if (id2 == icon_mappings[0].icon_id) { 474 EXPECT_EQ(kIconUrl1, icon_mappings[0].icon_url);
527 EXPECT_EQ(id3, icon_mappings[1].icon_id); 475 EXPECT_EQ(kIconUrl2, icon_mappings[1].icon_url);
528 } else { 476 EXPECT_EQ(kIconUrl3, icon_mappings[2].icon_url);
529 EXPECT_EQ(id3, icon_mappings[0].icon_id);
530 EXPECT_EQ(id2, icon_mappings[1].icon_id);
531 }
532
533 icon_mappings.clear();
534 EXPECT_TRUE(db.GetIconMappingsForPageURL(
535 url, favicon_base::TOUCH_ICON, &icon_mappings));
536 if (id2 == icon_mappings[0].icon_id) {
537 EXPECT_EQ(id3, icon_mappings[1].icon_id);
538 } else {
539 EXPECT_EQ(id3, icon_mappings[0].icon_id);
540 EXPECT_EQ(id2, icon_mappings[1].icon_id);
541 }
542
543 icon_mappings.clear();
544 EXPECT_TRUE(
545 db.GetIconMappingsForPageURL(url, favicon_base::FAVICON, &icon_mappings));
546 EXPECT_EQ(1u, icon_mappings.size());
547 EXPECT_EQ(id1, icon_mappings[0].icon_id);
548 } 477 }
549 478
550 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { 479 TEST_F(ThumbnailDatabaseTest, HasMappingFor) {
551 ThumbnailDatabase db(NULL); 480 ThumbnailDatabase db(NULL);
552 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 481 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
553 db.BeginTransaction(); 482 db.BeginTransaction();
554 483
555 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); 484 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
556 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); 485 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
557 486
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 // Version 6 is deprecated, the data should all be gone. 568 // Version 6 is deprecated, the data should all be gone.
640 VerifyDatabaseEmpty(&db->db_); 569 VerifyDatabaseEmpty(&db->db_);
641 } 570 }
642 571
643 // Test loading version 7 database. 572 // Test loading version 7 database.
644 TEST_F(ThumbnailDatabaseTest, Version7) { 573 TEST_F(ThumbnailDatabaseTest, Version7) {
645 std::unique_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v7.sql"); 574 std::unique_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v7.sql");
646 ASSERT_TRUE(db.get() != NULL); 575 ASSERT_TRUE(db.get() != NULL);
647 VerifyTablesAndColumns(&db->db_); 576 VerifyTablesAndColumns(&db->db_);
648 577
649 EXPECT_TRUE(CheckPageHasIcon(db.get(), 578 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl1, favicon_base::FAVICON,
650 kPageUrl1, 579 kIconUrl3, kLargeSize, sizeof(kBlob1), kBlob1));
651 favicon_base::FAVICON, 580 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl2, favicon_base::FAVICON,
652 kIconUrl1, 581 kIconUrl5, kLargeSize, sizeof(kBlob2), kBlob2));
653 kLargeSize, 582 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl3, favicon_base::FAVICON,
654 sizeof(kBlob1), 583 kIconUrl3, kLargeSize, sizeof(kBlob1), kBlob1));
655 kBlob1)); 584 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl3, favicon_base::TOUCH_ICON,
656 EXPECT_TRUE(CheckPageHasIcon(db.get(), 585 kIconUrl4, kLargeSize, sizeof(kBlob2), kBlob2));
657 kPageUrl2,
658 favicon_base::FAVICON,
659 kIconUrl2,
660 kLargeSize,
661 sizeof(kBlob2),
662 kBlob2));
663 EXPECT_TRUE(CheckPageHasIcon(db.get(),
664 kPageUrl3,
665 favicon_base::FAVICON,
666 kIconUrl1,
667 kLargeSize,
668 sizeof(kBlob1),
669 kBlob1));
670 EXPECT_TRUE(CheckPageHasIcon(db.get(),
671 kPageUrl3,
672 favicon_base::TOUCH_ICON,
673 kIconUrl3,
674 kLargeSize,
675 sizeof(kBlob2),
676 kBlob2));
677 } 586 }
678 587
679 // Test loading version 8 database. 588 // Test loading version 8 database.
680 TEST_F(ThumbnailDatabaseTest, Version8) { 589 TEST_F(ThumbnailDatabaseTest, Version8) {
681 std::unique_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v8.sql"); 590 std::unique_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v8.sql");
682 ASSERT_TRUE(db.get() != NULL); 591 ASSERT_TRUE(db.get() != NULL);
683 VerifyTablesAndColumns(&db->db_); 592 VerifyTablesAndColumns(&db->db_);
684 593
685 EXPECT_TRUE(CheckPageHasIcon(db.get(), 594 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl1, favicon_base::FAVICON,
686 kPageUrl1, 595 kIconUrl3, kLargeSize, sizeof(kBlob1), kBlob1));
687 favicon_base::FAVICON, 596 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl2, favicon_base::FAVICON,
688 kIconUrl1, 597 kIconUrl5, kLargeSize, sizeof(kBlob2), kBlob2));
689 kLargeSize, 598 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl3, favicon_base::FAVICON,
690 sizeof(kBlob1), 599 kIconUrl3, kLargeSize, sizeof(kBlob1), kBlob1));
691 kBlob1)); 600 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl3, favicon_base::TOUCH_ICON,
692 EXPECT_TRUE(CheckPageHasIcon(db.get(), 601 kIconUrl4, kLargeSize, sizeof(kBlob2), kBlob2));
693 kPageUrl2,
694 favicon_base::FAVICON,
695 kIconUrl2,
696 kLargeSize,
697 sizeof(kBlob2),
698 kBlob2));
699 EXPECT_TRUE(CheckPageHasIcon(db.get(),
700 kPageUrl3,
701 favicon_base::FAVICON,
702 kIconUrl1,
703 kLargeSize,
704 sizeof(kBlob1),
705 kBlob1));
706 EXPECT_TRUE(CheckPageHasIcon(db.get(),
707 kPageUrl3,
708 favicon_base::TOUCH_ICON,
709 kIconUrl3,
710 kLargeSize,
711 sizeof(kBlob2),
712 kBlob2));
713 } 602 }
714 603
715 TEST_F(ThumbnailDatabaseTest, Recovery) { 604 TEST_F(ThumbnailDatabaseTest, Recovery) {
716 // This code tests the recovery module in concert with Chromium's 605 // This code tests the recovery module in concert with Chromium's
717 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is 606 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is
718 // not available. This is detected dynamically because corrupt 607 // not available. This is detected dynamically because corrupt
719 // databases still need to be handled, perhaps by Raze(), and the 608 // databases still need to be handled, perhaps by Raze(), and the
720 // recovery module is an obvious layer to abstract that to. 609 // recovery module is an obvious layer to abstract that to.
721 // TODO(shess): Handle that case for real! 610 // TODO(shess): Handle that case for real!
722 if (!sql::Recovery::FullRecoverySupported()) 611 if (!sql::Recovery::FullRecoverySupported())
723 return; 612 return;
724 613
725 // Create an example database. 614 // Create an example database.
726 { 615 {
727 EXPECT_TRUE(CreateDatabaseFromSQL(file_name_, "Favicons.v8.sql")); 616 EXPECT_TRUE(CreateDatabaseFromSQL(file_name_, "Favicons.v8.sql"));
728 617
729 sql::Connection raw_db; 618 sql::Connection raw_db;
730 EXPECT_TRUE(raw_db.Open(file_name_)); 619 EXPECT_TRUE(raw_db.Open(file_name_));
731 VerifyTablesAndColumns(&raw_db); 620 VerifyTablesAndColumns(&raw_db);
732 } 621 }
733 622
734 // Test that the contents make sense after clean open. 623 // Test that the contents make sense after clean open.
735 { 624 {
736 ThumbnailDatabase db(NULL); 625 ThumbnailDatabase db(NULL);
737 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 626 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
738 627
739 EXPECT_TRUE(CheckPageHasIcon(&db, 628 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON,
740 kPageUrl1, 629 kIconUrl3, kLargeSize, sizeof(kBlob1),
741 favicon_base::FAVICON,
742 kIconUrl1,
743 kLargeSize,
744 sizeof(kBlob1),
745 kBlob1)); 630 kBlob1));
746 EXPECT_TRUE(CheckPageHasIcon(&db, 631 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl2, favicon_base::FAVICON,
747 kPageUrl2, 632 kIconUrl5, kLargeSize, sizeof(kBlob2),
748 favicon_base::FAVICON,
749 kIconUrl2,
750 kLargeSize,
751 sizeof(kBlob2),
752 kBlob2)); 633 kBlob2));
753 } 634 }
754 635
755 // Corrupt the |icon_mapping.page_url| index by deleting an element 636 // Corrupt the |icon_mapping.page_url| index by deleting an element
756 // from the backing table but not the index. 637 // from the backing table but not the index.
757 { 638 {
758 sql::Connection raw_db; 639 sql::Connection raw_db;
759 EXPECT_TRUE(raw_db.Open(file_name_)); 640 EXPECT_TRUE(raw_db.Open(file_name_));
760 ASSERT_EQ("ok", sql::test::IntegrityCheck(&raw_db)); 641 ASSERT_EQ("ok", sql::test::IntegrityCheck(&raw_db));
761 } 642 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 681
801 // Database should also be recovered at higher levels. 682 // Database should also be recovered at higher levels.
802 { 683 {
803 ThumbnailDatabase db(NULL); 684 ThumbnailDatabase db(NULL);
804 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 685 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
805 686
806 // Now this fails because there is no mapping. 687 // Now this fails because there is no mapping.
807 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); 688 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL));
808 689
809 // Other data was retained by recovery. 690 // Other data was retained by recovery.
810 EXPECT_TRUE(CheckPageHasIcon(&db, 691 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON,
811 kPageUrl1, 692 kIconUrl3, kLargeSize, sizeof(kBlob1),
812 favicon_base::FAVICON,
813 kIconUrl1,
814 kLargeSize,
815 sizeof(kBlob1),
816 kBlob1)); 693 kBlob1));
817 } 694 }
818 695
819 // Corrupt the database again by adjusting the header. 696 // Corrupt the database again by adjusting the header.
820 EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_)); 697 EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_));
821 698
822 // Database is unusable at the SQLite level. 699 // Database is unusable at the SQLite level.
823 { 700 {
824 sql::test::ScopedErrorExpecter expecter; 701 sql::test::ScopedErrorExpecter expecter;
825 expecter.ExpectError(SQLITE_CORRUPT); 702 expecter.ExpectError(SQLITE_CORRUPT);
826 sql::Connection raw_db; 703 sql::Connection raw_db;
827 EXPECT_TRUE(raw_db.Open(file_name_)); 704 EXPECT_TRUE(raw_db.Open(file_name_));
828 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check")); 705 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check"));
829 ASSERT_TRUE(expecter.SawExpectedErrors()); 706 ASSERT_TRUE(expecter.SawExpectedErrors());
830 } 707 }
831 708
832 // Database should be recovered during open. 709 // Database should be recovered during open.
833 { 710 {
834 sql::test::ScopedErrorExpecter expecter; 711 sql::test::ScopedErrorExpecter expecter;
835 expecter.ExpectError(SQLITE_CORRUPT); 712 expecter.ExpectError(SQLITE_CORRUPT);
836 ThumbnailDatabase db(NULL); 713 ThumbnailDatabase db(NULL);
837 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 714 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
838 715
839 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); 716 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL));
840 EXPECT_TRUE(CheckPageHasIcon(&db, 717 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON,
841 kPageUrl1, 718 kIconUrl3, kLargeSize, sizeof(kBlob1),
842 favicon_base::FAVICON,
843 kIconUrl1,
844 kLargeSize,
845 sizeof(kBlob1),
846 kBlob1)); 719 kBlob1));
847 720
848 ASSERT_TRUE(expecter.SawExpectedErrors()); 721 ASSERT_TRUE(expecter.SawExpectedErrors());
849 } 722 }
850 } 723 }
851 724
852 TEST_F(ThumbnailDatabaseTest, Recovery7) { 725 TEST_F(ThumbnailDatabaseTest, Recovery7) {
853 // This code tests the recovery module in concert with Chromium's 726 // This code tests the recovery module in concert with Chromium's
854 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is 727 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is
855 // not available. This is detected dynamically because corrupt 728 // not available. This is detected dynamically because corrupt
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 785
913 // Database should also be recovered at higher levels. 786 // Database should also be recovered at higher levels.
914 { 787 {
915 ThumbnailDatabase db(NULL); 788 ThumbnailDatabase db(NULL);
916 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 789 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
917 790
918 // Now this fails because there is no mapping. 791 // Now this fails because there is no mapping.
919 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); 792 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL));
920 793
921 // Other data was retained by recovery. 794 // Other data was retained by recovery.
922 EXPECT_TRUE(CheckPageHasIcon(&db, 795 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON,
923 kPageUrl1, 796 kIconUrl3, kLargeSize, sizeof(kBlob1),
924 favicon_base::FAVICON,
925 kIconUrl1,
926 kLargeSize,
927 sizeof(kBlob1),
928 kBlob1)); 797 kBlob1));
929 } 798 }
930 799
931 // Corrupt the database again by adjusting the header. 800 // Corrupt the database again by adjusting the header.
932 EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_)); 801 EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_));
933 802
934 // Database is unusable at the SQLite level. 803 // Database is unusable at the SQLite level.
935 { 804 {
936 sql::test::ScopedErrorExpecter expecter; 805 sql::test::ScopedErrorExpecter expecter;
937 expecter.ExpectError(SQLITE_CORRUPT); 806 expecter.ExpectError(SQLITE_CORRUPT);
938 sql::Connection raw_db; 807 sql::Connection raw_db;
939 EXPECT_TRUE(raw_db.Open(file_name_)); 808 EXPECT_TRUE(raw_db.Open(file_name_));
940 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check")); 809 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check"));
941 ASSERT_TRUE(expecter.SawExpectedErrors()); 810 ASSERT_TRUE(expecter.SawExpectedErrors());
942 } 811 }
943 812
944 // Database should be recovered during open. 813 // Database should be recovered during open.
945 { 814 {
946 sql::test::ScopedErrorExpecter expecter; 815 sql::test::ScopedErrorExpecter expecter;
947 expecter.ExpectError(SQLITE_CORRUPT); 816 expecter.ExpectError(SQLITE_CORRUPT);
948 ThumbnailDatabase db(NULL); 817 ThumbnailDatabase db(NULL);
949 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 818 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
950 819
951 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); 820 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL));
952 EXPECT_TRUE(CheckPageHasIcon(&db, 821 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON,
953 kPageUrl1, 822 kIconUrl3, kLargeSize, sizeof(kBlob1),
954 favicon_base::FAVICON,
955 kIconUrl1,
956 kLargeSize,
957 sizeof(kBlob1),
958 kBlob1)); 823 kBlob1));
959 824
960 ASSERT_TRUE(expecter.SawExpectedErrors()); 825 ASSERT_TRUE(expecter.SawExpectedErrors());
961 } 826 }
962 } 827 }
963 828
964 TEST_F(ThumbnailDatabaseTest, Recovery6) { 829 TEST_F(ThumbnailDatabaseTest, Recovery6) {
965 // TODO(shess): See comment at top of Recovery test. 830 // TODO(shess): See comment at top of Recovery test.
966 if (!sql::Recovery::FullRecoverySupported()) 831 if (!sql::Recovery::FullRecoverySupported())
967 return; 832 return;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 ThumbnailDatabase db(NULL); 945 ThumbnailDatabase db(NULL);
1081 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); 946 ASSERT_EQ(sql::INIT_OK, db.Init(db_path));
1082 947
1083 // Verify that the resulting schema is correct, whether it 948 // Verify that the resulting schema is correct, whether it
1084 // involved razing the file or fixing things in place. 949 // involved razing the file or fixing things in place.
1085 VerifyTablesAndColumns(&db.db_); 950 VerifyTablesAndColumns(&db.db_);
1086 } 951 }
1087 } 952 }
1088 953
1089 } // namespace history 954 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698