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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 EXPECT_TRUE(last_requested.is_null()); | 240 EXPECT_TRUE(last_requested.is_null()); |
241 | 241 |
242 // Setting the last requested time of an existing bitmap should succeed, and | 242 // Setting the last requested time of an existing bitmap should succeed, and |
243 // the set time should be returned by the corresponding "Get". | 243 // the set time should be returned by the corresponding "Get". |
244 last_requested = base::Time::UnixEpoch(); | 244 last_requested = base::Time::UnixEpoch(); |
245 EXPECT_TRUE(db.SetFaviconBitmapLastRequestedTime(id, now)); | 245 EXPECT_TRUE(db.SetFaviconBitmapLastRequestedTime(id, now)); |
246 EXPECT_TRUE(db.GetFaviconBitmap(id, NULL, &last_requested, NULL, NULL)); | 246 EXPECT_TRUE(db.GetFaviconBitmap(id, NULL, &last_requested, NULL, NULL)); |
247 EXPECT_EQ(last_requested, now); | 247 EXPECT_EQ(last_requested, now); |
248 } | 248 } |
249 | 249 |
250 TEST_F(ThumbnailDatabaseTest, UpdateIconMapping) { | |
251 ThumbnailDatabase db(NULL); | |
252 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | |
253 db.BeginTransaction(); | |
254 | |
255 GURL url("http://google.com"); | |
256 favicon_base::FaviconID id = db.AddFavicon(url, favicon_base::TOUCH_ICON); | |
257 | |
258 EXPECT_LT(0, db.AddIconMapping(url, id)); | |
259 std::vector<IconMapping> icon_mapping; | |
260 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | |
261 ASSERT_EQ(1u, icon_mapping.size()); | |
262 EXPECT_EQ(url, icon_mapping.front().page_url); | |
263 EXPECT_EQ(id, icon_mapping.front().icon_id); | |
264 | |
265 GURL url1("http://www.google.com/"); | |
266 favicon_base::FaviconID new_id = | |
267 db.AddFavicon(url1, favicon_base::TOUCH_ICON); | |
268 EXPECT_TRUE(db.UpdateIconMapping(icon_mapping.front().mapping_id, new_id)); | |
269 | |
270 icon_mapping.clear(); | |
271 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | |
272 ASSERT_EQ(1u, icon_mapping.size()); | |
273 EXPECT_EQ(url, icon_mapping.front().page_url); | |
274 EXPECT_EQ(new_id, icon_mapping.front().icon_id); | |
275 EXPECT_NE(id, icon_mapping.front().icon_id); | |
276 } | |
277 | |
278 TEST_F(ThumbnailDatabaseTest, DeleteIconMappings) { | 250 TEST_F(ThumbnailDatabaseTest, DeleteIconMappings) { |
279 ThumbnailDatabase db(NULL); | 251 ThumbnailDatabase db(NULL); |
280 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 252 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
281 db.BeginTransaction(); | 253 db.BeginTransaction(); |
282 | 254 |
283 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | 255 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
284 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 256 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
285 | 257 |
286 GURL url("http://google.com"); | 258 GURL url("http://google.com"); |
287 favicon_base::FaviconID id = db.AddFavicon(url, favicon_base::TOUCH_ICON); | 259 favicon_base::FaviconID id = db.AddFavicon(url, favicon_base::TOUCH_ICON); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 EXPECT_TRUE(db.HasMappingFor(id2)); | 579 EXPECT_TRUE(db.HasMappingFor(id2)); |
608 EXPECT_FALSE(db.HasMappingFor(id3)); | 580 EXPECT_FALSE(db.HasMappingFor(id3)); |
609 | 581 |
610 // Remove all mappings | 582 // Remove all mappings |
611 db.DeleteIconMappings(page_url); | 583 db.DeleteIconMappings(page_url); |
612 EXPECT_FALSE(db.HasMappingFor(id1)); | 584 EXPECT_FALSE(db.HasMappingFor(id1)); |
613 EXPECT_FALSE(db.HasMappingFor(id2)); | 585 EXPECT_FALSE(db.HasMappingFor(id2)); |
614 EXPECT_FALSE(db.HasMappingFor(id3)); | 586 EXPECT_FALSE(db.HasMappingFor(id3)); |
615 } | 587 } |
616 | 588 |
617 TEST_F(ThumbnailDatabaseTest, CloneIconMappings) { | |
618 ThumbnailDatabase db(NULL); | |
619 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | |
620 db.BeginTransaction(); | |
621 | |
622 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | |
623 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | |
624 | |
625 // Add a favicon which will have icon_mappings | |
626 favicon_base::FaviconID id1 = | |
627 db.AddFavicon(GURL("http://google.com"), favicon_base::FAVICON); | |
628 EXPECT_NE(0, id1); | |
629 base::Time time = base::Time::Now(); | |
630 db.AddFaviconBitmap(id1, favicon, time, gfx::Size()); | |
631 | |
632 // Add another type of favicon | |
633 favicon_base::FaviconID id2 = db.AddFavicon( | |
634 GURL("http://www.google.com/icon"), favicon_base::TOUCH_ICON); | |
635 EXPECT_NE(0, id2); | |
636 time = base::Time::Now(); | |
637 db.AddFaviconBitmap(id2, favicon, time, gfx::Size()); | |
638 | |
639 // Add 3rd favicon | |
640 favicon_base::FaviconID id3 = db.AddFavicon( | |
641 GURL("http://www.google.com/icon"), favicon_base::TOUCH_ICON); | |
642 EXPECT_NE(0, id3); | |
643 time = base::Time::Now(); | |
644 db.AddFaviconBitmap(id3, favicon, time, gfx::Size()); | |
645 | |
646 GURL page1_url("http://page1.com"); | |
647 EXPECT_TRUE(db.AddIconMapping(page1_url, id1)); | |
648 EXPECT_TRUE(db.AddIconMapping(page1_url, id2)); | |
649 | |
650 GURL page2_url("http://page2.com"); | |
651 EXPECT_TRUE(db.AddIconMapping(page2_url, id3)); | |
652 | |
653 // Test we do nothing with existing mappings. | |
654 std::vector<IconMapping> icon_mapping; | |
655 EXPECT_TRUE(db.GetIconMappingsForPageURL(page2_url, &icon_mapping)); | |
656 ASSERT_EQ(1U, icon_mapping.size()); | |
657 | |
658 EXPECT_TRUE(db.CloneIconMappings(page1_url, page2_url)); | |
659 | |
660 icon_mapping.clear(); | |
661 EXPECT_TRUE(db.GetIconMappingsForPageURL(page2_url, &icon_mapping)); | |
662 ASSERT_EQ(1U, icon_mapping.size()); | |
663 EXPECT_EQ(page2_url, icon_mapping[0].page_url); | |
664 EXPECT_EQ(id3, icon_mapping[0].icon_id); | |
665 | |
666 // Test we clone if the new page has no mappings. | |
667 GURL page3_url("http://page3.com"); | |
668 EXPECT_TRUE(db.CloneIconMappings(page1_url, page3_url)); | |
669 | |
670 icon_mapping.clear(); | |
671 EXPECT_TRUE(db.GetIconMappingsForPageURL(page3_url, &icon_mapping)); | |
672 | |
673 ASSERT_EQ(2U, icon_mapping.size()); | |
674 if (icon_mapping[0].icon_id == id2) | |
675 std::swap(icon_mapping[0], icon_mapping[1]); | |
676 EXPECT_EQ(page3_url, icon_mapping[0].page_url); | |
677 EXPECT_EQ(id1, icon_mapping[0].icon_id); | |
678 EXPECT_EQ(page3_url, icon_mapping[1].page_url); | |
679 EXPECT_EQ(id2, icon_mapping[1].icon_id); | |
680 } | |
681 | |
682 // Test loading version 3 database. | 589 // Test loading version 3 database. |
683 TEST_F(ThumbnailDatabaseTest, Version3) { | 590 TEST_F(ThumbnailDatabaseTest, Version3) { |
684 scoped_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v3.sql"); | 591 scoped_ptr<ThumbnailDatabase> db = LoadFromGolden("Favicons.v3.sql"); |
685 ASSERT_TRUE(db.get() != NULL); | 592 ASSERT_TRUE(db.get() != NULL); |
686 VerifyTablesAndColumns(&db->db_); | 593 VerifyTablesAndColumns(&db->db_); |
687 | 594 |
688 // Version 3 is deprecated, the data should all be gone. | 595 // Version 3 is deprecated, the data should all be gone. |
689 VerifyDatabaseEmpty(&db->db_); | 596 VerifyDatabaseEmpty(&db->db_); |
690 } | 597 } |
691 | 598 |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 ThumbnailDatabase db(NULL); | 1092 ThumbnailDatabase db(NULL); |
1186 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); | 1093 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); |
1187 | 1094 |
1188 // Verify that the resulting schema is correct, whether it | 1095 // Verify that the resulting schema is correct, whether it |
1189 // involved razing the file or fixing things in place. | 1096 // involved razing the file or fixing things in place. |
1190 VerifyTablesAndColumns(&db.db_); | 1097 VerifyTablesAndColumns(&db.db_); |
1191 } | 1098 } |
1192 } | 1099 } |
1193 | 1100 |
1194 } // namespace history | 1101 } // namespace history |
OLD | NEW |