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

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

Issue 10869047: Fix HistoryBackend::SetFavicons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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/thumbnail_database.cc » ('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 <set> 5 #include <set>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 history::MostVisitedURLList data) { 116 history::MostVisitedURLList data) {
117 most_visited_list_.swap(data); 117 most_visited_list_.swap(data);
118 } 118 }
119 119
120 // Callback for QueryFiltered. 120 // Callback for QueryFiltered.
121 void OnQueryFiltered(CancelableRequestProvider::Handle handle, 121 void OnQueryFiltered(CancelableRequestProvider::Handle handle,
122 const history::FilteredURLList& data) { 122 const history::FilteredURLList& data) {
123 filtered_list_ = data; 123 filtered_list_ = data;
124 } 124 }
125 125
126 // Callback for UpdateFaviconMappingsAndFetch.
127 void OnFaviconData(FaviconService::Handle handle,
128 history::FaviconData favicon_data) {
129 }
130
126 const history::MostVisitedURLList& get_most_visited_list() const { 131 const history::MostVisitedURLList& get_most_visited_list() const {
127 return most_visited_list_; 132 return most_visited_list_;
128 } 133 }
129 134
130 const history::FilteredURLList& get_filtered_list() const { 135 const history::FilteredURLList& get_filtered_list() const {
131 return filtered_list_; 136 return filtered_list_;
132 } 137 }
133 138
134 protected: 139 protected:
135 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. 140 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure.
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 EXPECT_FALSE(backend_->AddOrUpdateIconMapping( 1205 EXPECT_FALSE(backend_->AddOrUpdateIconMapping(
1201 url, icon_id, FAVICON, &replaced)); 1206 url, icon_id, FAVICON, &replaced));
1202 EXPECT_EQ(0, replaced); 1207 EXPECT_EQ(0, replaced);
1203 1208
1204 std::vector<IconMapping> icon_mapping; 1209 std::vector<IconMapping> icon_mapping;
1205 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1210 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1206 url, &icon_mapping)); 1211 url, &icon_mapping));
1207 EXPECT_EQ(1u, icon_mapping.size()); 1212 EXPECT_EQ(1u, icon_mapping.size());
1208 } 1213 }
1209 1214
1215 // Test that SetFavicon for a page which shares a FaviconID with another does
1216 // the right thing.
1217 TEST_F(HistoryBackendTest, SetSameFaviconURLForTwoPages) {
1218 GURL favicon_url("http://www.google.com/favicon.ico");
1219 GURL page_url1("http://www.google.com");
1220 GURL page_url2("http://www.google.ca");
1221
1222 scoped_refptr<base::RefCountedMemory> bitmap_data(
1223 new base::RefCountedBytes());
1224 backend_->SetFavicon(page_url1, favicon_url, bitmap_data, FAVICON);
1225
1226 scoped_refptr<GetFaviconRequest> request(new GetFaviconRequest(
1227 base::Bind(&HistoryBackendTest::OnFaviconData, base::Unretained(this))));
1228 HistoryBackendCancelableRequest cancellable_request;
1229 cancellable_request.MockScheduleOfRequest<GetFaviconRequest>(request);
1230 backend_->UpdateFaviconMappingAndFetch(request, page_url2, favicon_url,
1231 FAVICON);
1232
1233 // Check that the same FaviconID is mapped to both page URLs.
1234 std::vector<IconMapping> icon_mappings1;
1235 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1236 page_url1, &icon_mappings1));
1237 EXPECT_EQ(1u, icon_mappings1.size());
1238 FaviconID favicon_id = icon_mappings1[0].icon_id;
1239 EXPECT_NE(0, favicon_id);
1240
1241 std::vector<IconMapping> icon_mappings2;
1242 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1243 page_url2, &icon_mappings2));
1244 EXPECT_EQ(1u, icon_mappings2.size());
1245 EXPECT_EQ(favicon_id, icon_mappings2[0].icon_id);
1246
1247 // Update the bitmap data.
1248 backend_->SetFavicon(page_url1, favicon_url, bitmap_data, FAVICON);
1249
1250 // |page_url1| and |page_url2| should still map to the same FaviconID
1251 // and have valid bitmap data.
1252 icon_mappings1.clear();
1253 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1254 page_url1, &icon_mappings1));
1255 EXPECT_EQ(1u, icon_mappings1.size());
1256 EXPECT_EQ(favicon_id, icon_mappings1[0].icon_id);
1257
1258 icon_mappings2.clear();
1259 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1260 page_url2, &icon_mappings2));
1261 EXPECT_EQ(1u, icon_mappings2.size());
1262 EXPECT_EQ(favicon_id, icon_mappings2[0].icon_id);
1263
1264 std::vector<FaviconBitmap> favicon_bitmaps;
1265 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id,
1266 &favicon_bitmaps));
1267 EXPECT_EQ(1u, favicon_bitmaps.size());
1268 }
1269
1210 TEST_F(HistoryBackendTest, GetFaviconForURL) { 1270 TEST_F(HistoryBackendTest, GetFaviconForURL) {
1211 // This test will add a fav icon and touch icon for the same URL 1271 // This test will add a fav icon and touch icon for the same URL
1212 // and check the behaviour of backend's GetFaviconForURL implementation. 1272 // and check the behaviour of backend's GetFaviconForURL implementation.
1213 const GURL url("http://www.google.com/"); 1273 const GURL url("http://www.google.com/");
1214 const GURL icon_url("http://www.google.com/icon"); 1274 const GURL icon_url("http://www.google.com/icon");
1215 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); 1275 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1));
1216 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); 1276 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data));
1217 // Used for testing the icon data after getting from DB 1277 // Used for testing the icon data after getting from DB
1218 std::string blob_data(bytes->front(), 1278 std::string blob_data(bytes->front(),
1219 bytes->front() + bytes->size()); 1279 bytes->front() + bytes->size());
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 1667
1608 backend_->DeleteURL(url); 1668 backend_->DeleteURL(url);
1609 backend_->AddPageNoVisitForBookmark(url, string16()); 1669 backend_->AddPageNoVisitForBookmark(url, string16());
1610 backend_->GetURL(url, &row); 1670 backend_->GetURL(url, &row);
1611 EXPECT_EQ(url, row.url()); 1671 EXPECT_EQ(url, row.url());
1612 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); 1672 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title());
1613 EXPECT_EQ(0, row.visit_count()); 1673 EXPECT_EQ(0, row.visit_count());
1614 } 1674 }
1615 1675
1616 } // namespace history 1676 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/thumbnail_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698