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 "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 20 matching lines...) Expand all Loading... |
31 #include "chrome/common/importer/imported_favicon_usage.h" | 31 #include "chrome/common/importer/imported_favicon_usage.h" |
32 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
33 #include "components/history/core/browser/in_memory_database.h" | 33 #include "components/history/core/browser/in_memory_database.h" |
34 #include "components/history/core/browser/keyword_search_term.h" | 34 #include "components/history/core/browser/keyword_search_term.h" |
35 #include "components/history/core/test/history_client_fake_bookmarks.h" | 35 #include "components/history/core/test/history_client_fake_bookmarks.h" |
36 #include "content/public/browser/notification_details.h" | 36 #include "content/public/browser/notification_details.h" |
37 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
38 #include "content/public/test/test_browser_thread.h" | 38 #include "content/public/test/test_browser_thread.h" |
39 #include "testing/gmock/include/gmock/gmock.h" | 39 #include "testing/gmock/include/gmock/gmock.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 41 #include "third_party/skia/include/core/SkBitmap.h" |
| 42 #include "ui/gfx/codec/png_codec.h" |
41 #include "url/gurl.h" | 43 #include "url/gurl.h" |
42 | 44 |
43 using base::Time; | 45 using base::Time; |
44 | 46 |
45 // This file only tests functionality where it is most convenient to call the | 47 // This file only tests functionality where it is most convenient to call the |
46 // backend directly. Most of the history backend functions are tested by the | 48 // backend directly. Most of the history backend functions are tested by the |
47 // history unit test. Because of the elaborate callbacks involved, this is no | 49 // history unit test. Because of the elaborate callbacks involved, this is no |
48 // harder than calling it directly for many things. | 50 // harder than calling it directly for many things. |
49 | 51 |
50 namespace { | 52 namespace { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 int GetTransition(const GURL& url) { | 261 int GetTransition(const GURL& url) { |
260 if (!url.is_valid()) | 262 if (!url.is_valid()) |
261 return 0; | 263 return 0; |
262 URLRow row; | 264 URLRow row; |
263 URLID id = backend_->db()->GetRowForURL(url, &row); | 265 URLID id = backend_->db()->GetRowForURL(url, &row); |
264 VisitVector visits; | 266 VisitVector visits; |
265 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); | 267 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); |
266 return visits[0].transition; | 268 return visits[0].transition; |
267 } | 269 } |
268 | 270 |
269 // Returns a vector with the small edge size. | |
270 const std::vector<int> GetEdgeSizesSmall() { | |
271 std::vector<int> sizes_small; | |
272 sizes_small.push_back(kSmallEdgeSize); | |
273 return sizes_small; | |
274 } | |
275 | |
276 // Returns a vector with the large edge size. | |
277 const std::vector<int> GetEdgeSizesLarge() { | |
278 std::vector<int> sizes_large; | |
279 sizes_large.push_back(kLargeEdgeSize); | |
280 return sizes_large; | |
281 } | |
282 | |
283 // Returns a vector with the small and large edge sizes. | 271 // Returns a vector with the small and large edge sizes. |
284 const std::vector<int> GetEdgeSizesSmallAndLarge() { | 272 const std::vector<int> GetEdgeSizesSmallAndLarge() { |
285 std::vector<int> sizes_small_and_large; | 273 std::vector<int> sizes_small_and_large; |
286 sizes_small_and_large.push_back(kSmallEdgeSize); | 274 sizes_small_and_large.push_back(kSmallEdgeSize); |
287 sizes_small_and_large.push_back(kLargeEdgeSize); | 275 sizes_small_and_large.push_back(kLargeEdgeSize); |
288 return sizes_small_and_large; | 276 return sizes_small_and_large; |
289 } | 277 } |
290 | 278 |
291 // Returns a vector with the tiny, small, and large edge sizes. | |
292 const std::vector<int> GetEdgeSizesTinySmallAndLarge() { | |
293 std::vector<int> sizes_tiny_small_and_large; | |
294 sizes_tiny_small_and_large.push_back(kTinyEdgeSize); | |
295 sizes_tiny_small_and_large.push_back(kSmallEdgeSize); | |
296 sizes_tiny_small_and_large.push_back(kLargeEdgeSize); | |
297 return sizes_tiny_small_and_large; | |
298 } | |
299 | |
300 // Returns the number of icon mappings of |icon_type| to |page_url|. | 279 // Returns the number of icon mappings of |icon_type| to |page_url|. |
301 size_t NumIconMappingsForPageURL(const GURL& page_url, | 280 size_t NumIconMappingsForPageURL(const GURL& page_url, |
302 favicon_base::IconType icon_type) { | 281 favicon_base::IconType icon_type) { |
303 std::vector<IconMapping> icon_mappings; | 282 std::vector<IconMapping> icon_mappings; |
304 backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type, | 283 backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type, |
305 &icon_mappings); | 284 &icon_mappings); |
306 return icon_mappings.size(); | 285 return icon_mappings.size(); |
307 } | 286 } |
308 | 287 |
309 // Returns the icon mappings for |page_url| sorted alphabetically by icon | 288 // Returns the icon mappings for |page_url| sorted alphabetically by icon |
(...skipping 28 matching lines...) Expand all Loading... |
338 FaviconBitmap* favicon_bitmap) { | 317 FaviconBitmap* favicon_bitmap) { |
339 std::vector<FaviconBitmap> favicon_bitmaps; | 318 std::vector<FaviconBitmap> favicon_bitmaps; |
340 if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, &favicon_bitmaps)) | 319 if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, &favicon_bitmaps)) |
341 return false; | 320 return false; |
342 if (favicon_bitmaps.size() != 1) | 321 if (favicon_bitmaps.size() != 1) |
343 return false; | 322 return false; |
344 *favicon_bitmap = favicon_bitmaps[0]; | 323 *favicon_bitmap = favicon_bitmaps[0]; |
345 return true; | 324 return true; |
346 } | 325 } |
347 | 326 |
348 // Generates |favicon_bitmap_data| with entries for the icon_urls and sizes | 327 // Creates an |edge_size|x|edge_size| bitmap of |color|. |
349 // specified. The bitmap_data for entries are lowercase letters of the | 328 SkBitmap CreateBitmap(SkColor color, int edge_size) { |
350 // alphabet starting at 'a' for the entry at index 0. | 329 SkBitmap bitmap; |
351 void GenerateFaviconBitmapData( | 330 bitmap.allocN32Pixels(edge_size, edge_size); |
352 const GURL& icon_url1, | 331 bitmap.eraseColor(color); |
353 const std::vector<int>& icon_url1_sizes, | 332 return bitmap; |
354 std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) { | |
355 GenerateFaviconBitmapData(icon_url1, icon_url1_sizes, GURL(), | |
356 std::vector<int>(), favicon_bitmap_data); | |
357 } | |
358 | |
359 void GenerateFaviconBitmapData( | |
360 const GURL& icon_url1, | |
361 const std::vector<int>& icon_url1_sizes, | |
362 const GURL& icon_url2, | |
363 const std::vector<int>& icon_url2_sizes, | |
364 std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) { | |
365 favicon_bitmap_data->clear(); | |
366 | |
367 char bitmap_char = 'a'; | |
368 for (size_t i = 0; i < icon_url1_sizes.size(); ++i) { | |
369 std::vector<unsigned char> data; | |
370 data.push_back(bitmap_char); | |
371 favicon_base::FaviconRawBitmapData bitmap_data_element; | |
372 bitmap_data_element.bitmap_data = | |
373 base::RefCountedBytes::TakeVector(&data); | |
374 bitmap_data_element.pixel_size = | |
375 gfx::Size(icon_url1_sizes[i], icon_url1_sizes[i]); | |
376 bitmap_data_element.icon_url = icon_url1; | |
377 favicon_bitmap_data->push_back(bitmap_data_element); | |
378 | |
379 ++bitmap_char; | |
380 } | |
381 | |
382 for (size_t i = 0; i < icon_url2_sizes.size(); ++i) { | |
383 std::vector<unsigned char> data; | |
384 data.push_back(bitmap_char); | |
385 favicon_base::FaviconRawBitmapData bitmap_data_element; | |
386 bitmap_data_element.bitmap_data = | |
387 base::RefCountedBytes::TakeVector(&data); | |
388 bitmap_data_element.pixel_size = | |
389 gfx::Size(icon_url2_sizes[i], icon_url2_sizes[i]); | |
390 bitmap_data_element.icon_url = icon_url2; | |
391 favicon_bitmap_data->push_back(bitmap_data_element); | |
392 | |
393 ++bitmap_char; | |
394 } | |
395 } | 333 } |
396 | 334 |
397 // Returns true if |bitmap_data| is equal to |expected_data|. | 335 // Returns true if |bitmap_data| is equal to |expected_data|. |
398 bool BitmapDataEqual(char expected_data, | 336 bool BitmapDataEqual(char expected_data, |
399 scoped_refptr<base::RefCountedMemory> bitmap_data) { | 337 scoped_refptr<base::RefCountedMemory> bitmap_data) { |
400 return bitmap_data.get() && | 338 return bitmap_data.get() && |
401 bitmap_data->size() == 1u && | 339 bitmap_data->size() == 1u && |
402 *bitmap_data->front() == expected_data; | 340 *bitmap_data->front() == expected_data; |
403 } | 341 } |
404 | 342 |
| 343 // Returns true if |bitmap_data| is of |color|. |
| 344 bool BitmapColorEqual(SkColor expected_color, |
| 345 scoped_refptr<base::RefCountedMemory> bitmap_data) { |
| 346 SkBitmap bitmap; |
| 347 if (!gfx::PNGCodec::Decode( |
| 348 bitmap_data->front(), bitmap_data->size(), &bitmap)) |
| 349 return false; |
| 350 SkAutoLockPixels bitmap_lock(bitmap); |
| 351 return expected_color == bitmap.getColor(0, 0); |
| 352 } |
| 353 |
405 private: | 354 private: |
406 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTest); | 355 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTest); |
407 }; | 356 }; |
408 | 357 |
409 class InMemoryHistoryBackendTest : public HistoryBackendTestBase { | 358 class InMemoryHistoryBackendTest : public HistoryBackendTestBase { |
410 public: | 359 public: |
411 InMemoryHistoryBackendTest() {} | 360 InMemoryHistoryBackendTest() {} |
412 virtual ~InMemoryHistoryBackendTest() {} | 361 virtual ~InMemoryHistoryBackendTest() {} |
413 | 362 |
414 protected: | 363 protected: |
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 url_info2.set_hidden(false); | 1513 url_info2.set_hidden(false); |
1565 backend_->db_->AddURL(url_info2); | 1514 backend_->db_->AddURL(url_info2); |
1566 | 1515 |
1567 history::RedirectList redirects; | 1516 history::RedirectList redirects; |
1568 redirects.push_back(url2); | 1517 redirects.push_back(url2); |
1569 redirects.push_back(url1); | 1518 redirects.push_back(url1); |
1570 backend_->recent_redirects_.Put(url1, redirects); | 1519 backend_->recent_redirects_.Put(url1, redirects); |
1571 | 1520 |
1572 const GURL icon_url1("http://www.google.com/icon"); | 1521 const GURL icon_url1("http://www.google.com/icon"); |
1573 const GURL icon_url2("http://www.google.com/icon2"); | 1522 const GURL icon_url2("http://www.google.com/icon2"); |
| 1523 std::vector<SkBitmap> bitmaps; |
| 1524 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
| 1525 bitmaps.push_back(CreateBitmap(SK_ColorRED, kLargeEdgeSize)); |
1574 | 1526 |
1575 // Generate bitmap data for a page with two favicons. | 1527 // Add a favicon. |
1576 std::vector<favicon_base::FaviconRawBitmapData> two_favicon_bitmap_data; | 1528 backend_->SetFavicon(url1, favicon_base::FAVICON, icon_url1, bitmaps); |
1577 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmallAndLarge(), | 1529 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); |
1578 icon_url2, GetEdgeSizesSmallAndLarge(), &two_favicon_bitmap_data); | 1530 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON)); |
1579 | |
1580 // Generate bitmap data for a page with a single favicon. | |
1581 std::vector<favicon_base::FaviconRawBitmapData> one_favicon_bitmap_data; | |
1582 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmallAndLarge(), | |
1583 &one_favicon_bitmap_data); | |
1584 | |
1585 // Add two favicons | |
1586 backend_->SetFavicons(url1, favicon_base::FAVICON, two_favicon_bitmap_data); | |
1587 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); | |
1588 EXPECT_EQ(2u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON)); | |
1589 | 1531 |
1590 // Add one touch_icon | 1532 // Add one touch_icon |
1591 backend_->SetFavicons( | 1533 backend_->SetFavicon(url1, favicon_base::TOUCH_ICON, icon_url1, bitmaps); |
1592 url1, favicon_base::TOUCH_ICON, one_favicon_bitmap_data); | |
1593 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); | 1534 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); |
1594 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, favicon_base::TOUCH_ICON)); | 1535 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, favicon_base::TOUCH_ICON)); |
1595 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); | 1536 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); |
1596 | 1537 |
1597 // Add one TOUCH_PRECOMPOSED_ICON | 1538 // Add one TOUCH_PRECOMPOSED_ICON |
1598 backend_->SetFavicons( | 1539 backend_->SetFavicon( |
1599 url1, favicon_base::TOUCH_PRECOMPOSED_ICON, one_favicon_bitmap_data); | 1540 url1, favicon_base::TOUCH_PRECOMPOSED_ICON, icon_url1, bitmaps); |
1600 // The touch_icon was replaced. | 1541 // The touch_icon was replaced. |
1601 EXPECT_EQ(0u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); | 1542 EXPECT_EQ(0u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); |
1602 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); | 1543 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); |
1603 EXPECT_EQ( | 1544 EXPECT_EQ( |
1604 1u, | 1545 1u, |
1605 NumIconMappingsForPageURL(url1, favicon_base::TOUCH_PRECOMPOSED_ICON)); | 1546 NumIconMappingsForPageURL(url1, favicon_base::TOUCH_PRECOMPOSED_ICON)); |
1606 EXPECT_EQ( | 1547 EXPECT_EQ( |
1607 1u, | 1548 1u, |
1608 NumIconMappingsForPageURL(url2, favicon_base::TOUCH_PRECOMPOSED_ICON)); | 1549 NumIconMappingsForPageURL(url2, favicon_base::TOUCH_PRECOMPOSED_ICON)); |
1609 | 1550 |
1610 // Add a touch_icon. | 1551 // Add a touch_icon. |
1611 backend_->SetFavicons( | 1552 backend_->SetFavicon(url1, favicon_base::TOUCH_ICON, icon_url1, bitmaps); |
1612 url1, favicon_base::TOUCH_ICON, one_favicon_bitmap_data); | |
1613 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); | 1553 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); |
1614 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); | 1554 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); |
1615 // The TOUCH_PRECOMPOSED_ICON was replaced. | 1555 // The TOUCH_PRECOMPOSED_ICON was replaced. |
1616 EXPECT_EQ( | 1556 EXPECT_EQ( |
1617 0u, | 1557 0u, |
1618 NumIconMappingsForPageURL(url1, favicon_base::TOUCH_PRECOMPOSED_ICON)); | 1558 NumIconMappingsForPageURL(url1, favicon_base::TOUCH_PRECOMPOSED_ICON)); |
1619 | 1559 |
1620 // Add a single favicon. | 1560 // Add a different favicon. |
1621 backend_->SetFavicons(url1, favicon_base::FAVICON, one_favicon_bitmap_data); | 1561 backend_->SetFavicon(url1, favicon_base::FAVICON, icon_url2, bitmaps); |
1622 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); | 1562 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); |
1623 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); | 1563 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); |
1624 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON)); | 1564 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON)); |
1625 | |
1626 // Add two favicons. | |
1627 backend_->SetFavicons(url1, favicon_base::FAVICON, two_favicon_bitmap_data); | |
1628 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); | |
1629 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); | |
1630 } | 1565 } |
1631 | 1566 |
1632 // Test that there is no churn in icon mappings from calling | 1567 // Test that there is no churn in icon mappings from calling |
1633 // SetFavicons() twice with the same |favicon_bitmap_data| parameter. | 1568 // SetFavicon() twice with the same |bitmaps| parameter. |
1634 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageDuplicates) { | 1569 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageDuplicates) { |
1635 const GURL url("http://www.google.com/"); | 1570 const GURL url("http://www.google.com/"); |
1636 const GURL icon_url("http://www.google.com/icon"); | 1571 const GURL icon_url("http://www.google.com/icon"); |
1637 | 1572 |
1638 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 1573 std::vector<SkBitmap> bitmaps; |
1639 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(), | 1574 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
1640 &favicon_bitmap_data); | 1575 bitmaps.push_back(CreateBitmap(SK_ColorRED, kLargeEdgeSize)); |
1641 | 1576 |
1642 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data); | 1577 backend_->SetFavicon(url, favicon_base::FAVICON, icon_url, bitmaps); |
1643 | 1578 |
1644 std::vector<IconMapping> icon_mappings; | 1579 std::vector<IconMapping> icon_mappings; |
1645 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1580 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
1646 url, favicon_base::FAVICON, &icon_mappings)); | 1581 url, favicon_base::FAVICON, &icon_mappings)); |
1647 EXPECT_EQ(1u, icon_mappings.size()); | 1582 EXPECT_EQ(1u, icon_mappings.size()); |
1648 IconMappingID mapping_id = icon_mappings[0].mapping_id; | 1583 IconMappingID mapping_id = icon_mappings[0].mapping_id; |
1649 | 1584 |
1650 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data); | 1585 backend_->SetFavicon(url, favicon_base::FAVICON, icon_url, bitmaps); |
1651 | 1586 |
1652 icon_mappings.clear(); | 1587 icon_mappings.clear(); |
1653 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1588 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
1654 url, favicon_base::FAVICON, &icon_mappings)); | 1589 url, favicon_base::FAVICON, &icon_mappings)); |
1655 EXPECT_EQ(1u, icon_mappings.size()); | 1590 EXPECT_EQ(1u, icon_mappings.size()); |
1656 | 1591 |
1657 // The same row in the icon_mapping table should be used for the mapping as | 1592 // The same row in the icon_mapping table should be used for the mapping as |
1658 // before. | 1593 // before. |
1659 EXPECT_EQ(mapping_id, icon_mappings[0].mapping_id); | 1594 EXPECT_EQ(mapping_id, icon_mappings[0].mapping_id); |
1660 } | 1595 } |
1661 | 1596 |
1662 // Test that calling SetFavicons() with FaviconBitmapData of different pixel | 1597 // Test that calling SetFavicon() with FaviconBitmapData of different pixel |
1663 // sizes than the initially passed in FaviconBitmapData deletes the no longer | 1598 // sizes than the initially passed in FaviconBitmapData deletes the no longer |
1664 // used favicon bitmaps. | 1599 // used favicon bitmaps. |
1665 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) { | 1600 TEST_F(HistoryBackendTest, SetFaviconDeleteBitmaps) { |
1666 const GURL page_url("http://www.google.com/"); | 1601 const GURL page_url("http://www.google.com/"); |
1667 const GURL icon_url("http://www.google.com/icon"); | 1602 const GURL icon_url("http://www.google.com/icon"); |
1668 | 1603 |
1669 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 1604 std::vector<SkBitmap> bitmaps; |
1670 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(), | 1605 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
1671 &favicon_bitmap_data); | 1606 bitmaps.push_back(CreateBitmap(SK_ColorRED, kLargeEdgeSize)); |
1672 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | 1607 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url, bitmaps); |
1673 | 1608 |
1674 // Test initial state. | 1609 // Test initial state. |
1675 std::vector<IconMapping> icon_mappings; | 1610 std::vector<IconMapping> icon_mappings; |
1676 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings)); | 1611 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings)); |
1677 EXPECT_EQ(1u, icon_mappings.size()); | 1612 EXPECT_EQ(1u, icon_mappings.size()); |
1678 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); | 1613 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); |
1679 EXPECT_EQ(favicon_base::FAVICON, icon_mappings[0].icon_type); | 1614 EXPECT_EQ(favicon_base::FAVICON, icon_mappings[0].icon_type); |
1680 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id; | 1615 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id; |
1681 | 1616 |
1682 std::vector<FaviconBitmap> favicon_bitmaps; | 1617 std::vector<FaviconBitmap> favicon_bitmaps; |
1683 EXPECT_TRUE(GetSortedFaviconBitmaps(favicon_id, &favicon_bitmaps)); | 1618 EXPECT_TRUE(GetSortedFaviconBitmaps(favicon_id, &favicon_bitmaps)); |
1684 EXPECT_EQ(2u, favicon_bitmaps.size()); | 1619 EXPECT_EQ(2u, favicon_bitmaps.size()); |
1685 FaviconBitmapID small_bitmap_id = favicon_bitmaps[0].bitmap_id; | 1620 FaviconBitmapID small_bitmap_id = favicon_bitmaps[0].bitmap_id; |
1686 EXPECT_NE(0, small_bitmap_id); | 1621 EXPECT_NE(0, small_bitmap_id); |
1687 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmaps[0].bitmap_data)); | 1622 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmaps[0].bitmap_data)); |
1688 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size); | 1623 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size); |
1689 FaviconBitmapID large_bitmap_id = favicon_bitmaps[1].bitmap_id; | 1624 FaviconBitmapID large_bitmap_id = favicon_bitmaps[1].bitmap_id; |
1690 EXPECT_NE(0, large_bitmap_id); | 1625 EXPECT_NE(0, large_bitmap_id); |
1691 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data)); | 1626 EXPECT_TRUE(BitmapColorEqual(SK_ColorRED, favicon_bitmaps[1].bitmap_data)); |
1692 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size); | 1627 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size); |
1693 | 1628 |
1694 // Call SetFavicons() with bitmap data for only the large bitmap. Check that | 1629 // Call SetFavicon() with bitmap data for only the large bitmap. Check that |
1695 // the small bitmap is in fact deleted. | 1630 // the small bitmap is in fact deleted. |
1696 GenerateFaviconBitmapData(icon_url, GetEdgeSizesLarge(), | 1631 bitmaps.clear(); |
1697 &favicon_bitmap_data); | 1632 bitmaps.push_back(CreateBitmap(SK_ColorWHITE, kLargeEdgeSize)); |
1698 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | 1633 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url, bitmaps); |
1699 | 1634 |
1700 scoped_refptr<base::RefCountedMemory> bitmap_data_out; | 1635 scoped_refptr<base::RefCountedMemory> bitmap_data_out; |
1701 gfx::Size pixel_size_out; | 1636 gfx::Size pixel_size_out; |
1702 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(small_bitmap_id, | 1637 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(small_bitmap_id, |
1703 NULL, &bitmap_data_out, &pixel_size_out)); | 1638 NULL, &bitmap_data_out, &pixel_size_out)); |
1704 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, | 1639 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, |
1705 NULL, &bitmap_data_out, &pixel_size_out)); | 1640 NULL, &bitmap_data_out, &pixel_size_out)); |
1706 EXPECT_TRUE(BitmapDataEqual('a', bitmap_data_out)); | 1641 EXPECT_TRUE(BitmapColorEqual(SK_ColorWHITE, bitmap_data_out)); |
1707 EXPECT_EQ(kLargeSize, pixel_size_out); | 1642 EXPECT_EQ(kLargeSize, pixel_size_out); |
1708 | 1643 |
1709 icon_mappings.clear(); | 1644 icon_mappings.clear(); |
1710 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, | 1645 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
1711 &icon_mappings)); | 1646 &icon_mappings)); |
1712 EXPECT_EQ(1u, icon_mappings.size()); | 1647 EXPECT_EQ(1u, icon_mappings.size()); |
1713 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); | 1648 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); |
1714 | 1649 |
1715 // Call SetFavicons() with no bitmap data. Check that the bitmaps and icon | 1650 // Notifications should have been broadcast for each call to SetFavicon(). |
1716 // mappings are deleted. | 1651 EXPECT_EQ(2, num_broadcasted_notifications()); |
1717 favicon_bitmap_data.clear(); | |
1718 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | |
1719 | |
1720 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, NULL, | |
1721 NULL, NULL)); | |
1722 icon_mappings.clear(); | |
1723 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, | |
1724 &icon_mappings)); | |
1725 | |
1726 // Notifications should have been broadcast for each call to SetFavicons(). | |
1727 EXPECT_EQ(3, num_broadcasted_notifications()); | |
1728 } | 1652 } |
1729 | 1653 |
1730 // Test updating a single favicon bitmap's data via SetFavicons. | 1654 // Test updating a single favicon bitmap's data via SetFavicon. |
1731 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { | 1655 TEST_F(HistoryBackendTest, SetFaviconReplaceBitmapData) { |
1732 const GURL page_url("http://www.google.com/"); | 1656 const GURL page_url("http://www.google.com/"); |
1733 const GURL icon_url("http://www.google.com/icon"); | 1657 const GURL icon_url("http://www.google.com/icon"); |
1734 | 1658 std::vector<SkBitmap> bitmaps; |
1735 std::vector<unsigned char> data_initial; | 1659 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
1736 data_initial.push_back('a'); | |
1737 | |
1738 favicon_base::FaviconRawBitmapData bitmap_data_element; | |
1739 bitmap_data_element.bitmap_data = | |
1740 base::RefCountedBytes::TakeVector(&data_initial); | |
1741 bitmap_data_element.pixel_size = kSmallSize; | |
1742 bitmap_data_element.icon_url = icon_url; | |
1743 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | |
1744 favicon_bitmap_data.push_back(bitmap_data_element); | |
1745 | 1660 |
1746 // Add bitmap to the database. | 1661 // Add bitmap to the database. |
1747 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | 1662 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url, bitmaps); |
1748 | 1663 |
1749 favicon_base::FaviconID original_favicon_id = | 1664 favicon_base::FaviconID original_favicon_id = |
1750 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 1665 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
1751 icon_url, favicon_base::FAVICON, NULL); | 1666 icon_url, favicon_base::FAVICON, NULL); |
1752 EXPECT_NE(0, original_favicon_id); | 1667 EXPECT_NE(0, original_favicon_id); |
1753 FaviconBitmap original_favicon_bitmap; | 1668 FaviconBitmap original_favicon_bitmap; |
1754 EXPECT_TRUE( | 1669 EXPECT_TRUE( |
1755 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap)); | 1670 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap)); |
1756 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data)); | 1671 EXPECT_TRUE( |
| 1672 BitmapColorEqual(SK_ColorBLUE, original_favicon_bitmap.bitmap_data)); |
1757 | 1673 |
1758 EXPECT_EQ(1, num_broadcasted_notifications()); | 1674 EXPECT_EQ(1, num_broadcasted_notifications()); |
1759 | 1675 |
1760 // Call SetFavicons() with completely identical data. | 1676 // Call SetFavicon() with completely identical data. |
1761 std::vector<unsigned char> updated_data; | 1677 bitmaps[0] = CreateBitmap(SK_ColorBLUE, kSmallEdgeSize); |
1762 updated_data.push_back('a'); | 1678 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url, bitmaps); |
1763 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data); | |
1764 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | |
1765 | 1679 |
1766 favicon_base::FaviconID updated_favicon_id = | 1680 favicon_base::FaviconID updated_favicon_id = |
1767 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 1681 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
1768 icon_url, favicon_base::FAVICON, NULL); | 1682 icon_url, favicon_base::FAVICON, NULL); |
1769 EXPECT_NE(0, updated_favicon_id); | 1683 EXPECT_NE(0, updated_favicon_id); |
1770 FaviconBitmap updated_favicon_bitmap; | 1684 FaviconBitmap updated_favicon_bitmap; |
1771 EXPECT_TRUE( | 1685 EXPECT_TRUE( |
1772 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); | 1686 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); |
1773 EXPECT_TRUE(BitmapDataEqual('a', updated_favicon_bitmap.bitmap_data)); | 1687 EXPECT_TRUE( |
| 1688 BitmapColorEqual(SK_ColorBLUE, updated_favicon_bitmap.bitmap_data)); |
1774 | 1689 |
1775 // Because the bitmap data is byte equivalent, no notifications should have | 1690 // Because the bitmap data is byte equivalent, no notifications should have |
1776 // been broadcasted. | 1691 // been broadcasted. |
1777 EXPECT_EQ(1, num_broadcasted_notifications()); | 1692 EXPECT_EQ(1, num_broadcasted_notifications()); |
1778 | 1693 |
1779 // Call SetFavicons() with identical data but a different bitmap. | 1694 // Call SetFavicon() with a different bitmap of the same size. |
1780 updated_data[0] = 'b'; | 1695 bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize); |
1781 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data); | 1696 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url, bitmaps); |
1782 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | |
1783 | 1697 |
1784 updated_favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 1698 updated_favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
1785 icon_url, favicon_base::FAVICON, NULL); | 1699 icon_url, favicon_base::FAVICON, NULL); |
1786 EXPECT_NE(0, updated_favicon_id); | 1700 EXPECT_NE(0, updated_favicon_id); |
1787 EXPECT_TRUE( | 1701 EXPECT_TRUE( |
1788 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); | 1702 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); |
1789 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data)); | 1703 EXPECT_TRUE( |
| 1704 BitmapColorEqual(SK_ColorWHITE, updated_favicon_bitmap.bitmap_data)); |
1790 | 1705 |
1791 // There should be no churn in FaviconIDs or FaviconBitmapIds even though | 1706 // There should be no churn in FaviconIDs or FaviconBitmapIds even though |
1792 // the bitmap data changed. | 1707 // the bitmap data changed. |
1793 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id); | 1708 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id); |
1794 EXPECT_EQ(original_favicon_bitmap.bitmap_id, | 1709 EXPECT_EQ(original_favicon_bitmap.bitmap_id, |
1795 updated_favicon_bitmap.bitmap_id); | 1710 updated_favicon_bitmap.bitmap_id); |
1796 | 1711 |
1797 // A notification should have been broadcasted as the favicon bitmap data has | 1712 // A notification should have been broadcasted as the favicon bitmap data has |
1798 // changed. | 1713 // changed. |
1799 EXPECT_EQ(2, num_broadcasted_notifications()); | 1714 EXPECT_EQ(2, num_broadcasted_notifications()); |
1800 } | 1715 } |
1801 | 1716 |
1802 // Test that if two pages share the same FaviconID, changing the favicon for | 1717 // Test that if two pages share the same FaviconID, changing the favicon for |
1803 // one page does not affect the other. | 1718 // one page does not affect the other. |
1804 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) { | 1719 TEST_F(HistoryBackendTest, SetFaviconSameFaviconURLForTwoPages) { |
1805 GURL icon_url("http://www.google.com/favicon.ico"); | 1720 GURL icon_url("http://www.google.com/favicon.ico"); |
1806 GURL icon_url_new("http://www.google.com/favicon2.ico"); | 1721 GURL icon_url_new("http://www.google.com/favicon2.ico"); |
1807 GURL page_url1("http://www.google.com"); | 1722 GURL page_url1("http://www.google.com"); |
1808 GURL page_url2("http://www.google.ca"); | 1723 GURL page_url2("http://www.google.ca"); |
| 1724 std::vector<SkBitmap> bitmaps; |
| 1725 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
| 1726 bitmaps.push_back(CreateBitmap(SK_ColorRED, kLargeEdgeSize)); |
1809 | 1727 |
1810 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 1728 backend_->SetFavicon(page_url1, favicon_base::FAVICON, icon_url, bitmaps); |
1811 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(), | |
1812 &favicon_bitmap_data); | |
1813 | |
1814 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); | |
1815 | 1729 |
1816 std::vector<GURL> icon_urls; | 1730 std::vector<GURL> icon_urls; |
1817 icon_urls.push_back(icon_url); | 1731 icon_urls.push_back(icon_url); |
1818 | 1732 |
1819 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; | 1733 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; |
1820 backend_->UpdateFaviconMappingsAndFetch(page_url2, | 1734 backend_->UpdateFaviconMappingsAndFetch(page_url2, |
1821 icon_urls, | 1735 icon_urls, |
1822 favicon_base::FAVICON, | 1736 favicon_base::FAVICON, |
1823 GetEdgeSizesSmallAndLarge(), | 1737 GetEdgeSizesSmallAndLarge(), |
1824 &bitmap_results); | 1738 &bitmap_results); |
1825 | 1739 |
1826 // Check that the same FaviconID is mapped to both page URLs. | 1740 // Check that the same FaviconID is mapped to both page URLs. |
1827 std::vector<IconMapping> icon_mappings; | 1741 std::vector<IconMapping> icon_mappings; |
1828 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1742 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
1829 page_url1, &icon_mappings)); | 1743 page_url1, &icon_mappings)); |
1830 EXPECT_EQ(1u, icon_mappings.size()); | 1744 EXPECT_EQ(1u, icon_mappings.size()); |
1831 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id; | 1745 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id; |
1832 EXPECT_NE(0, favicon_id); | 1746 EXPECT_NE(0, favicon_id); |
1833 | 1747 |
1834 icon_mappings.clear(); | 1748 icon_mappings.clear(); |
1835 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1749 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
1836 page_url2, &icon_mappings)); | 1750 page_url2, &icon_mappings)); |
1837 EXPECT_EQ(1u, icon_mappings.size()); | 1751 EXPECT_EQ(1u, icon_mappings.size()); |
1838 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); | 1752 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); |
1839 | 1753 |
1840 // Change the icon URL that |page_url1| is mapped to. | 1754 // Change the icon URL that |page_url1| is mapped to. |
1841 GenerateFaviconBitmapData(icon_url_new, GetEdgeSizesSmall(), | 1755 bitmaps.clear(); |
1842 &favicon_bitmap_data); | 1756 bitmaps.push_back(CreateBitmap(SK_ColorWHITE, kSmallEdgeSize)); |
1843 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); | 1757 backend_->SetFavicon(page_url1, favicon_base::FAVICON, icon_url_new, bitmaps); |
1844 | 1758 |
1845 // |page_url1| should map to a new FaviconID and have valid bitmap data. | 1759 // |page_url1| should map to a new FaviconID and have valid bitmap data. |
1846 icon_mappings.clear(); | 1760 icon_mappings.clear(); |
1847 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1761 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
1848 page_url1, &icon_mappings)); | 1762 page_url1, &icon_mappings)); |
1849 EXPECT_EQ(1u, icon_mappings.size()); | 1763 EXPECT_EQ(1u, icon_mappings.size()); |
1850 EXPECT_EQ(icon_url_new, icon_mappings[0].icon_url); | 1764 EXPECT_EQ(icon_url_new, icon_mappings[0].icon_url); |
1851 EXPECT_NE(favicon_id, icon_mappings[0].icon_id); | 1765 EXPECT_NE(favicon_id, icon_mappings[0].icon_id); |
1852 | 1766 |
1853 std::vector<FaviconBitmap> favicon_bitmaps; | 1767 std::vector<FaviconBitmap> favicon_bitmaps; |
1854 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( | 1768 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( |
1855 icon_mappings[0].icon_id, &favicon_bitmaps)); | 1769 icon_mappings[0].icon_id, &favicon_bitmaps)); |
1856 EXPECT_EQ(1u, favicon_bitmaps.size()); | 1770 EXPECT_EQ(1u, favicon_bitmaps.size()); |
1857 | 1771 |
1858 // |page_url2| should still map to the same FaviconID and have valid bitmap | 1772 // |page_url2| should still map to the same FaviconID and have valid bitmap |
1859 // data. | 1773 // data. |
1860 icon_mappings.clear(); | 1774 icon_mappings.clear(); |
1861 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1775 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
1862 page_url2, &icon_mappings)); | 1776 page_url2, &icon_mappings)); |
1863 EXPECT_EQ(1u, icon_mappings.size()); | 1777 EXPECT_EQ(1u, icon_mappings.size()); |
1864 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); | 1778 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); |
1865 | 1779 |
1866 favicon_bitmaps.clear(); | 1780 favicon_bitmaps.clear(); |
1867 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, | 1781 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, |
1868 &favicon_bitmaps)); | 1782 &favicon_bitmaps)); |
1869 EXPECT_EQ(2u, favicon_bitmaps.size()); | 1783 EXPECT_EQ(2u, favicon_bitmaps.size()); |
1870 | 1784 |
1871 // A notification should have been broadcast for each call to SetFavicons() | 1785 // A notification should have been broadcast for each call to SetFavicon() |
1872 // and each call to UpdateFaviconMappingsAndFetch(). | 1786 // and each call to UpdateFaviconMappingsAndFetch(). |
1873 EXPECT_EQ(3, num_broadcasted_notifications()); | 1787 EXPECT_EQ(3, num_broadcasted_notifications()); |
1874 } | 1788 } |
1875 | 1789 |
1876 // Test that no notifications are broadcast as a result of calling | 1790 // Test that no notifications are broadcast as a result of calling |
1877 // UpdateFaviconMappingsAndFetch() for an icon URL which is already | 1791 // UpdateFaviconMappingsAndFetch() for an icon URL which is already |
1878 // mapped to the passed in page URL. | 1792 // mapped to the passed in page URL. |
1879 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { | 1793 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { |
1880 GURL page_url("http://www.google.com"); | 1794 GURL page_url("http://www.google.com"); |
1881 GURL icon_url("http://www.google.com/favicon.ico"); | 1795 GURL icon_url("http://www.google.com/favicon.ico"); |
1882 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 1796 std::vector<SkBitmap> bitmaps; |
1883 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(), | 1797 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
1884 &favicon_bitmap_data); | |
1885 | 1798 |
1886 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | 1799 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url, bitmaps); |
1887 | 1800 |
1888 favicon_base::FaviconID icon_id = | 1801 favicon_base::FaviconID icon_id = |
1889 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 1802 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
1890 icon_url, favicon_base::FAVICON, NULL); | 1803 icon_url, favicon_base::FAVICON, NULL); |
1891 EXPECT_NE(0, icon_id); | 1804 EXPECT_NE(0, icon_id); |
1892 EXPECT_EQ(1, num_broadcasted_notifications()); | 1805 EXPECT_EQ(1, num_broadcasted_notifications()); |
1893 | 1806 |
1894 std::vector<GURL> icon_urls; | 1807 std::vector<GURL> icon_urls; |
1895 icon_urls.push_back(icon_url); | 1808 icon_urls.push_back(icon_url); |
1896 | 1809 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1955 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); | 1868 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); |
1956 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); | 1869 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); |
1957 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); | 1870 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
1958 } | 1871 } |
1959 | 1872 |
1960 // Test calling MergeFavicon() when |page_url| is known to the database. | 1873 // Test calling MergeFavicon() when |page_url| is known to the database. |
1961 TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) { | 1874 TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) { |
1962 GURL page_url("http://www.google.com"); | 1875 GURL page_url("http://www.google.com"); |
1963 GURL icon_url1("http:/www.google.com/favicon.ico"); | 1876 GURL icon_url1("http:/www.google.com/favicon.ico"); |
1964 GURL icon_url2("http://www.google.com/favicon2.ico"); | 1877 GURL icon_url2("http://www.google.com/favicon2.ico"); |
| 1878 std::vector<SkBitmap> bitmaps; |
| 1879 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
1965 | 1880 |
1966 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 1881 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url1, bitmaps); |
1967 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(), | |
1968 &favicon_bitmap_data); | |
1969 | |
1970 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | |
1971 | 1882 |
1972 // Test initial state. | 1883 // Test initial state. |
1973 std::vector<IconMapping> icon_mappings; | 1884 std::vector<IconMapping> icon_mappings; |
1974 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, | 1885 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
1975 &icon_mappings)); | 1886 &icon_mappings)); |
1976 EXPECT_EQ(1u, icon_mappings.size()); | 1887 EXPECT_EQ(1u, icon_mappings.size()); |
1977 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); | 1888 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); |
1978 | 1889 |
1979 FaviconBitmap favicon_bitmap; | 1890 FaviconBitmap favicon_bitmap; |
1980 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); | 1891 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); |
1981 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); | 1892 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); |
1982 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); | 1893 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data)); |
1983 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); | 1894 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
1984 | 1895 |
1985 EXPECT_EQ(1, num_broadcasted_notifications()); | 1896 EXPECT_EQ(1, num_broadcasted_notifications()); |
1986 | 1897 |
1987 // 1) Merge identical favicon bitmap. | 1898 // 1) Merge identical favicon bitmap. |
1988 std::vector<unsigned char> data; | 1899 std::vector<unsigned char> data; |
1989 data.push_back('a'); | 1900 gfx::PNGCodec::EncodeBGRASkBitmap(bitmaps[0], false, &data); |
1990 scoped_refptr<base::RefCountedBytes> bitmap_data( | 1901 scoped_refptr<base::RefCountedBytes> bitmap_data( |
1991 new base::RefCountedBytes(data)); | 1902 new base::RefCountedBytes(data)); |
1992 backend_->MergeFavicon( | 1903 backend_->MergeFavicon( |
1993 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); | 1904 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); |
1994 | 1905 |
1995 // All the data should stay the same and no notifications should have been | 1906 // All the data should stay the same and no notifications should have been |
1996 // sent. | 1907 // sent. |
1997 icon_mappings.clear(); | 1908 icon_mappings.clear(); |
1998 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, | 1909 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
1999 &icon_mappings)); | 1910 &icon_mappings)); |
2000 EXPECT_EQ(1u, icon_mappings.size()); | 1911 EXPECT_EQ(1u, icon_mappings.size()); |
2001 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); | 1912 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); |
2002 | 1913 |
2003 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); | 1914 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); |
2004 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); | 1915 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); |
2005 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); | 1916 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data)); |
2006 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); | 1917 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
2007 | 1918 |
2008 EXPECT_EQ(1, num_broadcasted_notifications()); | 1919 EXPECT_EQ(1, num_broadcasted_notifications()); |
2009 | 1920 |
2010 // 2) Merge favicon bitmap of the same size. | 1921 // 2) Merge favicon bitmap of the same size. |
2011 data[0] = 'b'; | 1922 data.clear(); |
| 1923 data.push_back('b'); |
2012 bitmap_data = new base::RefCountedBytes(data); | 1924 bitmap_data = new base::RefCountedBytes(data); |
2013 backend_->MergeFavicon( | 1925 backend_->MergeFavicon( |
2014 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); | 1926 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); |
2015 | 1927 |
2016 // The small favicon bitmap at |icon_url1| should be overwritten. | 1928 // The small favicon bitmap at |icon_url1| should be overwritten. |
2017 icon_mappings.clear(); | 1929 icon_mappings.clear(); |
2018 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, | 1930 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
2019 &icon_mappings)); | 1931 &icon_mappings)); |
2020 EXPECT_EQ(1u, icon_mappings.size()); | 1932 EXPECT_EQ(1u, icon_mappings.size()); |
2021 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); | 1933 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2070 &favicon_bitmaps)); | 1982 &favicon_bitmaps)); |
2071 EXPECT_EQ(base::Time(), favicon_bitmaps[0].last_updated); | 1983 EXPECT_EQ(base::Time(), favicon_bitmaps[0].last_updated); |
2072 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); | 1984 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); |
2073 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); | 1985 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); |
2074 // The favicon being merged should take precedence over the preexisting | 1986 // The favicon being merged should take precedence over the preexisting |
2075 // favicon bitmaps. | 1987 // favicon bitmaps. |
2076 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated); | 1988 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated); |
2077 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data)); | 1989 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data)); |
2078 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); | 1990 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); |
2079 | 1991 |
2080 // A notification should have been broadcast for each call to SetFavicons() | 1992 // A notification should have been broadcast for each call to SetFavicon() |
2081 // and MergeFavicon(). | 1993 // and MergeFavicon(). |
2082 EXPECT_EQ(4, num_broadcasted_notifications()); | 1994 EXPECT_EQ(4, num_broadcasted_notifications()); |
2083 } | 1995 } |
2084 | 1996 |
2085 // Test calling MergeFavicon() when |icon_url| is known to the database but not | 1997 // Test calling MergeFavicon() when |icon_url| is known to the database but not |
2086 // mapped to |page_url|. | 1998 // mapped to |page_url|. |
2087 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { | 1999 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { |
2088 GURL page_url1("http://www.google.com"); | 2000 GURL page_url1("http://www.google.com"); |
2089 GURL page_url2("http://news.google.com"); | 2001 GURL page_url2("http://news.google.com"); |
2090 GURL page_url3("http://maps.google.com"); | 2002 GURL page_url3("http://maps.google.com"); |
2091 GURL icon_url("http:/www.google.com/favicon.ico"); | 2003 GURL icon_url("http:/www.google.com/favicon.ico"); |
| 2004 std::vector<SkBitmap> bitmaps; |
| 2005 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
2092 | 2006 |
2093 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 2007 backend_->SetFavicon(page_url1, favicon_base::FAVICON, icon_url, bitmaps); |
2094 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(), | |
2095 &favicon_bitmap_data); | |
2096 | |
2097 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); | |
2098 | 2008 |
2099 // Test initial state. | 2009 // Test initial state. |
2100 std::vector<IconMapping> icon_mappings; | 2010 std::vector<IconMapping> icon_mappings; |
2101 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1, | 2011 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1, |
2102 &icon_mappings)); | 2012 &icon_mappings)); |
2103 EXPECT_EQ(1u, icon_mappings.size()); | 2013 EXPECT_EQ(1u, icon_mappings.size()); |
2104 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); | 2014 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); |
2105 | 2015 |
2106 FaviconBitmap favicon_bitmap; | 2016 FaviconBitmap favicon_bitmap; |
2107 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); | 2017 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); |
2108 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); | 2018 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); |
2109 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); | 2019 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data)); |
2110 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); | 2020 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
2111 | 2021 |
2112 // 1) Merge in an identical favicon bitmap data but for a different page URL. | 2022 // 1) Merge in an identical favicon bitmap data but for a different page URL. |
2113 std::vector<unsigned char> data; | 2023 std::vector<unsigned char> data; |
2114 data.push_back('a'); | 2024 gfx::PNGCodec::EncodeBGRASkBitmap(bitmaps[0], false, &data); |
2115 scoped_refptr<base::RefCountedBytes> bitmap_data( | 2025 scoped_refptr<base::RefCountedBytes> bitmap_data( |
2116 new base::RefCountedBytes(data)); | 2026 new base::RefCountedBytes(data)); |
2117 | 2027 |
2118 backend_->MergeFavicon( | 2028 backend_->MergeFavicon( |
2119 page_url2, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize); | 2029 page_url2, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize); |
2120 | 2030 |
2121 favicon_base::FaviconID favicon_id = | 2031 favicon_base::FaviconID favicon_id = |
2122 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 2032 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
2123 icon_url, favicon_base::FAVICON, NULL); | 2033 icon_url, favicon_base::FAVICON, NULL); |
2124 EXPECT_NE(0, favicon_id); | 2034 EXPECT_NE(0, favicon_id); |
2125 | 2035 |
2126 EXPECT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap)); | 2036 EXPECT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap)); |
2127 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); | 2037 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); |
2128 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); | 2038 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data)); |
2129 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); | 2039 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); |
2130 | 2040 |
2131 // 2) Merging a favicon bitmap with different bitmap data for the same icon | 2041 // 2) Merging a favicon bitmap with different bitmap data for the same icon |
2132 // URL should overwrite the small favicon bitmap at |icon_url|. | 2042 // URL should overwrite the small favicon bitmap at |icon_url|. |
2133 bitmap_data->data()[0] = 'b'; | 2043 data.clear(); |
| 2044 data.push_back('b'); |
| 2045 bitmap_data = new base::RefCountedBytes(data); |
2134 backend_->MergeFavicon( | 2046 backend_->MergeFavicon( |
2135 page_url3, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize); | 2047 page_url3, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize); |
2136 | 2048 |
2137 favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 2049 favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
2138 icon_url, favicon_base::FAVICON, NULL); | 2050 icon_url, favicon_base::FAVICON, NULL); |
2139 EXPECT_NE(0, favicon_id); | 2051 EXPECT_NE(0, favicon_id); |
2140 | 2052 |
2141 EXPECT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap)); | 2053 EXPECT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap)); |
2142 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); | 2054 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); |
2143 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); | 2055 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); |
(...skipping 11 matching lines...) Expand all Loading... |
2155 &icon_mappings)); | 2067 &icon_mappings)); |
2156 EXPECT_EQ(1u, icon_mappings.size()); | 2068 EXPECT_EQ(1u, icon_mappings.size()); |
2157 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); | 2069 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); |
2158 | 2070 |
2159 icon_mappings.clear(); | 2071 icon_mappings.clear(); |
2160 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3, | 2072 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3, |
2161 &icon_mappings)); | 2073 &icon_mappings)); |
2162 EXPECT_EQ(1u, icon_mappings.size()); | 2074 EXPECT_EQ(1u, icon_mappings.size()); |
2163 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); | 2075 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); |
2164 | 2076 |
2165 // A notification should have been broadcast for each call to SetFavicons() | 2077 // A notification should have been broadcast for each call to SetFavicon() |
2166 // and MergeFavicon(). | 2078 // and MergeFavicon(). |
2167 EXPECT_EQ(3, num_broadcasted_notifications()); | 2079 EXPECT_EQ(3, num_broadcasted_notifications()); |
2168 } | 2080 } |
2169 | 2081 |
2170 // Test that MergeFavicon() does not add more than | 2082 // Test that MergeFavicon() does not add more than |
2171 // |kMaxFaviconBitmapsPerIconURL| to a favicon. | 2083 // |kMaxFaviconBitmapsPerIconURL| to a favicon. |
2172 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) { | 2084 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) { |
2173 GURL page_url("http://www.google.com"); | 2085 GURL page_url("http://www.google.com"); |
2174 std::string icon_url_string("http://www.google.com/favicon.ico"); | 2086 std::string icon_url_string("http://www.google.com/favicon.ico"); |
2175 size_t replace_index = icon_url_string.size() - 1; | 2087 size_t replace_index = icon_url_string.size() - 1; |
(...skipping 27 matching lines...) Expand all Loading... |
2203 icon_mappings[0].icon_id, &favicon_bitmaps)); | 2115 icon_mappings[0].icon_id, &favicon_bitmaps)); |
2204 EXPECT_EQ(kMaxFaviconBitmapsPerIconURL, favicon_bitmaps.size()); | 2116 EXPECT_EQ(kMaxFaviconBitmapsPerIconURL, favicon_bitmaps.size()); |
2205 } | 2117 } |
2206 | 2118 |
2207 // Tests that the favicon set by MergeFavicon() shows up in the result of | 2119 // Tests that the favicon set by MergeFavicon() shows up in the result of |
2208 // GetFaviconsForURL(). | 2120 // GetFaviconsForURL(). |
2209 TEST_F(HistoryBackendTest, MergeFaviconShowsUpInGetFaviconsForURLResult) { | 2121 TEST_F(HistoryBackendTest, MergeFaviconShowsUpInGetFaviconsForURLResult) { |
2210 GURL page_url("http://www.google.com"); | 2122 GURL page_url("http://www.google.com"); |
2211 GURL icon_url("http://www.google.com/favicon.ico"); | 2123 GURL icon_url("http://www.google.com/favicon.ico"); |
2212 GURL merged_icon_url("http://wwww.google.com/favicon2.ico"); | 2124 GURL merged_icon_url("http://wwww.google.com/favicon2.ico"); |
2213 | 2125 std::vector<SkBitmap> bitmaps; |
2214 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 2126 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
2215 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(), | 2127 bitmaps.push_back(CreateBitmap(SK_ColorRED, kLargeEdgeSize)); |
2216 &favicon_bitmap_data); | |
2217 | 2128 |
2218 // Set some preexisting favicons for |page_url|. | 2129 // Set some preexisting favicons for |page_url|. |
2219 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | 2130 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url, bitmaps); |
2220 | 2131 |
2221 // Merge small favicon. | 2132 // Merge small favicon. |
2222 std::vector<unsigned char> data; | 2133 std::vector<unsigned char> data; |
2223 data.push_back('c'); | 2134 data.push_back('c'); |
2224 scoped_refptr<base::RefCountedBytes> bitmap_data( | 2135 scoped_refptr<base::RefCountedBytes> bitmap_data( |
2225 new base::RefCountedBytes(data)); | 2136 new base::RefCountedBytes(data)); |
2226 backend_->MergeFavicon(page_url, | 2137 backend_->MergeFavicon(page_url, |
2227 merged_icon_url, | 2138 merged_icon_url, |
2228 favicon_base::FAVICON, | 2139 favicon_base::FAVICON, |
2229 bitmap_data, | 2140 bitmap_data, |
(...skipping 14 matching lines...) Expand all Loading... |
2244 : bitmap_results[1]; | 2155 : bitmap_results[1]; |
2245 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data)); | 2156 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data)); |
2246 } | 2157 } |
2247 | 2158 |
2248 // Tests GetFaviconsForURL with icon_types priority, | 2159 // Tests GetFaviconsForURL with icon_types priority, |
2249 TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) { | 2160 TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) { |
2250 GURL page_url("http://www.google.com"); | 2161 GURL page_url("http://www.google.com"); |
2251 GURL icon_url("http://www.google.com/favicon.ico"); | 2162 GURL icon_url("http://www.google.com/favicon.ico"); |
2252 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico"); | 2163 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico"); |
2253 | 2164 |
2254 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 2165 std::vector<SkBitmap> favicon_bitmaps; |
2255 std::vector<int> favicon_size; | 2166 favicon_bitmaps.push_back(CreateBitmap(SK_ColorBLUE, 16)); |
2256 favicon_size.push_back(16); | 2167 favicon_bitmaps.push_back(CreateBitmap(SK_ColorRED, 32)); |
2257 favicon_size.push_back(32); | |
2258 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data); | |
2259 ASSERT_EQ(2u, favicon_bitmap_data.size()); | |
2260 | 2168 |
2261 std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data; | 2169 std::vector<SkBitmap> touch_bitmaps; |
2262 std::vector<int> touch_icon_size; | 2170 touch_bitmaps.push_back(CreateBitmap(SK_ColorWHITE, 64)); |
2263 touch_icon_size.push_back(64); | |
2264 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data); | |
2265 ASSERT_EQ(1u, touch_icon_bitmap_data.size()); | |
2266 | 2171 |
2267 // Set some preexisting favicons for |page_url|. | 2172 // Set some preexisting favicons for |page_url|. |
2268 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | 2173 backend_->SetFavicon( |
2269 backend_->SetFavicons( | 2174 page_url, favicon_base::FAVICON, icon_url, favicon_bitmaps); |
2270 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data); | 2175 backend_->SetFavicon( |
| 2176 page_url, favicon_base::TOUCH_ICON, touch_icon_url, touch_bitmaps); |
2271 | 2177 |
2272 favicon_base::FaviconRawBitmapResult result; | 2178 favicon_base::FaviconRawBitmapResult result; |
2273 std::vector<int> icon_types; | 2179 std::vector<int> icon_types; |
2274 icon_types.push_back(favicon_base::FAVICON); | 2180 icon_types.push_back(favicon_base::FAVICON); |
2275 icon_types.push_back(favicon_base::TOUCH_ICON); | 2181 icon_types.push_back(favicon_base::TOUCH_ICON); |
2276 | 2182 |
2277 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result); | 2183 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result); |
2278 | 2184 |
2279 // Verify the result icon is 32x32 favicon. | 2185 // Verify the result icon is 32x32 favicon. |
2280 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size); | 2186 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size); |
2281 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); | 2187 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); |
2282 | 2188 |
2283 // Change Minimal size to 32x32 and verify the 64x64 touch icon returned. | 2189 // Change Minimal size to 32x32 and verify the 64x64 touch icon returned. |
2284 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result); | 2190 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result); |
2285 EXPECT_EQ(gfx::Size(64, 64), result.pixel_size); | 2191 EXPECT_EQ(gfx::Size(64, 64), result.pixel_size); |
2286 EXPECT_EQ(favicon_base::TOUCH_ICON, result.icon_type); | 2192 EXPECT_EQ(favicon_base::TOUCH_ICON, result.icon_type); |
2287 } | 2193 } |
2288 | 2194 |
2289 // Test the the first types of icon is returned if its size equal to the | 2195 // Test the the first types of icon is returned if its size equal to the |
2290 // second types icon. | 2196 // second types icon. |
2291 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) { | 2197 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) { |
2292 GURL page_url("http://www.google.com"); | 2198 GURL page_url("http://www.google.com"); |
2293 GURL icon_url("http://www.google.com/favicon.ico"); | 2199 GURL icon_url("http://www.google.com/favicon.ico"); |
2294 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico"); | 2200 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico"); |
2295 | 2201 |
2296 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 2202 std::vector<SkBitmap> favicon_bitmaps; |
2297 std::vector<int> favicon_size; | 2203 favicon_bitmaps.push_back(CreateBitmap(SK_ColorBLUE, 16)); |
2298 favicon_size.push_back(16); | 2204 favicon_bitmaps.push_back(CreateBitmap(SK_ColorRED, 32)); |
2299 favicon_size.push_back(32); | |
2300 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data); | |
2301 ASSERT_EQ(2u, favicon_bitmap_data.size()); | |
2302 | 2205 |
2303 std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data; | 2206 std::vector<SkBitmap> touch_bitmaps; |
2304 std::vector<int> touch_icon_size; | 2207 touch_bitmaps.push_back(CreateBitmap(SK_ColorWHITE, 32)); |
2305 touch_icon_size.push_back(32); | |
2306 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data); | |
2307 ASSERT_EQ(1u, touch_icon_bitmap_data.size()); | |
2308 | 2208 |
2309 // Set some preexisting favicons for |page_url|. | 2209 // Set some preexisting favicons for |page_url|. |
2310 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | 2210 backend_->SetFavicon( |
2311 backend_->SetFavicons( | 2211 page_url, favicon_base::FAVICON, icon_url, favicon_bitmaps); |
2312 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data); | 2212 backend_->SetFavicon( |
| 2213 page_url, favicon_base::TOUCH_ICON, touch_icon_url, touch_bitmaps); |
2313 | 2214 |
2314 favicon_base::FaviconRawBitmapResult result; | 2215 favicon_base::FaviconRawBitmapResult result; |
2315 std::vector<int> icon_types; | 2216 std::vector<int> icon_types; |
2316 icon_types.push_back(favicon_base::FAVICON); | 2217 icon_types.push_back(favicon_base::FAVICON); |
2317 icon_types.push_back(favicon_base::TOUCH_ICON); | 2218 icon_types.push_back(favicon_base::TOUCH_ICON); |
2318 | 2219 |
2319 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result); | 2220 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result); |
2320 | 2221 |
2321 // Verify the result icon is 32x32 favicon. | 2222 // Verify the result icon is 32x32 favicon. |
2322 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size); | 2223 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size); |
2323 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); | 2224 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); |
2324 | 2225 |
2325 // Change minimal size to 32x32 and verify the 32x32 favicon returned. | 2226 // Change minimal size to 32x32 and verify the 32x32 favicon returned. |
2326 favicon_base::FaviconRawBitmapResult result1; | 2227 favicon_base::FaviconRawBitmapResult result1; |
2327 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result1); | 2228 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result1); |
2328 EXPECT_EQ(gfx::Size(32, 32), result1.pixel_size); | 2229 EXPECT_EQ(gfx::Size(32, 32), result1.pixel_size); |
2329 EXPECT_EQ(favicon_base::FAVICON, result1.icon_type); | 2230 EXPECT_EQ(favicon_base::FAVICON, result1.icon_type); |
2330 } | 2231 } |
2331 | 2232 |
2332 // Test the favicon is returned if its size is smaller than minimal size, | 2233 // Test the favicon is returned if its size is smaller than minimal size, |
2333 // because it is only one available. | 2234 // because it is only one available. |
2334 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) { | 2235 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) { |
2335 GURL page_url("http://www.google.com"); | 2236 GURL page_url("http://www.google.com"); |
2336 GURL icon_url("http://www.google.com/favicon.ico"); | 2237 GURL icon_url("http://www.google.com/favicon.ico"); |
2337 | 2238 |
2338 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 2239 std::vector<SkBitmap> bitmaps; |
2339 std::vector<int> favicon_size; | 2240 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, 16)); |
2340 favicon_size.push_back(16); | |
2341 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data); | |
2342 ASSERT_EQ(1u, favicon_bitmap_data.size()); | |
2343 | 2241 |
2344 // Set preexisting favicons for |page_url|. | 2242 // Set preexisting favicons for |page_url|. |
2345 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | 2243 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url, bitmaps); |
2346 | 2244 |
2347 favicon_base::FaviconRawBitmapResult result; | 2245 favicon_base::FaviconRawBitmapResult result; |
2348 std::vector<int> icon_types; | 2246 std::vector<int> icon_types; |
2349 icon_types.push_back(favicon_base::FAVICON); | 2247 icon_types.push_back(favicon_base::FAVICON); |
2350 icon_types.push_back(favicon_base::TOUCH_ICON); | 2248 icon_types.push_back(favicon_base::TOUCH_ICON); |
2351 | 2249 |
2352 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result); | 2250 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result); |
2353 | 2251 |
2354 // Verify 16x16 icon is returned, even it small than minimal_size. | 2252 // Verify 16x16 icon is returned, even it small than minimal_size. |
2355 EXPECT_EQ(gfx::Size(16, 16), result.pixel_size); | 2253 EXPECT_EQ(gfx::Size(16, 16), result.pixel_size); |
2356 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); | 2254 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); |
2357 } | 2255 } |
2358 | 2256 |
2359 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in. | 2257 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in. |
2360 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) { | 2258 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) { |
2361 GURL page_url1("http://www.google.com"); | 2259 GURL page_url1("http://www.google.com"); |
2362 GURL page_url2("http://news.google.com"); | 2260 GURL page_url2("http://news.google.com"); |
2363 GURL page_url3("http://mail.google.com"); | 2261 GURL page_url3("http://mail.google.com"); |
2364 GURL icon_urla("http://www.google.com/favicon1.ico"); | 2262 GURL icon_urla("http://www.google.com/favicon1.ico"); |
2365 GURL icon_urlb("http://www.google.com/favicon2.ico"); | 2263 GURL icon_urlb("http://www.google.com/favicon2.ico"); |
2366 GURL icon_urlc("http://www.google.com/favicon3.ico"); | 2264 std::vector<SkBitmap> bitmaps; |
| 2265 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
2367 | 2266 |
2368 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON. | 2267 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON. |
2369 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 2268 backend_->SetFavicon(page_url1, favicon_base::TOUCH_ICON, icon_urla, bitmaps); |
2370 GenerateFaviconBitmapData(icon_urla, GetEdgeSizesSmall(), | |
2371 &favicon_bitmap_data); | |
2372 backend_->SetFavicons( | |
2373 page_url1, favicon_base::TOUCH_ICON, favicon_bitmap_data); | |
2374 | 2269 |
2375 // |page_url2| is mapped to |icon_urlb| and |icon_urlc| which are of type | 2270 // |page_url2| is mapped to |icon_urlb| which is of type |
2376 // TOUCH_PRECOMPOSED_ICON. | 2271 // TOUCH_PRECOMPOSED_ICON. |
2377 GenerateFaviconBitmapData(icon_urlb, GetEdgeSizesSmall(), icon_urlc, | 2272 backend_->SetFavicon( |
2378 GetEdgeSizesSmall(), &favicon_bitmap_data); | 2273 page_url2, favicon_base::TOUCH_PRECOMPOSED_ICON, icon_urlb, bitmaps); |
2379 backend_->SetFavicons( | |
2380 page_url2, favicon_base::TOUCH_PRECOMPOSED_ICON, favicon_bitmap_data); | |
2381 | 2274 |
2382 std::vector<GURL> icon_urls; | 2275 std::vector<GURL> icon_urls; |
2383 icon_urls.push_back(icon_urla); | 2276 icon_urls.push_back(icon_urla); |
2384 icon_urls.push_back(icon_urlb); | 2277 icon_urls.push_back(icon_urlb); |
2385 icon_urls.push_back(icon_urlc); | |
2386 | 2278 |
2387 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; | 2279 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; |
2388 backend_->UpdateFaviconMappingsAndFetch( | 2280 backend_->UpdateFaviconMappingsAndFetch( |
2389 page_url3, | 2281 page_url3, |
2390 icon_urls, | 2282 icon_urls, |
2391 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON), | 2283 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON), |
2392 GetEdgeSizesSmallAndLarge(), | 2284 GetEdgeSizesSmallAndLarge(), |
2393 &bitmap_results); | 2285 &bitmap_results); |
2394 | 2286 |
2395 // |page_url1| and |page_url2| should still be mapped to the same icon URLs. | 2287 // |page_url1| and |page_url2| should still be mapped to the same icon URLs. |
2396 std::vector<IconMapping> icon_mappings; | 2288 std::vector<IconMapping> icon_mappings; |
2397 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1, | 2289 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1, |
2398 &icon_mappings)); | 2290 &icon_mappings)); |
2399 EXPECT_EQ(1u, icon_mappings.size()); | 2291 EXPECT_EQ(1u, icon_mappings.size()); |
2400 EXPECT_EQ(icon_urla, icon_mappings[0].icon_url); | 2292 EXPECT_EQ(icon_urla, icon_mappings[0].icon_url); |
2401 EXPECT_EQ(favicon_base::TOUCH_ICON, icon_mappings[0].icon_type); | 2293 EXPECT_EQ(favicon_base::TOUCH_ICON, icon_mappings[0].icon_type); |
2402 | 2294 |
2403 icon_mappings.clear(); | 2295 icon_mappings.clear(); |
2404 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url2, &icon_mappings)); | 2296 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url2, &icon_mappings)); |
2405 EXPECT_EQ(2u, icon_mappings.size()); | 2297 EXPECT_EQ(1u, icon_mappings.size()); |
2406 EXPECT_EQ(icon_urlb, icon_mappings[0].icon_url); | 2298 EXPECT_EQ(icon_urlb, icon_mappings[0].icon_url); |
2407 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type); | 2299 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type); |
2408 EXPECT_EQ(icon_urlc, icon_mappings[1].icon_url); | |
2409 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type); | |
2410 | 2300 |
2411 // |page_url3| should be mapped only to |icon_urlb| and |icon_urlc| as | 2301 // |page_url3| should be mapped only to |icon_urlb| as TOUCH_PRECOMPOSED_ICON |
2412 // TOUCH_PRECOMPOSED_ICON is the largest IconType. | 2302 // is the largest IconType. |
2413 icon_mappings.clear(); | 2303 icon_mappings.clear(); |
2414 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url3, &icon_mappings)); | 2304 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url3, &icon_mappings)); |
2415 EXPECT_EQ(2u, icon_mappings.size()); | 2305 EXPECT_EQ(1u, icon_mappings.size()); |
2416 EXPECT_EQ(icon_urlb, icon_mappings[0].icon_url); | 2306 EXPECT_EQ(icon_urlb, icon_mappings[0].icon_url); |
2417 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type); | 2307 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type); |
2418 EXPECT_EQ(icon_urlc, icon_mappings[1].icon_url); | |
2419 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type); | |
2420 } | 2308 } |
2421 | 2309 |
2422 // Test the results of GetFaviconsFromDB() when there are no found | 2310 // Test the results of GetFaviconsFromDB() when there are no found favicons. |
2423 // favicons. | |
2424 TEST_F(HistoryBackendTest, GetFaviconsFromDBEmpty) { | 2311 TEST_F(HistoryBackendTest, GetFaviconsFromDBEmpty) { |
2425 const GURL page_url("http://www.google.com/"); | 2312 const GURL page_url("http://www.google.com/"); |
2426 | 2313 |
2427 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; | 2314 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; |
2428 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, | 2315 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, |
2429 favicon_base::FAVICON, | 2316 favicon_base::FAVICON, |
2430 GetEdgeSizesSmallAndLarge(), | 2317 GetEdgeSizesSmallAndLarge(), |
2431 &bitmap_results)); | 2318 &bitmap_results)); |
2432 EXPECT_TRUE(bitmap_results.empty()); | 2319 EXPECT_TRUE(bitmap_results.empty()); |
2433 } | 2320 } |
(...skipping 15 matching lines...) Expand all Loading... |
2449 GetEdgeSizesSmallAndLarge(), | 2336 GetEdgeSizesSmallAndLarge(), |
2450 &bitmap_results_out)); | 2337 &bitmap_results_out)); |
2451 EXPECT_TRUE(bitmap_results_out.empty()); | 2338 EXPECT_TRUE(bitmap_results_out.empty()); |
2452 } | 2339 } |
2453 | 2340 |
2454 // Test that GetFaviconsFromDB() returns results for the bitmaps which most | 2341 // Test that GetFaviconsFromDB() returns results for the bitmaps which most |
2455 // closely match the passed in the desired pixel sizes. | 2342 // closely match the passed in the desired pixel sizes. |
2456 TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) { | 2343 TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) { |
2457 const GURL page_url("http://www.google.com/"); | 2344 const GURL page_url("http://www.google.com/"); |
2458 const GURL icon_url("http://www.google.com/icon1"); | 2345 const GURL icon_url("http://www.google.com/icon1"); |
| 2346 std::vector<SkBitmap> bitmaps; |
| 2347 bitmaps.push_back(CreateBitmap(SK_ColorWHITE, kTinyEdgeSize)); |
| 2348 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
| 2349 bitmaps.push_back(CreateBitmap(SK_ColorRED, kLargeEdgeSize)); |
2459 | 2350 |
2460 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 2351 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url, bitmaps); |
2461 GenerateFaviconBitmapData(icon_url, GetEdgeSizesTinySmallAndLarge(), | |
2462 &favicon_bitmap_data); | |
2463 | |
2464 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | |
2465 | 2352 |
2466 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; | 2353 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; |
2467 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, | 2354 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, |
2468 favicon_base::FAVICON, | 2355 favicon_base::FAVICON, |
2469 GetEdgeSizesSmallAndLarge(), | 2356 GetEdgeSizesSmallAndLarge(), |
2470 &bitmap_results_out)); | 2357 &bitmap_results_out)); |
2471 | 2358 |
2472 // The bitmap data for the small and large bitmaps should be returned as their | 2359 // The bitmap data for the small and large bitmaps should be returned as their |
2473 // sizes match exactly. | 2360 // sizes match exactly. |
2474 EXPECT_EQ(2u, bitmap_results_out.size()); | 2361 EXPECT_EQ(2u, bitmap_results_out.size()); |
2475 // No required order for results. | 2362 // No required order for results. |
2476 if (bitmap_results_out[0].pixel_size == kLargeSize) { | 2363 if (bitmap_results_out[0].pixel_size == kLargeSize) { |
2477 favicon_base::FaviconRawBitmapResult tmp_result = bitmap_results_out[0]; | 2364 favicon_base::FaviconRawBitmapResult tmp_result = bitmap_results_out[0]; |
2478 bitmap_results_out[0] = bitmap_results_out[1]; | 2365 bitmap_results_out[0] = bitmap_results_out[1]; |
2479 bitmap_results_out[1] = tmp_result; | 2366 bitmap_results_out[1] = tmp_result; |
2480 } | 2367 } |
2481 | 2368 |
2482 EXPECT_FALSE(bitmap_results_out[0].expired); | 2369 EXPECT_FALSE(bitmap_results_out[0].expired); |
2483 EXPECT_TRUE(BitmapDataEqual('b', bitmap_results_out[0].bitmap_data)); | 2370 EXPECT_TRUE( |
| 2371 BitmapColorEqual(SK_ColorBLUE, bitmap_results_out[0].bitmap_data)); |
2484 EXPECT_EQ(kSmallSize, bitmap_results_out[0].pixel_size); | 2372 EXPECT_EQ(kSmallSize, bitmap_results_out[0].pixel_size); |
2485 EXPECT_EQ(icon_url, bitmap_results_out[0].icon_url); | 2373 EXPECT_EQ(icon_url, bitmap_results_out[0].icon_url); |
2486 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type); | 2374 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type); |
2487 | 2375 |
2488 EXPECT_FALSE(bitmap_results_out[1].expired); | 2376 EXPECT_FALSE(bitmap_results_out[1].expired); |
2489 EXPECT_TRUE(BitmapDataEqual('c', bitmap_results_out[1].bitmap_data)); | 2377 EXPECT_TRUE(BitmapColorEqual(SK_ColorRED, bitmap_results_out[1].bitmap_data)); |
2490 EXPECT_EQ(kLargeSize, bitmap_results_out[1].pixel_size); | 2378 EXPECT_EQ(kLargeSize, bitmap_results_out[1].pixel_size); |
2491 EXPECT_EQ(icon_url, bitmap_results_out[1].icon_url); | 2379 EXPECT_EQ(icon_url, bitmap_results_out[1].icon_url); |
2492 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[1].icon_type); | 2380 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[1].icon_type); |
2493 } | 2381 } |
2494 | 2382 |
2495 // Test that GetFaviconsFromDB() returns results from the icon URL whose | |
2496 // bitmaps most closely match the passed in desired sizes. | |
2497 TEST_F(HistoryBackendTest, GetFaviconsFromDBSingleIconURL) { | |
2498 const GURL page_url("http://www.google.com/"); | |
2499 | |
2500 const GURL icon_url1("http://www.google.com/icon1"); | |
2501 const GURL icon_url2("http://www.google.com/icon2"); | |
2502 | |
2503 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | |
2504 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(), icon_url2, | |
2505 GetEdgeSizesLarge(), &favicon_bitmap_data); | |
2506 | |
2507 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | |
2508 | |
2509 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; | |
2510 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, | |
2511 favicon_base::FAVICON, | |
2512 GetEdgeSizesSmallAndLarge(), | |
2513 &bitmap_results_out)); | |
2514 | |
2515 // The results should have results for the icon URL with the large bitmap as | |
2516 // downscaling is preferred to upscaling. | |
2517 EXPECT_EQ(1u, bitmap_results_out.size()); | |
2518 EXPECT_EQ(kLargeSize, bitmap_results_out[0].pixel_size); | |
2519 EXPECT_EQ(icon_url2, bitmap_results_out[0].icon_url); | |
2520 } | |
2521 | |
2522 // Test the results of GetFaviconsFromDB() when called with different | 2383 // Test the results of GetFaviconsFromDB() when called with different |
2523 // |icon_types|. | 2384 // |icon_types|. |
2524 TEST_F(HistoryBackendTest, GetFaviconsFromDBIconType) { | 2385 TEST_F(HistoryBackendTest, GetFaviconsFromDBIconType) { |
2525 const GURL page_url("http://www.google.com/"); | 2386 const GURL page_url("http://www.google.com/"); |
2526 const GURL icon_url1("http://www.google.com/icon1.png"); | 2387 const GURL icon_url1("http://www.google.com/icon1.png"); |
2527 const GURL icon_url2("http://www.google.com/icon2.png"); | 2388 const GURL icon_url2("http://www.google.com/icon2.png"); |
| 2389 std::vector<SkBitmap> bitmaps; |
| 2390 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
2528 | 2391 |
2529 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 2392 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; |
2530 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(), | 2393 backend_->SetFavicon(page_url, favicon_base::FAVICON, icon_url1, bitmaps); |
2531 &favicon_bitmap_data); | 2394 backend_->SetFavicon(page_url, favicon_base::TOUCH_ICON, icon_url2, bitmaps); |
2532 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); | |
2533 | |
2534 GenerateFaviconBitmapData( | |
2535 icon_url2, GetEdgeSizesSmall(), &favicon_bitmap_data); | |
2536 backend_->SetFavicons( | |
2537 page_url, favicon_base::TOUCH_ICON, favicon_bitmap_data); | |
2538 | 2395 |
2539 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; | 2396 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; |
2540 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, | 2397 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, |
2541 favicon_base::FAVICON, | 2398 favicon_base::FAVICON, |
2542 GetEdgeSizesSmallAndLarge(), | 2399 GetEdgeSizesSmallAndLarge(), |
2543 &bitmap_results_out)); | 2400 &bitmap_results_out)); |
2544 | 2401 |
2545 EXPECT_EQ(1u, bitmap_results_out.size()); | 2402 EXPECT_EQ(1u, bitmap_results_out.size()); |
2546 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type); | 2403 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type); |
2547 EXPECT_EQ(icon_url1, bitmap_results_out[0].icon_url); | 2404 EXPECT_EQ(icon_url1, bitmap_results_out[0].icon_url); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2598 &bitmap_results); | 2455 &bitmap_results); |
2599 | 2456 |
2600 EXPECT_TRUE(bitmap_results.empty()); | 2457 EXPECT_TRUE(bitmap_results.empty()); |
2601 } | 2458 } |
2602 | 2459 |
2603 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { | 2460 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { |
2604 const GURL url("http://www.google.com/"); | 2461 const GURL url("http://www.google.com/"); |
2605 const GURL same_domain_url("http://www.google.com/subdir/index.html"); | 2462 const GURL same_domain_url("http://www.google.com/subdir/index.html"); |
2606 const GURL foreign_domain_url("http://www.not-google.com/"); | 2463 const GURL foreign_domain_url("http://www.not-google.com/"); |
2607 const GURL icon_url("http://www.google.com/icon.png"); | 2464 const GURL icon_url("http://www.google.com/icon.png"); |
| 2465 std::vector<SkBitmap> bitmaps; |
| 2466 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); |
2608 | 2467 |
2609 // Add a favicon | 2468 // Add a favicon |
2610 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; | 2469 backend_->SetFavicon(url, favicon_base::FAVICON, icon_url, bitmaps); |
2611 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(), | |
2612 &favicon_bitmap_data); | |
2613 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data); | |
2614 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 2470 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
2615 url, favicon_base::FAVICON, NULL)); | 2471 url, favicon_base::FAVICON, NULL)); |
2616 | 2472 |
2617 // Validate starting state. | 2473 // Validate starting state. |
2618 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; | 2474 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; |
2619 EXPECT_TRUE(backend_->GetFaviconsFromDB(url, | 2475 EXPECT_TRUE(backend_->GetFaviconsFromDB(url, |
2620 favicon_base::FAVICON, | 2476 favicon_base::FAVICON, |
2621 GetEdgeSizesSmallAndLarge(), | 2477 GetEdgeSizesSmallAndLarge(), |
2622 &bitmap_results_out)); | 2478 &bitmap_results_out)); |
2623 EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url, | 2479 EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url, |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3336 // Verify that the second term is no longer returned as result, and also check | 3192 // 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 | 3193 // at the low level that it is gone for good. The term corresponding to the |
3338 // first URLRow should not be affected. | 3194 // first URLRow should not be affected. |
3339 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3195 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
3340 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3196 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
3341 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3197 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
3342 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3198 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
3343 } | 3199 } |
3344 | 3200 |
3345 } // namespace history | 3201 } // namespace history |
OLD | NEW |