OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. | 126 // Callback for UpdateFaviconMappingsAndFetch. |
127 void OnFaviconData(FaviconService::Handle handle, | 127 void OnFaviconResults( |
128 history::FaviconData favicon_data) { | 128 FaviconService::Handle handle, |
| 129 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, |
| 130 history::IconURLSizesMap icon_url_sizes) { |
129 } | 131 } |
130 | 132 |
131 const history::MostVisitedURLList& get_most_visited_list() const { | 133 const history::MostVisitedURLList& get_most_visited_list() const { |
132 return most_visited_list_; | 134 return most_visited_list_; |
133 } | 135 } |
134 | 136 |
135 const history::FilteredURLList& get_filtered_list() const { | 137 const history::FilteredURLList& get_filtered_list() const { |
136 return filtered_list_; | 138 return filtered_list_; |
137 } | 139 } |
138 | 140 |
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 TEST_F(HistoryBackendTest, SetSameFaviconURLForTwoPages) { | 1219 TEST_F(HistoryBackendTest, SetSameFaviconURLForTwoPages) { |
1218 GURL favicon_url("http://www.google.com/favicon.ico"); | 1220 GURL favicon_url("http://www.google.com/favicon.ico"); |
1219 GURL page_url1("http://www.google.com"); | 1221 GURL page_url1("http://www.google.com"); |
1220 GURL page_url2("http://www.google.ca"); | 1222 GURL page_url2("http://www.google.ca"); |
1221 | 1223 |
1222 scoped_refptr<base::RefCountedMemory> bitmap_data( | 1224 scoped_refptr<base::RefCountedMemory> bitmap_data( |
1223 new base::RefCountedBytes()); | 1225 new base::RefCountedBytes()); |
1224 backend_->SetFavicon(page_url1, favicon_url, bitmap_data, FAVICON); | 1226 backend_->SetFavicon(page_url1, favicon_url, bitmap_data, FAVICON); |
1225 | 1227 |
1226 scoped_refptr<GetFaviconRequest> request(new GetFaviconRequest( | 1228 scoped_refptr<GetFaviconRequest> request(new GetFaviconRequest( |
1227 base::Bind(&HistoryBackendTest::OnFaviconData, base::Unretained(this)))); | 1229 base::Bind(&HistoryBackendTest::OnFaviconResults, |
| 1230 base::Unretained(this)))); |
1228 HistoryBackendCancelableRequest cancellable_request; | 1231 HistoryBackendCancelableRequest cancellable_request; |
1229 cancellable_request.MockScheduleOfRequest<GetFaviconRequest>(request); | 1232 cancellable_request.MockScheduleOfRequest<GetFaviconRequest>(request); |
1230 backend_->UpdateFaviconMappingAndFetch(request, page_url2, favicon_url, | 1233 backend_->UpdateFaviconMappingAndFetch(request, page_url2, favicon_url, |
1231 FAVICON); | 1234 FAVICON); |
1232 | 1235 |
1233 // Check that the same FaviconID is mapped to both page URLs. | 1236 // Check that the same FaviconID is mapped to both page URLs. |
1234 std::vector<IconMapping> icon_mappings1; | 1237 std::vector<IconMapping> icon_mappings1; |
1235 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1238 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
1236 page_url1, &icon_mappings1)); | 1239 page_url1, &icon_mappings1)); |
1237 EXPECT_EQ(1u, icon_mappings1.size()); | 1240 EXPECT_EQ(1u, icon_mappings1.size()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1287 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
1285 url, FAVICON, NULL)); | 1288 url, FAVICON, NULL)); |
1286 | 1289 |
1287 // Add a touch_icon | 1290 // Add a touch_icon |
1288 backend_->SetFavicon( | 1291 backend_->SetFavicon( |
1289 url, icon_url, bytes.get(), TOUCH_ICON); | 1292 url, icon_url, bytes.get(), TOUCH_ICON); |
1290 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1293 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
1291 url, TOUCH_ICON, NULL)); | 1294 url, TOUCH_ICON, NULL)); |
1292 | 1295 |
1293 // Test the Fav icon for this URL. | 1296 // Test the Fav icon for this URL. |
1294 FaviconData favicon; | 1297 std::vector<FaviconBitmapResult> favicon_bitmap_results; |
1295 ASSERT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, &favicon)); | 1298 ASSERT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, |
| 1299 &favicon_bitmap_results)); |
| 1300 EXPECT_EQ(1u, favicon_bitmap_results.size()); |
| 1301 FaviconBitmapResult bitmap_result = favicon_bitmap_results[0]; |
1296 std::string favicon_data( | 1302 std::string favicon_data( |
1297 favicon.image_data->front(), | 1303 bitmap_result.bitmap_data->front(), |
1298 favicon.image_data->front() + favicon.image_data->size()); | 1304 bitmap_result.bitmap_data->front() + bitmap_result.bitmap_data->size()); |
1299 | 1305 |
1300 EXPECT_EQ(FAVICON, favicon.icon_type); | 1306 EXPECT_EQ(FAVICON, bitmap_result.icon_type); |
1301 EXPECT_EQ(icon_url, favicon.icon_url); | 1307 EXPECT_EQ(icon_url, bitmap_result.icon_url); |
1302 EXPECT_EQ(blob_data, favicon_data); | 1308 EXPECT_EQ(blob_data, favicon_data); |
1303 | 1309 |
1304 // Test the touch icon for this URL. | 1310 // Test the touch icon for this URL. |
1305 ASSERT_TRUE(backend_->GetFaviconFromDB(url, TOUCH_ICON, &favicon)); | 1311 ASSERT_TRUE(backend_->GetFaviconFromDB(url, TOUCH_ICON, |
| 1312 &favicon_bitmap_results)); |
| 1313 EXPECT_EQ(1u, favicon_bitmap_results.size()); |
| 1314 bitmap_result = favicon_bitmap_results[0]; |
1306 std::string touchicon_data( | 1315 std::string touchicon_data( |
1307 favicon.image_data->front(), | 1316 bitmap_result.bitmap_data->front(), |
1308 favicon.image_data->front() + favicon.image_data->size()); | 1317 bitmap_result.bitmap_data->front() + bitmap_result.bitmap_data->size()); |
1309 | 1318 |
1310 EXPECT_EQ(TOUCH_ICON, favicon.icon_type); | 1319 EXPECT_EQ(TOUCH_ICON, bitmap_result.icon_type); |
1311 EXPECT_EQ(icon_url, favicon.icon_url); | 1320 EXPECT_EQ(icon_url, bitmap_result.icon_url); |
1312 EXPECT_EQ(blob_data, touchicon_data); | 1321 EXPECT_EQ(blob_data, touchicon_data); |
1313 } | 1322 } |
1314 | 1323 |
1315 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { | 1324 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { |
1316 const GURL url("http://www.google.com/"); | 1325 const GURL url("http://www.google.com/"); |
1317 const GURL icon_url("http://www.google.com/icon"); | 1326 const GURL icon_url("http://www.google.com/icon"); |
1318 const GURL same_domain_url("http://www.google.com/subdir/index.html"); | 1327 const GURL same_domain_url("http://www.google.com/subdir/index.html"); |
1319 const GURL foreign_domain_url("http://www.not-google.com/"); | 1328 const GURL foreign_domain_url("http://www.not-google.com/"); |
1320 | 1329 |
1321 // Add a favicon | 1330 // Add a favicon |
1322 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1331 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
1323 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 1332 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
1324 backend_->SetFavicon( | 1333 backend_->SetFavicon( |
1325 url, icon_url, bytes.get(), FAVICON); | 1334 url, icon_url, bytes.get(), FAVICON); |
1326 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1335 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
1327 url, FAVICON, NULL)); | 1336 url, FAVICON, NULL)); |
1328 | 1337 |
1329 // Validate starting state. | 1338 // Validate starting state. |
1330 FaviconData favicon; | 1339 std::vector<FaviconBitmapResult> favicon_bitmap_results; |
1331 EXPECT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, &favicon)); | 1340 EXPECT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, |
1332 EXPECT_FALSE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, &favicon)); | 1341 &favicon_bitmap_results)); |
1333 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, | 1342 EXPECT_FALSE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, |
1334 FAVICON, &favicon)); | 1343 &favicon_bitmap_results)); |
| 1344 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, FAVICON, |
| 1345 &favicon_bitmap_results)); |
1335 | 1346 |
1336 // Same-domain cloning should work. | 1347 // Same-domain cloning should work. |
1337 backend_->CloneFavicon(url, same_domain_url); | 1348 backend_->CloneFavicon(url, same_domain_url); |
1338 EXPECT_TRUE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, &favicon)); | 1349 EXPECT_TRUE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, |
| 1350 &favicon_bitmap_results)); |
1339 | 1351 |
1340 // Foreign-domain cloning is forbidden. | 1352 // Foreign-domain cloning is forbidden. |
1341 backend_->CloneFavicon(url, foreign_domain_url); | 1353 backend_->CloneFavicon(url, foreign_domain_url); |
1342 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, | 1354 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, FAVICON, |
1343 FAVICON, &favicon)); | 1355 &favicon_bitmap_results)); |
1344 } | 1356 } |
1345 | 1357 |
1346 TEST_F(HistoryBackendTest, QueryFilteredURLs) { | 1358 TEST_F(HistoryBackendTest, QueryFilteredURLs) { |
1347 const char* google = "http://www.google.com/"; | 1359 const char* google = "http://www.google.com/"; |
1348 const char* yahoo = "http://www.yahoo.com/"; | 1360 const char* yahoo = "http://www.yahoo.com/"; |
1349 const char* yahoo_sports = "http://sports.yahoo.com/"; | 1361 const char* yahoo_sports = "http://sports.yahoo.com/"; |
1350 const char* yahoo_sports_with_article1 = | 1362 const char* yahoo_sports_with_article1 = |
1351 "http://sports.yahoo.com/article1.htm"; | 1363 "http://sports.yahoo.com/article1.htm"; |
1352 const char* yahoo_sports_with_article2 = | 1364 const char* yahoo_sports_with_article2 = |
1353 "http://sports.yahoo.com/article2.htm"; | 1365 "http://sports.yahoo.com/article2.htm"; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1667 | 1679 |
1668 backend_->DeleteURL(url); | 1680 backend_->DeleteURL(url); |
1669 backend_->AddPageNoVisitForBookmark(url, string16()); | 1681 backend_->AddPageNoVisitForBookmark(url, string16()); |
1670 backend_->GetURL(url, &row); | 1682 backend_->GetURL(url, &row); |
1671 EXPECT_EQ(url, row.url()); | 1683 EXPECT_EQ(url, row.url()); |
1672 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); | 1684 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); |
1673 EXPECT_EQ(0, row.visit_count()); | 1685 EXPECT_EQ(0, row.visit_count()); |
1674 } | 1686 } |
1675 | 1687 |
1676 } // namespace history | 1688 } // namespace history |
OLD | NEW |