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 <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 Loading... | |
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 Loading... | |
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, | |
mastiz
2017/04/20 08:55:59
Nit: s/Map/Mapping/?
'Map' can otherwise interpre
pkotwicz
2017/04/30 03:49:56
Done.
| |
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 Loading... | |
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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 icon_mappings.clear(); | 505 icon_mappings.clear(); |
484 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings)); | 506 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings)); |
485 | 507 |
486 EXPECT_EQ(page_url, icon_mappings.front().page_url); | 508 EXPECT_EQ(page_url, icon_mappings.front().page_url); |
487 EXPECT_EQ(id3, icon_mappings.front().icon_id); | 509 EXPECT_EQ(id3, icon_mappings.front().icon_id); |
488 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, | 510 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, |
489 icon_mappings.front().icon_type); | 511 icon_mappings.front().icon_type); |
490 EXPECT_EQ(icon_url, icon_mappings.front().icon_url); | 512 EXPECT_EQ(icon_url, icon_mappings.front().icon_url); |
491 } | 513 } |
492 | 514 |
493 // Test result of GetIconMappingsForPageURL when an icon type is passed in. | 515 // Test that when multiple icon types are passed to GetIconMappingsForPageURL() |
494 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLWithIconType) { | 516 // that the results are filtered according to the passed in types. |
517 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLWithIconTypes) { | |
495 ThumbnailDatabase db(NULL); | 518 ThumbnailDatabase db(NULL); |
496 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 519 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
497 db.BeginTransaction(); | 520 db.BeginTransaction(); |
498 | 521 |
499 GURL url("http://google.com"); | 522 GURL page_url("http://www.google.com"); |
500 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | 523 AddFaviconAndMapSimple(&db, page_url, kIconUrl1, favicon_base::FAVICON); |
501 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 524 AddFaviconAndMapSimple(&db, page_url, kIconUrl2, favicon_base::TOUCH_ICON); |
502 base::Time time = base::Time::Now(); | 525 AddFaviconAndMapSimple(&db, page_url, kIconUrl3, favicon_base::TOUCH_ICON); |
526 AddFaviconAndMapSimple(&db, page_url, kIconUrl4, | |
527 favicon_base::TOUCH_PRECOMPOSED_ICON); | |
503 | 528 |
504 favicon_base::FaviconID id1 = | 529 // Only the mappings for FAVICON and TOUCH_ICON should be returned. |
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; | 530 std::vector<IconMapping> icon_mappings; |
519 EXPECT_TRUE(db.GetIconMappingsForPageURL( | 531 EXPECT_TRUE(db.GetIconMappingsForPageURL( |
520 url, | 532 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)); | 533 &icon_mappings)); |
534 SortMappingsByIconUrl(&icon_mappings); | |
524 | 535 |
525 EXPECT_EQ(2u, icon_mappings.size()); | 536 EXPECT_EQ(3u, icon_mappings.size()); |
526 if (id2 == icon_mappings[0].icon_id) { | 537 EXPECT_EQ(kIconUrl1, icon_mappings[0].icon_url); |
527 EXPECT_EQ(id3, icon_mappings[1].icon_id); | 538 EXPECT_EQ(kIconUrl2, icon_mappings[1].icon_url); |
528 } else { | 539 EXPECT_EQ(kIconUrl3, icon_mappings[2].icon_url); |
mastiz
2017/04/20 08:55:59
A more natural way to do this would be to get rid
pkotwicz
2017/04/30 03:49:56
I chose to not add a GMock dependency to this test
| |
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 } | 540 } |
549 | 541 |
550 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { | 542 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { |
551 ThumbnailDatabase db(NULL); | 543 ThumbnailDatabase db(NULL); |
552 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 544 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
553 db.BeginTransaction(); | 545 db.BeginTransaction(); |
554 | 546 |
555 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | 547 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
556 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 548 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
557 | 549 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
639 // Version 6 is deprecated, the data should all be gone. | 631 // Version 6 is deprecated, the data should all be gone. |
640 VerifyDatabaseEmpty(&db->db_); | 632 VerifyDatabaseEmpty(&db->db_); |
641 } | 633 } |
642 | 634 |
643 // Test loading version 7 database. | 635 // Test loading version 7 database. |
644 TEST_F(ThumbnailDatabaseTest, Version7) { | 636 TEST_F(ThumbnailDatabaseTest, Version7) { |
645 std::unique_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v7.sql"); | 637 std::unique_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v7.sql"); |
646 ASSERT_TRUE(db.get() != NULL); | 638 ASSERT_TRUE(db.get() != NULL); |
647 VerifyTablesAndColumns(&db->db_); | 639 VerifyTablesAndColumns(&db->db_); |
648 | 640 |
649 EXPECT_TRUE(CheckPageHasIcon(db.get(), | 641 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl1, favicon_base::FAVICON, |
650 kPageUrl1, | 642 kIconUrl3, kLargeSize, sizeof(kBlob1), kBlob1)); |
651 favicon_base::FAVICON, | 643 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl2, favicon_base::FAVICON, |
652 kIconUrl1, | 644 kIconUrl5, kLargeSize, sizeof(kBlob2), kBlob2)); |
653 kLargeSize, | 645 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl3, favicon_base::FAVICON, |
654 sizeof(kBlob1), | 646 kIconUrl3, kLargeSize, sizeof(kBlob1), kBlob1)); |
655 kBlob1)); | 647 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl3, favicon_base::TOUCH_ICON, |
656 EXPECT_TRUE(CheckPageHasIcon(db.get(), | 648 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 } | 649 } |
678 | 650 |
679 // Test loading version 8 database. | 651 // Test loading version 8 database. |
680 TEST_F(ThumbnailDatabaseTest, Version8) { | 652 TEST_F(ThumbnailDatabaseTest, Version8) { |
681 std::unique_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v8.sql"); | 653 std::unique_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v8.sql"); |
682 ASSERT_TRUE(db.get() != NULL); | 654 ASSERT_TRUE(db.get() != NULL); |
683 VerifyTablesAndColumns(&db->db_); | 655 VerifyTablesAndColumns(&db->db_); |
684 | 656 |
685 EXPECT_TRUE(CheckPageHasIcon(db.get(), | 657 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl1, favicon_base::FAVICON, |
686 kPageUrl1, | 658 kIconUrl3, kLargeSize, sizeof(kBlob1), kBlob1)); |
687 favicon_base::FAVICON, | 659 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl2, favicon_base::FAVICON, |
688 kIconUrl1, | 660 kIconUrl5, kLargeSize, sizeof(kBlob2), kBlob2)); |
689 kLargeSize, | 661 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl3, favicon_base::FAVICON, |
690 sizeof(kBlob1), | 662 kIconUrl3, kLargeSize, sizeof(kBlob1), kBlob1)); |
691 kBlob1)); | 663 EXPECT_TRUE(CheckPageHasIcon(db.get(), kPageUrl3, favicon_base::TOUCH_ICON, |
692 EXPECT_TRUE(CheckPageHasIcon(db.get(), | 664 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 } | 665 } |
714 | 666 |
715 TEST_F(ThumbnailDatabaseTest, Recovery) { | 667 TEST_F(ThumbnailDatabaseTest, Recovery) { |
716 // This code tests the recovery module in concert with Chromium's | 668 // This code tests the recovery module in concert with Chromium's |
717 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is | 669 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is |
718 // not available. This is detected dynamically because corrupt | 670 // not available. This is detected dynamically because corrupt |
719 // databases still need to be handled, perhaps by Raze(), and the | 671 // databases still need to be handled, perhaps by Raze(), and the |
720 // recovery module is an obvious layer to abstract that to. | 672 // recovery module is an obvious layer to abstract that to. |
721 // TODO(shess): Handle that case for real! | 673 // TODO(shess): Handle that case for real! |
722 if (!sql::Recovery::FullRecoverySupported()) | 674 if (!sql::Recovery::FullRecoverySupported()) |
723 return; | 675 return; |
724 | 676 |
725 // Create an example database. | 677 // Create an example database. |
726 { | 678 { |
727 EXPECT_TRUE(CreateDatabaseFromSQL(file_name_, "Favicons.v8.sql")); | 679 EXPECT_TRUE(CreateDatabaseFromSQL(file_name_, "Favicons.v8.sql")); |
728 | 680 |
729 sql::Connection raw_db; | 681 sql::Connection raw_db; |
730 EXPECT_TRUE(raw_db.Open(file_name_)); | 682 EXPECT_TRUE(raw_db.Open(file_name_)); |
731 VerifyTablesAndColumns(&raw_db); | 683 VerifyTablesAndColumns(&raw_db); |
732 } | 684 } |
733 | 685 |
734 // Test that the contents make sense after clean open. | 686 // Test that the contents make sense after clean open. |
735 { | 687 { |
736 ThumbnailDatabase db(NULL); | 688 ThumbnailDatabase db(NULL); |
737 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 689 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
738 | 690 |
739 EXPECT_TRUE(CheckPageHasIcon(&db, | 691 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON, |
740 kPageUrl1, | 692 kIconUrl3, kLargeSize, sizeof(kBlob1), |
741 favicon_base::FAVICON, | |
742 kIconUrl1, | |
743 kLargeSize, | |
744 sizeof(kBlob1), | |
745 kBlob1)); | 693 kBlob1)); |
746 EXPECT_TRUE(CheckPageHasIcon(&db, | 694 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl2, favicon_base::FAVICON, |
747 kPageUrl2, | 695 kIconUrl5, kLargeSize, sizeof(kBlob2), |
748 favicon_base::FAVICON, | |
749 kIconUrl2, | |
750 kLargeSize, | |
751 sizeof(kBlob2), | |
752 kBlob2)); | 696 kBlob2)); |
753 } | 697 } |
754 | 698 |
755 // Corrupt the |icon_mapping.page_url| index by deleting an element | 699 // Corrupt the |icon_mapping.page_url| index by deleting an element |
756 // from the backing table but not the index. | 700 // from the backing table but not the index. |
757 { | 701 { |
758 sql::Connection raw_db; | 702 sql::Connection raw_db; |
759 EXPECT_TRUE(raw_db.Open(file_name_)); | 703 EXPECT_TRUE(raw_db.Open(file_name_)); |
760 ASSERT_EQ("ok", sql::test::IntegrityCheck(&raw_db)); | 704 ASSERT_EQ("ok", sql::test::IntegrityCheck(&raw_db)); |
761 } | 705 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
800 | 744 |
801 // Database should also be recovered at higher levels. | 745 // Database should also be recovered at higher levels. |
802 { | 746 { |
803 ThumbnailDatabase db(NULL); | 747 ThumbnailDatabase db(NULL); |
804 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 748 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
805 | 749 |
806 // Now this fails because there is no mapping. | 750 // Now this fails because there is no mapping. |
807 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); | 751 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); |
808 | 752 |
809 // Other data was retained by recovery. | 753 // Other data was retained by recovery. |
810 EXPECT_TRUE(CheckPageHasIcon(&db, | 754 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON, |
811 kPageUrl1, | 755 kIconUrl3, kLargeSize, sizeof(kBlob1), |
812 favicon_base::FAVICON, | |
813 kIconUrl1, | |
814 kLargeSize, | |
815 sizeof(kBlob1), | |
816 kBlob1)); | 756 kBlob1)); |
817 } | 757 } |
818 | 758 |
819 // Corrupt the database again by adjusting the header. | 759 // Corrupt the database again by adjusting the header. |
820 EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_)); | 760 EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_)); |
821 | 761 |
822 // Database is unusable at the SQLite level. | 762 // Database is unusable at the SQLite level. |
823 { | 763 { |
824 sql::test::ScopedErrorExpecter expecter; | 764 sql::test::ScopedErrorExpecter expecter; |
825 expecter.ExpectError(SQLITE_CORRUPT); | 765 expecter.ExpectError(SQLITE_CORRUPT); |
826 sql::Connection raw_db; | 766 sql::Connection raw_db; |
827 EXPECT_TRUE(raw_db.Open(file_name_)); | 767 EXPECT_TRUE(raw_db.Open(file_name_)); |
828 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check")); | 768 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check")); |
829 ASSERT_TRUE(expecter.SawExpectedErrors()); | 769 ASSERT_TRUE(expecter.SawExpectedErrors()); |
830 } | 770 } |
831 | 771 |
832 // Database should be recovered during open. | 772 // Database should be recovered during open. |
833 { | 773 { |
834 sql::test::ScopedErrorExpecter expecter; | 774 sql::test::ScopedErrorExpecter expecter; |
835 expecter.ExpectError(SQLITE_CORRUPT); | 775 expecter.ExpectError(SQLITE_CORRUPT); |
836 ThumbnailDatabase db(NULL); | 776 ThumbnailDatabase db(NULL); |
837 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 777 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
838 | 778 |
839 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); | 779 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); |
840 EXPECT_TRUE(CheckPageHasIcon(&db, | 780 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON, |
841 kPageUrl1, | 781 kIconUrl3, kLargeSize, sizeof(kBlob1), |
842 favicon_base::FAVICON, | |
843 kIconUrl1, | |
844 kLargeSize, | |
845 sizeof(kBlob1), | |
846 kBlob1)); | 782 kBlob1)); |
847 | 783 |
848 ASSERT_TRUE(expecter.SawExpectedErrors()); | 784 ASSERT_TRUE(expecter.SawExpectedErrors()); |
849 } | 785 } |
850 } | 786 } |
851 | 787 |
852 TEST_F(ThumbnailDatabaseTest, Recovery7) { | 788 TEST_F(ThumbnailDatabaseTest, Recovery7) { |
853 // This code tests the recovery module in concert with Chromium's | 789 // This code tests the recovery module in concert with Chromium's |
854 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is | 790 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is |
855 // not available. This is detected dynamically because corrupt | 791 // not available. This is detected dynamically because corrupt |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 | 848 |
913 // Database should also be recovered at higher levels. | 849 // Database should also be recovered at higher levels. |
914 { | 850 { |
915 ThumbnailDatabase db(NULL); | 851 ThumbnailDatabase db(NULL); |
916 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 852 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
917 | 853 |
918 // Now this fails because there is no mapping. | 854 // Now this fails because there is no mapping. |
919 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); | 855 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); |
920 | 856 |
921 // Other data was retained by recovery. | 857 // Other data was retained by recovery. |
922 EXPECT_TRUE(CheckPageHasIcon(&db, | 858 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON, |
923 kPageUrl1, | 859 kIconUrl3, kLargeSize, sizeof(kBlob1), |
924 favicon_base::FAVICON, | |
925 kIconUrl1, | |
926 kLargeSize, | |
927 sizeof(kBlob1), | |
928 kBlob1)); | 860 kBlob1)); |
929 } | 861 } |
930 | 862 |
931 // Corrupt the database again by adjusting the header. | 863 // Corrupt the database again by adjusting the header. |
932 EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_)); | 864 EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_)); |
933 | 865 |
934 // Database is unusable at the SQLite level. | 866 // Database is unusable at the SQLite level. |
935 { | 867 { |
936 sql::test::ScopedErrorExpecter expecter; | 868 sql::test::ScopedErrorExpecter expecter; |
937 expecter.ExpectError(SQLITE_CORRUPT); | 869 expecter.ExpectError(SQLITE_CORRUPT); |
938 sql::Connection raw_db; | 870 sql::Connection raw_db; |
939 EXPECT_TRUE(raw_db.Open(file_name_)); | 871 EXPECT_TRUE(raw_db.Open(file_name_)); |
940 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check")); | 872 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check")); |
941 ASSERT_TRUE(expecter.SawExpectedErrors()); | 873 ASSERT_TRUE(expecter.SawExpectedErrors()); |
942 } | 874 } |
943 | 875 |
944 // Database should be recovered during open. | 876 // Database should be recovered during open. |
945 { | 877 { |
946 sql::test::ScopedErrorExpecter expecter; | 878 sql::test::ScopedErrorExpecter expecter; |
947 expecter.ExpectError(SQLITE_CORRUPT); | 879 expecter.ExpectError(SQLITE_CORRUPT); |
948 ThumbnailDatabase db(NULL); | 880 ThumbnailDatabase db(NULL); |
949 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 881 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
950 | 882 |
951 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); | 883 EXPECT_FALSE(db.GetIconMappingsForPageURL(kPageUrl2, NULL)); |
952 EXPECT_TRUE(CheckPageHasIcon(&db, | 884 EXPECT_TRUE(CheckPageHasIcon(&db, kPageUrl1, favicon_base::FAVICON, |
953 kPageUrl1, | 885 kIconUrl3, kLargeSize, sizeof(kBlob1), |
954 favicon_base::FAVICON, | |
955 kIconUrl1, | |
956 kLargeSize, | |
957 sizeof(kBlob1), | |
958 kBlob1)); | 886 kBlob1)); |
959 | 887 |
960 ASSERT_TRUE(expecter.SawExpectedErrors()); | 888 ASSERT_TRUE(expecter.SawExpectedErrors()); |
961 } | 889 } |
962 } | 890 } |
963 | 891 |
964 TEST_F(ThumbnailDatabaseTest, Recovery6) { | 892 TEST_F(ThumbnailDatabaseTest, Recovery6) { |
965 // TODO(shess): See comment at top of Recovery test. | 893 // TODO(shess): See comment at top of Recovery test. |
966 if (!sql::Recovery::FullRecoverySupported()) | 894 if (!sql::Recovery::FullRecoverySupported()) |
967 return; | 895 return; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1080 ThumbnailDatabase db(NULL); | 1008 ThumbnailDatabase db(NULL); |
1081 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); | 1009 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); |
1082 | 1010 |
1083 // Verify that the resulting schema is correct, whether it | 1011 // Verify that the resulting schema is correct, whether it |
1084 // involved razing the file or fixing things in place. | 1012 // involved razing the file or fixing things in place. |
1085 VerifyTablesAndColumns(&db.db_); | 1013 VerifyTablesAndColumns(&db.db_); |
1086 } | 1014 } |
1087 } | 1015 } |
1088 | 1016 |
1089 } // namespace history | 1017 } // namespace history |
OLD | NEW |