| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 | 519 |
| 520 FaviconID id = db.AddFavicon(icon_url, FAVICON, GetDefaultFaviconSizes(), | 520 FaviconID id = db.AddFavicon(icon_url, FAVICON, GetDefaultFaviconSizes(), |
| 521 favicon, time, gfx::Size()); | 521 favicon, time, gfx::Size()); |
| 522 EXPECT_NE(0, db.AddIconMapping(page_url, id)); | 522 EXPECT_NE(0, db.AddIconMapping(page_url, id)); |
| 523 std::vector<IconMapping> icon_mappings; | 523 std::vector<IconMapping> icon_mappings; |
| 524 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings)); | 524 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings)); |
| 525 | 525 |
| 526 EXPECT_EQ(page_url, icon_mappings.front().page_url); | 526 EXPECT_EQ(page_url, icon_mappings.front().page_url); |
| 527 EXPECT_EQ(id, icon_mappings.front().icon_id); | 527 EXPECT_EQ(id, icon_mappings.front().icon_id); |
| 528 EXPECT_EQ(FAVICON, icon_mappings.front().icon_type); | 528 EXPECT_EQ(FAVICON, icon_mappings.front().icon_type); |
| 529 EXPECT_EQ(icon_url, icon_mappings.front().icon_url); |
| 529 | 530 |
| 530 // Add a touch icon | 531 // Add a touch icon |
| 531 std::vector<unsigned char> data2(blob2, blob2 + sizeof(blob2)); | 532 std::vector<unsigned char> data2(blob2, blob2 + sizeof(blob2)); |
| 532 scoped_refptr<base::RefCountedBytes> favicon2 = | 533 scoped_refptr<base::RefCountedBytes> favicon2 = |
| 533 new base::RefCountedBytes(data); | 534 new base::RefCountedBytes(data); |
| 534 | 535 |
| 535 FaviconID id2 = db.AddFavicon(icon_url, TOUCH_ICON, | 536 FaviconID id2 = db.AddFavicon(icon_url, TOUCH_ICON, |
| 536 GetDefaultFaviconSizes(), favicon2, time, gfx::Size()); | 537 GetDefaultFaviconSizes(), favicon2, time, gfx::Size()); |
| 537 EXPECT_NE(0, db.AddIconMapping(page_url, id2)); | 538 EXPECT_NE(0, db.AddIconMapping(page_url, id2)); |
| 538 | 539 |
| 539 icon_mappings.clear(); | 540 icon_mappings.clear(); |
| 540 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings)); | 541 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings)); |
| 541 | 542 |
| 542 EXPECT_EQ(page_url, icon_mappings.front().page_url); | 543 EXPECT_EQ(page_url, icon_mappings.front().page_url); |
| 543 EXPECT_EQ(id2, icon_mappings.front().icon_id); | 544 EXPECT_EQ(id2, icon_mappings.front().icon_id); |
| 544 EXPECT_EQ(TOUCH_ICON, icon_mappings.front().icon_type); | 545 EXPECT_EQ(TOUCH_ICON, icon_mappings.front().icon_type); |
| 546 EXPECT_EQ(icon_url, icon_mappings.front().icon_url); |
| 545 | 547 |
| 546 // Add a touch precomposed icon | 548 // Add a touch precomposed icon |
| 547 scoped_refptr<base::RefCountedBytes> favicon3 = | 549 scoped_refptr<base::RefCountedBytes> favicon3 = |
| 548 new base::RefCountedBytes(data2); | 550 new base::RefCountedBytes(data2); |
| 549 | 551 |
| 550 FaviconID id3 = db.AddFavicon(icon_url, TOUCH_PRECOMPOSED_ICON, | 552 FaviconID id3 = db.AddFavicon(icon_url, TOUCH_PRECOMPOSED_ICON, |
| 551 GetDefaultFaviconSizes(), favicon3, time, gfx::Size()); | 553 GetDefaultFaviconSizes(), favicon3, time, gfx::Size()); |
| 552 EXPECT_NE(0, db.AddIconMapping(page_url, id3)); | 554 EXPECT_NE(0, db.AddIconMapping(page_url, id3)); |
| 553 | 555 |
| 554 icon_mappings.clear(); | 556 icon_mappings.clear(); |
| 555 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings)); | 557 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, &icon_mappings)); |
| 556 | 558 |
| 557 EXPECT_EQ(page_url, icon_mappings.front().page_url); | 559 EXPECT_EQ(page_url, icon_mappings.front().page_url); |
| 558 EXPECT_EQ(id3, icon_mappings.front().icon_id); | 560 EXPECT_EQ(id3, icon_mappings.front().icon_id); |
| 559 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mappings.front().icon_type); | 561 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mappings.front().icon_type); |
| 562 EXPECT_EQ(icon_url, icon_mappings.front().icon_url); |
| 560 } | 563 } |
| 561 | 564 |
| 562 // Test result of GetIconMappingsForPageURL when an icon type is passed in. | 565 // Test result of GetIconMappingsForPageURL when an icon type is passed in. |
| 563 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLWithIconType) { | 566 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLWithIconType) { |
| 564 ThumbnailDatabase db; | 567 ThumbnailDatabase db; |
| 565 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 568 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 566 db.BeginTransaction(); | 569 db.BeginTransaction(); |
| 567 | 570 |
| 568 GURL url("http://google.com"); | 571 GURL url("http://google.com"); |
| 569 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 572 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 | 737 |
| 735 // Migration should be done. | 738 // Migration should be done. |
| 736 // Test one icon_mapping. | 739 // Test one icon_mapping. |
| 737 GURL page_url1 = GURL("http://google.com/"); | 740 GURL page_url1 = GURL("http://google.com/"); |
| 738 std::vector<IconMapping> icon_mappings; | 741 std::vector<IconMapping> icon_mappings; |
| 739 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url1, &icon_mappings)); | 742 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url1, &icon_mappings)); |
| 740 ASSERT_EQ(1u, icon_mappings.size()); | 743 ASSERT_EQ(1u, icon_mappings.size()); |
| 741 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); | 744 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); |
| 742 EXPECT_EQ(page_url1, icon_mappings[0].page_url); | 745 EXPECT_EQ(page_url1, icon_mappings[0].page_url); |
| 743 EXPECT_EQ(1, icon_mappings[0].icon_id); | 746 EXPECT_EQ(1, icon_mappings[0].icon_id); |
| 744 GURL out_icon_url; | 747 EXPECT_EQ(icon1, icon_mappings[0].icon_url); |
| 745 ASSERT_TRUE(db.GetFaviconHeader( | |
| 746 icon_mappings[0].icon_id, &out_icon_url, NULL, NULL)); | |
| 747 EXPECT_EQ(icon1, out_icon_url); | |
| 748 | 748 |
| 749 // Test a page which has the same icon. | 749 // Test a page which has the same icon. |
| 750 GURL page_url3 = GURL("http://www.google.com/"); | 750 GURL page_url3 = GURL("http://www.google.com/"); |
| 751 icon_mappings.clear(); | 751 icon_mappings.clear(); |
| 752 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url3, &icon_mappings)); | 752 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url3, &icon_mappings)); |
| 753 ASSERT_EQ(1u, icon_mappings.size()); | 753 ASSERT_EQ(1u, icon_mappings.size()); |
| 754 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); | 754 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); |
| 755 EXPECT_EQ(page_url3, icon_mappings[0].page_url); | 755 EXPECT_EQ(page_url3, icon_mappings[0].page_url); |
| 756 EXPECT_EQ(1, icon_mappings[0].icon_id); | 756 EXPECT_EQ(1, icon_mappings[0].icon_id); |
| 757 EXPECT_EQ(icon1, icon_mappings[0].icon_url); |
| 757 | 758 |
| 758 // Test a icon_mapping with different IconID. | 759 // Test a icon_mapping with different IconID. |
| 759 GURL page_url2 = GURL("http://yahoo.com/"); | 760 GURL page_url2 = GURL("http://yahoo.com/"); |
| 760 icon_mappings.clear(); | 761 icon_mappings.clear(); |
| 761 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url2, &icon_mappings)); | 762 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url2, &icon_mappings)); |
| 762 ASSERT_EQ(1u, icon_mappings.size()); | 763 ASSERT_EQ(1u, icon_mappings.size()); |
| 763 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); | 764 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); |
| 764 EXPECT_EQ(page_url2, icon_mappings[0].page_url); | 765 EXPECT_EQ(page_url2, icon_mappings[0].page_url); |
| 765 EXPECT_EQ(2, icon_mappings[0].icon_id); | 766 EXPECT_EQ(2, icon_mappings[0].icon_id); |
| 766 ASSERT_TRUE(db.GetFaviconHeader( | 767 EXPECT_EQ(icon2, icon_mappings[0].icon_url); |
| 767 icon_mappings[0].icon_id, &out_icon_url, NULL, NULL)); | |
| 768 EXPECT_EQ(icon2, out_icon_url); | |
| 769 | 768 |
| 770 // Test a page without icon | 769 // Test a page without icon |
| 771 GURL page_url4 = GURL("http://www.google.com/blank.html"); | 770 GURL page_url4 = GURL("http://www.google.com/blank.html"); |
| 772 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL)); | 771 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL)); |
| 773 } | 772 } |
| 774 | 773 |
| 775 TEST_F(ThumbnailDatabaseTest, IconMappingEnumerator) { | 774 TEST_F(ThumbnailDatabaseTest, IconMappingEnumerator) { |
| 776 ThumbnailDatabase db; | 775 ThumbnailDatabase db; |
| 777 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 776 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 778 db.BeginTransaction(); | 777 db.BeginTransaction(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 808 // There are 2 favicon mappings. | 807 // There are 2 favicon mappings. |
| 809 bool has_favicon_mapping1 = false; | 808 bool has_favicon_mapping1 = false; |
| 810 bool has_favicon_mapping2 = false; | 809 bool has_favicon_mapping2 = false; |
| 811 int mapping_count = 0; | 810 int mapping_count = 0; |
| 812 while (enumerator1.GetNextIconMapping(&icon_mapping)) { | 811 while (enumerator1.GetNextIconMapping(&icon_mapping)) { |
| 813 mapping_count++; | 812 mapping_count++; |
| 814 if (favicon_mapping_id1 == icon_mapping.mapping_id) { | 813 if (favicon_mapping_id1 == icon_mapping.mapping_id) { |
| 815 has_favicon_mapping1 = true; | 814 has_favicon_mapping1 = true; |
| 816 EXPECT_EQ(url, icon_mapping.page_url); | 815 EXPECT_EQ(url, icon_mapping.page_url); |
| 817 EXPECT_EQ(favicon_id1, icon_mapping.icon_id); | 816 EXPECT_EQ(favicon_id1, icon_mapping.icon_id); |
| 817 EXPECT_EQ(icon_url1, icon_mapping.icon_url); |
| 818 EXPECT_EQ(FAVICON, icon_mapping.icon_type); | 818 EXPECT_EQ(FAVICON, icon_mapping.icon_type); |
| 819 } else if (favicon_mapping_id2 == icon_mapping.mapping_id) { | 819 } else if (favicon_mapping_id2 == icon_mapping.mapping_id) { |
| 820 has_favicon_mapping2 = true; | 820 has_favicon_mapping2 = true; |
| 821 EXPECT_EQ(url2, icon_mapping.page_url); | 821 EXPECT_EQ(url2, icon_mapping.page_url); |
| 822 EXPECT_EQ(favicon_id2, icon_mapping.icon_id); | 822 EXPECT_EQ(favicon_id2, icon_mapping.icon_id); |
| 823 EXPECT_EQ(icon_url2, icon_mapping.icon_url); |
| 823 EXPECT_EQ(FAVICON, icon_mapping.icon_type); | 824 EXPECT_EQ(FAVICON, icon_mapping.icon_type); |
| 824 } | 825 } |
| 825 } | 826 } |
| 826 EXPECT_EQ(2, mapping_count); | 827 EXPECT_EQ(2, mapping_count); |
| 827 EXPECT_TRUE(has_favicon_mapping1); | 828 EXPECT_TRUE(has_favicon_mapping1); |
| 828 EXPECT_TRUE(has_favicon_mapping2); | 829 EXPECT_TRUE(has_favicon_mapping2); |
| 829 | 830 |
| 830 ThumbnailDatabase::IconMappingEnumerator enumerator2; | 831 ThumbnailDatabase::IconMappingEnumerator enumerator2; |
| 831 ASSERT_TRUE(db.InitIconMappingEnumerator(TOUCH_ICON, &enumerator2)); | 832 ASSERT_TRUE(db.InitIconMappingEnumerator(TOUCH_ICON, &enumerator2)); |
| 832 ASSERT_TRUE(enumerator2.GetNextIconMapping(&icon_mapping)); | 833 ASSERT_TRUE(enumerator2.GetNextIconMapping(&icon_mapping)); |
| 833 EXPECT_EQ(touch_mapping_id1, icon_mapping.mapping_id); | 834 EXPECT_EQ(touch_mapping_id1, icon_mapping.mapping_id); |
| 834 EXPECT_EQ(url, icon_mapping.page_url); | 835 EXPECT_EQ(url, icon_mapping.page_url); |
| 835 EXPECT_EQ(touch_icon_id1, icon_mapping.icon_id); | 836 EXPECT_EQ(touch_icon_id1, icon_mapping.icon_id); |
| 837 EXPECT_EQ(icon_url1, icon_mapping.icon_url); |
| 836 EXPECT_EQ(TOUCH_ICON, icon_mapping.icon_type); | 838 EXPECT_EQ(TOUCH_ICON, icon_mapping.icon_type); |
| 837 | 839 |
| 838 EXPECT_FALSE(enumerator2.GetNextIconMapping(&icon_mapping)); | 840 EXPECT_FALSE(enumerator2.GetNextIconMapping(&icon_mapping)); |
| 839 } | 841 } |
| 840 | 842 |
| 841 TEST_F(ThumbnailDatabaseTest, FaviconSizesToAndFromString) { | 843 TEST_F(ThumbnailDatabaseTest, FaviconSizesToAndFromString) { |
| 842 // Invalid input. | 844 // Invalid input. |
| 843 FaviconSizes sizes_missing_height; | 845 FaviconSizes sizes_missing_height; |
| 844 ThumbnailDatabase::DatabaseStringToFaviconSizes("0 0 10", | 846 ThumbnailDatabase::DatabaseStringToFaviconSizes("0 0 10", |
| 845 &sizes_missing_height); | 847 &sizes_missing_height); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 866 } | 868 } |
| 867 | 869 |
| 868 std::string sizes_as_string; | 870 std::string sizes_as_string; |
| 869 ThumbnailDatabase::FaviconSizesToDatabaseString(sizes_valid, | 871 ThumbnailDatabase::FaviconSizesToDatabaseString(sizes_valid, |
| 870 &sizes_as_string); | 872 &sizes_as_string); |
| 871 EXPECT_TRUE(sizes_as_string == "10 15 20 25" || | 873 EXPECT_TRUE(sizes_as_string == "10 15 20 25" || |
| 872 sizes_as_string == "20 25 10 15"); | 874 sizes_as_string == "20 25 10 15"); |
| 873 } | 875 } |
| 874 | 876 |
| 875 } // namespace history | 877 } // namespace history |
| OLD | NEW |