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

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

Issue 484213002: Refactor HistoryService to not send NOTIFICATION_FAVICON_CHANGED (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android compilation Created 6 years, 4 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 "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // This must be a separate object since HistoryBackend manages its lifetime. 83 // This must be a separate object since HistoryBackend manages its lifetime.
84 // This just forwards the messages we're interested in to the test object. 84 // This just forwards the messages we're interested in to the test object.
85 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { 85 class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
86 public: 86 public:
87 explicit HistoryBackendTestDelegate(HistoryBackendTestBase* test) 87 explicit HistoryBackendTestDelegate(HistoryBackendTestBase* test)
88 : test_(test) {} 88 : test_(test) {}
89 89
90 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {} 90 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {}
91 virtual void SetInMemoryBackend( 91 virtual void SetInMemoryBackend(
92 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE; 92 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE;
93 virtual void NotifyFaviconChanged(const std::set<GURL>& urls) OVERRIDE;
93 virtual void BroadcastNotifications( 94 virtual void BroadcastNotifications(
94 int type, 95 int type,
95 scoped_ptr<HistoryDetails> details) OVERRIDE; 96 scoped_ptr<HistoryDetails> details) OVERRIDE;
96 virtual void DBLoaded() OVERRIDE; 97 virtual void DBLoaded() OVERRIDE;
97 virtual void NotifyVisitDBObserversOnAddVisit( 98 virtual void NotifyVisitDBObserversOnAddVisit(
98 const BriefVisitInfo& info) OVERRIDE {} 99 const BriefVisitInfo& info) OVERRIDE {}
99 100
100 private: 101 private:
101 // Not owned by us. 102 // Not owned by us.
102 HistoryBackendTestBase* test_; 103 HistoryBackendTestBase* test_;
103 104
104 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate); 105 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate);
105 }; 106 };
106 107
107 class HistoryBackendTestBase : public testing::Test { 108 class HistoryBackendTestBase : public testing::Test {
108 public: 109 public:
109 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; 110 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList;
110 111
111 HistoryBackendTestBase() 112 HistoryBackendTestBase()
112 : loaded_(false), 113 : loaded_(false),
114 favicon_changed_notifications_(0),
113 ui_thread_(content::BrowserThread::UI, &message_loop_) {} 115 ui_thread_(content::BrowserThread::UI, &message_loop_) {}
114 116
115 virtual ~HistoryBackendTestBase() { 117 virtual ~HistoryBackendTestBase() {
116 STLDeleteValues(&broadcasted_notifications_); 118 STLDeleteValues(&broadcasted_notifications_);
117 } 119 }
118 120
119 protected: 121 protected:
122 int favicon_changed_notifications() const {
123 return favicon_changed_notifications_;
124 }
125
126 void ClearFaviconChangedNotificationCounter() {
127 favicon_changed_notifications_ = 0;
128 }
129
120 int num_broadcasted_notifications() const { 130 int num_broadcasted_notifications() const {
121 return broadcasted_notifications_.size(); 131 return broadcasted_notifications_.size();
122 } 132 }
123 133
124 const NotificationList& broadcasted_notifications() const { 134 const NotificationList& broadcasted_notifications() const {
125 return broadcasted_notifications_; 135 return broadcasted_notifications_;
126 } 136 }
127 137
128 void ClearBroadcastedNotifications() { 138 void ClearBroadcastedNotifications() {
129 STLDeleteValues(&broadcasted_notifications_); 139 STLDeleteValues(&broadcasted_notifications_);
130 } 140 }
131 141
132 base::FilePath test_dir() { 142 base::FilePath test_dir() {
133 return test_dir_; 143 return test_dir_;
134 } 144 }
135 145
146 void NotifyFaviconChanged(const std::set<GURL>& changed_favicons) {
147 ++favicon_changed_notifications_;
148 }
149
136 void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) { 150 void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) {
137 // Send the notifications directly to the in-memory database. 151 // Send the notifications directly to the in-memory database.
138 content::Details<HistoryDetails> det(details.get()); 152 content::Details<HistoryDetails> det(details.get());
139 mem_backend_->Observe( 153 mem_backend_->Observe(
140 type, content::Source<HistoryBackendTestBase>(NULL), det); 154 type, content::Source<HistoryBackendTestBase>(NULL), det);
141 155
142 // The backend passes ownership of the details pointer to us. 156 // The backend passes ownership of the details pointer to us.
143 broadcasted_notifications_.push_back( 157 broadcasted_notifications_.push_back(
144 std::make_pair(type, details.release())); 158 std::make_pair(type, details.release()));
145 } 159 }
(...skipping 25 matching lines...) Expand all
171 base::RunLoop().RunUntilIdle(); 185 base::RunLoop().RunUntilIdle();
172 history_client_.ClearAllBookmarks(); 186 history_client_.ClearAllBookmarks();
173 } 187 }
174 188
175 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { 189 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) {
176 mem_backend_.swap(backend); 190 mem_backend_.swap(backend);
177 } 191 }
178 192
179 // The types and details of notifications which were broadcasted. 193 // The types and details of notifications which were broadcasted.
180 NotificationList broadcasted_notifications_; 194 NotificationList broadcasted_notifications_;
195 int favicon_changed_notifications_;
181 196
182 base::MessageLoop message_loop_; 197 base::MessageLoop message_loop_;
183 base::FilePath test_dir_; 198 base::FilePath test_dir_;
184 content::TestBrowserThread ui_thread_; 199 content::TestBrowserThread ui_thread_;
185 200
186 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase); 201 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase);
187 }; 202 };
188 203
189 void HistoryBackendTestDelegate::SetInMemoryBackend( 204 void HistoryBackendTestDelegate::SetInMemoryBackend(
190 scoped_ptr<InMemoryHistoryBackend> backend) { 205 scoped_ptr<InMemoryHistoryBackend> backend) {
191 test_->SetInMemoryBackend(backend.Pass()); 206 test_->SetInMemoryBackend(backend.Pass());
192 } 207 }
193 208
209 void HistoryBackendTestDelegate::NotifyFaviconChanged(
210 const std::set<GURL>& changed_favicons) {
211 test_->NotifyFaviconChanged(changed_favicons);
212 }
213
194 void HistoryBackendTestDelegate::BroadcastNotifications( 214 void HistoryBackendTestDelegate::BroadcastNotifications(
195 int type, 215 int type,
196 scoped_ptr<HistoryDetails> details) { 216 scoped_ptr<HistoryDetails> details) {
197 test_->BroadcastNotifications(type, details.Pass()); 217 test_->BroadcastNotifications(type, details.Pass());
198 } 218 }
199 219
200 void HistoryBackendTestDelegate::DBLoaded() { 220 void HistoryBackendTestDelegate::DBLoaded() {
201 test_->loaded_ = true; 221 test_->loaded_ = true;
202 } 222 }
203 223
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 EXPECT_EQ(mapping_id, icon_mappings[0].mapping_id); 1679 EXPECT_EQ(mapping_id, icon_mappings[0].mapping_id);
1660 } 1680 }
1661 1681
1662 // Test that calling SetFavicons() with FaviconBitmapData of different pixel 1682 // Test that calling SetFavicons() with FaviconBitmapData of different pixel
1663 // sizes than the initially passed in FaviconBitmapData deletes the no longer 1683 // sizes than the initially passed in FaviconBitmapData deletes the no longer
1664 // used favicon bitmaps. 1684 // used favicon bitmaps.
1665 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) { 1685 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) {
1666 const GURL page_url("http://www.google.com/"); 1686 const GURL page_url("http://www.google.com/");
1667 const GURL icon_url("http://www.google.com/icon"); 1687 const GURL icon_url("http://www.google.com/icon");
1668 1688
1689 ClearFaviconChangedNotificationCounter();
1669 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1690 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1670 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(), 1691 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
1671 &favicon_bitmap_data); 1692 &favicon_bitmap_data);
1672 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1693 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1673 1694
1674 // Test initial state. 1695 // Test initial state.
1675 std::vector<IconMapping> icon_mappings; 1696 std::vector<IconMapping> icon_mappings;
1676 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings)); 1697 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings));
1677 EXPECT_EQ(1u, icon_mappings.size()); 1698 EXPECT_EQ(1u, icon_mappings.size());
1678 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); 1699 EXPECT_EQ(icon_url, icon_mappings[0].icon_url);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 favicon_bitmap_data.clear(); 1738 favicon_bitmap_data.clear();
1718 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1739 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1719 1740
1720 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, NULL, 1741 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, NULL,
1721 NULL, NULL)); 1742 NULL, NULL));
1722 icon_mappings.clear(); 1743 icon_mappings.clear();
1723 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1744 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1724 &icon_mappings)); 1745 &icon_mappings));
1725 1746
1726 // Notifications should have been broadcast for each call to SetFavicons(). 1747 // Notifications should have been broadcast for each call to SetFavicons().
1727 EXPECT_EQ(3, num_broadcasted_notifications()); 1748 EXPECT_EQ(3, favicon_changed_notifications());
1728 } 1749 }
1729 1750
1730 // Test updating a single favicon bitmap's data via SetFavicons. 1751 // Test updating a single favicon bitmap's data via SetFavicons.
1731 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { 1752 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
1732 const GURL page_url("http://www.google.com/"); 1753 const GURL page_url("http://www.google.com/");
1733 const GURL icon_url("http://www.google.com/icon"); 1754 const GURL icon_url("http://www.google.com/icon");
1734 1755
1756 ClearFaviconChangedNotificationCounter();
1735 std::vector<unsigned char> data_initial; 1757 std::vector<unsigned char> data_initial;
1736 data_initial.push_back('a'); 1758 data_initial.push_back('a');
1737 1759
1738 favicon_base::FaviconRawBitmapData bitmap_data_element; 1760 favicon_base::FaviconRawBitmapData bitmap_data_element;
1739 bitmap_data_element.bitmap_data = 1761 bitmap_data_element.bitmap_data =
1740 base::RefCountedBytes::TakeVector(&data_initial); 1762 base::RefCountedBytes::TakeVector(&data_initial);
1741 bitmap_data_element.pixel_size = kSmallSize; 1763 bitmap_data_element.pixel_size = kSmallSize;
1742 bitmap_data_element.icon_url = icon_url; 1764 bitmap_data_element.icon_url = icon_url;
1743 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1765 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1744 favicon_bitmap_data.push_back(bitmap_data_element); 1766 favicon_bitmap_data.push_back(bitmap_data_element);
1745 1767
1746 // Add bitmap to the database. 1768 // Add bitmap to the database.
1747 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1769 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1748 1770
1749 favicon_base::FaviconID original_favicon_id = 1771 favicon_base::FaviconID original_favicon_id =
1750 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1772 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1751 icon_url, favicon_base::FAVICON, NULL); 1773 icon_url, favicon_base::FAVICON, NULL);
1752 EXPECT_NE(0, original_favicon_id); 1774 EXPECT_NE(0, original_favicon_id);
1753 FaviconBitmap original_favicon_bitmap; 1775 FaviconBitmap original_favicon_bitmap;
1754 EXPECT_TRUE( 1776 EXPECT_TRUE(
1755 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap)); 1777 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap));
1756 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data)); 1778 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data));
1757 1779
1758 EXPECT_EQ(1, num_broadcasted_notifications()); 1780 EXPECT_EQ(1, favicon_changed_notifications());
1759 1781
1760 // Call SetFavicons() with completely identical data. 1782 // Call SetFavicons() with completely identical data.
1761 std::vector<unsigned char> updated_data; 1783 std::vector<unsigned char> updated_data;
1762 updated_data.push_back('a'); 1784 updated_data.push_back('a');
1763 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data); 1785 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
1764 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1786 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1765 1787
1766 favicon_base::FaviconID updated_favicon_id = 1788 favicon_base::FaviconID updated_favicon_id =
1767 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1789 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1768 icon_url, favicon_base::FAVICON, NULL); 1790 icon_url, favicon_base::FAVICON, NULL);
1769 EXPECT_NE(0, updated_favicon_id); 1791 EXPECT_NE(0, updated_favicon_id);
1770 FaviconBitmap updated_favicon_bitmap; 1792 FaviconBitmap updated_favicon_bitmap;
1771 EXPECT_TRUE( 1793 EXPECT_TRUE(
1772 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); 1794 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
1773 EXPECT_TRUE(BitmapDataEqual('a', updated_favicon_bitmap.bitmap_data)); 1795 EXPECT_TRUE(BitmapDataEqual('a', updated_favicon_bitmap.bitmap_data));
1774 1796
1775 // Because the bitmap data is byte equivalent, no notifications should have 1797 // Because the bitmap data is byte equivalent, no notifications should have
1776 // been broadcasted. 1798 // been broadcasted.
1777 EXPECT_EQ(1, num_broadcasted_notifications()); 1799 EXPECT_EQ(1, favicon_changed_notifications());
1778 1800
1779 // Call SetFavicons() with identical data but a different bitmap. 1801 // Call SetFavicons() with identical data but a different bitmap.
1780 updated_data[0] = 'b'; 1802 updated_data[0] = 'b';
1781 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data); 1803 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
1782 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1804 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1783 1805
1784 updated_favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1806 updated_favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1785 icon_url, favicon_base::FAVICON, NULL); 1807 icon_url, favicon_base::FAVICON, NULL);
1786 EXPECT_NE(0, updated_favicon_id); 1808 EXPECT_NE(0, updated_favicon_id);
1787 EXPECT_TRUE( 1809 EXPECT_TRUE(
1788 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); 1810 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
1789 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data)); 1811 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data));
1790 1812
1791 // There should be no churn in FaviconIDs or FaviconBitmapIds even though 1813 // There should be no churn in FaviconIDs or FaviconBitmapIds even though
1792 // the bitmap data changed. 1814 // the bitmap data changed.
1793 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id); 1815 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id);
1794 EXPECT_EQ(original_favicon_bitmap.bitmap_id, 1816 EXPECT_EQ(original_favicon_bitmap.bitmap_id,
1795 updated_favicon_bitmap.bitmap_id); 1817 updated_favicon_bitmap.bitmap_id);
1796 1818
1797 // A notification should have been broadcasted as the favicon bitmap data has 1819 // A notification should have been broadcasted as the favicon bitmap data has
1798 // changed. 1820 // changed.
1799 EXPECT_EQ(2, num_broadcasted_notifications()); 1821 EXPECT_EQ(2, favicon_changed_notifications());
1800 } 1822 }
1801 1823
1802 // Test that if two pages share the same FaviconID, changing the favicon for 1824 // Test that if two pages share the same FaviconID, changing the favicon for
1803 // one page does not affect the other. 1825 // one page does not affect the other.
1804 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) { 1826 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
1805 GURL icon_url("http://www.google.com/favicon.ico"); 1827 GURL icon_url("http://www.google.com/favicon.ico");
1806 GURL icon_url_new("http://www.google.com/favicon2.ico"); 1828 GURL icon_url_new("http://www.google.com/favicon2.ico");
1807 GURL page_url1("http://www.google.com"); 1829 GURL page_url1("http://www.google.com");
1808 GURL page_url2("http://www.google.ca"); 1830 GURL page_url2("http://www.google.ca");
1809 1831
1832 ClearFaviconChangedNotificationCounter();
1810 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1833 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1811 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(), 1834 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
1812 &favicon_bitmap_data); 1835 &favicon_bitmap_data);
1813 1836
1814 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); 1837 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
1815 1838
1816 std::vector<GURL> icon_urls; 1839 std::vector<GURL> icon_urls;
1817 icon_urls.push_back(icon_url); 1840 icon_urls.push_back(icon_url);
1818 1841
1819 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; 1842 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 EXPECT_EQ(1u, icon_mappings.size()); 1886 EXPECT_EQ(1u, icon_mappings.size());
1864 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1887 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1865 1888
1866 favicon_bitmaps.clear(); 1889 favicon_bitmaps.clear();
1867 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, 1890 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id,
1868 &favicon_bitmaps)); 1891 &favicon_bitmaps));
1869 EXPECT_EQ(2u, favicon_bitmaps.size()); 1892 EXPECT_EQ(2u, favicon_bitmaps.size());
1870 1893
1871 // A notification should have been broadcast for each call to SetFavicons() 1894 // A notification should have been broadcast for each call to SetFavicons()
1872 // and each call to UpdateFaviconMappingsAndFetch(). 1895 // and each call to UpdateFaviconMappingsAndFetch().
1873 EXPECT_EQ(3, num_broadcasted_notifications()); 1896 EXPECT_EQ(3, favicon_changed_notifications());
1874 } 1897 }
1875 1898
1876 // Test that no notifications are broadcast as a result of calling 1899 // Test that no notifications are broadcast as a result of calling
1877 // UpdateFaviconMappingsAndFetch() for an icon URL which is already 1900 // UpdateFaviconMappingsAndFetch() for an icon URL which is already
1878 // mapped to the passed in page URL. 1901 // mapped to the passed in page URL.
1879 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { 1902 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) {
1880 GURL page_url("http://www.google.com"); 1903 GURL page_url("http://www.google.com");
1881 GURL icon_url("http://www.google.com/favicon.ico"); 1904 GURL icon_url("http://www.google.com/favicon.ico");
1882 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1905 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1883 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(), 1906 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(),
1884 &favicon_bitmap_data); 1907 &favicon_bitmap_data);
1885 1908
1909 ClearFaviconChangedNotificationCounter();
1886 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1910 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1887 1911
1888 favicon_base::FaviconID icon_id = 1912 favicon_base::FaviconID icon_id =
1889 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1913 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1890 icon_url, favicon_base::FAVICON, NULL); 1914 icon_url, favicon_base::FAVICON, NULL);
1891 EXPECT_NE(0, icon_id); 1915 EXPECT_NE(0, icon_id);
1892 EXPECT_EQ(1, num_broadcasted_notifications()); 1916 EXPECT_EQ(1, favicon_changed_notifications());
1893 1917
1894 std::vector<GURL> icon_urls; 1918 std::vector<GURL> icon_urls;
1895 icon_urls.push_back(icon_url); 1919 icon_urls.push_back(icon_url);
1896 1920
1897 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; 1921 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
1898 backend_->UpdateFaviconMappingsAndFetch(page_url, 1922 backend_->UpdateFaviconMappingsAndFetch(page_url,
1899 icon_urls, 1923 icon_urls,
1900 favicon_base::FAVICON, 1924 favicon_base::FAVICON,
1901 GetEdgeSizesSmallAndLarge(), 1925 GetEdgeSizesSmallAndLarge(),
1902 &bitmap_results); 1926 &bitmap_results);
1903 1927
1904 EXPECT_EQ(icon_id, 1928 EXPECT_EQ(icon_id,
1905 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1929 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1906 icon_url, favicon_base::FAVICON, NULL)); 1930 icon_url, favicon_base::FAVICON, NULL));
1907 1931
1908 // No notification should have been broadcast as no icon mapping, favicon, 1932 // No notification should have been broadcast as no icon mapping, favicon,
1909 // or favicon bitmap was updated, added or removed. 1933 // or favicon bitmap was updated, added or removed.
1910 EXPECT_EQ(1, num_broadcasted_notifications()); 1934 EXPECT_EQ(1, favicon_changed_notifications());
1911 } 1935 }
1912 1936
1913 // Test repeatedly calling MergeFavicon(). |page_url| is initially not known 1937 // Test repeatedly calling MergeFavicon(). |page_url| is initially not known
1914 // to the database. 1938 // to the database.
1915 TEST_F(HistoryBackendTest, MergeFaviconPageURLNotInDB) { 1939 TEST_F(HistoryBackendTest, MergeFaviconPageURLNotInDB) {
1916 GURL page_url("http://www.google.com"); 1940 GURL page_url("http://www.google.com");
1917 GURL icon_url("http:/www.google.com/favicon.ico"); 1941 GURL icon_url("http:/www.google.com/favicon.ico");
1918 1942
1919 std::vector<unsigned char> data; 1943 std::vector<unsigned char> data;
1920 data.push_back('a'); 1944 data.push_back('a');
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); 1980 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data));
1957 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1981 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1958 } 1982 }
1959 1983
1960 // Test calling MergeFavicon() when |page_url| is known to the database. 1984 // Test calling MergeFavicon() when |page_url| is known to the database.
1961 TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) { 1985 TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) {
1962 GURL page_url("http://www.google.com"); 1986 GURL page_url("http://www.google.com");
1963 GURL icon_url1("http:/www.google.com/favicon.ico"); 1987 GURL icon_url1("http:/www.google.com/favicon.ico");
1964 GURL icon_url2("http://www.google.com/favicon2.ico"); 1988 GURL icon_url2("http://www.google.com/favicon2.ico");
1965 1989
1990 ClearFaviconChangedNotificationCounter();
1966 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1991 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1967 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(), 1992 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(),
1968 &favicon_bitmap_data); 1993 &favicon_bitmap_data);
1969 1994
1970 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1995 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1971 1996
1972 // Test initial state. 1997 // Test initial state.
1973 std::vector<IconMapping> icon_mappings; 1998 std::vector<IconMapping> icon_mappings;
1974 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1999 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1975 &icon_mappings)); 2000 &icon_mappings));
1976 EXPECT_EQ(1u, icon_mappings.size()); 2001 EXPECT_EQ(1u, icon_mappings.size());
1977 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 2002 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1978 2003
1979 FaviconBitmap favicon_bitmap; 2004 FaviconBitmap favicon_bitmap;
1980 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 2005 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1981 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 2006 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1982 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 2007 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
1983 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 2008 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1984 2009
1985 EXPECT_EQ(1, num_broadcasted_notifications()); 2010 EXPECT_EQ(1, favicon_changed_notifications());
1986 2011
1987 // 1) Merge identical favicon bitmap. 2012 // 1) Merge identical favicon bitmap.
1988 std::vector<unsigned char> data; 2013 std::vector<unsigned char> data;
1989 data.push_back('a'); 2014 data.push_back('a');
1990 scoped_refptr<base::RefCountedBytes> bitmap_data( 2015 scoped_refptr<base::RefCountedBytes> bitmap_data(
1991 new base::RefCountedBytes(data)); 2016 new base::RefCountedBytes(data));
1992 backend_->MergeFavicon( 2017 backend_->MergeFavicon(
1993 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); 2018 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize);
1994 2019
1995 // All the data should stay the same and no notifications should have been 2020 // All the data should stay the same and no notifications should have been
1996 // sent. 2021 // sent.
1997 icon_mappings.clear(); 2022 icon_mappings.clear();
1998 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 2023 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1999 &icon_mappings)); 2024 &icon_mappings));
2000 EXPECT_EQ(1u, icon_mappings.size()); 2025 EXPECT_EQ(1u, icon_mappings.size());
2001 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 2026 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
2002 2027
2003 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 2028 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
2004 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 2029 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
2005 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 2030 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
2006 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 2031 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
2007 2032
2008 EXPECT_EQ(1, num_broadcasted_notifications()); 2033 EXPECT_EQ(1, favicon_changed_notifications());
2009 2034
2010 // 2) Merge favicon bitmap of the same size. 2035 // 2) Merge favicon bitmap of the same size.
2011 data[0] = 'b'; 2036 data[0] = 'b';
2012 bitmap_data = new base::RefCountedBytes(data); 2037 bitmap_data = new base::RefCountedBytes(data);
2013 backend_->MergeFavicon( 2038 backend_->MergeFavicon(
2014 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); 2039 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize);
2015 2040
2016 // The small favicon bitmap at |icon_url1| should be overwritten. 2041 // The small favicon bitmap at |icon_url1| should be overwritten.
2017 icon_mappings.clear(); 2042 icon_mappings.clear();
2018 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 2043 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); 2097 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data));
2073 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); 2098 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size);
2074 // The favicon being merged should take precedence over the preexisting 2099 // The favicon being merged should take precedence over the preexisting
2075 // favicon bitmaps. 2100 // favicon bitmaps.
2076 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated); 2101 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated);
2077 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data)); 2102 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data));
2078 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); 2103 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size);
2079 2104
2080 // A notification should have been broadcast for each call to SetFavicons() 2105 // A notification should have been broadcast for each call to SetFavicons()
2081 // and MergeFavicon(). 2106 // and MergeFavicon().
2082 EXPECT_EQ(4, num_broadcasted_notifications()); 2107 EXPECT_EQ(4, favicon_changed_notifications());
2083 } 2108 }
2084 2109
2085 // Test calling MergeFavicon() when |icon_url| is known to the database but not 2110 // Test calling MergeFavicon() when |icon_url| is known to the database but not
2086 // mapped to |page_url|. 2111 // mapped to |page_url|.
2087 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { 2112 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) {
2088 GURL page_url1("http://www.google.com"); 2113 GURL page_url1("http://www.google.com");
2089 GURL page_url2("http://news.google.com"); 2114 GURL page_url2("http://news.google.com");
2090 GURL page_url3("http://maps.google.com"); 2115 GURL page_url3("http://maps.google.com");
2091 GURL icon_url("http:/www.google.com/favicon.ico"); 2116 GURL icon_url("http:/www.google.com/favicon.ico");
2092 2117
2118 ClearFaviconChangedNotificationCounter();
2093 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2119 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2094 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(), 2120 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(),
2095 &favicon_bitmap_data); 2121 &favicon_bitmap_data);
2096 2122
2097 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); 2123 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
2098 2124
2099 // Test initial state. 2125 // Test initial state.
2100 std::vector<IconMapping> icon_mappings; 2126 std::vector<IconMapping> icon_mappings;
2101 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1, 2127 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1,
2102 &icon_mappings)); 2128 &icon_mappings));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2157 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 2183 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
2158 2184
2159 icon_mappings.clear(); 2185 icon_mappings.clear();
2160 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3, 2186 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3,
2161 &icon_mappings)); 2187 &icon_mappings));
2162 EXPECT_EQ(1u, icon_mappings.size()); 2188 EXPECT_EQ(1u, icon_mappings.size());
2163 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 2189 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
2164 2190
2165 // A notification should have been broadcast for each call to SetFavicons() 2191 // A notification should have been broadcast for each call to SetFavicons()
2166 // and MergeFavicon(). 2192 // and MergeFavicon().
2167 EXPECT_EQ(3, num_broadcasted_notifications()); 2193 EXPECT_EQ(3, favicon_changed_notifications());
2168 } 2194 }
2169 2195
2170 // Test that MergeFavicon() does not add more than 2196 // Test that MergeFavicon() does not add more than
2171 // |kMaxFaviconBitmapsPerIconURL| to a favicon. 2197 // |kMaxFaviconBitmapsPerIconURL| to a favicon.
2172 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) { 2198 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) {
2173 GURL page_url("http://www.google.com"); 2199 GURL page_url("http://www.google.com");
2174 std::string icon_url_string("http://www.google.com/favicon.ico"); 2200 std::string icon_url_string("http://www.google.com/favicon.ico");
2175 size_t replace_index = icon_url_string.size() - 1; 2201 size_t replace_index = icon_url_string.size() - 1;
2176 2202
2177 std::vector<unsigned char> data; 2203 std::vector<unsigned char> data;
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
3336 // Verify that the second term is no longer returned as result, and also check 3362 // Verify that the second term is no longer returned as result, and also check
3337 // at the low level that it is gone for good. The term corresponding to the 3363 // at the low level that it is gone for good. The term corresponding to the
3338 // first URLRow should not be affected. 3364 // first URLRow should not be affected.
3339 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3365 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3340 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3366 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3341 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3367 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3342 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3368 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3343 } 3369 }
3344 3370
3345 } // namespace history 3371 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698