Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: chrome/browser/history/history_backend_unittest.cc

Issue 11830007: Avoid sending notifications when the bitmap data in history has not changed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 favicon_bitmaps.clear(); 1440 favicon_bitmaps.clear();
1441 EXPECT_TRUE(GetSortedFaviconBitmaps(icon_mappings[1].icon_id, 1441 EXPECT_TRUE(GetSortedFaviconBitmaps(icon_mappings[1].icon_id,
1442 &favicon_bitmaps)); 1442 &favicon_bitmaps));
1443 1443
1444 EXPECT_EQ(2u, favicon_bitmaps.size()); 1444 EXPECT_EQ(2u, favicon_bitmaps.size());
1445 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[0].bitmap_data)); 1445 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[0].bitmap_data));
1446 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size); 1446 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size);
1447 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[1].bitmap_data)); 1447 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[1].bitmap_data));
1448 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size); 1448 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size);
1449 1449
1450 // Notifications should have been broadcast for each call to SetFavicons().
1451 EXPECT_EQ(2, num_broadcasted_notifications());
1452
1450 // Change the sizes for which the favicon at icon_url1 is available at from 1453 // Change the sizes for which the favicon at icon_url1 is available at from
1451 // the web. Verify that all the data remains valid. 1454 // the web. Verify that all the data remains valid.
1452 icon_url_sizes[icon_url1] = GetSizesTinySmallAndLarge(); 1455 icon_url_sizes[icon_url1] = GetSizesTinySmallAndLarge();
1453 favicon_bitmap_data.clear(); 1456 favicon_bitmap_data.clear();
1454 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data, 1457 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1455 icon_url_sizes); 1458 icon_url_sizes);
1456 1459
1457 icon_mappings.clear(); 1460 icon_mappings.clear();
1458 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings)); 1461 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings));
1459 EXPECT_EQ(2u, icon_mappings.size()); 1462 EXPECT_EQ(2u, icon_mappings.size());
(...skipping 15 matching lines...) Expand all
1475 icon_mappings[1].icon_id, &icon_url, &icon_type, &favicon_sizes)); 1478 icon_mappings[1].icon_id, &icon_url, &icon_type, &favicon_sizes));
1476 EXPECT_EQ(icon_url2, icon_url); 1479 EXPECT_EQ(icon_url2, icon_url);
1477 EXPECT_EQ(FAVICON, icon_type); 1480 EXPECT_EQ(FAVICON, icon_type);
1478 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes); 1481 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes);
1479 1482
1480 favicon_bitmaps.clear(); 1483 favicon_bitmaps.clear();
1481 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( 1484 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(
1482 icon_mappings[1].icon_id, &favicon_bitmaps)); 1485 icon_mappings[1].icon_id, &favicon_bitmaps));
1483 EXPECT_EQ(2u, favicon_bitmaps.size()); 1486 EXPECT_EQ(2u, favicon_bitmaps.size());
1484 1487
1485 // Notifications should have been broadcast for each call to SetFavicons(). 1488 // No notifications should have been sent because changing the favicon sizes
1486 EXPECT_EQ(3, num_broadcasted_notifications()); 1489 // did not result in deleting any favicon bitmaps.
1490 EXPECT_EQ(2, num_broadcasted_notifications());
1487 } 1491 }
1488 1492
1489 // Test that changing the sizes that a favicon is available at from the web 1493 // Test that changing the sizes that a favicon is available at from the web
1490 // deletes stale favicons and favicon bitmaps. 1494 // deletes stale favicons and favicon bitmaps.
1491 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) { 1495 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) {
1492 const GURL page_url("http://www.google.com/"); 1496 const GURL page_url("http://www.google.com/");
1493 const GURL icon_url("http://www.google.com/icon"); 1497 const GURL icon_url("http://www.google.com/icon");
1494 1498
1495 // Set |page_url| as having one favicon with two different sizes. 1499 // Set |page_url| as having one favicon with two different sizes.
1496 IconURLSizesMap icon_url_sizes; 1500 IconURLSizesMap icon_url_sizes;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 1567
1564 FaviconID original_favicon_id = 1568 FaviconID original_favicon_id =
1565 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, FAVICON, 1569 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, FAVICON,
1566 NULL); 1570 NULL);
1567 EXPECT_NE(0, original_favicon_id); 1571 EXPECT_NE(0, original_favicon_id);
1568 FaviconBitmap original_favicon_bitmap; 1572 FaviconBitmap original_favicon_bitmap;
1569 EXPECT_TRUE( 1573 EXPECT_TRUE(
1570 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap)); 1574 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap));
1571 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data)); 1575 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data));
1572 1576
1573 // SetFavicons with identical data but a different bitmap. 1577 EXPECT_EQ(1, num_broadcasted_notifications());
1578
1579 // Call SetFavicons() with completely identical data.
1574 std::vector<unsigned char> updated_data; 1580 std::vector<unsigned char> updated_data;
1575 updated_data.push_back('b'); 1581 updated_data.push_back('a');
1576 favicon_bitmap_data[0].bitmap_data = 1582 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
1577 base::RefCountedBytes::TakeVector(&updated_data);
1578 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data, 1583 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1579 icon_url_sizes); 1584 icon_url_sizes);
1580 1585
1581 FaviconID updated_favicon_id = 1586 FaviconID updated_favicon_id =
1582 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, FAVICON, 1587 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, FAVICON,
1583 NULL); 1588 NULL);
1584 EXPECT_NE(0, updated_favicon_id); 1589 EXPECT_NE(0, updated_favicon_id);
1585 FaviconBitmap updated_favicon_bitmap; 1590 FaviconBitmap updated_favicon_bitmap;
1586 EXPECT_TRUE( 1591 EXPECT_TRUE(
1587 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); 1592 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
1593 EXPECT_TRUE(BitmapDataEqual('a', updated_favicon_bitmap.bitmap_data));
1594
1595 // Because the bitmap data is byte equivalent, no notifications should have
1596 // been broadcasted.
1597 EXPECT_EQ(1, num_broadcasted_notifications());
1598
1599 // Call SetFavicons() with identical data but a different bitmap.
1600 updated_data[0] = 'b';
1601 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
1602 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1603 icon_url_sizes);
1604
1605 updated_favicon_id =
1606 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, FAVICON,
1607 NULL);
1608 EXPECT_NE(0, updated_favicon_id);
1609 EXPECT_TRUE(
1610 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
1588 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data)); 1611 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data));
1589 1612
1590 // There should be no churn in FaviconIDs or FaviconBitmapIds. 1613 // There should be no churn in FaviconIDs or FaviconBitmapIds even though
1614 // the bitmap data changed.
1591 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id); 1615 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id);
1592 EXPECT_EQ(original_favicon_bitmap.bitmap_id, 1616 EXPECT_EQ(original_favicon_bitmap.bitmap_id,
1593 updated_favicon_bitmap.bitmap_id); 1617 updated_favicon_bitmap.bitmap_id);
1618
1619 // A notification should have been broadcasted as the favicon bitmap data has
1620 // changed.
1621 EXPECT_EQ(2, num_broadcasted_notifications());
1594 } 1622 }
1595 1623
1596 // Test that if two pages share the same FaviconID, changing the favicon for 1624 // Test that if two pages share the same FaviconID, changing the favicon for
1597 // one page does not affect the other. 1625 // one page does not affect the other.
1598 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) { 1626 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
1599 GURL icon_url("http://www.google.com/favicon.ico"); 1627 GURL icon_url("http://www.google.com/favicon.ico");
1600 GURL icon_url_new("http://www.google.com/favicon2.ico"); 1628 GURL icon_url_new("http://www.google.com/favicon2.ico");
1601 GURL page_url1("http://www.google.com"); 1629 GURL page_url1("http://www.google.com");
1602 GURL page_url2("http://www.google.ca"); 1630 GURL page_url2("http://www.google.ca");
1603 1631
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 FaviconSizes favicon_sizes; 1813 FaviconSizes favicon_sizes;
1786 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( 1814 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(
1787 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); 1815 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes));
1788 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes); 1816 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes);
1789 1817
1790 FaviconBitmap favicon_bitmap; 1818 FaviconBitmap favicon_bitmap;
1791 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1819 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1792 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 1820 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
1793 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1821 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1794 1822
1795 // 1) Merge favicon of the same size. 1823 EXPECT_EQ(1, num_broadcasted_notifications());
1824
1825 // 1) Merge identical favicon bitmap.
1796 std::vector<unsigned char> data; 1826 std::vector<unsigned char> data;
1797 data.push_back('b'); 1827 data.push_back('a');
1798 scoped_refptr<base::RefCountedBytes> bitmap_data( 1828 scoped_refptr<base::RefCountedBytes> bitmap_data(
1799 new base::RefCountedBytes(data)); 1829 new base::RefCountedBytes(data));
1800 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kSmallSize); 1830 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kSmallSize);
1801 1831
1832 // All the data should stay the same and no notifications should have been
1833 // sent.
1834 icon_mappings.clear();
1835 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1836 &icon_mappings));
1837 EXPECT_EQ(1u, icon_mappings.size());
1838 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1839
1840 favicon_sizes.clear();
1841 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(
1842 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes));
1843 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes);
1844
1845 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1846 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
1847 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1848
1849 EXPECT_EQ(1, num_broadcasted_notifications());
1850
1851 // 2) Merge favicon bitmap of the same size.
1852 data[0] = 'b';
1853 bitmap_data = new base::RefCountedBytes(data);
1854 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kSmallSize);
1855
1802 // The small favicon bitmap at |icon_url1| should be overwritten and favicon 1856 // The small favicon bitmap at |icon_url1| should be overwritten and favicon
1803 // sizes should remain unchanged. 1857 // sizes should remain unchanged.
1804 icon_mappings.clear(); 1858 icon_mappings.clear();
1805 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1859 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1806 &icon_mappings)); 1860 &icon_mappings));
1807 EXPECT_EQ(1u, icon_mappings.size()); 1861 EXPECT_EQ(1u, icon_mappings.size());
1808 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1862 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1809 1863
1810 favicon_sizes.clear(); 1864 favicon_sizes.clear();
1811 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( 1865 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(
1812 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); 1866 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes));
1813 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes); 1867 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes);
1814 1868
1815 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1869 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1816 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); 1870 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data));
1817 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1871 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1818 1872
1819 // 2) Merge favicon for the same icon URL, but a pixel size for which there is 1873 // 3) Merge favicon for the same icon URL, but a pixel size for which there is
1820 // no favicon bitmap. 1874 // no favicon bitmap.
1821 data[0] = 'c'; 1875 data[0] = 'c';
1822 bitmap_data = new base::RefCountedBytes(data); 1876 bitmap_data = new base::RefCountedBytes(data);
1823 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kTinySize); 1877 backend_->MergeFavicon(page_url, icon_url1, FAVICON, bitmap_data, kTinySize);
1824 1878
1825 // A new favicon bitmap should be created and favicon sizes should be set to 1879 // A new favicon bitmap should be created and favicon sizes should be set to
1826 // the default. 1880 // the default.
1827 icon_mappings.clear(); 1881 icon_mappings.clear();
1828 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1882 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1829 &icon_mappings)); 1883 &icon_mappings));
1830 EXPECT_EQ(1u, icon_mappings.size()); 1884 EXPECT_EQ(1u, icon_mappings.size());
1831 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1885 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1832 1886
1833 favicon_sizes.clear(); 1887 favicon_sizes.clear();
1834 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader( 1888 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(
1835 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes)); 1889 icon_mappings[0].icon_id, NULL, NULL, &favicon_sizes));
1836 EXPECT_EQ(GetDefaultFaviconSizes(), favicon_sizes); 1890 EXPECT_EQ(GetDefaultFaviconSizes(), favicon_sizes);
1837 1891
1838 std::vector<FaviconBitmap> favicon_bitmaps; 1892 std::vector<FaviconBitmap> favicon_bitmaps;
1839 EXPECT_TRUE(GetSortedFaviconBitmaps(icon_mappings[0].icon_id, 1893 EXPECT_TRUE(GetSortedFaviconBitmaps(icon_mappings[0].icon_id,
1840 &favicon_bitmaps)); 1894 &favicon_bitmaps));
1841 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); 1895 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data));
1842 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); 1896 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size);
1843 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data)); 1897 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data));
1844 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); 1898 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size);
1845 1899
1846 // 3) Merge favicon for an icon URL different from the icon URLs already 1900 // 4) Merge favicon for an icon URL different from the icon URLs already
1847 // mapped to page URL. 1901 // mapped to page URL.
1848 data[0] = 'd'; 1902 data[0] = 'd';
1849 bitmap_data = new base::RefCountedBytes(data); 1903 bitmap_data = new base::RefCountedBytes(data);
1850 backend_->MergeFavicon(page_url, icon_url2, FAVICON, bitmap_data, kSmallSize); 1904 backend_->MergeFavicon(page_url, icon_url2, FAVICON, bitmap_data, kSmallSize);
1851 1905
1852 // The existing favicon bitmaps should be copied over to the newly created 1906 // 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|. 1907 // favicon at |icon_url2|. |page_url| should solely be mapped to |icon_url2|.
1854 icon_mappings.clear(); 1908 icon_mappings.clear();
1855 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1909 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1856 &icon_mappings)); 1910 &icon_mappings));
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 backend_->GetFirstRecordedTimeForTest()); 2737 backend_->GetFirstRecordedTimeForTest());
2684 2738
2685 EXPECT_FALSE(backend_->GetURL(args[0].url, &row)); 2739 EXPECT_FALSE(backend_->GetURL(args[0].url, &row));
2686 EXPECT_TRUE(backend_->GetURL(args[1].url, &row)); 2740 EXPECT_TRUE(backend_->GetURL(args[1].url, &row));
2687 EXPECT_FALSE(backend_->GetURL(args[2].url, &row)); 2741 EXPECT_FALSE(backend_->GetURL(args[2].url, &row));
2688 EXPECT_TRUE(backend_->GetURL(args[3].url, &row)); 2742 EXPECT_TRUE(backend_->GetURL(args[3].url, &row));
2689 EXPECT_FALSE(backend_->GetURL(args[4].url, &row)); 2743 EXPECT_FALSE(backend_->GetURL(args[4].url, &row));
2690 } 2744 }
2691 2745
2692 } // namespace history 2746 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698