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

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 unit tests Created 6 years, 3 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
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // This must be a separate object since HistoryBackend manages its lifetime. 85 // This must be a separate object since HistoryBackend manages its lifetime.
86 // This just forwards the messages we're interested in to the test object. 86 // This just forwards the messages we're interested in to the test object.
87 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { 87 class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
88 public: 88 public:
89 explicit HistoryBackendTestDelegate(HistoryBackendTestBase* test) 89 explicit HistoryBackendTestDelegate(HistoryBackendTestBase* test)
90 : test_(test) {} 90 : test_(test) {}
91 91
92 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {} 92 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {}
93 virtual void SetInMemoryBackend( 93 virtual void SetInMemoryBackend(
94 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE; 94 scoped_ptr<InMemoryHistoryBackend> backend) OVERRIDE;
95 virtual void NotifyFaviconChanged(const std::set<GURL>& urls) OVERRIDE;
95 virtual void BroadcastNotifications( 96 virtual void BroadcastNotifications(
96 int type, 97 int type,
97 scoped_ptr<HistoryDetails> details) OVERRIDE; 98 scoped_ptr<HistoryDetails> details) OVERRIDE;
98 virtual void DBLoaded() OVERRIDE; 99 virtual void DBLoaded() OVERRIDE;
99 virtual void NotifyVisitDBObserversOnAddVisit( 100 virtual void NotifyVisitDBObserversOnAddVisit(
100 const BriefVisitInfo& info) OVERRIDE {} 101 const BriefVisitInfo& info) OVERRIDE {}
101 102
102 private: 103 private:
103 // Not owned by us. 104 // Not owned by us.
104 HistoryBackendTestBase* test_; 105 HistoryBackendTestBase* test_;
105 106
106 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate); 107 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate);
107 }; 108 };
108 109
109 class HistoryBackendTestBase : public testing::Test { 110 class HistoryBackendTestBase : public testing::Test {
110 public: 111 public:
111 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; 112 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList;
112 113
113 HistoryBackendTestBase() 114 HistoryBackendTestBase()
114 : loaded_(false), 115 : loaded_(false),
116 favicon_changed_notifications_(0),
115 ui_thread_(content::BrowserThread::UI, &message_loop_) {} 117 ui_thread_(content::BrowserThread::UI, &message_loop_) {}
116 118
117 virtual ~HistoryBackendTestBase() { 119 virtual ~HistoryBackendTestBase() {
118 STLDeleteValues(&broadcasted_notifications_); 120 STLDeleteValues(&broadcasted_notifications_);
119 } 121 }
120 122
121 protected: 123 protected:
124 int favicon_changed_notifications() const {
125 return favicon_changed_notifications_;
126 }
127
128 void ClearFaviconChangedNotificationCounter() {
129 favicon_changed_notifications_ = 0;
130 }
131
122 int num_broadcasted_notifications() const { 132 int num_broadcasted_notifications() const {
123 return broadcasted_notifications_.size(); 133 return broadcasted_notifications_.size();
124 } 134 }
125 135
126 const NotificationList& broadcasted_notifications() const { 136 const NotificationList& broadcasted_notifications() const {
127 return broadcasted_notifications_; 137 return broadcasted_notifications_;
128 } 138 }
129 139
130 void ClearBroadcastedNotifications() { 140 void ClearBroadcastedNotifications() {
131 STLDeleteValues(&broadcasted_notifications_); 141 STLDeleteValues(&broadcasted_notifications_);
132 } 142 }
133 143
134 base::FilePath test_dir() { 144 base::FilePath test_dir() {
135 return test_dir_; 145 return test_dir_;
136 } 146 }
137 147
148 void NotifyFaviconChanged(const std::set<GURL>& changed_favicons) {
149 ++favicon_changed_notifications_;
150 }
151
138 void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) { 152 void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) {
139 // Send the notifications directly to the in-memory database. 153 // Send the notifications directly to the in-memory database.
140 content::Details<HistoryDetails> det(details.get()); 154 content::Details<HistoryDetails> det(details.get());
141 mem_backend_->Observe( 155 mem_backend_->Observe(
142 type, content::Source<HistoryBackendTestBase>(NULL), det); 156 type, content::Source<HistoryBackendTestBase>(NULL), det);
143 157
144 // The backend passes ownership of the details pointer to us. 158 // The backend passes ownership of the details pointer to us.
145 broadcasted_notifications_.push_back( 159 broadcasted_notifications_.push_back(
146 std::make_pair(type, details.release())); 160 std::make_pair(type, details.release()));
147 } 161 }
148 162
149 history::HistoryClientFakeBookmarks history_client_; 163 history::HistoryClientFakeBookmarks history_client_;
150 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. 164 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure.
151 scoped_ptr<InMemoryHistoryBackend> mem_backend_; 165 scoped_ptr<InMemoryHistoryBackend> mem_backend_;
152 bool loaded_; 166 bool loaded_;
153 167
154 private: 168 private:
155 friend class HistoryBackendTestDelegate; 169 friend class HistoryBackendTestDelegate;
156 170
157 // testing::Test 171 // testing::Test
158 virtual void SetUp() { 172 virtual void SetUp() {
173 ClearFaviconChangedNotificationCounter();
159 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), 174 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"),
160 &test_dir_)) 175 &test_dir_))
161 return; 176 return;
162 backend_ = new HistoryBackend( 177 backend_ = new HistoryBackend(
163 test_dir_, new HistoryBackendTestDelegate(this), &history_client_); 178 test_dir_, new HistoryBackendTestDelegate(this), &history_client_);
164 backend_->Init(std::string(), false); 179 backend_->Init(std::string(), false);
165 } 180 }
166 181
167 virtual void TearDown() { 182 virtual void TearDown() {
168 if (backend_.get()) 183 if (backend_.get())
169 backend_->Closing(); 184 backend_->Closing();
170 backend_ = NULL; 185 backend_ = NULL;
171 mem_backend_.reset(); 186 mem_backend_.reset();
172 base::DeleteFile(test_dir_, true); 187 base::DeleteFile(test_dir_, true);
173 base::RunLoop().RunUntilIdle(); 188 base::RunLoop().RunUntilIdle();
174 history_client_.ClearAllBookmarks(); 189 history_client_.ClearAllBookmarks();
175 } 190 }
176 191
177 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { 192 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) {
178 mem_backend_.swap(backend); 193 mem_backend_.swap(backend);
179 } 194 }
180 195
181 // The types and details of notifications which were broadcasted. 196 // The types and details of notifications which were broadcasted.
182 NotificationList broadcasted_notifications_; 197 NotificationList broadcasted_notifications_;
198 int favicon_changed_notifications_;
183 199
184 base::MessageLoop message_loop_; 200 base::MessageLoop message_loop_;
185 base::FilePath test_dir_; 201 base::FilePath test_dir_;
186 content::TestBrowserThread ui_thread_; 202 content::TestBrowserThread ui_thread_;
187 203
188 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase); 204 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase);
189 }; 205 };
190 206
191 void HistoryBackendTestDelegate::SetInMemoryBackend( 207 void HistoryBackendTestDelegate::SetInMemoryBackend(
192 scoped_ptr<InMemoryHistoryBackend> backend) { 208 scoped_ptr<InMemoryHistoryBackend> backend) {
193 test_->SetInMemoryBackend(backend.Pass()); 209 test_->SetInMemoryBackend(backend.Pass());
194 } 210 }
195 211
212 void HistoryBackendTestDelegate::NotifyFaviconChanged(
213 const std::set<GURL>& changed_favicons) {
214 test_->NotifyFaviconChanged(changed_favicons);
215 }
216
196 void HistoryBackendTestDelegate::BroadcastNotifications( 217 void HistoryBackendTestDelegate::BroadcastNotifications(
197 int type, 218 int type,
198 scoped_ptr<HistoryDetails> details) { 219 scoped_ptr<HistoryDetails> details) {
199 test_->BroadcastNotifications(type, details.Pass()); 220 test_->BroadcastNotifications(type, details.Pass());
200 } 221 }
201 222
202 void HistoryBackendTestDelegate::DBLoaded() { 223 void HistoryBackendTestDelegate::DBLoaded() {
203 test_->loaded_ = true; 224 test_->loaded_ = true;
204 } 225 }
205 226
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 EXPECT_TRUE(BitmapColorEqual(SK_ColorWHITE, bitmap_data_out)); 1662 EXPECT_TRUE(BitmapColorEqual(SK_ColorWHITE, bitmap_data_out));
1642 EXPECT_EQ(kLargeSize, pixel_size_out); 1663 EXPECT_EQ(kLargeSize, pixel_size_out);
1643 1664
1644 icon_mappings.clear(); 1665 icon_mappings.clear();
1645 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1666 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1646 &icon_mappings)); 1667 &icon_mappings));
1647 EXPECT_EQ(1u, icon_mappings.size()); 1668 EXPECT_EQ(1u, icon_mappings.size());
1648 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1669 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1649 1670
1650 // Notifications should have been broadcast for each call to SetFavicons(). 1671 // Notifications should have been broadcast for each call to SetFavicons().
1651 EXPECT_EQ(2, num_broadcasted_notifications()); 1672 EXPECT_EQ(2, favicon_changed_notifications());
1652 } 1673 }
1653 1674
1654 // Test updating a single favicon bitmap's data via SetFavicons. 1675 // Test updating a single favicon bitmap's data via SetFavicons.
1655 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { 1676 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
1656 const GURL page_url("http://www.google.com/"); 1677 const GURL page_url("http://www.google.com/");
1657 const GURL icon_url("http://www.google.com/icon"); 1678 const GURL icon_url("http://www.google.com/icon");
1658 std::vector<SkBitmap> bitmaps; 1679 std::vector<SkBitmap> bitmaps;
1659 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); 1680 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize));
1660 1681
1661 // Add bitmap to the database. 1682 // Add bitmap to the database.
1662 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url, bitmaps); 1683 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url, bitmaps);
1663 1684
1664 favicon_base::FaviconID original_favicon_id = 1685 favicon_base::FaviconID original_favicon_id =
1665 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1686 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1666 icon_url, favicon_base::FAVICON, NULL); 1687 icon_url, favicon_base::FAVICON, NULL);
1667 EXPECT_NE(0, original_favicon_id); 1688 EXPECT_NE(0, original_favicon_id);
1668 FaviconBitmap original_favicon_bitmap; 1689 FaviconBitmap original_favicon_bitmap;
1669 EXPECT_TRUE( 1690 EXPECT_TRUE(
1670 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap)); 1691 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap));
1671 EXPECT_TRUE( 1692 EXPECT_TRUE(
1672 BitmapColorEqual(SK_ColorBLUE, original_favicon_bitmap.bitmap_data)); 1693 BitmapColorEqual(SK_ColorBLUE, original_favicon_bitmap.bitmap_data));
1673 1694
1674 EXPECT_EQ(1, num_broadcasted_notifications()); 1695 EXPECT_EQ(1, favicon_changed_notifications());
1675 1696
1676 // Call SetFavicons() with completely identical data. 1697 // Call SetFavicons() with completely identical data.
1677 bitmaps[0] = CreateBitmap(SK_ColorBLUE, kSmallEdgeSize); 1698 bitmaps[0] = CreateBitmap(SK_ColorBLUE, kSmallEdgeSize);
1678 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url, bitmaps); 1699 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url, bitmaps);
1679 1700
1680 favicon_base::FaviconID updated_favicon_id = 1701 favicon_base::FaviconID updated_favicon_id =
1681 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1702 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1682 icon_url, favicon_base::FAVICON, NULL); 1703 icon_url, favicon_base::FAVICON, NULL);
1683 EXPECT_NE(0, updated_favicon_id); 1704 EXPECT_NE(0, updated_favicon_id);
1684 FaviconBitmap updated_favicon_bitmap; 1705 FaviconBitmap updated_favicon_bitmap;
1685 EXPECT_TRUE( 1706 EXPECT_TRUE(
1686 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); 1707 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
1687 EXPECT_TRUE( 1708 EXPECT_TRUE(
1688 BitmapColorEqual(SK_ColorBLUE, updated_favicon_bitmap.bitmap_data)); 1709 BitmapColorEqual(SK_ColorBLUE, updated_favicon_bitmap.bitmap_data));
1689 1710
1690 // Because the bitmap data is byte equivalent, no notifications should have 1711 // Because the bitmap data is byte equivalent, no notifications should have
1691 // been broadcasted. 1712 // been broadcasted.
1692 EXPECT_EQ(1, num_broadcasted_notifications()); 1713 EXPECT_EQ(1, favicon_changed_notifications());
1693 1714
1694 // Call SetFavicons() with a different bitmap of the same size. 1715 // Call SetFavicons() with a different bitmap of the same size.
1695 bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize); 1716 bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize);
1696 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url, bitmaps); 1717 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url, bitmaps);
1697 1718
1698 updated_favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1719 updated_favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1699 icon_url, favicon_base::FAVICON, NULL); 1720 icon_url, favicon_base::FAVICON, NULL);
1700 EXPECT_NE(0, updated_favicon_id); 1721 EXPECT_NE(0, updated_favicon_id);
1701 EXPECT_TRUE( 1722 EXPECT_TRUE(
1702 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); 1723 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
1703 EXPECT_TRUE( 1724 EXPECT_TRUE(
1704 BitmapColorEqual(SK_ColorWHITE, updated_favicon_bitmap.bitmap_data)); 1725 BitmapColorEqual(SK_ColorWHITE, updated_favicon_bitmap.bitmap_data));
1705 1726
1706 // There should be no churn in FaviconIDs or FaviconBitmapIds even though 1727 // There should be no churn in FaviconIDs or FaviconBitmapIds even though
1707 // the bitmap data changed. 1728 // the bitmap data changed.
1708 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id); 1729 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id);
1709 EXPECT_EQ(original_favicon_bitmap.bitmap_id, 1730 EXPECT_EQ(original_favicon_bitmap.bitmap_id,
1710 updated_favicon_bitmap.bitmap_id); 1731 updated_favicon_bitmap.bitmap_id);
1711 1732
1712 // A notification should have been broadcasted as the favicon bitmap data has 1733 // A notification should have been broadcasted as the favicon bitmap data has
1713 // changed. 1734 // changed.
1714 EXPECT_EQ(2, num_broadcasted_notifications()); 1735 EXPECT_EQ(2, favicon_changed_notifications());
1715 } 1736 }
1716 1737
1717 // Test that if two pages share the same FaviconID, changing the favicon for 1738 // Test that if two pages share the same FaviconID, changing the favicon for
1718 // one page does not affect the other. 1739 // one page does not affect the other.
1719 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) { 1740 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
1720 GURL icon_url("http://www.google.com/favicon.ico"); 1741 GURL icon_url("http://www.google.com/favicon.ico");
1721 GURL icon_url_new("http://www.google.com/favicon2.ico"); 1742 GURL icon_url_new("http://www.google.com/favicon2.ico");
1722 GURL page_url1("http://www.google.com"); 1743 GURL page_url1("http://www.google.com");
1723 GURL page_url2("http://www.google.ca"); 1744 GURL page_url2("http://www.google.ca");
1724 std::vector<SkBitmap> bitmaps; 1745 std::vector<SkBitmap> bitmaps;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 EXPECT_EQ(1u, icon_mappings.size()); 1799 EXPECT_EQ(1u, icon_mappings.size());
1779 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1800 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1780 1801
1781 favicon_bitmaps.clear(); 1802 favicon_bitmaps.clear();
1782 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, 1803 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id,
1783 &favicon_bitmaps)); 1804 &favicon_bitmaps));
1784 EXPECT_EQ(2u, favicon_bitmaps.size()); 1805 EXPECT_EQ(2u, favicon_bitmaps.size());
1785 1806
1786 // A notification should have been broadcast for each call to SetFavicons() 1807 // A notification should have been broadcast for each call to SetFavicons()
1787 // and each call to UpdateFaviconMappingsAndFetch(). 1808 // and each call to UpdateFaviconMappingsAndFetch().
1788 EXPECT_EQ(3, num_broadcasted_notifications()); 1809 EXPECT_EQ(3, favicon_changed_notifications());
1789 } 1810 }
1790 1811
1791 // Test that no notifications are broadcast as a result of calling 1812 // Test that no notifications are broadcast as a result of calling
1792 // UpdateFaviconMappingsAndFetch() for an icon URL which is already 1813 // UpdateFaviconMappingsAndFetch() for an icon URL which is already
1793 // mapped to the passed in page URL. 1814 // mapped to the passed in page URL.
1794 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { 1815 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) {
1795 GURL page_url("http://www.google.com"); 1816 GURL page_url("http://www.google.com");
1796 GURL icon_url("http://www.google.com/favicon.ico"); 1817 GURL icon_url("http://www.google.com/favicon.ico");
1797 std::vector<SkBitmap> bitmaps; 1818 std::vector<SkBitmap> bitmaps;
1798 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); 1819 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize));
1799 1820
1800 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url, bitmaps); 1821 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url, bitmaps);
1801 1822
1802 favicon_base::FaviconID icon_id = 1823 favicon_base::FaviconID icon_id =
1803 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1824 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1804 icon_url, favicon_base::FAVICON, NULL); 1825 icon_url, favicon_base::FAVICON, NULL);
1805 EXPECT_NE(0, icon_id); 1826 EXPECT_NE(0, icon_id);
1806 EXPECT_EQ(1, num_broadcasted_notifications()); 1827 EXPECT_EQ(1, favicon_changed_notifications());
1807 1828
1808 std::vector<GURL> icon_urls; 1829 std::vector<GURL> icon_urls;
1809 icon_urls.push_back(icon_url); 1830 icon_urls.push_back(icon_url);
1810 1831
1811 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; 1832 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
1812 backend_->UpdateFaviconMappingsAndFetch(page_url, 1833 backend_->UpdateFaviconMappingsAndFetch(page_url,
1813 icon_urls, 1834 icon_urls,
1814 favicon_base::FAVICON, 1835 favicon_base::FAVICON,
1815 GetEdgeSizesSmallAndLarge(), 1836 GetEdgeSizesSmallAndLarge(),
1816 &bitmap_results); 1837 &bitmap_results);
1817 1838
1818 EXPECT_EQ(icon_id, 1839 EXPECT_EQ(icon_id,
1819 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1840 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1820 icon_url, favicon_base::FAVICON, NULL)); 1841 icon_url, favicon_base::FAVICON, NULL));
1821 1842
1822 // No notification should have been broadcast as no icon mapping, favicon, 1843 // No notification should have been broadcast as no icon mapping, favicon,
1823 // or favicon bitmap was updated, added or removed. 1844 // or favicon bitmap was updated, added or removed.
1824 EXPECT_EQ(1, num_broadcasted_notifications()); 1845 EXPECT_EQ(1, favicon_changed_notifications());
1825 } 1846 }
1826 1847
1827 // Test repeatedly calling MergeFavicon(). |page_url| is initially not known 1848 // Test repeatedly calling MergeFavicon(). |page_url| is initially not known
1828 // to the database. 1849 // to the database.
1829 TEST_F(HistoryBackendTest, MergeFaviconPageURLNotInDB) { 1850 TEST_F(HistoryBackendTest, MergeFaviconPageURLNotInDB) {
1830 GURL page_url("http://www.google.com"); 1851 GURL page_url("http://www.google.com");
1831 GURL icon_url("http:/www.google.com/favicon.ico"); 1852 GURL icon_url("http:/www.google.com/favicon.ico");
1832 1853
1833 std::vector<unsigned char> data; 1854 std::vector<unsigned char> data;
1834 data.push_back('a'); 1855 data.push_back('a');
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 &icon_mappings)); 1908 &icon_mappings));
1888 EXPECT_EQ(1u, icon_mappings.size()); 1909 EXPECT_EQ(1u, icon_mappings.size());
1889 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1910 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1890 1911
1891 FaviconBitmap favicon_bitmap; 1912 FaviconBitmap favicon_bitmap;
1892 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1913 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1893 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 1914 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1894 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data)); 1915 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data));
1895 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1916 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1896 1917
1897 EXPECT_EQ(1, num_broadcasted_notifications()); 1918 EXPECT_EQ(1, favicon_changed_notifications());
1898 1919
1899 // 1) Merge identical favicon bitmap. 1920 // 1) Merge identical favicon bitmap.
1900 std::vector<unsigned char> data; 1921 std::vector<unsigned char> data;
1901 gfx::PNGCodec::EncodeBGRASkBitmap(bitmaps[0], false, &data); 1922 gfx::PNGCodec::EncodeBGRASkBitmap(bitmaps[0], false, &data);
1902 scoped_refptr<base::RefCountedBytes> bitmap_data( 1923 scoped_refptr<base::RefCountedBytes> bitmap_data(
1903 new base::RefCountedBytes(data)); 1924 new base::RefCountedBytes(data));
1904 backend_->MergeFavicon( 1925 backend_->MergeFavicon(
1905 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); 1926 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize);
1906 1927
1907 // All the data should stay the same and no notifications should have been 1928 // All the data should stay the same and no notifications should have been
1908 // sent. 1929 // sent.
1909 icon_mappings.clear(); 1930 icon_mappings.clear();
1910 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1931 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1911 &icon_mappings)); 1932 &icon_mappings));
1912 EXPECT_EQ(1u, icon_mappings.size()); 1933 EXPECT_EQ(1u, icon_mappings.size());
1913 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1934 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1914 1935
1915 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1936 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1916 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 1937 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1917 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data)); 1938 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data));
1918 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1939 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1919 1940
1920 EXPECT_EQ(1, num_broadcasted_notifications()); 1941 EXPECT_EQ(1, favicon_changed_notifications());
1921 1942
1922 // 2) Merge favicon bitmap of the same size. 1943 // 2) Merge favicon bitmap of the same size.
1923 data.clear(); 1944 data.clear();
1924 data.push_back('b'); 1945 data.push_back('b');
1925 bitmap_data = new base::RefCountedBytes(data); 1946 bitmap_data = new base::RefCountedBytes(data);
1926 backend_->MergeFavicon( 1947 backend_->MergeFavicon(
1927 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); 1948 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize);
1928 1949
1929 // The small favicon bitmap at |icon_url1| should be overwritten. 1950 // The small favicon bitmap at |icon_url1| should be overwritten.
1930 icon_mappings.clear(); 1951 icon_mappings.clear();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); 2006 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data));
1986 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); 2007 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size);
1987 // The favicon being merged should take precedence over the preexisting 2008 // The favicon being merged should take precedence over the preexisting
1988 // favicon bitmaps. 2009 // favicon bitmaps.
1989 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated); 2010 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated);
1990 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data)); 2011 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data));
1991 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); 2012 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size);
1992 2013
1993 // A notification should have been broadcast for each call to SetFavicons() 2014 // A notification should have been broadcast for each call to SetFavicons()
1994 // and MergeFavicon(). 2015 // and MergeFavicon().
1995 EXPECT_EQ(4, num_broadcasted_notifications()); 2016 EXPECT_EQ(4, favicon_changed_notifications());
1996 } 2017 }
1997 2018
1998 // Test calling MergeFavicon() when |icon_url| is known to the database but not 2019 // Test calling MergeFavicon() when |icon_url| is known to the database but not
1999 // mapped to |page_url|. 2020 // mapped to |page_url|.
2000 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { 2021 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) {
2001 GURL page_url1("http://www.google.com"); 2022 GURL page_url1("http://www.google.com");
2002 GURL page_url2("http://news.google.com"); 2023 GURL page_url2("http://news.google.com");
2003 GURL page_url3("http://maps.google.com"); 2024 GURL page_url3("http://maps.google.com");
2004 GURL icon_url("http:/www.google.com/favicon.ico"); 2025 GURL icon_url("http:/www.google.com/favicon.ico");
2005 std::vector<SkBitmap> bitmaps; 2026 std::vector<SkBitmap> bitmaps;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 2091 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
2071 2092
2072 icon_mappings.clear(); 2093 icon_mappings.clear();
2073 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3, 2094 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3,
2074 &icon_mappings)); 2095 &icon_mappings));
2075 EXPECT_EQ(1u, icon_mappings.size()); 2096 EXPECT_EQ(1u, icon_mappings.size());
2076 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 2097 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
2077 2098
2078 // A notification should have been broadcast for each call to SetFavicons() 2099 // A notification should have been broadcast for each call to SetFavicons()
2079 // and MergeFavicon(). 2100 // and MergeFavicon().
2080 EXPECT_EQ(3, num_broadcasted_notifications()); 2101 EXPECT_EQ(3, favicon_changed_notifications());
2081 } 2102 }
2082 2103
2083 // Test that MergeFavicon() does not add more than 2104 // Test that MergeFavicon() does not add more than
2084 // |kMaxFaviconBitmapsPerIconURL| to a favicon. 2105 // |kMaxFaviconBitmapsPerIconURL| to a favicon.
2085 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) { 2106 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) {
2086 GURL page_url("http://www.google.com"); 2107 GURL page_url("http://www.google.com");
2087 std::string icon_url_string("http://www.google.com/favicon.ico"); 2108 std::string icon_url_string("http://www.google.com/favicon.ico");
2088 size_t replace_index = icon_url_string.size() - 1; 2109 size_t replace_index = icon_url_string.size() - 1;
2089 2110
2090 std::vector<unsigned char> data; 2111 std::vector<unsigned char> data;
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3194 // Verify that the second term is no longer returned as result, and also check 3215 // Verify that the second term is no longer returned as result, and also check
3195 // at the low level that it is gone for good. The term corresponding to the 3216 // at the low level that it is gone for good. The term corresponding to the
3196 // first URLRow should not be affected. 3217 // first URLRow should not be affected.
3197 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3218 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3198 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3219 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3199 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3220 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3200 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3221 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3201 } 3222 }
3202 3223
3203 } // namespace history 3224 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698