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

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

Issue 330603004: Rename FaviconBitmapXxx to FaviconRawBitmapXxx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // history unit test. Because of the elaborate callbacks involved, this is no 46 // history unit test. Because of the elaborate callbacks involved, this is no
47 // harder than calling it directly for many things. 47 // harder than calling it directly for many things.
48 48
49 namespace { 49 namespace {
50 50
51 static const gfx::Size kTinySize = gfx::Size(10, 10); 51 static const gfx::Size kTinySize = gfx::Size(10, 10);
52 static const gfx::Size kSmallSize = gfx::Size(16, 16); 52 static const gfx::Size kSmallSize = gfx::Size(16, 16);
53 static const gfx::Size kLargeSize = gfx::Size(32, 32); 53 static const gfx::Size kLargeSize = gfx::Size(32, 32);
54 54
55 // Comparison functions as to make it easier to check results of 55 // Comparison functions as to make it easier to check results of
56 // GetFaviconBitmaps() and GetIconMappingsForPageURL(). 56 // GetFaviconRawBitmaps() and GetIconMappingsForPageURL().
57 bool IconMappingLessThan(const history::IconMapping& a, 57 bool IconMappingLessThan(const history::IconMapping& a,
58 const history::IconMapping& b) { 58 const history::IconMapping& b) {
59 return a.icon_url < b.icon_url; 59 return a.icon_url < b.icon_url;
60 } 60 }
61 61
62 bool FaviconBitmapLessThan(const history::FaviconBitmap& a, 62 bool FaviconRawBitmapLessThan(const history::FaviconRawBitmap& a,
63 const history::FaviconBitmap& b) { 63 const history::FaviconRawBitmap& b) {
64 return a.pixel_size.GetArea() < b.pixel_size.GetArea(); 64 return a.pixel_size.GetArea() < b.pixel_size.GetArea();
65 } 65 }
66 66
67 class HistoryClientMock : public history::HistoryClientFakeBookmarks { 67 class HistoryClientMock : public history::HistoryClientFakeBookmarks {
68 public: 68 public:
69 MOCK_METHOD0(BlockUntilBookmarksLoaded, void()); 69 MOCK_METHOD0(BlockUntilBookmarksLoaded, void());
70 }; 70 };
71 71
72 } // namespace 72 } // namespace
73 73
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 icon_mappings)) { 353 icon_mappings)) {
354 return false; 354 return false;
355 } 355 }
356 std::sort(icon_mappings->begin(), icon_mappings->end(), 356 std::sort(icon_mappings->begin(), icon_mappings->end(),
357 IconMappingLessThan); 357 IconMappingLessThan);
358 return true; 358 return true;
359 } 359 }
360 360
361 // Returns the favicon bitmaps for |icon_id| sorted by pixel size in 361 // Returns the favicon bitmaps for |icon_id| sorted by pixel size in
362 // ascending order. Returns true if there is at least one favicon bitmap. 362 // ascending order. Returns true if there is at least one favicon bitmap.
363 bool GetSortedFaviconBitmaps(favicon_base::FaviconID icon_id, 363 bool GetSortedFaviconRawBitmaps(
364 std::vector<FaviconBitmap>* favicon_bitmaps) { 364 favicon_base::FaviconID icon_id,
365 if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, favicon_bitmaps)) 365 std::vector<FaviconRawBitmap>* favicon_bitmaps) {
366 if (!backend_->thumbnail_db_->GetFaviconRawBitmaps(icon_id,
367 favicon_bitmaps))
366 return false; 368 return false;
367 std::sort(favicon_bitmaps->begin(), favicon_bitmaps->end(), 369 std::sort(favicon_bitmaps->begin(),
368 FaviconBitmapLessThan); 370 favicon_bitmaps->end(),
371 FaviconRawBitmapLessThan);
369 return true; 372 return true;
370 } 373 }
371 374
372 // Returns true if there is exactly one favicon bitmap associated to 375 // Returns true if there is exactly one favicon bitmap associated to
373 // |favicon_id|. If true, returns favicon bitmap in output parameter. 376 // |favicon_id|. If true, returns favicon bitmap in output parameter.
374 bool GetOnlyFaviconBitmap(const favicon_base::FaviconID icon_id, 377 bool GetOnlyFaviconRawBitmap(const favicon_base::FaviconID icon_id,
375 FaviconBitmap* favicon_bitmap) { 378 FaviconRawBitmap* favicon_bitmap) {
376 std::vector<FaviconBitmap> favicon_bitmaps; 379 std::vector<FaviconRawBitmap> favicon_bitmaps;
377 if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, &favicon_bitmaps)) 380 if (!backend_->thumbnail_db_->GetFaviconRawBitmaps(icon_id,
381 &favicon_bitmaps))
378 return false; 382 return false;
379 if (favicon_bitmaps.size() != 1) 383 if (favicon_bitmaps.size() != 1)
380 return false; 384 return false;
381 *favicon_bitmap = favicon_bitmaps[0]; 385 *favicon_bitmap = favicon_bitmaps[0];
382 return true; 386 return true;
383 } 387 }
384 388
385 // Generates |favicon_bitmap_data| with entries for the icon_urls and sizes 389 // Generates |favicon_bitmap_data| with entries for the icon_urls and sizes
386 // specified. The bitmap_data for entries are lowercase letters of the 390 // specified. The bitmap_data for entries are lowercase letters of the
387 // alphabet starting at 'a' for the entry at index 0. 391 // alphabet starting at 'a' for the entry at index 0.
388 void GenerateFaviconBitmapData( 392 void GenerateFaviconRawBitmapData(
389 const GURL& icon_url1, 393 const GURL& icon_url1,
390 const std::vector<gfx::Size>& icon_url1_sizes, 394 const std::vector<gfx::Size>& icon_url1_sizes,
391 std::vector<favicon_base::FaviconBitmapData>* favicon_bitmap_data) { 395 std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) {
392 GenerateFaviconBitmapData(icon_url1, icon_url1_sizes, GURL(), 396 GenerateFaviconRawBitmapData(icon_url1,
393 std::vector<gfx::Size>(), favicon_bitmap_data); 397 icon_url1_sizes,
398 GURL(),
399 std::vector<gfx::Size>(),
400 favicon_bitmap_data);
394 } 401 }
395 402
396 void GenerateFaviconBitmapData( 403 void GenerateFaviconRawBitmapData(
397 const GURL& icon_url1, 404 const GURL& icon_url1,
398 const std::vector<gfx::Size>& icon_url1_sizes, 405 const std::vector<gfx::Size>& icon_url1_sizes,
399 const GURL& icon_url2, 406 const GURL& icon_url2,
400 const std::vector<gfx::Size>& icon_url2_sizes, 407 const std::vector<gfx::Size>& icon_url2_sizes,
401 std::vector<favicon_base::FaviconBitmapData>* favicon_bitmap_data) { 408 std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) {
402 favicon_bitmap_data->clear(); 409 favicon_bitmap_data->clear();
403 410
404 char bitmap_char = 'a'; 411 char bitmap_char = 'a';
405 for (size_t i = 0; i < icon_url1_sizes.size(); ++i) { 412 for (size_t i = 0; i < icon_url1_sizes.size(); ++i) {
406 std::vector<unsigned char> data; 413 std::vector<unsigned char> data;
407 data.push_back(bitmap_char); 414 data.push_back(bitmap_char);
408 favicon_base::FaviconBitmapData bitmap_data_element; 415 favicon_base::FaviconRawBitmapData bitmap_data_element;
409 bitmap_data_element.bitmap_data = 416 bitmap_data_element.bitmap_data =
410 base::RefCountedBytes::TakeVector(&data); 417 base::RefCountedBytes::TakeVector(&data);
411 bitmap_data_element.pixel_size = icon_url1_sizes[i]; 418 bitmap_data_element.pixel_size = icon_url1_sizes[i];
412 bitmap_data_element.icon_url = icon_url1; 419 bitmap_data_element.icon_url = icon_url1;
413 favicon_bitmap_data->push_back(bitmap_data_element); 420 favicon_bitmap_data->push_back(bitmap_data_element);
414 421
415 ++bitmap_char; 422 ++bitmap_char;
416 } 423 }
417 424
418 for (size_t i = 0; i < icon_url2_sizes.size(); ++i) { 425 for (size_t i = 0; i < icon_url2_sizes.size(); ++i) {
419 std::vector<unsigned char> data; 426 std::vector<unsigned char> data;
420 data.push_back(bitmap_char); 427 data.push_back(bitmap_char);
421 favicon_base::FaviconBitmapData bitmap_data_element; 428 favicon_base::FaviconRawBitmapData bitmap_data_element;
422 bitmap_data_element.bitmap_data = 429 bitmap_data_element.bitmap_data =
423 base::RefCountedBytes::TakeVector(&data); 430 base::RefCountedBytes::TakeVector(&data);
424 bitmap_data_element.pixel_size = icon_url2_sizes[i]; 431 bitmap_data_element.pixel_size = icon_url2_sizes[i];
425 bitmap_data_element.icon_url = icon_url2; 432 bitmap_data_element.icon_url = icon_url2;
426 favicon_bitmap_data->push_back(bitmap_data_element); 433 favicon_bitmap_data->push_back(bitmap_data_element);
427 434
428 ++bitmap_char; 435 ++bitmap_char;
429 } 436 }
430 } 437 }
431 438
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 // we can test that updating works properly. 561 // we can test that updating works properly.
555 GURL favicon_url1("http://www.google.com/favicon.ico"); 562 GURL favicon_url1("http://www.google.com/favicon.ico");
556 GURL favicon_url2("http://news.google.com/favicon.ico"); 563 GURL favicon_url2("http://news.google.com/favicon.ico");
557 favicon_base::FaviconID favicon2 = 564 favicon_base::FaviconID favicon2 =
558 backend_->thumbnail_db_->AddFavicon(favicon_url2, favicon_base::FAVICON); 565 backend_->thumbnail_db_->AddFavicon(favicon_url2, favicon_base::FAVICON);
559 favicon_base::FaviconID favicon1 = 566 favicon_base::FaviconID favicon1 =
560 backend_->thumbnail_db_->AddFavicon(favicon_url1, favicon_base::FAVICON); 567 backend_->thumbnail_db_->AddFavicon(favicon_url1, favicon_base::FAVICON);
561 568
562 std::vector<unsigned char> data; 569 std::vector<unsigned char> data;
563 data.push_back('a'); 570 data.push_back('a');
564 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1, 571 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconRawBitmap(
565 new base::RefCountedBytes(data), Time::Now(), kSmallSize)); 572 favicon1, new base::RefCountedBytes(data), Time::Now(), kSmallSize));
566 data[0] = 'b'; 573 data[0] = 'b';
567 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1, 574 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconRawBitmap(
568 new base::RefCountedBytes(data), Time::Now(), kLargeSize)); 575 favicon1, new base::RefCountedBytes(data), Time::Now(), kLargeSize));
569 576
570 data[0] = 'c'; 577 data[0] = 'c';
571 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon2, 578 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconRawBitmap(
572 new base::RefCountedBytes(data), Time::Now(), kSmallSize)); 579 favicon2, new base::RefCountedBytes(data), Time::Now(), kSmallSize));
573 data[0] = 'd'; 580 data[0] = 'd';
574 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon2, 581 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconRawBitmap(
575 new base::RefCountedBytes(data), Time::Now(), kLargeSize)); 582 favicon2, new base::RefCountedBytes(data), Time::Now(), kLargeSize));
576 583
577 // First visit two URLs. 584 // First visit two URLs.
578 URLRow row1(GURL("http://www.google.com/")); 585 URLRow row1(GURL("http://www.google.com/"));
579 row1.set_visit_count(2); 586 row1.set_visit_count(2);
580 row1.set_typed_count(1); 587 row1.set_typed_count(1);
581 row1.set_last_visit(Time::Now()); 588 row1.set_last_visit(Time::Now());
582 backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1); 589 backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1);
583 590
584 URLRow row2(GURL("http://news.google.com/")); 591 URLRow row2(GURL("http://news.google.com/"));
585 row2.set_visit_count(1); 592 row2.set_visit_count(1);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); 639 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits);
633 ASSERT_EQ(0U, all_visits.size()); 640 ASSERT_EQ(0U, all_visits.size());
634 641
635 // We should have a favicon and favicon bitmaps for the first URL only. We 642 // We should have a favicon and favicon bitmaps for the first URL only. We
636 // look them up by favicon URL since the IDs may have changed. 643 // look them up by favicon URL since the IDs may have changed.
637 favicon_base::FaviconID out_favicon1 = 644 favicon_base::FaviconID out_favicon1 =
638 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 645 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
639 favicon_url1, favicon_base::FAVICON, NULL); 646 favicon_url1, favicon_base::FAVICON, NULL);
640 EXPECT_TRUE(out_favicon1); 647 EXPECT_TRUE(out_favicon1);
641 648
642 std::vector<FaviconBitmap> favicon_bitmaps; 649 std::vector<FaviconRawBitmap> favicon_bitmaps;
643 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( 650 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconRawBitmaps(out_favicon1,
644 out_favicon1, &favicon_bitmaps)); 651 &favicon_bitmaps));
645 ASSERT_EQ(2u, favicon_bitmaps.size()); 652 ASSERT_EQ(2u, favicon_bitmaps.size());
646 653
647 FaviconBitmap favicon_bitmap1 = favicon_bitmaps[0]; 654 FaviconRawBitmap favicon_bitmap1 = favicon_bitmaps[0];
648 FaviconBitmap favicon_bitmap2 = favicon_bitmaps[1]; 655 FaviconRawBitmap favicon_bitmap2 = favicon_bitmaps[1];
649 656
650 // Favicon bitmaps do not need to be in particular order. 657 // Favicon bitmaps do not need to be in particular order.
651 if (favicon_bitmap1.pixel_size == kLargeSize) { 658 if (favicon_bitmap1.pixel_size == kLargeSize) {
652 FaviconBitmap tmp_favicon_bitmap = favicon_bitmap1; 659 FaviconRawBitmap tmp_favicon_bitmap = favicon_bitmap1;
653 favicon_bitmap1 = favicon_bitmap2; 660 favicon_bitmap1 = favicon_bitmap2;
654 favicon_bitmap2 = tmp_favicon_bitmap; 661 favicon_bitmap2 = tmp_favicon_bitmap;
655 } 662 }
656 663
657 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap1.bitmap_data)); 664 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap1.bitmap_data));
658 EXPECT_EQ(kSmallSize, favicon_bitmap1.pixel_size); 665 EXPECT_EQ(kSmallSize, favicon_bitmap1.pixel_size);
659 666
660 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap2.bitmap_data)); 667 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap2.bitmap_data));
661 EXPECT_EQ(kLargeSize, favicon_bitmap2.pixel_size); 668 EXPECT_EQ(kLargeSize, favicon_bitmap2.pixel_size);
662 669
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 1537
1531 history::RedirectList redirects; 1538 history::RedirectList redirects;
1532 redirects.push_back(url2); 1539 redirects.push_back(url2);
1533 redirects.push_back(url1); 1540 redirects.push_back(url1);
1534 backend_->recent_redirects_.Put(url1, redirects); 1541 backend_->recent_redirects_.Put(url1, redirects);
1535 1542
1536 const GURL icon_url1("http://www.google.com/icon"); 1543 const GURL icon_url1("http://www.google.com/icon");
1537 const GURL icon_url2("http://www.google.com/icon2"); 1544 const GURL icon_url2("http://www.google.com/icon2");
1538 1545
1539 // Generate bitmap data for a page with two favicons. 1546 // Generate bitmap data for a page with two favicons.
1540 std::vector<favicon_base::FaviconBitmapData> two_favicon_bitmap_data; 1547 std::vector<favicon_base::FaviconRawBitmapData> two_favicon_bitmap_data;
1541 GenerateFaviconBitmapData(icon_url1, GetSizesSmallAndLarge(), 1548 GenerateFaviconRawBitmapData(icon_url1,
1542 icon_url2, GetSizesSmallAndLarge(), &two_favicon_bitmap_data); 1549 GetSizesSmallAndLarge(),
1550 icon_url2,
1551 GetSizesSmallAndLarge(),
1552 &two_favicon_bitmap_data);
1543 1553
1544 // Generate bitmap data for a page with a single favicon. 1554 // Generate bitmap data for a page with a single favicon.
1545 std::vector<favicon_base::FaviconBitmapData> one_favicon_bitmap_data; 1555 std::vector<favicon_base::FaviconRawBitmapData> one_favicon_bitmap_data;
1546 GenerateFaviconBitmapData(icon_url1, GetSizesSmallAndLarge(), 1556 GenerateFaviconRawBitmapData(
1547 &one_favicon_bitmap_data); 1557 icon_url1, GetSizesSmallAndLarge(), &one_favicon_bitmap_data);
1548 1558
1549 // Add two favicons 1559 // Add two favicons
1550 backend_->SetFavicons(url1, favicon_base::FAVICON, two_favicon_bitmap_data); 1560 backend_->SetFavicons(url1, favicon_base::FAVICON, two_favicon_bitmap_data);
1551 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); 1561 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
1552 EXPECT_EQ(2u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON)); 1562 EXPECT_EQ(2u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON));
1553 1563
1554 // Add one touch_icon 1564 // Add one touch_icon
1555 backend_->SetFavicons( 1565 backend_->SetFavicons(
1556 url1, favicon_base::TOUCH_ICON, one_favicon_bitmap_data); 1566 url1, favicon_base::TOUCH_ICON, one_favicon_bitmap_data);
1557 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); 1567 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON)); 1602 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, favicon_base::TOUCH_ICON));
1593 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); 1603 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
1594 } 1604 }
1595 1605
1596 // Test that there is no churn in icon mappings from calling 1606 // Test that there is no churn in icon mappings from calling
1597 // SetFavicons() twice with the same |favicon_bitmap_data| parameter. 1607 // SetFavicons() twice with the same |favicon_bitmap_data| parameter.
1598 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageDuplicates) { 1608 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageDuplicates) {
1599 const GURL url("http://www.google.com/"); 1609 const GURL url("http://www.google.com/");
1600 const GURL icon_url("http://www.google.com/icon"); 1610 const GURL icon_url("http://www.google.com/icon");
1601 1611
1602 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 1612 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1603 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(), 1613 GenerateFaviconRawBitmapData(
1604 &favicon_bitmap_data); 1614 icon_url, GetSizesSmallAndLarge(), &favicon_bitmap_data);
1605 1615
1606 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data); 1616 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data);
1607 1617
1608 std::vector<IconMapping> icon_mappings; 1618 std::vector<IconMapping> icon_mappings;
1609 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1619 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1610 url, favicon_base::FAVICON, &icon_mappings)); 1620 url, favicon_base::FAVICON, &icon_mappings));
1611 EXPECT_EQ(1u, icon_mappings.size()); 1621 EXPECT_EQ(1u, icon_mappings.size());
1612 IconMappingID mapping_id = icon_mappings[0].mapping_id; 1622 IconMappingID mapping_id = icon_mappings[0].mapping_id;
1613 1623
1614 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data); 1624 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data);
1615 1625
1616 icon_mappings.clear(); 1626 icon_mappings.clear();
1617 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1627 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1618 url, favicon_base::FAVICON, &icon_mappings)); 1628 url, favicon_base::FAVICON, &icon_mappings));
1619 EXPECT_EQ(1u, icon_mappings.size()); 1629 EXPECT_EQ(1u, icon_mappings.size());
1620 1630
1621 // The same row in the icon_mapping table should be used for the mapping as 1631 // The same row in the icon_mapping table should be used for the mapping as
1622 // before. 1632 // before.
1623 EXPECT_EQ(mapping_id, icon_mappings[0].mapping_id); 1633 EXPECT_EQ(mapping_id, icon_mappings[0].mapping_id);
1624 } 1634 }
1625 1635
1626 // Test that calling SetFavicons() with FaviconBitmapData of different pixel 1636 // Test that calling SetFavicons() with FaviconRawBitmapData of different pixel
1627 // sizes than the initially passed in FaviconBitmapData deletes the no longer 1637 // sizes than the initially passed in FaviconRawBitmapData deletes the no longer
1628 // used favicon bitmaps. 1638 // used favicon bitmaps.
1629 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) { 1639 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) {
1630 const GURL page_url("http://www.google.com/"); 1640 const GURL page_url("http://www.google.com/");
1631 const GURL icon_url("http://www.google.com/icon"); 1641 const GURL icon_url("http://www.google.com/icon");
1632 1642
1633 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 1643 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1634 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(), 1644 GenerateFaviconRawBitmapData(
1635 &favicon_bitmap_data); 1645 icon_url, GetSizesSmallAndLarge(), &favicon_bitmap_data);
1636 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1646 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1637 1647
1638 // Test initial state. 1648 // Test initial state.
1639 std::vector<IconMapping> icon_mappings; 1649 std::vector<IconMapping> icon_mappings;
1640 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings)); 1650 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings));
1641 EXPECT_EQ(1u, icon_mappings.size()); 1651 EXPECT_EQ(1u, icon_mappings.size());
1642 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); 1652 EXPECT_EQ(icon_url, icon_mappings[0].icon_url);
1643 EXPECT_EQ(favicon_base::FAVICON, icon_mappings[0].icon_type); 1653 EXPECT_EQ(favicon_base::FAVICON, icon_mappings[0].icon_type);
1644 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id; 1654 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id;
1645 1655
1646 std::vector<FaviconBitmap> favicon_bitmaps; 1656 std::vector<FaviconRawBitmap> favicon_bitmaps;
1647 EXPECT_TRUE(GetSortedFaviconBitmaps(favicon_id, &favicon_bitmaps)); 1657 EXPECT_TRUE(GetSortedFaviconRawBitmaps(favicon_id, &favicon_bitmaps));
1648 EXPECT_EQ(2u, favicon_bitmaps.size()); 1658 EXPECT_EQ(2u, favicon_bitmaps.size());
1649 FaviconBitmapID small_bitmap_id = favicon_bitmaps[0].bitmap_id; 1659 FaviconRawBitmapID small_bitmap_id = favicon_bitmaps[0].bitmap_id;
1650 EXPECT_NE(0, small_bitmap_id); 1660 EXPECT_NE(0, small_bitmap_id);
1651 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmaps[0].bitmap_data)); 1661 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmaps[0].bitmap_data));
1652 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size); 1662 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size);
1653 FaviconBitmapID large_bitmap_id = favicon_bitmaps[1].bitmap_id; 1663 FaviconRawBitmapID large_bitmap_id = favicon_bitmaps[1].bitmap_id;
1654 EXPECT_NE(0, large_bitmap_id); 1664 EXPECT_NE(0, large_bitmap_id);
1655 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data)); 1665 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data));
1656 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size); 1666 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size);
1657 1667
1658 // Call SetFavicons() with bitmap data for only the large bitmap. Check that 1668 // Call SetFavicons() with bitmap data for only the large bitmap. Check that
1659 // the small bitmap is in fact deleted. 1669 // the small bitmap is in fact deleted.
1660 GenerateFaviconBitmapData(icon_url, GetSizesLarge(), &favicon_bitmap_data); 1670 GenerateFaviconRawBitmapData(icon_url, GetSizesLarge(), &favicon_bitmap_data);
1661 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1671 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1662 1672
1663 scoped_refptr<base::RefCountedMemory> bitmap_data_out; 1673 scoped_refptr<base::RefCountedMemory> bitmap_data_out;
1664 gfx::Size pixel_size_out; 1674 gfx::Size pixel_size_out;
1665 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(small_bitmap_id, 1675 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconRawBitmap(
1666 NULL, &bitmap_data_out, &pixel_size_out)); 1676 small_bitmap_id, NULL, &bitmap_data_out, &pixel_size_out));
1667 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, 1677 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconRawBitmap(
1668 NULL, &bitmap_data_out, &pixel_size_out)); 1678 large_bitmap_id, NULL, &bitmap_data_out, &pixel_size_out));
1669 EXPECT_TRUE(BitmapDataEqual('a', bitmap_data_out)); 1679 EXPECT_TRUE(BitmapDataEqual('a', bitmap_data_out));
1670 EXPECT_EQ(kLargeSize, pixel_size_out); 1680 EXPECT_EQ(kLargeSize, pixel_size_out);
1671 1681
1672 icon_mappings.clear(); 1682 icon_mappings.clear();
1673 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1683 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1674 &icon_mappings)); 1684 &icon_mappings));
1675 EXPECT_EQ(1u, icon_mappings.size()); 1685 EXPECT_EQ(1u, icon_mappings.size());
1676 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1686 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1677 1687
1678 // Call SetFavicons() with no bitmap data. Check that the bitmaps and icon 1688 // Call SetFavicons() with no bitmap data. Check that the bitmaps and icon
1679 // mappings are deleted. 1689 // mappings are deleted.
1680 favicon_bitmap_data.clear(); 1690 favicon_bitmap_data.clear();
1681 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1691 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1682 1692
1683 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, NULL, 1693 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconRawBitmap(
1684 NULL, NULL)); 1694 large_bitmap_id, NULL, NULL, NULL));
1685 icon_mappings.clear(); 1695 icon_mappings.clear();
1686 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1696 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1687 &icon_mappings)); 1697 &icon_mappings));
1688 1698
1689 // Notifications should have been broadcast for each call to SetFavicons(). 1699 // Notifications should have been broadcast for each call to SetFavicons().
1690 EXPECT_EQ(3, num_broadcasted_notifications()); 1700 EXPECT_EQ(3, num_broadcasted_notifications());
1691 } 1701 }
1692 1702
1693 // Test updating a single favicon bitmap's data via SetFavicons. 1703 // Test updating a single favicon bitmap's data via SetFavicons.
1694 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { 1704 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
1695 const GURL page_url("http://www.google.com/"); 1705 const GURL page_url("http://www.google.com/");
1696 const GURL icon_url("http://www.google.com/icon"); 1706 const GURL icon_url("http://www.google.com/icon");
1697 1707
1698 std::vector<unsigned char> data_initial; 1708 std::vector<unsigned char> data_initial;
1699 data_initial.push_back('a'); 1709 data_initial.push_back('a');
1700 1710
1701 favicon_base::FaviconBitmapData bitmap_data_element; 1711 favicon_base::FaviconRawBitmapData bitmap_data_element;
1702 bitmap_data_element.bitmap_data = 1712 bitmap_data_element.bitmap_data =
1703 base::RefCountedBytes::TakeVector(&data_initial); 1713 base::RefCountedBytes::TakeVector(&data_initial);
1704 bitmap_data_element.pixel_size = kSmallSize; 1714 bitmap_data_element.pixel_size = kSmallSize;
1705 bitmap_data_element.icon_url = icon_url; 1715 bitmap_data_element.icon_url = icon_url;
1706 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 1716 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1707 favicon_bitmap_data.push_back(bitmap_data_element); 1717 favicon_bitmap_data.push_back(bitmap_data_element);
1708 1718
1709 // Add bitmap to the database. 1719 // Add bitmap to the database.
1710 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1720 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1711 1721
1712 favicon_base::FaviconID original_favicon_id = 1722 favicon_base::FaviconID original_favicon_id =
1713 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1723 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1714 icon_url, favicon_base::FAVICON, NULL); 1724 icon_url, favicon_base::FAVICON, NULL);
1715 EXPECT_NE(0, original_favicon_id); 1725 EXPECT_NE(0, original_favicon_id);
1716 FaviconBitmap original_favicon_bitmap; 1726 FaviconRawBitmap original_favicon_bitmap;
1717 EXPECT_TRUE( 1727 EXPECT_TRUE(
1718 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap)); 1728 GetOnlyFaviconRawBitmap(original_favicon_id, &original_favicon_bitmap));
1719 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data)); 1729 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data));
1720 1730
1721 EXPECT_EQ(1, num_broadcasted_notifications()); 1731 EXPECT_EQ(1, num_broadcasted_notifications());
1722 1732
1723 // Call SetFavicons() with completely identical data. 1733 // Call SetFavicons() with completely identical data.
1724 std::vector<unsigned char> updated_data; 1734 std::vector<unsigned char> updated_data;
1725 updated_data.push_back('a'); 1735 updated_data.push_back('a');
1726 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data); 1736 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
1727 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1737 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1728 1738
1729 favicon_base::FaviconID updated_favicon_id = 1739 favicon_base::FaviconID updated_favicon_id =
1730 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1740 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1731 icon_url, favicon_base::FAVICON, NULL); 1741 icon_url, favicon_base::FAVICON, NULL);
1732 EXPECT_NE(0, updated_favicon_id); 1742 EXPECT_NE(0, updated_favicon_id);
1733 FaviconBitmap updated_favicon_bitmap; 1743 FaviconRawBitmap updated_favicon_bitmap;
1734 EXPECT_TRUE( 1744 EXPECT_TRUE(
1735 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); 1745 GetOnlyFaviconRawBitmap(updated_favicon_id, &updated_favicon_bitmap));
1736 EXPECT_TRUE(BitmapDataEqual('a', updated_favicon_bitmap.bitmap_data)); 1746 EXPECT_TRUE(BitmapDataEqual('a', updated_favicon_bitmap.bitmap_data));
1737 1747
1738 // Because the bitmap data is byte equivalent, no notifications should have 1748 // Because the bitmap data is byte equivalent, no notifications should have
1739 // been broadcasted. 1749 // been broadcasted.
1740 EXPECT_EQ(1, num_broadcasted_notifications()); 1750 EXPECT_EQ(1, num_broadcasted_notifications());
1741 1751
1742 // Call SetFavicons() with identical data but a different bitmap. 1752 // Call SetFavicons() with identical data but a different bitmap.
1743 updated_data[0] = 'b'; 1753 updated_data[0] = 'b';
1744 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data); 1754 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
1745 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1755 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1746 1756
1747 updated_favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1757 updated_favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1748 icon_url, favicon_base::FAVICON, NULL); 1758 icon_url, favicon_base::FAVICON, NULL);
1749 EXPECT_NE(0, updated_favicon_id); 1759 EXPECT_NE(0, updated_favicon_id);
1750 EXPECT_TRUE( 1760 EXPECT_TRUE(
1751 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); 1761 GetOnlyFaviconRawBitmap(updated_favicon_id, &updated_favicon_bitmap));
1752 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data)); 1762 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data));
1753 1763
1754 // There should be no churn in FaviconIDs or FaviconBitmapIds even though 1764 // There should be no churn in FaviconIDs or FaviconRawBitmapIds even though
1755 // the bitmap data changed. 1765 // the bitmap data changed.
1756 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id); 1766 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id);
1757 EXPECT_EQ(original_favicon_bitmap.bitmap_id, 1767 EXPECT_EQ(original_favicon_bitmap.bitmap_id,
1758 updated_favicon_bitmap.bitmap_id); 1768 updated_favicon_bitmap.bitmap_id);
1759 1769
1760 // A notification should have been broadcasted as the favicon bitmap data has 1770 // A notification should have been broadcasted as the favicon bitmap data has
1761 // changed. 1771 // changed.
1762 EXPECT_EQ(2, num_broadcasted_notifications()); 1772 EXPECT_EQ(2, num_broadcasted_notifications());
1763 } 1773 }
1764 1774
1765 // Test that if two pages share the same FaviconID, changing the favicon for 1775 // Test that if two pages share the same FaviconID, changing the favicon for
1766 // one page does not affect the other. 1776 // one page does not affect the other.
1767 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) { 1777 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
1768 GURL icon_url("http://www.google.com/favicon.ico"); 1778 GURL icon_url("http://www.google.com/favicon.ico");
1769 GURL icon_url_new("http://www.google.com/favicon2.ico"); 1779 GURL icon_url_new("http://www.google.com/favicon2.ico");
1770 GURL page_url1("http://www.google.com"); 1780 GURL page_url1("http://www.google.com");
1771 GURL page_url2("http://www.google.ca"); 1781 GURL page_url2("http://www.google.ca");
1772 1782
1773 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 1783 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1774 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(), 1784 GenerateFaviconRawBitmapData(
1775 &favicon_bitmap_data); 1785 icon_url, GetSizesSmallAndLarge(), &favicon_bitmap_data);
1776 1786
1777 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); 1787 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
1778 1788
1779 std::vector<GURL> icon_urls; 1789 std::vector<GURL> icon_urls;
1780 icon_urls.push_back(icon_url); 1790 icon_urls.push_back(icon_url);
1781 1791
1782 std::vector<favicon_base::FaviconBitmapResult> bitmap_results; 1792 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
1783 backend_->UpdateFaviconMappingsAndFetch(page_url2, 1793 backend_->UpdateFaviconMappingsAndFetch(page_url2,
1784 icon_urls, 1794 icon_urls,
1785 favicon_base::FAVICON, 1795 favicon_base::FAVICON,
1786 kSmallSize.width(), 1796 kSmallSize.width(),
1787 GetScaleFactors1x2x(), 1797 GetScaleFactors1x2x(),
1788 &bitmap_results); 1798 &bitmap_results);
1789 1799
1790 // Check that the same FaviconID is mapped to both page URLs. 1800 // Check that the same FaviconID is mapped to both page URLs.
1791 std::vector<IconMapping> icon_mappings; 1801 std::vector<IconMapping> icon_mappings;
1792 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1802 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1793 page_url1, &icon_mappings)); 1803 page_url1, &icon_mappings));
1794 EXPECT_EQ(1u, icon_mappings.size()); 1804 EXPECT_EQ(1u, icon_mappings.size());
1795 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id; 1805 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id;
1796 EXPECT_NE(0, favicon_id); 1806 EXPECT_NE(0, favicon_id);
1797 1807
1798 icon_mappings.clear(); 1808 icon_mappings.clear();
1799 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1809 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1800 page_url2, &icon_mappings)); 1810 page_url2, &icon_mappings));
1801 EXPECT_EQ(1u, icon_mappings.size()); 1811 EXPECT_EQ(1u, icon_mappings.size());
1802 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1812 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1803 1813
1804 // Change the icon URL that |page_url1| is mapped to. 1814 // Change the icon URL that |page_url1| is mapped to.
1805 GenerateFaviconBitmapData(icon_url_new, GetSizesSmall(), 1815 GenerateFaviconRawBitmapData(
1806 &favicon_bitmap_data); 1816 icon_url_new, GetSizesSmall(), &favicon_bitmap_data);
1807 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); 1817 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
1808 1818
1809 // |page_url1| should map to a new FaviconID and have valid bitmap data. 1819 // |page_url1| should map to a new FaviconID and have valid bitmap data.
1810 icon_mappings.clear(); 1820 icon_mappings.clear();
1811 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1821 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1812 page_url1, &icon_mappings)); 1822 page_url1, &icon_mappings));
1813 EXPECT_EQ(1u, icon_mappings.size()); 1823 EXPECT_EQ(1u, icon_mappings.size());
1814 EXPECT_EQ(icon_url_new, icon_mappings[0].icon_url); 1824 EXPECT_EQ(icon_url_new, icon_mappings[0].icon_url);
1815 EXPECT_NE(favicon_id, icon_mappings[0].icon_id); 1825 EXPECT_NE(favicon_id, icon_mappings[0].icon_id);
1816 1826
1817 std::vector<FaviconBitmap> favicon_bitmaps; 1827 std::vector<FaviconRawBitmap> favicon_bitmaps;
1818 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( 1828 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconRawBitmaps(
1819 icon_mappings[0].icon_id, &favicon_bitmaps)); 1829 icon_mappings[0].icon_id, &favicon_bitmaps));
1820 EXPECT_EQ(1u, favicon_bitmaps.size()); 1830 EXPECT_EQ(1u, favicon_bitmaps.size());
1821 1831
1822 // |page_url2| should still map to the same FaviconID and have valid bitmap 1832 // |page_url2| should still map to the same FaviconID and have valid bitmap
1823 // data. 1833 // data.
1824 icon_mappings.clear(); 1834 icon_mappings.clear();
1825 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1835 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1826 page_url2, &icon_mappings)); 1836 page_url2, &icon_mappings));
1827 EXPECT_EQ(1u, icon_mappings.size()); 1837 EXPECT_EQ(1u, icon_mappings.size());
1828 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1838 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1829 1839
1830 favicon_bitmaps.clear(); 1840 favicon_bitmaps.clear();
1831 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, 1841 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconRawBitmaps(favicon_id,
1832 &favicon_bitmaps)); 1842 &favicon_bitmaps));
1833 EXPECT_EQ(2u, favicon_bitmaps.size()); 1843 EXPECT_EQ(2u, favicon_bitmaps.size());
1834 1844
1835 // A notification should have been broadcast for each call to SetFavicons() 1845 // A notification should have been broadcast for each call to SetFavicons()
1836 // and each call to UpdateFaviconMappingsAndFetch(). 1846 // and each call to UpdateFaviconMappingsAndFetch().
1837 EXPECT_EQ(3, num_broadcasted_notifications()); 1847 EXPECT_EQ(3, num_broadcasted_notifications());
1838 } 1848 }
1839 1849
1840 // Test that no notifications are broadcast as a result of calling 1850 // Test that no notifications are broadcast as a result of calling
1841 // UpdateFaviconMappingsAndFetch() for an icon URL which is already 1851 // UpdateFaviconMappingsAndFetch() for an icon URL which is already
1842 // mapped to the passed in page URL. 1852 // mapped to the passed in page URL.
1843 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { 1853 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) {
1844 GURL page_url("http://www.google.com"); 1854 GURL page_url("http://www.google.com");
1845 GURL icon_url("http://www.google.com/favicon.ico"); 1855 GURL icon_url("http://www.google.com/favicon.ico");
1846 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 1856 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1847 GenerateFaviconBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data); 1857 GenerateFaviconRawBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data);
1848 1858
1849 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1859 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1850 1860
1851 favicon_base::FaviconID icon_id = 1861 favicon_base::FaviconID icon_id =
1852 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1862 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1853 icon_url, favicon_base::FAVICON, NULL); 1863 icon_url, favicon_base::FAVICON, NULL);
1854 EXPECT_NE(0, icon_id); 1864 EXPECT_NE(0, icon_id);
1855 EXPECT_EQ(1, num_broadcasted_notifications()); 1865 EXPECT_EQ(1, num_broadcasted_notifications());
1856 1866
1857 std::vector<GURL> icon_urls; 1867 std::vector<GURL> icon_urls;
1858 icon_urls.push_back(icon_url); 1868 icon_urls.push_back(icon_url);
1859 1869
1860 std::vector<favicon_base::FaviconBitmapResult> bitmap_results; 1870 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
1861 backend_->UpdateFaviconMappingsAndFetch(page_url, 1871 backend_->UpdateFaviconMappingsAndFetch(page_url,
1862 icon_urls, 1872 icon_urls,
1863 favicon_base::FAVICON, 1873 favicon_base::FAVICON,
1864 kSmallSize.width(), 1874 kSmallSize.width(),
1865 GetScaleFactors1x2x(), 1875 GetScaleFactors1x2x(),
1866 &bitmap_results); 1876 &bitmap_results);
1867 1877
1868 EXPECT_EQ(icon_id, 1878 EXPECT_EQ(icon_id,
1869 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1879 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1870 icon_url, favicon_base::FAVICON, NULL)); 1880 icon_url, favicon_base::FAVICON, NULL));
(...skipping 18 matching lines...) Expand all
1889 page_url, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize); 1899 page_url, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize);
1890 1900
1891 // |page_url| should now be mapped to |icon_url| and the favicon bitmap should 1901 // |page_url| should now be mapped to |icon_url| and the favicon bitmap should
1892 // not be expired. 1902 // not be expired.
1893 std::vector<IconMapping> icon_mappings; 1903 std::vector<IconMapping> icon_mappings;
1894 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1904 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1895 &icon_mappings)); 1905 &icon_mappings));
1896 EXPECT_EQ(1u, icon_mappings.size()); 1906 EXPECT_EQ(1u, icon_mappings.size());
1897 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); 1907 EXPECT_EQ(icon_url, icon_mappings[0].icon_url);
1898 1908
1899 FaviconBitmap favicon_bitmap; 1909 FaviconRawBitmap favicon_bitmap;
1900 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1910 EXPECT_TRUE(
1911 GetOnlyFaviconRawBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1901 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 1912 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1902 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 1913 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
1903 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1914 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1904 1915
1905 data[0] = 'b'; 1916 data[0] = 'b';
1906 bitmap_data = new base::RefCountedBytes(data); 1917 bitmap_data = new base::RefCountedBytes(data);
1907 backend_->MergeFavicon( 1918 backend_->MergeFavicon(
1908 page_url, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize); 1919 page_url, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize);
1909 1920
1910 // |page_url| should still have a single favicon bitmap. The bitmap data 1921 // |page_url| should still have a single favicon bitmap. The bitmap data
1911 // should be updated. 1922 // should be updated.
1912 icon_mappings.clear(); 1923 icon_mappings.clear();
1913 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1924 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1914 &icon_mappings)); 1925 &icon_mappings));
1915 EXPECT_EQ(1u, icon_mappings.size()); 1926 EXPECT_EQ(1u, icon_mappings.size());
1916 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); 1927 EXPECT_EQ(icon_url, icon_mappings[0].icon_url);
1917 1928
1918 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1929 EXPECT_TRUE(
1930 GetOnlyFaviconRawBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1919 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 1931 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1920 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); 1932 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data));
1921 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1933 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1922 } 1934 }
1923 1935
1924 // Test calling MergeFavicon() when |page_url| is known to the database. 1936 // Test calling MergeFavicon() when |page_url| is known to the database.
1925 TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) { 1937 TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) {
1926 GURL page_url("http://www.google.com"); 1938 GURL page_url("http://www.google.com");
1927 GURL icon_url1("http:/www.google.com/favicon.ico"); 1939 GURL icon_url1("http:/www.google.com/favicon.ico");
1928 GURL icon_url2("http://www.google.com/favicon2.ico"); 1940 GURL icon_url2("http://www.google.com/favicon2.ico");
1929 1941
1930 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 1942 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1931 GenerateFaviconBitmapData(icon_url1, GetSizesSmall(), 1943 GenerateFaviconRawBitmapData(
1932 &favicon_bitmap_data); 1944 icon_url1, GetSizesSmall(), &favicon_bitmap_data);
1933 1945
1934 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1946 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1935 1947
1936 // Test initial state. 1948 // Test initial state.
1937 std::vector<IconMapping> icon_mappings; 1949 std::vector<IconMapping> icon_mappings;
1938 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1950 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1939 &icon_mappings)); 1951 &icon_mappings));
1940 EXPECT_EQ(1u, icon_mappings.size()); 1952 EXPECT_EQ(1u, icon_mappings.size());
1941 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1953 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1942 1954
1943 FaviconBitmap favicon_bitmap; 1955 FaviconRawBitmap favicon_bitmap;
1944 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1956 EXPECT_TRUE(
1957 GetOnlyFaviconRawBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1945 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 1958 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1946 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 1959 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
1947 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1960 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1948 1961
1949 EXPECT_EQ(1, num_broadcasted_notifications()); 1962 EXPECT_EQ(1, num_broadcasted_notifications());
1950 1963
1951 // 1) Merge identical favicon bitmap. 1964 // 1) Merge identical favicon bitmap.
1952 std::vector<unsigned char> data; 1965 std::vector<unsigned char> data;
1953 data.push_back('a'); 1966 data.push_back('a');
1954 scoped_refptr<base::RefCountedBytes> bitmap_data( 1967 scoped_refptr<base::RefCountedBytes> bitmap_data(
1955 new base::RefCountedBytes(data)); 1968 new base::RefCountedBytes(data));
1956 backend_->MergeFavicon( 1969 backend_->MergeFavicon(
1957 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); 1970 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize);
1958 1971
1959 // All the data should stay the same and no notifications should have been 1972 // All the data should stay the same and no notifications should have been
1960 // sent. 1973 // sent.
1961 icon_mappings.clear(); 1974 icon_mappings.clear();
1962 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1975 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1963 &icon_mappings)); 1976 &icon_mappings));
1964 EXPECT_EQ(1u, icon_mappings.size()); 1977 EXPECT_EQ(1u, icon_mappings.size());
1965 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1978 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1966 1979
1967 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1980 EXPECT_TRUE(
1981 GetOnlyFaviconRawBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1968 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 1982 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1969 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 1983 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
1970 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1984 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1971 1985
1972 EXPECT_EQ(1, num_broadcasted_notifications()); 1986 EXPECT_EQ(1, num_broadcasted_notifications());
1973 1987
1974 // 2) Merge favicon bitmap of the same size. 1988 // 2) Merge favicon bitmap of the same size.
1975 data[0] = 'b'; 1989 data[0] = 'b';
1976 bitmap_data = new base::RefCountedBytes(data); 1990 bitmap_data = new base::RefCountedBytes(data);
1977 backend_->MergeFavicon( 1991 backend_->MergeFavicon(
1978 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize); 1992 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kSmallSize);
1979 1993
1980 // The small favicon bitmap at |icon_url1| should be overwritten. 1994 // The small favicon bitmap at |icon_url1| should be overwritten.
1981 icon_mappings.clear(); 1995 icon_mappings.clear();
1982 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1996 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1983 &icon_mappings)); 1997 &icon_mappings));
1984 EXPECT_EQ(1u, icon_mappings.size()); 1998 EXPECT_EQ(1u, icon_mappings.size());
1985 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1999 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1986 2000
1987 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 2001 EXPECT_TRUE(
2002 GetOnlyFaviconRawBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1988 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 2003 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1989 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); 2004 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data));
1990 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 2005 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1991 2006
1992 // 3) Merge favicon for the same icon URL, but a pixel size for which there is 2007 // 3) Merge favicon for the same icon URL, but a pixel size for which there is
1993 // no favicon bitmap. 2008 // no favicon bitmap.
1994 data[0] = 'c'; 2009 data[0] = 'c';
1995 bitmap_data = new base::RefCountedBytes(data); 2010 bitmap_data = new base::RefCountedBytes(data);
1996 backend_->MergeFavicon( 2011 backend_->MergeFavicon(
1997 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kTinySize); 2012 page_url, icon_url1, favicon_base::FAVICON, bitmap_data, kTinySize);
1998 2013
1999 // A new favicon bitmap should be created and the preexisting favicon bitmap 2014 // A new favicon bitmap should be created and the preexisting favicon bitmap
2000 // ('b') should be expired. 2015 // ('b') should be expired.
2001 icon_mappings.clear(); 2016 icon_mappings.clear();
2002 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 2017 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
2003 &icon_mappings)); 2018 &icon_mappings));
2004 EXPECT_EQ(1u, icon_mappings.size()); 2019 EXPECT_EQ(1u, icon_mappings.size());
2005 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 2020 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
2006 2021
2007 std::vector<FaviconBitmap> favicon_bitmaps; 2022 std::vector<FaviconRawBitmap> favicon_bitmaps;
2008 EXPECT_TRUE(GetSortedFaviconBitmaps(icon_mappings[0].icon_id, 2023 EXPECT_TRUE(
2009 &favicon_bitmaps)); 2024 GetSortedFaviconRawBitmaps(icon_mappings[0].icon_id, &favicon_bitmaps));
2010 EXPECT_NE(base::Time(), favicon_bitmaps[0].last_updated); 2025 EXPECT_NE(base::Time(), favicon_bitmaps[0].last_updated);
2011 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); 2026 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data));
2012 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); 2027 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size);
2013 EXPECT_EQ(base::Time(), favicon_bitmaps[1].last_updated); 2028 EXPECT_EQ(base::Time(), favicon_bitmaps[1].last_updated);
2014 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data)); 2029 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data));
2015 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); 2030 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size);
2016 2031
2017 // 4) Merge favicon for an icon URL different from the icon URLs already 2032 // 4) Merge favicon for an icon URL different from the icon URLs already
2018 // mapped to page URL. 2033 // mapped to page URL.
2019 data[0] = 'd'; 2034 data[0] = 'd';
2020 bitmap_data = new base::RefCountedBytes(data); 2035 bitmap_data = new base::RefCountedBytes(data);
2021 backend_->MergeFavicon( 2036 backend_->MergeFavicon(
2022 page_url, icon_url2, favicon_base::FAVICON, bitmap_data, kSmallSize); 2037 page_url, icon_url2, favicon_base::FAVICON, bitmap_data, kSmallSize);
2023 2038
2024 // The existing favicon bitmaps should be copied over to the newly created 2039 // The existing favicon bitmaps should be copied over to the newly created
2025 // favicon at |icon_url2|. |page_url| should solely be mapped to |icon_url2|. 2040 // favicon at |icon_url2|. |page_url| should solely be mapped to |icon_url2|.
2026 icon_mappings.clear(); 2041 icon_mappings.clear();
2027 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 2042 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
2028 &icon_mappings)); 2043 &icon_mappings));
2029 EXPECT_EQ(1u, icon_mappings.size()); 2044 EXPECT_EQ(1u, icon_mappings.size());
2030 EXPECT_EQ(icon_url2, icon_mappings[0].icon_url); 2045 EXPECT_EQ(icon_url2, icon_mappings[0].icon_url);
2031 2046
2032 favicon_bitmaps.clear(); 2047 favicon_bitmaps.clear();
2033 EXPECT_TRUE(GetSortedFaviconBitmaps(icon_mappings[0].icon_id, 2048 EXPECT_TRUE(
2034 &favicon_bitmaps)); 2049 GetSortedFaviconRawBitmaps(icon_mappings[0].icon_id, &favicon_bitmaps));
2035 EXPECT_EQ(base::Time(), favicon_bitmaps[0].last_updated); 2050 EXPECT_EQ(base::Time(), favicon_bitmaps[0].last_updated);
2036 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); 2051 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data));
2037 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); 2052 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size);
2038 // The favicon being merged should take precedence over the preexisting 2053 // The favicon being merged should take precedence over the preexisting
2039 // favicon bitmaps. 2054 // favicon bitmaps.
2040 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated); 2055 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated);
2041 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data)); 2056 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data));
2042 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); 2057 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size);
2043 2058
2044 // A notification should have been broadcast for each call to SetFavicons() 2059 // A notification should have been broadcast for each call to SetFavicons()
2045 // and MergeFavicon(). 2060 // and MergeFavicon().
2046 EXPECT_EQ(4, num_broadcasted_notifications()); 2061 EXPECT_EQ(4, num_broadcasted_notifications());
2047 } 2062 }
2048 2063
2049 // Test calling MergeFavicon() when |icon_url| is known to the database but not 2064 // Test calling MergeFavicon() when |icon_url| is known to the database but not
2050 // mapped to |page_url|. 2065 // mapped to |page_url|.
2051 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { 2066 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) {
2052 GURL page_url1("http://www.google.com"); 2067 GURL page_url1("http://www.google.com");
2053 GURL page_url2("http://news.google.com"); 2068 GURL page_url2("http://news.google.com");
2054 GURL page_url3("http://maps.google.com"); 2069 GURL page_url3("http://maps.google.com");
2055 GURL icon_url("http:/www.google.com/favicon.ico"); 2070 GURL icon_url("http:/www.google.com/favicon.ico");
2056 2071
2057 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2072 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2058 GenerateFaviconBitmapData(icon_url, GetSizesSmall(), 2073 GenerateFaviconRawBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data);
2059 &favicon_bitmap_data);
2060 2074
2061 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); 2075 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
2062 2076
2063 // Test initial state. 2077 // Test initial state.
2064 std::vector<IconMapping> icon_mappings; 2078 std::vector<IconMapping> icon_mappings;
2065 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1, 2079 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1,
2066 &icon_mappings)); 2080 &icon_mappings));
2067 EXPECT_EQ(1u, icon_mappings.size()); 2081 EXPECT_EQ(1u, icon_mappings.size());
2068 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); 2082 EXPECT_EQ(icon_url, icon_mappings[0].icon_url);
2069 2083
2070 FaviconBitmap favicon_bitmap; 2084 FaviconRawBitmap favicon_bitmap;
2071 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 2085 EXPECT_TRUE(
2086 GetOnlyFaviconRawBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
2072 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 2087 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
2073 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 2088 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
2074 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 2089 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
2075 2090
2076 // 1) Merge in an identical favicon bitmap data but for a different page URL. 2091 // 1) Merge in an identical favicon bitmap data but for a different page URL.
2077 std::vector<unsigned char> data; 2092 std::vector<unsigned char> data;
2078 data.push_back('a'); 2093 data.push_back('a');
2079 scoped_refptr<base::RefCountedBytes> bitmap_data( 2094 scoped_refptr<base::RefCountedBytes> bitmap_data(
2080 new base::RefCountedBytes(data)); 2095 new base::RefCountedBytes(data));
2081 2096
2082 backend_->MergeFavicon( 2097 backend_->MergeFavicon(
2083 page_url2, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize); 2098 page_url2, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize);
2084 2099
2085 favicon_base::FaviconID favicon_id = 2100 favicon_base::FaviconID favicon_id =
2086 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 2101 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
2087 icon_url, favicon_base::FAVICON, NULL); 2102 icon_url, favicon_base::FAVICON, NULL);
2088 EXPECT_NE(0, favicon_id); 2103 EXPECT_NE(0, favicon_id);
2089 2104
2090 EXPECT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap)); 2105 EXPECT_TRUE(GetOnlyFaviconRawBitmap(favicon_id, &favicon_bitmap));
2091 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 2106 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
2092 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 2107 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
2093 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 2108 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
2094 2109
2095 // 2) Merging a favicon bitmap with different bitmap data for the same icon 2110 // 2) Merging a favicon bitmap with different bitmap data for the same icon
2096 // URL should overwrite the small favicon bitmap at |icon_url|. 2111 // URL should overwrite the small favicon bitmap at |icon_url|.
2097 bitmap_data->data()[0] = 'b'; 2112 bitmap_data->data()[0] = 'b';
2098 backend_->MergeFavicon( 2113 backend_->MergeFavicon(
2099 page_url3, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize); 2114 page_url3, icon_url, favicon_base::FAVICON, bitmap_data, kSmallSize);
2100 2115
2101 favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 2116 favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
2102 icon_url, favicon_base::FAVICON, NULL); 2117 icon_url, favicon_base::FAVICON, NULL);
2103 EXPECT_NE(0, favicon_id); 2118 EXPECT_NE(0, favicon_id);
2104 2119
2105 EXPECT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap)); 2120 EXPECT_TRUE(GetOnlyFaviconRawBitmap(favicon_id, &favicon_bitmap));
2106 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 2121 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
2107 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); 2122 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data));
2108 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 2123 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
2109 2124
2110 // |icon_url| should be mapped to all three page URLs. 2125 // |icon_url| should be mapped to all three page URLs.
2111 icon_mappings.clear(); 2126 icon_mappings.clear();
2112 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1, 2127 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1,
2113 &icon_mappings)); 2128 &icon_mappings));
2114 EXPECT_EQ(1u, icon_mappings.size()); 2129 EXPECT_EQ(1u, icon_mappings.size());
2115 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 2130 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
2116 2131
2117 icon_mappings.clear(); 2132 icon_mappings.clear();
2118 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url2, 2133 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url2,
2119 &icon_mappings)); 2134 &icon_mappings));
2120 EXPECT_EQ(1u, icon_mappings.size()); 2135 EXPECT_EQ(1u, icon_mappings.size());
2121 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 2136 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
2122 2137
2123 icon_mappings.clear(); 2138 icon_mappings.clear();
2124 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3, 2139 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3,
2125 &icon_mappings)); 2140 &icon_mappings));
2126 EXPECT_EQ(1u, icon_mappings.size()); 2141 EXPECT_EQ(1u, icon_mappings.size());
2127 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 2142 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
2128 2143
2129 // A notification should have been broadcast for each call to SetFavicons() 2144 // A notification should have been broadcast for each call to SetFavicons()
2130 // and MergeFavicon(). 2145 // and MergeFavicon().
2131 EXPECT_EQ(3, num_broadcasted_notifications()); 2146 EXPECT_EQ(3, num_broadcasted_notifications());
2132 } 2147 }
2133 2148
2134 // Test that MergeFavicon() does not add more than 2149 // Test that MergeFavicon() does not add more than
2135 // |kMaxFaviconBitmapsPerIconURL| to a favicon. 2150 // |kMaxFaviconRawBitmapsPerIconURL| to a favicon.
2136 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) { 2151 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconRawBitmapsPerIconURL) {
2137 GURL page_url("http://www.google.com"); 2152 GURL page_url("http://www.google.com");
2138 std::string icon_url_string("http://www.google.com/favicon.ico"); 2153 std::string icon_url_string("http://www.google.com/favicon.ico");
2139 size_t replace_index = icon_url_string.size() - 1; 2154 size_t replace_index = icon_url_string.size() - 1;
2140 2155
2141 std::vector<unsigned char> data; 2156 std::vector<unsigned char> data;
2142 data.push_back('a'); 2157 data.push_back('a');
2143 scoped_refptr<base::RefCountedMemory> bitmap_data = 2158 scoped_refptr<base::RefCountedMemory> bitmap_data =
2144 base::RefCountedBytes::TakeVector(&data); 2159 base::RefCountedBytes::TakeVector(&data);
2145 2160
2146 int pixel_size = 1; 2161 int pixel_size = 1;
2147 for (size_t i = 0; i < kMaxFaviconBitmapsPerIconURL + 1; ++i) { 2162 for (size_t i = 0; i < kMaxFaviconRawBitmapsPerIconURL + 1; ++i) {
2148 icon_url_string[replace_index] = '0' + i; 2163 icon_url_string[replace_index] = '0' + i;
2149 GURL icon_url(icon_url_string); 2164 GURL icon_url(icon_url_string);
2150 2165
2151 backend_->MergeFavicon(page_url, 2166 backend_->MergeFavicon(page_url,
2152 icon_url, 2167 icon_url,
2153 favicon_base::FAVICON, 2168 favicon_base::FAVICON,
2154 bitmap_data, 2169 bitmap_data,
2155 gfx::Size(pixel_size, pixel_size)); 2170 gfx::Size(pixel_size, pixel_size));
2156 ++pixel_size; 2171 ++pixel_size;
2157 } 2172 }
2158 2173
2159 // There should be a single favicon mapped to |page_url| with exactly 2174 // There should be a single favicon mapped to |page_url| with exactly
2160 // kMaxFaviconBitmapsPerIconURL favicon bitmaps. 2175 // kMaxFaviconRawBitmapsPerIconURL favicon bitmaps.
2161 std::vector<IconMapping> icon_mappings; 2176 std::vector<IconMapping> icon_mappings;
2162 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 2177 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
2163 &icon_mappings)); 2178 &icon_mappings));
2164 EXPECT_EQ(1u, icon_mappings.size()); 2179 EXPECT_EQ(1u, icon_mappings.size());
2165 std::vector<FaviconBitmap> favicon_bitmaps; 2180 std::vector<FaviconRawBitmap> favicon_bitmaps;
2166 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( 2181 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconRawBitmaps(
2167 icon_mappings[0].icon_id, &favicon_bitmaps)); 2182 icon_mappings[0].icon_id, &favicon_bitmaps));
2168 EXPECT_EQ(kMaxFaviconBitmapsPerIconURL, favicon_bitmaps.size()); 2183 EXPECT_EQ(kMaxFaviconRawBitmapsPerIconURL, favicon_bitmaps.size());
2169 } 2184 }
2170 2185
2171 // Tests that the favicon set by MergeFavicon() shows up in the result of 2186 // Tests that the favicon set by MergeFavicon() shows up in the result of
2172 // GetFaviconsForURL(). 2187 // GetFaviconsForURL().
2173 TEST_F(HistoryBackendTest, MergeFaviconShowsUpInGetFaviconsForURLResult) { 2188 TEST_F(HistoryBackendTest, MergeFaviconShowsUpInGetFaviconsForURLResult) {
2174 GURL page_url("http://www.google.com"); 2189 GURL page_url("http://www.google.com");
2175 GURL icon_url("http://www.google.com/favicon.ico"); 2190 GURL icon_url("http://www.google.com/favicon.ico");
2176 GURL merged_icon_url("http://wwww.google.com/favicon2.ico"); 2191 GURL merged_icon_url("http://wwww.google.com/favicon2.ico");
2177 2192
2178 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2193 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2179 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(), 2194 GenerateFaviconRawBitmapData(
2180 &favicon_bitmap_data); 2195 icon_url, GetSizesSmallAndLarge(), &favicon_bitmap_data);
2181 2196
2182 // Set some preexisting favicons for |page_url|. 2197 // Set some preexisting favicons for |page_url|.
2183 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2198 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2184 2199
2185 // Merge small favicon. 2200 // Merge small favicon.
2186 std::vector<unsigned char> data; 2201 std::vector<unsigned char> data;
2187 data.push_back('c'); 2202 data.push_back('c');
2188 scoped_refptr<base::RefCountedBytes> bitmap_data( 2203 scoped_refptr<base::RefCountedBytes> bitmap_data(
2189 new base::RefCountedBytes(data)); 2204 new base::RefCountedBytes(data));
2190 backend_->MergeFavicon(page_url, 2205 backend_->MergeFavicon(page_url,
2191 merged_icon_url, 2206 merged_icon_url,
2192 favicon_base::FAVICON, 2207 favicon_base::FAVICON,
2193 bitmap_data, 2208 bitmap_data,
2194 kSmallSize); 2209 kSmallSize);
2195 2210
2196 // Request favicon bitmaps for both 1x and 2x to simulate request done by 2211 // Request favicon bitmaps for both 1x and 2x to simulate request done by
2197 // BookmarkModel::GetFavicon(). 2212 // BookmarkModel::GetFavicon().
2198 std::vector<favicon_base::FaviconBitmapResult> bitmap_results; 2213 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
2199 backend_->GetFaviconsForURL(page_url, 2214 backend_->GetFaviconsForURL(page_url,
2200 favicon_base::FAVICON, 2215 favicon_base::FAVICON,
2201 kSmallSize.width(), 2216 kSmallSize.width(),
2202 GetScaleFactors1x2x(), 2217 GetScaleFactors1x2x(),
2203 &bitmap_results); 2218 &bitmap_results);
2204 2219
2205 EXPECT_EQ(2u, bitmap_results.size()); 2220 EXPECT_EQ(2u, bitmap_results.size());
2206 const favicon_base::FaviconBitmapResult& first_result = bitmap_results[0]; 2221 const favicon_base::FaviconRawBitmapResult& first_result = bitmap_results[0];
2207 const favicon_base::FaviconBitmapResult& result = 2222 const favicon_base::FaviconRawBitmapResult& result =
2208 (first_result.pixel_size == kSmallSize) ? first_result 2223 (first_result.pixel_size == kSmallSize) ? first_result
2209 : bitmap_results[1]; 2224 : bitmap_results[1];
2210 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data)); 2225 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data));
2211 } 2226 }
2212 2227
2213 // Tests GetFaviconsForURL with icon_types priority, 2228 // Tests GetFaviconsForURL with icon_types priority,
2214 TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) { 2229 TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) {
2215 GURL page_url("http://www.google.com"); 2230 GURL page_url("http://www.google.com");
2216 GURL icon_url("http://www.google.com/favicon.ico"); 2231 GURL icon_url("http://www.google.com/favicon.ico");
2217 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico"); 2232 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
2218 2233
2219 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2234 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2220 std::vector<gfx::Size> favicon_size; 2235 std::vector<gfx::Size> favicon_size;
2221 favicon_size.push_back(gfx::Size(16, 16)); 2236 favicon_size.push_back(gfx::Size(16, 16));
2222 favicon_size.push_back(gfx::Size(32, 32)); 2237 favicon_size.push_back(gfx::Size(32, 32));
2223 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data); 2238 GenerateFaviconRawBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
2224 ASSERT_EQ(2u, favicon_bitmap_data.size()); 2239 ASSERT_EQ(2u, favicon_bitmap_data.size());
2225 2240
2226 std::vector<favicon_base::FaviconBitmapData> touch_icon_bitmap_data; 2241 std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data;
2227 std::vector<gfx::Size> touch_icon_size; 2242 std::vector<gfx::Size> touch_icon_size;
2228 touch_icon_size.push_back(gfx::Size(64, 64)); 2243 touch_icon_size.push_back(gfx::Size(64, 64));
2229 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data); 2244 GenerateFaviconRawBitmapData(
2245 icon_url, touch_icon_size, &touch_icon_bitmap_data);
2230 ASSERT_EQ(1u, touch_icon_bitmap_data.size()); 2246 ASSERT_EQ(1u, touch_icon_bitmap_data.size());
2231 2247
2232 // Set some preexisting favicons for |page_url|. 2248 // Set some preexisting favicons for |page_url|.
2233 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2249 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2234 backend_->SetFavicons( 2250 backend_->SetFavicons(
2235 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data); 2251 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data);
2236 2252
2237 favicon_base::FaviconBitmapResult result; 2253 favicon_base::FaviconRawBitmapResult result;
2238 std::vector<int> icon_types; 2254 std::vector<int> icon_types;
2239 icon_types.push_back(favicon_base::FAVICON); 2255 icon_types.push_back(favicon_base::FAVICON);
2240 icon_types.push_back(favicon_base::TOUCH_ICON); 2256 icon_types.push_back(favicon_base::TOUCH_ICON);
2241 2257
2242 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result); 2258 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result);
2243 2259
2244 // Verify the result icon is 32x32 favicon. 2260 // Verify the result icon is 32x32 favicon.
2245 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size); 2261 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
2246 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); 2262 EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
2247 2263
2248 // Change Minimal size to 32x32 and verify the 64x64 touch icon returned. 2264 // Change Minimal size to 32x32 and verify the 64x64 touch icon returned.
2249 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result); 2265 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result);
2250 EXPECT_EQ(gfx::Size(64, 64), result.pixel_size); 2266 EXPECT_EQ(gfx::Size(64, 64), result.pixel_size);
2251 EXPECT_EQ(favicon_base::TOUCH_ICON, result.icon_type); 2267 EXPECT_EQ(favicon_base::TOUCH_ICON, result.icon_type);
2252 } 2268 }
2253 2269
2254 // Test the the first types of icon is returned if its size equal to the 2270 // Test the the first types of icon is returned if its size equal to the
2255 // second types icon. 2271 // second types icon.
2256 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) { 2272 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) {
2257 GURL page_url("http://www.google.com"); 2273 GURL page_url("http://www.google.com");
2258 GURL icon_url("http://www.google.com/favicon.ico"); 2274 GURL icon_url("http://www.google.com/favicon.ico");
2259 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico"); 2275 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
2260 2276
2261 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2277 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2262 std::vector<gfx::Size> favicon_size; 2278 std::vector<gfx::Size> favicon_size;
2263 favicon_size.push_back(gfx::Size(16, 16)); 2279 favicon_size.push_back(gfx::Size(16, 16));
2264 favicon_size.push_back(gfx::Size(32, 32)); 2280 favicon_size.push_back(gfx::Size(32, 32));
2265 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data); 2281 GenerateFaviconRawBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
2266 ASSERT_EQ(2u, favicon_bitmap_data.size()); 2282 ASSERT_EQ(2u, favicon_bitmap_data.size());
2267 2283
2268 std::vector<favicon_base::FaviconBitmapData> touch_icon_bitmap_data; 2284 std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data;
2269 std::vector<gfx::Size> touch_icon_size; 2285 std::vector<gfx::Size> touch_icon_size;
2270 touch_icon_size.push_back(gfx::Size(32, 32)); 2286 touch_icon_size.push_back(gfx::Size(32, 32));
2271 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data); 2287 GenerateFaviconRawBitmapData(
2288 icon_url, touch_icon_size, &touch_icon_bitmap_data);
2272 ASSERT_EQ(1u, touch_icon_bitmap_data.size()); 2289 ASSERT_EQ(1u, touch_icon_bitmap_data.size());
2273 2290
2274 // Set some preexisting favicons for |page_url|. 2291 // Set some preexisting favicons for |page_url|.
2275 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2292 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2276 backend_->SetFavicons( 2293 backend_->SetFavicons(
2277 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data); 2294 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data);
2278 2295
2279 favicon_base::FaviconBitmapResult result; 2296 favicon_base::FaviconRawBitmapResult result;
2280 std::vector<int> icon_types; 2297 std::vector<int> icon_types;
2281 icon_types.push_back(favicon_base::FAVICON); 2298 icon_types.push_back(favicon_base::FAVICON);
2282 icon_types.push_back(favicon_base::TOUCH_ICON); 2299 icon_types.push_back(favicon_base::TOUCH_ICON);
2283 2300
2284 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result); 2301 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result);
2285 2302
2286 // Verify the result icon is 32x32 favicon. 2303 // Verify the result icon is 32x32 favicon.
2287 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size); 2304 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
2288 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); 2305 EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
2289 2306
2290 // Change minimal size to 32x32 and verify the 32x32 favicon returned. 2307 // Change minimal size to 32x32 and verify the 32x32 favicon returned.
2291 favicon_base::FaviconBitmapResult result1; 2308 favicon_base::FaviconRawBitmapResult result1;
2292 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result1); 2309 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result1);
2293 EXPECT_EQ(gfx::Size(32, 32), result1.pixel_size); 2310 EXPECT_EQ(gfx::Size(32, 32), result1.pixel_size);
2294 EXPECT_EQ(favicon_base::FAVICON, result1.icon_type); 2311 EXPECT_EQ(favicon_base::FAVICON, result1.icon_type);
2295 } 2312 }
2296 2313
2297 // Test the favicon is returned if its size is smaller than minimal size, 2314 // Test the favicon is returned if its size is smaller than minimal size,
2298 // because it is only one available. 2315 // because it is only one available.
2299 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) { 2316 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) {
2300 GURL page_url("http://www.google.com"); 2317 GURL page_url("http://www.google.com");
2301 GURL icon_url("http://www.google.com/favicon.ico"); 2318 GURL icon_url("http://www.google.com/favicon.ico");
2302 2319
2303 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2320 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2304 std::vector<gfx::Size> favicon_size; 2321 std::vector<gfx::Size> favicon_size;
2305 favicon_size.push_back(gfx::Size(16, 16)); 2322 favicon_size.push_back(gfx::Size(16, 16));
2306 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data); 2323 GenerateFaviconRawBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
2307 ASSERT_EQ(1u, favicon_bitmap_data.size()); 2324 ASSERT_EQ(1u, favicon_bitmap_data.size());
2308 2325
2309 // Set preexisting favicons for |page_url|. 2326 // Set preexisting favicons for |page_url|.
2310 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2327 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2311 2328
2312 favicon_base::FaviconBitmapResult result; 2329 favicon_base::FaviconRawBitmapResult result;
2313 std::vector<int> icon_types; 2330 std::vector<int> icon_types;
2314 icon_types.push_back(favicon_base::FAVICON); 2331 icon_types.push_back(favicon_base::FAVICON);
2315 icon_types.push_back(favicon_base::TOUCH_ICON); 2332 icon_types.push_back(favicon_base::TOUCH_ICON);
2316 2333
2317 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result); 2334 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result);
2318 2335
2319 // Verify 16x16 icon is returned, even it small than minimal_size. 2336 // Verify 16x16 icon is returned, even it small than minimal_size.
2320 EXPECT_EQ(gfx::Size(16, 16), result.pixel_size); 2337 EXPECT_EQ(gfx::Size(16, 16), result.pixel_size);
2321 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); 2338 EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
2322 } 2339 }
2323 2340
2324 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in. 2341 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in.
2325 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) { 2342 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
2326 GURL page_url1("http://www.google.com"); 2343 GURL page_url1("http://www.google.com");
2327 GURL page_url2("http://news.google.com"); 2344 GURL page_url2("http://news.google.com");
2328 GURL page_url3("http://mail.google.com"); 2345 GURL page_url3("http://mail.google.com");
2329 GURL icon_urla("http://www.google.com/favicon1.ico"); 2346 GURL icon_urla("http://www.google.com/favicon1.ico");
2330 GURL icon_urlb("http://www.google.com/favicon2.ico"); 2347 GURL icon_urlb("http://www.google.com/favicon2.ico");
2331 GURL icon_urlc("http://www.google.com/favicon3.ico"); 2348 GURL icon_urlc("http://www.google.com/favicon3.ico");
2332 2349
2333 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON. 2350 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON.
2334 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2351 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2335 GenerateFaviconBitmapData(icon_urla, GetSizesSmall(), &favicon_bitmap_data); 2352 GenerateFaviconRawBitmapData(
2353 icon_urla, GetSizesSmall(), &favicon_bitmap_data);
2336 backend_->SetFavicons( 2354 backend_->SetFavicons(
2337 page_url1, favicon_base::TOUCH_ICON, favicon_bitmap_data); 2355 page_url1, favicon_base::TOUCH_ICON, favicon_bitmap_data);
2338 2356
2339 // |page_url2| is mapped to |icon_urlb| and |icon_urlc| which are of type 2357 // |page_url2| is mapped to |icon_urlb| and |icon_urlc| which are of type
2340 // TOUCH_PRECOMPOSED_ICON. 2358 // TOUCH_PRECOMPOSED_ICON.
2341 GenerateFaviconBitmapData(icon_urlb, GetSizesSmall(), icon_urlc, 2359 GenerateFaviconRawBitmapData(icon_urlb,
2342 GetSizesSmall(), &favicon_bitmap_data); 2360 GetSizesSmall(),
2361 icon_urlc,
2362 GetSizesSmall(),
2363 &favicon_bitmap_data);
2343 backend_->SetFavicons( 2364 backend_->SetFavicons(
2344 page_url2, favicon_base::TOUCH_PRECOMPOSED_ICON, favicon_bitmap_data); 2365 page_url2, favicon_base::TOUCH_PRECOMPOSED_ICON, favicon_bitmap_data);
2345 2366
2346 std::vector<GURL> icon_urls; 2367 std::vector<GURL> icon_urls;
2347 icon_urls.push_back(icon_urla); 2368 icon_urls.push_back(icon_urla);
2348 icon_urls.push_back(icon_urlb); 2369 icon_urls.push_back(icon_urlb);
2349 icon_urls.push_back(icon_urlc); 2370 icon_urls.push_back(icon_urlc);
2350 2371
2351 std::vector<favicon_base::FaviconBitmapResult> bitmap_results; 2372 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
2352 backend_->UpdateFaviconMappingsAndFetch( 2373 backend_->UpdateFaviconMappingsAndFetch(
2353 page_url3, 2374 page_url3,
2354 icon_urls, 2375 icon_urls,
2355 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON), 2376 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON),
2356 kSmallSize.width(), 2377 kSmallSize.width(),
2357 GetScaleFactors1x2x(), 2378 GetScaleFactors1x2x(),
2358 &bitmap_results); 2379 &bitmap_results);
2359 2380
2360 // |page_url1| and |page_url2| should still be mapped to the same icon URLs. 2381 // |page_url1| and |page_url2| should still be mapped to the same icon URLs.
2361 std::vector<IconMapping> icon_mappings; 2382 std::vector<IconMapping> icon_mappings;
(...skipping 20 matching lines...) Expand all
2382 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type); 2403 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type);
2383 EXPECT_EQ(icon_urlc, icon_mappings[1].icon_url); 2404 EXPECT_EQ(icon_urlc, icon_mappings[1].icon_url);
2384 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type); 2405 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type);
2385 } 2406 }
2386 2407
2387 // Test the results of GetFaviconsFromDB() when there are no found 2408 // Test the results of GetFaviconsFromDB() when there are no found
2388 // favicons. 2409 // favicons.
2389 TEST_F(HistoryBackendTest, GetFaviconsFromDBEmpty) { 2410 TEST_F(HistoryBackendTest, GetFaviconsFromDBEmpty) {
2390 const GURL page_url("http://www.google.com/"); 2411 const GURL page_url("http://www.google.com/");
2391 2412
2392 std::vector<favicon_base::FaviconBitmapResult> bitmap_results; 2413 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
2393 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, 2414 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url,
2394 favicon_base::FAVICON, 2415 favicon_base::FAVICON,
2395 kSmallSize.width(), 2416 kSmallSize.width(),
2396 GetScaleFactors1x2x(), 2417 GetScaleFactors1x2x(),
2397 &bitmap_results)); 2418 &bitmap_results));
2398 EXPECT_TRUE(bitmap_results.empty()); 2419 EXPECT_TRUE(bitmap_results.empty());
2399 } 2420 }
2400 2421
2401 // Test the results of GetFaviconsFromDB() when there are matching favicons 2422 // Test the results of GetFaviconsFromDB() when there are matching favicons
2402 // but there are no associated favicon bitmaps. 2423 // but there are no associated favicon bitmaps.
2403 TEST_F(HistoryBackendTest, GetFaviconsFromDBNoFaviconBitmaps) { 2424 TEST_F(HistoryBackendTest, GetFaviconsFromDBNoFaviconRawBitmaps) {
2404 const GURL page_url("http://www.google.com/"); 2425 const GURL page_url("http://www.google.com/");
2405 const GURL icon_url("http://www.google.com/icon1"); 2426 const GURL icon_url("http://www.google.com/icon1");
2406 2427
2407 favicon_base::FaviconID icon_id = 2428 favicon_base::FaviconID icon_id =
2408 backend_->thumbnail_db_->AddFavicon(icon_url, favicon_base::FAVICON); 2429 backend_->thumbnail_db_->AddFavicon(icon_url, favicon_base::FAVICON);
2409 EXPECT_NE(0, icon_id); 2430 EXPECT_NE(0, icon_id);
2410 EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id)); 2431 EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id));
2411 2432
2412 std::vector<favicon_base::FaviconBitmapResult> bitmap_results_out; 2433 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2413 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, 2434 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url,
2414 favicon_base::FAVICON, 2435 favicon_base::FAVICON,
2415 kSmallSize.width(), 2436 kSmallSize.width(),
2416 GetScaleFactors1x2x(), 2437 GetScaleFactors1x2x(),
2417 &bitmap_results_out)); 2438 &bitmap_results_out));
2418 EXPECT_TRUE(bitmap_results_out.empty()); 2439 EXPECT_TRUE(bitmap_results_out.empty());
2419 } 2440 }
2420 2441
2421 // Test that GetFaviconsFromDB() returns results for the bitmaps which most 2442 // Test that GetFaviconsFromDB() returns results for the bitmaps which most
2422 // closely match the passed in desired size and scale factors. 2443 // closely match the passed in desired size and scale factors.
2423 TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) { 2444 TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) {
2424 const GURL page_url("http://www.google.com/"); 2445 const GURL page_url("http://www.google.com/");
2425 const GURL icon_url("http://www.google.com/icon1"); 2446 const GURL icon_url("http://www.google.com/icon1");
2426 2447
2427 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2448 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2428 GenerateFaviconBitmapData(icon_url, GetSizesTinySmallAndLarge(), 2449 GenerateFaviconRawBitmapData(
2429 &favicon_bitmap_data); 2450 icon_url, GetSizesTinySmallAndLarge(), &favicon_bitmap_data);
2430 2451
2431 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2452 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2432 2453
2433 std::vector<favicon_base::FaviconBitmapResult> bitmap_results_out; 2454 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2434 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, 2455 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
2435 favicon_base::FAVICON, 2456 favicon_base::FAVICON,
2436 kSmallSize.width(), 2457 kSmallSize.width(),
2437 GetScaleFactors1x2x(), 2458 GetScaleFactors1x2x(),
2438 &bitmap_results_out)); 2459 &bitmap_results_out));
2439 2460
2440 // The bitmap data for the small and large bitmaps should be returned as their 2461 // The bitmap data for the small and large bitmaps should be returned as their
2441 // sizes match exactly. 2462 // sizes match exactly.
2442 EXPECT_EQ(2u, bitmap_results_out.size()); 2463 EXPECT_EQ(2u, bitmap_results_out.size());
2443 // No required order for results. 2464 // No required order for results.
2444 if (bitmap_results_out[0].pixel_size == kLargeSize) { 2465 if (bitmap_results_out[0].pixel_size == kLargeSize) {
2445 favicon_base::FaviconBitmapResult tmp_result = bitmap_results_out[0]; 2466 favicon_base::FaviconRawBitmapResult tmp_result = bitmap_results_out[0];
2446 bitmap_results_out[0] = bitmap_results_out[1]; 2467 bitmap_results_out[0] = bitmap_results_out[1];
2447 bitmap_results_out[1] = tmp_result; 2468 bitmap_results_out[1] = tmp_result;
2448 } 2469 }
2449 2470
2450 EXPECT_FALSE(bitmap_results_out[0].expired); 2471 EXPECT_FALSE(bitmap_results_out[0].expired);
2451 EXPECT_TRUE(BitmapDataEqual('b', bitmap_results_out[0].bitmap_data)); 2472 EXPECT_TRUE(BitmapDataEqual('b', bitmap_results_out[0].bitmap_data));
2452 EXPECT_EQ(kSmallSize, bitmap_results_out[0].pixel_size); 2473 EXPECT_EQ(kSmallSize, bitmap_results_out[0].pixel_size);
2453 EXPECT_EQ(icon_url, bitmap_results_out[0].icon_url); 2474 EXPECT_EQ(icon_url, bitmap_results_out[0].icon_url);
2454 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type); 2475 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type);
2455 2476
2456 EXPECT_FALSE(bitmap_results_out[1].expired); 2477 EXPECT_FALSE(bitmap_results_out[1].expired);
2457 EXPECT_TRUE(BitmapDataEqual('c', bitmap_results_out[1].bitmap_data)); 2478 EXPECT_TRUE(BitmapDataEqual('c', bitmap_results_out[1].bitmap_data));
2458 EXPECT_EQ(kLargeSize, bitmap_results_out[1].pixel_size); 2479 EXPECT_EQ(kLargeSize, bitmap_results_out[1].pixel_size);
2459 EXPECT_EQ(icon_url, bitmap_results_out[1].icon_url); 2480 EXPECT_EQ(icon_url, bitmap_results_out[1].icon_url);
2460 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[1].icon_type); 2481 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[1].icon_type);
2461 } 2482 }
2462 2483
2463 // Test that GetFaviconsFromDB() returns results from the icon URL whose 2484 // Test that GetFaviconsFromDB() returns results from the icon URL whose
2464 // bitmaps most closely match the passed in desired size and scale factors. 2485 // bitmaps most closely match the passed in desired size and scale factors.
2465 TEST_F(HistoryBackendTest, GetFaviconsFromDBSingleIconURL) { 2486 TEST_F(HistoryBackendTest, GetFaviconsFromDBSingleIconURL) {
2466 const GURL page_url("http://www.google.com/"); 2487 const GURL page_url("http://www.google.com/");
2467 2488
2468 const GURL icon_url1("http://www.google.com/icon1"); 2489 const GURL icon_url1("http://www.google.com/icon1");
2469 const GURL icon_url2("http://www.google.com/icon2"); 2490 const GURL icon_url2("http://www.google.com/icon2");
2470 2491
2471 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2492 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2472 GenerateFaviconBitmapData(icon_url1, GetSizesSmall(), icon_url2, 2493 GenerateFaviconRawBitmapData(icon_url1,
2473 GetSizesLarge(), &favicon_bitmap_data); 2494 GetSizesSmall(),
2495 icon_url2,
2496 GetSizesLarge(),
2497 &favicon_bitmap_data);
2474 2498
2475 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2499 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2476 2500
2477 std::vector<favicon_base::FaviconBitmapResult> bitmap_results_out; 2501 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2478 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, 2502 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
2479 favicon_base::FAVICON, 2503 favicon_base::FAVICON,
2480 kSmallSize.width(), 2504 kSmallSize.width(),
2481 GetScaleFactors1x2x(), 2505 GetScaleFactors1x2x(),
2482 &bitmap_results_out)); 2506 &bitmap_results_out));
2483 2507
2484 // The results should have results for the icon URL with the large bitmap as 2508 // The results should have results for the icon URL with the large bitmap as
2485 // downscaling is preferred to upscaling. 2509 // downscaling is preferred to upscaling.
2486 EXPECT_EQ(1u, bitmap_results_out.size()); 2510 EXPECT_EQ(1u, bitmap_results_out.size());
2487 EXPECT_EQ(kLargeSize, bitmap_results_out[0].pixel_size); 2511 EXPECT_EQ(kLargeSize, bitmap_results_out[0].pixel_size);
2488 EXPECT_EQ(icon_url2, bitmap_results_out[0].icon_url); 2512 EXPECT_EQ(icon_url2, bitmap_results_out[0].icon_url);
2489 } 2513 }
2490 2514
2491 // Test the results of GetFaviconsFromDB() when called with different 2515 // Test the results of GetFaviconsFromDB() when called with different
2492 // |icon_types|. 2516 // |icon_types|.
2493 TEST_F(HistoryBackendTest, GetFaviconsFromDBIconType) { 2517 TEST_F(HistoryBackendTest, GetFaviconsFromDBIconType) {
2494 const GURL page_url("http://www.google.com/"); 2518 const GURL page_url("http://www.google.com/");
2495 const GURL icon_url1("http://www.google.com/icon1.png"); 2519 const GURL icon_url1("http://www.google.com/icon1.png");
2496 const GURL icon_url2("http://www.google.com/icon2.png"); 2520 const GURL icon_url2("http://www.google.com/icon2.png");
2497 2521
2498 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2522 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2499 GenerateFaviconBitmapData(icon_url1, GetSizesSmall(), &favicon_bitmap_data); 2523 GenerateFaviconRawBitmapData(
2524 icon_url1, GetSizesSmall(), &favicon_bitmap_data);
2500 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2525 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2501 2526
2502 GenerateFaviconBitmapData(icon_url2, GetSizesSmall(), &favicon_bitmap_data); 2527 GenerateFaviconRawBitmapData(
2528 icon_url2, GetSizesSmall(), &favicon_bitmap_data);
2503 backend_->SetFavicons( 2529 backend_->SetFavicons(
2504 page_url, favicon_base::TOUCH_ICON, favicon_bitmap_data); 2530 page_url, favicon_base::TOUCH_ICON, favicon_bitmap_data);
2505 2531
2506 std::vector<favicon_base::FaviconBitmapResult> bitmap_results_out; 2532 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2507 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, 2533 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
2508 favicon_base::FAVICON, 2534 favicon_base::FAVICON,
2509 kSmallSize.width(), 2535 kSmallSize.width(),
2510 GetScaleFactors1x2x(), 2536 GetScaleFactors1x2x(),
2511 &bitmap_results_out)); 2537 &bitmap_results_out));
2512 2538
2513 EXPECT_EQ(1u, bitmap_results_out.size()); 2539 EXPECT_EQ(1u, bitmap_results_out.size());
2514 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type); 2540 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type);
2515 EXPECT_EQ(icon_url1, bitmap_results_out[0].icon_url); 2541 EXPECT_EQ(icon_url1, bitmap_results_out[0].icon_url);
2516 2542
(...skipping 18 matching lines...) Expand all
2535 std::vector<unsigned char> data; 2561 std::vector<unsigned char> data;
2536 data.push_back('a'); 2562 data.push_back('a');
2537 scoped_refptr<base::RefCountedBytes> bitmap_data( 2563 scoped_refptr<base::RefCountedBytes> bitmap_data(
2538 base::RefCountedBytes::TakeVector(&data)); 2564 base::RefCountedBytes::TakeVector(&data));
2539 base::Time last_updated = base::Time::FromTimeT(0); 2565 base::Time last_updated = base::Time::FromTimeT(0);
2540 favicon_base::FaviconID icon_id = backend_->thumbnail_db_->AddFavicon( 2566 favicon_base::FaviconID icon_id = backend_->thumbnail_db_->AddFavicon(
2541 icon_url, favicon_base::FAVICON, bitmap_data, last_updated, kSmallSize); 2567 icon_url, favicon_base::FAVICON, bitmap_data, last_updated, kSmallSize);
2542 EXPECT_NE(0, icon_id); 2568 EXPECT_NE(0, icon_id);
2543 EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id)); 2569 EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id));
2544 2570
2545 std::vector<favicon_base::FaviconBitmapResult> bitmap_results_out; 2571 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2546 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, 2572 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
2547 favicon_base::FAVICON, 2573 favicon_base::FAVICON,
2548 kSmallSize.width(), 2574 kSmallSize.width(),
2549 GetScaleFactors1x2x(), 2575 GetScaleFactors1x2x(),
2550 &bitmap_results_out)); 2576 &bitmap_results_out));
2551 2577
2552 EXPECT_EQ(1u, bitmap_results_out.size()); 2578 EXPECT_EQ(1u, bitmap_results_out.size());
2553 EXPECT_TRUE(bitmap_results_out[0].expired); 2579 EXPECT_TRUE(bitmap_results_out[0].expired);
2554 } 2580 }
2555 2581
2556 // Check that UpdateFaviconMappingsAndFetch() call back to the UI when there is 2582 // Check that UpdateFaviconMappingsAndFetch() call back to the UI when there is
2557 // no valid thumbnail database. 2583 // no valid thumbnail database.
2558 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoDB) { 2584 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoDB) {
2559 // Make the thumbnail database invalid. 2585 // Make the thumbnail database invalid.
2560 backend_->thumbnail_db_.reset(); 2586 backend_->thumbnail_db_.reset();
2561 2587
2562 std::vector<favicon_base::FaviconBitmapResult> bitmap_results; 2588 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
2563 2589
2564 backend_->UpdateFaviconMappingsAndFetch(GURL(), 2590 backend_->UpdateFaviconMappingsAndFetch(GURL(),
2565 std::vector<GURL>(), 2591 std::vector<GURL>(),
2566 favicon_base::FAVICON, 2592 favicon_base::FAVICON,
2567 kSmallSize.width(), 2593 kSmallSize.width(),
2568 GetScaleFactors1x2x(), 2594 GetScaleFactors1x2x(),
2569 &bitmap_results); 2595 &bitmap_results);
2570 2596
2571 EXPECT_TRUE(bitmap_results.empty()); 2597 EXPECT_TRUE(bitmap_results.empty());
2572 } 2598 }
2573 2599
2574 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { 2600 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) {
2575 const GURL url("http://www.google.com/"); 2601 const GURL url("http://www.google.com/");
2576 const GURL same_domain_url("http://www.google.com/subdir/index.html"); 2602 const GURL same_domain_url("http://www.google.com/subdir/index.html");
2577 const GURL foreign_domain_url("http://www.not-google.com/"); 2603 const GURL foreign_domain_url("http://www.not-google.com/");
2578 const GURL icon_url("http://www.google.com/icon.png"); 2604 const GURL icon_url("http://www.google.com/icon.png");
2579 2605
2580 // Add a favicon 2606 // Add a favicon
2581 std::vector<favicon_base::FaviconBitmapData> favicon_bitmap_data; 2607 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2582 GenerateFaviconBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data); 2608 GenerateFaviconRawBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data);
2583 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data); 2609 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data);
2584 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 2610 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
2585 url, favicon_base::FAVICON, NULL)); 2611 url, favicon_base::FAVICON, NULL));
2586 2612
2587 // Validate starting state. 2613 // Validate starting state.
2588 std::vector<favicon_base::FaviconBitmapResult> bitmap_results_out; 2614 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2589 EXPECT_TRUE(backend_->GetFaviconsFromDB(url, 2615 EXPECT_TRUE(backend_->GetFaviconsFromDB(url,
2590 favicon_base::FAVICON, 2616 favicon_base::FAVICON,
2591 kSmallSize.width(), 2617 kSmallSize.width(),
2592 GetScaleFactors1x2x(), 2618 GetScaleFactors1x2x(),
2593 &bitmap_results_out)); 2619 &bitmap_results_out));
2594 EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url, 2620 EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url,
2595 favicon_base::FAVICON, 2621 favicon_base::FAVICON,
2596 kSmallSize.width(), 2622 kSmallSize.width(),
2597 GetScaleFactors1x2x(), 2623 GetScaleFactors1x2x(),
2598 &bitmap_results_out)); 2624 &bitmap_results_out));
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
3357 // Verify that the second term is no longer returned as result, and also check 3383 // Verify that the second term is no longer returned as result, and also check
3358 // at the low level that it is gone for good. The term corresponding to the 3384 // at the low level that it is gone for good. The term corresponding to the
3359 // first URLRow should not be affected. 3385 // first URLRow should not be affected.
3360 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3386 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3361 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3387 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3362 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3388 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3363 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3389 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3364 } 3390 }
3365 3391
3366 } // namespace history 3392 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698