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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1224 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
1225 url, FAVICON, NULL)); | 1225 url, FAVICON, NULL)); |
1226 | 1226 |
1227 // Add a touch_icon | 1227 // Add a touch_icon |
1228 backend_->SetFavicon( | 1228 backend_->SetFavicon( |
1229 url, icon_url, bytes.get(), TOUCH_ICON); | 1229 url, icon_url, bytes.get(), TOUCH_ICON); |
1230 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1230 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
1231 url, TOUCH_ICON, NULL)); | 1231 url, TOUCH_ICON, NULL)); |
1232 | 1232 |
1233 // Test the Fav icon for this URL. | 1233 // Test the Fav icon for this URL. |
1234 FaviconData favicon; | 1234 std::vector<FaviconBitmapResult> favicon_bitmap_results; |
1235 ASSERT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, &favicon)); | 1235 ASSERT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, |
| 1236 &favicon_bitmap_results)); |
| 1237 EXPECT_EQ(1u, favicon_bitmap_results.size()); |
| 1238 FaviconBitmapResult bitmap_result = favicon_bitmap_results[0]; |
1236 std::string favicon_data( | 1239 std::string favicon_data( |
1237 favicon.image_data->front(), | 1240 bitmap_result.bitmap_data->front(), |
1238 favicon.image_data->front() + favicon.image_data->size()); | 1241 bitmap_result.bitmap_data->front() + bitmap_result.bitmap_data->size()); |
1239 | 1242 |
1240 EXPECT_EQ(FAVICON, favicon.icon_type); | 1243 EXPECT_EQ(FAVICON, bitmap_result.icon_type); |
1241 EXPECT_EQ(icon_url, favicon.icon_url); | 1244 EXPECT_EQ(icon_url, bitmap_result.icon_url); |
1242 EXPECT_EQ(blob_data, favicon_data); | 1245 EXPECT_EQ(blob_data, favicon_data); |
1243 | 1246 |
1244 // Test the touch icon for this URL. | 1247 // Test the touch icon for this URL. |
1245 ASSERT_TRUE(backend_->GetFaviconFromDB(url, TOUCH_ICON, &favicon)); | 1248 ASSERT_TRUE(backend_->GetFaviconFromDB(url, TOUCH_ICON, |
| 1249 &favicon_bitmap_results)); |
| 1250 EXPECT_EQ(1u, favicon_bitmap_results.size()); |
| 1251 bitmap_result = favicon_bitmap_results[0]; |
1246 std::string touchicon_data( | 1252 std::string touchicon_data( |
1247 favicon.image_data->front(), | 1253 bitmap_result.bitmap_data->front(), |
1248 favicon.image_data->front() + favicon.image_data->size()); | 1254 bitmap_result.bitmap_data->front() + bitmap_result.bitmap_data->size()); |
1249 | 1255 |
1250 EXPECT_EQ(TOUCH_ICON, favicon.icon_type); | 1256 EXPECT_EQ(TOUCH_ICON, bitmap_result.icon_type); |
1251 EXPECT_EQ(icon_url, favicon.icon_url); | 1257 EXPECT_EQ(icon_url, bitmap_result.icon_url); |
1252 EXPECT_EQ(blob_data, touchicon_data); | 1258 EXPECT_EQ(blob_data, touchicon_data); |
1253 } | 1259 } |
1254 | 1260 |
1255 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { | 1261 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { |
1256 const GURL url("http://www.google.com/"); | 1262 const GURL url("http://www.google.com/"); |
1257 const GURL icon_url("http://www.google.com/icon"); | 1263 const GURL icon_url("http://www.google.com/icon"); |
1258 const GURL same_domain_url("http://www.google.com/subdir/index.html"); | 1264 const GURL same_domain_url("http://www.google.com/subdir/index.html"); |
1259 const GURL foreign_domain_url("http://www.not-google.com/"); | 1265 const GURL foreign_domain_url("http://www.not-google.com/"); |
1260 | 1266 |
1261 // Add a favicon | 1267 // Add a favicon |
1262 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1268 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
1263 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 1269 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
1264 backend_->SetFavicon( | 1270 backend_->SetFavicon( |
1265 url, icon_url, bytes.get(), FAVICON); | 1271 url, icon_url, bytes.get(), FAVICON); |
1266 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1272 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
1267 url, FAVICON, NULL)); | 1273 url, FAVICON, NULL)); |
1268 | 1274 |
1269 // Validate starting state. | 1275 // Validate starting state. |
1270 FaviconData favicon; | 1276 std::vector<FaviconBitmapResult> favicon_bitmap_results; |
1271 EXPECT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, &favicon)); | 1277 EXPECT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, |
1272 EXPECT_FALSE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, &favicon)); | 1278 &favicon_bitmap_results)); |
1273 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, | 1279 EXPECT_FALSE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, |
1274 FAVICON, &favicon)); | 1280 &favicon_bitmap_results)); |
| 1281 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, FAVICON, |
| 1282 &favicon_bitmap_results)); |
1275 | 1283 |
1276 // Same-domain cloning should work. | 1284 // Same-domain cloning should work. |
1277 backend_->CloneFavicon(url, same_domain_url); | 1285 backend_->CloneFavicon(url, same_domain_url); |
1278 EXPECT_TRUE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, &favicon)); | 1286 EXPECT_TRUE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, |
| 1287 &favicon_bitmap_results)); |
1279 | 1288 |
1280 // Foreign-domain cloning is forbidden. | 1289 // Foreign-domain cloning is forbidden. |
1281 backend_->CloneFavicon(url, foreign_domain_url); | 1290 backend_->CloneFavicon(url, foreign_domain_url); |
1282 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, | 1291 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, FAVICON, |
1283 FAVICON, &favicon)); | 1292 &favicon_bitmap_results)); |
1284 } | 1293 } |
1285 | 1294 |
1286 TEST_F(HistoryBackendTest, QueryFilteredURLs) { | 1295 TEST_F(HistoryBackendTest, QueryFilteredURLs) { |
1287 const char* google = "http://www.google.com/"; | 1296 const char* google = "http://www.google.com/"; |
1288 const char* yahoo = "http://www.yahoo.com/"; | 1297 const char* yahoo = "http://www.yahoo.com/"; |
1289 const char* yahoo_sports = "http://sports.yahoo.com/"; | 1298 const char* yahoo_sports = "http://sports.yahoo.com/"; |
1290 const char* yahoo_sports_with_article1 = | 1299 const char* yahoo_sports_with_article1 = |
1291 "http://sports.yahoo.com/article1.htm"; | 1300 "http://sports.yahoo.com/article1.htm"; |
1292 const char* yahoo_sports_with_article2 = | 1301 const char* yahoo_sports_with_article2 = |
1293 "http://sports.yahoo.com/article2.htm"; | 1302 "http://sports.yahoo.com/article2.htm"; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 | 1616 |
1608 backend_->DeleteURL(url); | 1617 backend_->DeleteURL(url); |
1609 backend_->AddPageNoVisitForBookmark(url, string16()); | 1618 backend_->AddPageNoVisitForBookmark(url, string16()); |
1610 backend_->GetURL(url, &row); | 1619 backend_->GetURL(url, &row); |
1611 EXPECT_EQ(url, row.url()); | 1620 EXPECT_EQ(url, row.url()); |
1612 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); | 1621 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); |
1613 EXPECT_EQ(0, row.visit_count()); | 1622 EXPECT_EQ(0, row.visit_count()); |
1614 } | 1623 } |
1615 | 1624 |
1616 } // namespace history | 1625 } // namespace history |
OLD | NEW |