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/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 | 61 |
62 // Verify that the up-to-date database has the expected tables and | 62 // Verify that the up-to-date database has the expected tables and |
63 // columns. Functional tests only check whether the things which | 63 // columns. Functional tests only check whether the things which |
64 // should be there are, but do not check if extraneous items are | 64 // should be there are, but do not check if extraneous items are |
65 // present. Any extraneous items have the potential to interact | 65 // present. Any extraneous items have the potential to interact |
66 // negatively with future schema changes. | 66 // negatively with future schema changes. |
67 void VerifyTablesAndColumns(sql::Connection* db) { | 67 void VerifyTablesAndColumns(sql::Connection* db) { |
68 // [meta], [favicons], [favicon_bitmaps], and [icon_mapping]. | 68 // [meta], [favicons], [favicon_bitmaps], and [icon_mapping]. |
69 EXPECT_EQ(4u, sql::test::CountSQLTables(db)); | 69 EXPECT_EQ(4u, sql::test::CountSQLTables(db)); |
70 | 70 |
71 // Implicit index on [meta], index on [favicons], index on | 71 // Implicit index on [meta], index on [favicons], two indices on |
72 // [favicon_bitmaps], two indices on [icon_mapping]. | 72 // [favicon_bitmaps], two indices on [icon_mapping]. |
73 EXPECT_EQ(5u, sql::test::CountSQLIndices(db)); | 73 EXPECT_EQ(6u, sql::test::CountSQLIndices(db)); |
74 | 74 |
75 // [key] and [value]. | 75 // [key] and [value]. |
76 EXPECT_EQ(2u, sql::test::CountTableColumns(db, "meta")); | 76 EXPECT_EQ(2u, sql::test::CountTableColumns(db, "meta")); |
77 | 77 |
78 // [id], [url], and [icon_type]. | 78 // [id], [url], and [icon_type]. |
79 EXPECT_EQ(3u, sql::test::CountTableColumns(db, "favicons")); | 79 EXPECT_EQ(3u, sql::test::CountTableColumns(db, "favicons")); |
80 | 80 |
81 // [id], [icon_id], [last_updated], [image_data], [width], and [height]. | 81 // [id], [icon_id], [last_updated], [last_requested], [image_data], [width], |
82 EXPECT_EQ(6u, sql::test::CountTableColumns(db, "favicon_bitmaps")); | 82 // and [height]. |
83 EXPECT_EQ(7u, sql::test::CountTableColumns(db, "favicon_bitmaps")); | |
83 | 84 |
84 // [id], [page_url], and [icon_id]. | 85 // [id], [page_url], and [icon_id]. |
85 EXPECT_EQ(3u, sql::test::CountTableColumns(db, "icon_mapping")); | 86 EXPECT_EQ(3u, sql::test::CountTableColumns(db, "icon_mapping")); |
86 } | 87 } |
87 | 88 |
88 void VerifyDatabaseEmpty(sql::Connection* db) { | 89 void VerifyDatabaseEmpty(sql::Connection* db) { |
89 size_t rows = 0; | 90 size_t rows = 0; |
90 EXPECT_TRUE(sql::test::CountTableRows(db, "favicons", &rows)); | 91 EXPECT_TRUE(sql::test::CountTableRows(db, "favicons", &rows)); |
91 EXPECT_EQ(0u, rows); | 92 EXPECT_EQ(0u, rows); |
92 EXPECT_TRUE(sql::test::CountTableRows(db, "favicon_bitmaps", &rows)); | 93 EXPECT_TRUE(sql::test::CountTableRows(db, "favicon_bitmaps", &rows)); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 EXPECT_NE(0, id); | 207 EXPECT_NE(0, id); |
207 | 208 |
208 EXPECT_NE(0, db.AddIconMapping(url, id)); | 209 EXPECT_NE(0, db.AddIconMapping(url, id)); |
209 std::vector<IconMapping> icon_mappings; | 210 std::vector<IconMapping> icon_mappings; |
210 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mappings)); | 211 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mappings)); |
211 EXPECT_EQ(1u, icon_mappings.size()); | 212 EXPECT_EQ(1u, icon_mappings.size()); |
212 EXPECT_EQ(url, icon_mappings.front().page_url); | 213 EXPECT_EQ(url, icon_mappings.front().page_url); |
213 EXPECT_EQ(id, icon_mappings.front().icon_id); | 214 EXPECT_EQ(id, icon_mappings.front().icon_id); |
214 } | 215 } |
215 | 216 |
217 TEST_F(ThumbnailDatabaseTest, LastRequestedTime) { | |
218 ThumbnailDatabase db(NULL); | |
219 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | |
220 db.BeginTransaction(); | |
221 | |
222 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | |
223 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | |
224 | |
225 GURL url("http://google.com"); | |
226 base::Time now = base::Time::Now(); | |
227 favicon_base::FaviconID id = | |
228 db.AddFavicon(url, favicon_base::TOUCH_ICON, favicon, now, gfx::Size()); | |
229 EXPECT_NE(0, id); | |
230 | |
231 // Fetching the last requested time of a non-existent bitmap should fail. | |
232 base::Time last_requested = base::Time::UnixEpoch(); | |
233 EXPECT_FALSE(db.GetFaviconBitmapLastRequestedTime(id + 1, &last_requested)); | |
234 EXPECT_EQ(last_requested, base::Time::UnixEpoch()); // Remains unchanged. | |
235 | |
236 // Fetching the last requested time of a bitmap that has no last request | |
237 // should return a null timestamp. | |
238 last_requested = base::Time::UnixEpoch(); | |
239 EXPECT_TRUE(db.GetFaviconBitmapLastRequestedTime(id, &last_requested)); | |
240 EXPECT_TRUE(last_requested.is_null()); | |
241 | |
242 // Setting the last requested time of an existing bitmap should succeed, and | |
243 // the set time should be returned by the corresponding "Get". | |
244 EXPECT_TRUE(db.SetFaviconBitmapLastRequestedTime(id, now)); | |
245 EXPECT_TRUE(db.GetFaviconBitmapLastRequestedTime(id, &last_requested)); | |
246 EXPECT_EQ(last_requested, now); | |
247 } | |
248 | |
216 TEST_F(ThumbnailDatabaseTest, UpdateIconMapping) { | 249 TEST_F(ThumbnailDatabaseTest, UpdateIconMapping) { |
217 ThumbnailDatabase db(NULL); | 250 ThumbnailDatabase db(NULL); |
218 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 251 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
219 db.BeginTransaction(); | 252 db.BeginTransaction(); |
220 | 253 |
221 GURL url("http://google.com"); | 254 GURL url("http://google.com"); |
222 favicon_base::FaviconID id = db.AddFavicon(url, favicon_base::TOUCH_ICON); | 255 favicon_base::FaviconID id = db.AddFavicon(url, favicon_base::TOUCH_ICON); |
223 | 256 |
224 EXPECT_LT(0, db.AddIconMapping(url, id)); | 257 EXPECT_LT(0, db.AddIconMapping(url, id)); |
225 std::vector<IconMapping> icon_mapping; | 258 std::vector<IconMapping> icon_mapping; |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 kBlob1)); | 792 kBlob1)); |
760 EXPECT_TRUE(CheckPageHasIcon(db.get(), | 793 EXPECT_TRUE(CheckPageHasIcon(db.get(), |
761 kPageUrl3, | 794 kPageUrl3, |
762 favicon_base::TOUCH_ICON, | 795 favicon_base::TOUCH_ICON, |
763 kIconUrl3, | 796 kIconUrl3, |
764 kLargeSize, | 797 kLargeSize, |
765 sizeof(kBlob2), | 798 sizeof(kBlob2), |
766 kBlob2)); | 799 kBlob2)); |
767 } | 800 } |
768 | 801 |
802 // Test loading version 8 database. | |
803 TEST_F(ThumbnailDatabaseTest, Version8) { | |
804 scoped_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v8.sql"); | |
805 ASSERT_TRUE(db.get() != NULL); | |
806 VerifyTablesAndColumns(&db->db_); | |
807 | |
808 EXPECT_TRUE(CheckPageHasIcon(db.get(), | |
809 kPageUrl1, | |
810 favicon_base::FAVICON, | |
811 kIconUrl1, | |
812 kLargeSize, | |
813 sizeof(kBlob1), | |
814 kBlob1)); | |
815 EXPECT_TRUE(CheckPageHasIcon(db.get(), | |
816 kPageUrl2, | |
817 favicon_base::FAVICON, | |
818 kIconUrl2, | |
819 kLargeSize, | |
820 sizeof(kBlob2), | |
821 kBlob2)); | |
822 EXPECT_TRUE(CheckPageHasIcon(db.get(), | |
823 kPageUrl3, | |
824 favicon_base::FAVICON, | |
825 kIconUrl1, | |
826 kLargeSize, | |
827 sizeof(kBlob1), | |
828 kBlob1)); | |
829 EXPECT_TRUE(CheckPageHasIcon(db.get(), | |
830 kPageUrl3, | |
831 favicon_base::TOUCH_ICON, | |
832 kIconUrl3, | |
833 kLargeSize, | |
834 sizeof(kBlob2), | |
835 kBlob2)); | |
836 } | |
837 | |
769 TEST_F(ThumbnailDatabaseTest, Recovery) { | 838 TEST_F(ThumbnailDatabaseTest, Recovery) { |
770 // This code tests the recovery module in concert with Chromium's | 839 // This code tests the recovery module in concert with Chromium's |
771 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is | 840 // custom recover virtual table. Under USE_SYSTEM_SQLITE, this is |
772 // not available. This is detected dynamically because corrupt | 841 // not available. This is detected dynamically because corrupt |
773 // databases still need to be handled, perhaps by Raze(), and the | 842 // databases still need to be handled, perhaps by Raze(), and the |
774 // recovery module is an obvious layer to abstract that to. | 843 // recovery module is an obvious layer to abstract that to. |
775 // TODO(shess): Handle that case for real! | 844 // TODO(shess): Handle that case for real! |
776 if (!sql::Recovery::FullRecoverySupported()) | 845 if (!sql::Recovery::FullRecoverySupported()) |
777 return; | 846 return; |
778 | 847 |
779 // Create an example database. | 848 // Create an example database. |
780 { | 849 { |
781 EXPECT_TRUE(CreateDatabaseFromSQL(file_name_, "Favicons.v7.sql")); | 850 EXPECT_TRUE(CreateDatabaseFromSQL(file_name_, "Favicons.v8.sql")); |
Scott Hess - ex-Googler
2015/03/17 22:07:44
Create test for Recovery7 which runs the recovery
Roger McFarlane (Chromium)
2015/03/19 17:55:51
Done.
| |
782 | 851 |
783 sql::Connection raw_db; | 852 sql::Connection raw_db; |
784 EXPECT_TRUE(raw_db.Open(file_name_)); | 853 EXPECT_TRUE(raw_db.Open(file_name_)); |
785 VerifyTablesAndColumns(&raw_db); | 854 VerifyTablesAndColumns(&raw_db); |
786 } | 855 } |
787 | 856 |
788 // Test that the contents make sense after clean open. | 857 // Test that the contents make sense after clean open. |
789 { | 858 { |
790 ThumbnailDatabase db(NULL); | 859 ThumbnailDatabase db(NULL); |
791 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 860 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1022 ThumbnailDatabase db(NULL); | 1091 ThumbnailDatabase db(NULL); |
1023 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); | 1092 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); |
1024 | 1093 |
1025 // Verify that the resulting schema is correct, whether it | 1094 // Verify that the resulting schema is correct, whether it |
1026 // involved razing the file or fixing things in place. | 1095 // involved razing the file or fixing things in place. |
1027 VerifyTablesAndColumns(&db.db_); | 1096 VerifyTablesAndColumns(&db.db_); |
1028 } | 1097 } |
1029 } | 1098 } |
1030 | 1099 |
1031 } // namespace history | 1100 } // namespace history |
OLD | NEW |