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 <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1785 FaviconSizes favicon_sizes; | 1785 FaviconSizes favicon_sizes; |
1786 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( | 1786 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( |
1787 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); | 1787 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); |
1788 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes); | 1788 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes); |
1789 | 1789 |
1790 FaviconBitmap favicon_bitmap; | 1790 FaviconBitmap favicon_bitmap; |
1791 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); | 1791 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); |
1792 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); | 1792 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); |
1793 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); | 1793 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
1794 | 1794 |
1795 // 1) Merge favicon of the same size. | 1795 EXPECT_EQ(1, num_broadcasted_notifications()); |
| 1796 |
| 1797 // 1) Merge identical favicon bitmap. |
1796 std::vector<unsigned char> data; | 1798 std::vector<unsigned char> data; |
1797 data.push_back('b'); | 1799 data.push_back('a'); |
1798 scoped_refptr<base::RefCountedBytes> bitmap_data( | 1800 scoped_refptr<base::RefCountedBytes> bitmap_data( |
1799 new base::RefCountedBytes(data)); | 1801 new base::RefCountedBytes(data)); |
1800 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kSmallSize); | 1802 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kSmallSize); |
1801 | 1803 |
| 1804 // All the data should stay the same and no notifications should have been |
| 1805 // sent. |
| 1806 icon_mappings.clear(); |
| 1807 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
| 1808 &icon_mappings)); |
| 1809 EXPECT_EQ(1u, icon_mappings.size()); |
| 1810 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); |
| 1811 |
| 1812 favicon_sizes.clear(); |
| 1813 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( |
| 1814 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); |
| 1815 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes); |
| 1816 |
| 1817 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); |
| 1818 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); |
| 1819 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
| 1820 |
| 1821 EXPECT_EQ(1, num_broadcasted_notifications()); |
| 1822 |
| 1823 // 2) Merge favicon bitmap of the same size. |
| 1824 data[0] = 'b'; |
| 1825 bitmap_data = new base::RefCountedBytes(data); |
| 1826 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kSmallSize); |
| 1827 |
1802 // The small favicon bitmap at |icon_url1| should be overwritten and favicon | 1828 // The small favicon bitmap at |icon_url1| should be overwritten and favicon |
1803 // sizes should remain unchanged. | 1829 // sizes should remain unchanged. |
1804 icon_mappings.clear(); | 1830 icon_mappings.clear(); |
1805 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, | 1831 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
1806 &icon_mappings)); | 1832 &icon_mappings)); |
1807 EXPECT_EQ(1u, icon_mappings.size()); | 1833 EXPECT_EQ(1u, icon_mappings.size()); |
1808 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); | 1834 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); |
1809 | 1835 |
1810 favicon_sizes.clear(); | 1836 favicon_sizes.clear(); |
1811 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( | 1837 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( |
1812 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); | 1838 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); |
1813 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes); | 1839 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes); |
1814 | 1840 |
1815 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); | 1841 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); |
1816 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); | 1842 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); |
1817 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); | 1843 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
1818 | 1844 |
1819 // 2) Merge favicon for the same icon URL, but a pixel size for which there is | 1845 // 3) Merge favicon for the same icon URL, but a pixel size for which there is |
1820 // no favicon bitmap. | 1846 // no favicon bitmap. |
1821 data[0] = 'c'; | 1847 data[0] = 'c'; |
1822 bitmap_data = new base::RefCountedBytes(data); | 1848 bitmap_data = new base::RefCountedBytes(data); |
1823 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kTinySize); | 1849 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kTinySize); |
1824 | 1850 |
1825 // A new favicon bitmap should be created and favicon sizes should be set to | 1851 // A new favicon bitmap should be created and favicon sizes should be set to |
1826 // the default. | 1852 // the default. |
1827 icon_mappings.clear(); | 1853 icon_mappings.clear(); |
1828 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, | 1854 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
1829 &icon_mappings)); | 1855 &icon_mappings)); |
1830 EXPECT_EQ(1u, icon_mappings.size()); | 1856 EXPECT_EQ(1u, icon_mappings.size()); |
1831 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); | 1857 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); |
1832 | 1858 |
1833 favicon_sizes.clear(); | 1859 favicon_sizes.clear(); |
1834 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( | 1860 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( |
1835 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); | 1861 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); |
1836 EXPECT_EQ(GetDefaultFaviconSizes(), favicon_sizes); | 1862 EXPECT_EQ(GetDefaultFaviconSizes(), favicon_sizes); |
1837 | 1863 |
1838 std::vector<FaviconBitmap> favicon_bitmaps; | 1864 std::vector<FaviconBitmap> favicon_bitmaps; |
1839 EXPECT_TRUE(GetSortedFaviconBitmaps(icon_mappings[0].icon_id, | 1865 EXPECT_TRUE(GetSortedFaviconBitmaps(icon_mappings[0].icon_id, |
1840 &favicon_bitmaps)); | 1866 &favicon_bitmaps)); |
1841 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); | 1867 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); |
1842 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); | 1868 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); |
1843 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data)); | 1869 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data)); |
1844 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); | 1870 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); |
1845 | 1871 |
1846 // 3) Merge favicon for an icon URL different from the icon URLs already | 1872 // 4) Merge favicon for an icon URL different from the icon URLs already |
1847 // mapped to page URL. | 1873 // mapped to page URL. |
1848 data[0] = 'd'; | 1874 data[0] = 'd'; |
1849 bitmap_data = new base::RefCountedBytes(data); | 1875 bitmap_data = new base::RefCountedBytes(data); |
1850 backend_->MergeFavicon(page_url, icon_url2, FAVICON, bitmap_data, kSmallSize); | 1876 backend_->MergeFavicon(page_url, icon_url2, FAVICON, bitmap_data, kSmallSize); |
1851 | 1877 |
1852 // The existing favicon bitmaps should be copied over to the newly created | 1878 // The existing favicon bitmaps should be copied over to the newly created |
1853 // favicon at |icon_url2|. |page_url| should solely be mapped to |icon_url2|. | 1879 // favicon at |icon_url2|. |page_url| should solely be mapped to |icon_url2|. |
1854 icon_mappings.clear(); | 1880 icon_mappings.clear(); |
1855 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, | 1881 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
1856 &icon_mappings)); | 1882 &icon_mappings)); |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2683 backend_->GetFirstRecordedTimeForTest()); | 2709 backend_->GetFirstRecordedTimeForTest()); |
2684 | 2710 |
2685 EXPECT_FALSE(backend_->GetURL(args[0].url, &row)); | 2711 EXPECT_FALSE(backend_->GetURL(args[0].url, &row)); |
2686 EXPECT_TRUE(backend_->GetURL(args[1].url, &row)); | 2712 EXPECT_TRUE(backend_->GetURL(args[1].url, &row)); |
2687 EXPECT_FALSE(backend_->GetURL(args[2].url, &row)); | 2713 EXPECT_FALSE(backend_->GetURL(args[2].url, &row)); |
2688 EXPECT_TRUE(backend_->GetURL(args[3].url, &row)); | 2714 EXPECT_TRUE(backend_->GetURL(args[3].url, &row)); |
2689 EXPECT_FALSE(backend_->GetURL(args[4].url, &row)); | 2715 EXPECT_FALSE(backend_->GetURL(args[4].url, &row)); |
2690 } | 2716 } |
2691 | 2717 |
2692 } // namespace history | 2718 } // namespace history |
OLD | NEW |