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

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

Issue 336423006: Pass in a set of requested favicon pixel sizes to the HistoryService (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
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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 30 matching lines...) Expand all
41 41
42 using base::Time; 42 using base::Time;
43 43
44 // This file only tests functionality where it is most convenient to call the 44 // This file only tests functionality where it is most convenient to call the
45 // backend directly. Most of the history backend functions are tested by the 45 // backend directly. Most of the history backend functions are tested by the
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 const int kTinyEdgeSize = 10;
52 static const gfx::Size kSmallSize = gfx::Size(16, 16); 52 const int kSmallEdgeSize = 16;
53 static const gfx::Size kLargeSize = gfx::Size(32, 32); 53 const int kLargeEdgeSize = 32;
54
55 const gfx::Size kTinySize = gfx::Size(kTinyEdgeSize, kTinyEdgeSize);
56 const gfx::Size kSmallSize = gfx::Size(kSmallEdgeSize, kSmallEdgeSize);
57 const gfx::Size kLargeSize = gfx::Size(kLargeEdgeSize, kLargeEdgeSize);
54 58
55 // Comparison functions as to make it easier to check results of 59 // Comparison functions as to make it easier to check results of
56 // GetFaviconBitmaps() and GetIconMappingsForPageURL(). 60 // GetFaviconBitmaps() and GetIconMappingsForPageURL().
57 bool IconMappingLessThan(const history::IconMapping& a, 61 bool IconMappingLessThan(const history::IconMapping& a,
58 const history::IconMapping& b) { 62 const history::IconMapping& b) {
59 return a.icon_url < b.icon_url; 63 return a.icon_url < b.icon_url;
60 } 64 }
61 65
62 bool FaviconBitmapLessThan(const history::FaviconBitmap& a, 66 bool FaviconBitmapLessThan(const history::FaviconBitmap& a,
63 const history::FaviconBitmap& b) { 67 const history::FaviconBitmap& b) {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 int GetTransition(const GURL& url) { 292 int GetTransition(const GURL& url) {
289 if (!url.is_valid()) 293 if (!url.is_valid())
290 return 0; 294 return 0;
291 URLRow row; 295 URLRow row;
292 URLID id = backend_->db()->GetRowForURL(url, &row); 296 URLID id = backend_->db()->GetRowForURL(url, &row);
293 VisitVector visits; 297 VisitVector visits;
294 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); 298 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
295 return visits[0].transition; 299 return visits[0].transition;
296 } 300 }
297 301
298 // Returns a gfx::Size vector with small size. 302 // Returns a vector with the small edge size.
299 const std::vector<gfx::Size> GetSizesSmall() { 303 const std::vector<int> GetEdgeSizesSmall() {
300 std::vector<gfx::Size> sizes_small; 304 std::vector<int> sizes_small;
301 sizes_small.push_back(kSmallSize); 305 sizes_small.push_back(kSmallEdgeSize);
302 return sizes_small; 306 return sizes_small;
303 } 307 }
304 308
305 // Returns a gfx::Size vector with large size. 309 // Returns a vector with the large edge size.
306 const std::vector<gfx::Size> GetSizesLarge() { 310 const std::vector<int> GetEdgeSizesLarge() {
307 std::vector<gfx::Size> sizes_large; 311 std::vector<int> sizes_large;
308 sizes_large.push_back(kLargeSize); 312 sizes_large.push_back(kLargeEdgeSize);
309 return sizes_large; 313 return sizes_large;
310 } 314 }
311 315
312 // Returns a gfx::Size vector with small and large sizes. 316 // Returns a vector with the small and large edge sizes.
313 const std::vector<gfx::Size> GetSizesSmallAndLarge() { 317 const std::vector<int> GetEdgeSizesSmallAndLarge() {
314 std::vector<gfx::Size> sizes_small_and_large; 318 std::vector<int> sizes_small_and_large;
315 sizes_small_and_large.push_back(kSmallSize); 319 sizes_small_and_large.push_back(kSmallEdgeSize);
316 sizes_small_and_large.push_back(kLargeSize); 320 sizes_small_and_large.push_back(kLargeEdgeSize);
317 return sizes_small_and_large; 321 return sizes_small_and_large;
318 } 322 }
319 323
320 // Returns a gfx::Size vector with tiny, small and large sizes. 324 // Returns a vector with the tiny, small, and large edge sizes.
321 const std::vector<gfx::Size> GetSizesTinySmallAndLarge() { 325 const std::vector<int> GetEdgeSizesTinySmallAndLarge() {
322 std::vector<gfx::Size> sizes_tiny_small_and_large; 326 std::vector<int> sizes_tiny_small_and_large;
323 sizes_tiny_small_and_large.push_back(kTinySize); 327 sizes_tiny_small_and_large.push_back(kTinyEdgeSize);
324 sizes_tiny_small_and_large.push_back(kSmallSize); 328 sizes_tiny_small_and_large.push_back(kSmallEdgeSize);
325 sizes_tiny_small_and_large.push_back(kLargeSize); 329 sizes_tiny_small_and_large.push_back(kLargeEdgeSize);
326 return sizes_tiny_small_and_large; 330 return sizes_tiny_small_and_large;
327 } 331 }
328 332
329 // Returns 1x and 2x scale factors.
330 const std::vector<ui::ScaleFactor> GetScaleFactors1x2x() {
331 std::vector<ui::ScaleFactor> scale_factors_1x_2x;
332 scale_factors_1x_2x.push_back(ui::SCALE_FACTOR_100P);
333 scale_factors_1x_2x.push_back(ui::SCALE_FACTOR_200P);
334 return scale_factors_1x_2x;
335 }
336
337 // Returns the number of icon mappings of |icon_type| to |page_url|. 333 // Returns the number of icon mappings of |icon_type| to |page_url|.
338 size_t NumIconMappingsForPageURL(const GURL& page_url, 334 size_t NumIconMappingsForPageURL(const GURL& page_url,
339 favicon_base::IconType icon_type) { 335 favicon_base::IconType icon_type) {
340 std::vector<IconMapping> icon_mappings; 336 std::vector<IconMapping> icon_mappings;
341 backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type, 337 backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type,
342 &icon_mappings); 338 &icon_mappings);
343 return icon_mappings.size(); 339 return icon_mappings.size();
344 } 340 }
345 341
346 // Returns the icon mappings for |page_url| sorted alphabetically by icon 342 // Returns the icon mappings for |page_url| sorted alphabetically by icon
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 return false; 376 return false;
381 *favicon_bitmap = favicon_bitmaps[0]; 377 *favicon_bitmap = favicon_bitmaps[0];
382 return true; 378 return true;
383 } 379 }
384 380
385 // Generates |favicon_bitmap_data| with entries for the icon_urls and sizes 381 // Generates |favicon_bitmap_data| with entries for the icon_urls and sizes
386 // specified. The bitmap_data for entries are lowercase letters of the 382 // specified. The bitmap_data for entries are lowercase letters of the
387 // alphabet starting at 'a' for the entry at index 0. 383 // alphabet starting at 'a' for the entry at index 0.
388 void GenerateFaviconBitmapData( 384 void GenerateFaviconBitmapData(
389 const GURL& icon_url1, 385 const GURL& icon_url1,
390 const std::vector<gfx::Size>& icon_url1_sizes, 386 const std::vector<int>& icon_url1_sizes,
391 std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) { 387 std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) {
392 GenerateFaviconBitmapData(icon_url1, icon_url1_sizes, GURL(), 388 GenerateFaviconBitmapData(icon_url1, icon_url1_sizes, GURL(),
393 std::vector<gfx::Size>(), favicon_bitmap_data); 389 std::vector<int>(), favicon_bitmap_data);
394 } 390 }
395 391
396 void GenerateFaviconBitmapData( 392 void GenerateFaviconBitmapData(
397 const GURL& icon_url1, 393 const GURL& icon_url1,
398 const std::vector<gfx::Size>& icon_url1_sizes, 394 const std::vector<int>& icon_url1_sizes,
399 const GURL& icon_url2, 395 const GURL& icon_url2,
400 const std::vector<gfx::Size>& icon_url2_sizes, 396 const std::vector<int>& icon_url2_sizes,
401 std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) { 397 std::vector<favicon_base::FaviconRawBitmapData>* favicon_bitmap_data) {
402 favicon_bitmap_data->clear(); 398 favicon_bitmap_data->clear();
403 399
404 char bitmap_char = 'a'; 400 char bitmap_char = 'a';
405 for (size_t i = 0; i < icon_url1_sizes.size(); ++i) { 401 for (size_t i = 0; i < icon_url1_sizes.size(); ++i) {
406 std::vector<unsigned char> data; 402 std::vector<unsigned char> data;
407 data.push_back(bitmap_char); 403 data.push_back(bitmap_char);
408 favicon_base::FaviconRawBitmapData bitmap_data_element; 404 favicon_base::FaviconRawBitmapData bitmap_data_element;
409 bitmap_data_element.bitmap_data = 405 bitmap_data_element.bitmap_data =
410 base::RefCountedBytes::TakeVector(&data); 406 base::RefCountedBytes::TakeVector(&data);
411 bitmap_data_element.pixel_size = icon_url1_sizes[i]; 407 bitmap_data_element.pixel_size =
408 gfx::Size(icon_url1_sizes[i], icon_url1_sizes[i]);
412 bitmap_data_element.icon_url = icon_url1; 409 bitmap_data_element.icon_url = icon_url1;
413 favicon_bitmap_data->push_back(bitmap_data_element); 410 favicon_bitmap_data->push_back(bitmap_data_element);
414 411
415 ++bitmap_char; 412 ++bitmap_char;
416 } 413 }
417 414
418 for (size_t i = 0; i < icon_url2_sizes.size(); ++i) { 415 for (size_t i = 0; i < icon_url2_sizes.size(); ++i) {
419 std::vector<unsigned char> data; 416 std::vector<unsigned char> data;
420 data.push_back(bitmap_char); 417 data.push_back(bitmap_char);
421 favicon_base::FaviconRawBitmapData bitmap_data_element; 418 favicon_base::FaviconRawBitmapData bitmap_data_element;
422 bitmap_data_element.bitmap_data = 419 bitmap_data_element.bitmap_data =
423 base::RefCountedBytes::TakeVector(&data); 420 base::RefCountedBytes::TakeVector(&data);
424 bitmap_data_element.pixel_size = icon_url2_sizes[i]; 421 bitmap_data_element.pixel_size =
422 gfx::Size(icon_url2_sizes[i], icon_url2_sizes[i]);
425 bitmap_data_element.icon_url = icon_url2; 423 bitmap_data_element.icon_url = icon_url2;
426 favicon_bitmap_data->push_back(bitmap_data_element); 424 favicon_bitmap_data->push_back(bitmap_data_element);
427 425
428 ++bitmap_char; 426 ++bitmap_char;
429 } 427 }
430 } 428 }
431 429
432 // Returns true if |bitmap_data| is equal to |expected_data|. 430 // Returns true if |bitmap_data| is equal to |expected_data|.
433 bool BitmapDataEqual(char expected_data, 431 bool BitmapDataEqual(char expected_data,
434 scoped_refptr<base::RefCountedMemory> bitmap_data) { 432 scoped_refptr<base::RefCountedMemory> bitmap_data) {
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 history::RedirectList redirects; 1529 history::RedirectList redirects;
1532 redirects.push_back(url2); 1530 redirects.push_back(url2);
1533 redirects.push_back(url1); 1531 redirects.push_back(url1);
1534 backend_->recent_redirects_.Put(url1, redirects); 1532 backend_->recent_redirects_.Put(url1, redirects);
1535 1533
1536 const GURL icon_url1("http://www.google.com/icon"); 1534 const GURL icon_url1("http://www.google.com/icon");
1537 const GURL icon_url2("http://www.google.com/icon2"); 1535 const GURL icon_url2("http://www.google.com/icon2");
1538 1536
1539 // Generate bitmap data for a page with two favicons. 1537 // Generate bitmap data for a page with two favicons.
1540 std::vector<favicon_base::FaviconRawBitmapData> two_favicon_bitmap_data; 1538 std::vector<favicon_base::FaviconRawBitmapData> two_favicon_bitmap_data;
1541 GenerateFaviconBitmapData(icon_url1, GetSizesSmallAndLarge(), 1539 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmallAndLarge(),
1542 icon_url2, GetSizesSmallAndLarge(), &two_favicon_bitmap_data); 1540 icon_url2, GetEdgeSizesSmallAndLarge(), &two_favicon_bitmap_data);
1543 1541
1544 // Generate bitmap data for a page with a single favicon. 1542 // Generate bitmap data for a page with a single favicon.
1545 std::vector<favicon_base::FaviconRawBitmapData> one_favicon_bitmap_data; 1543 std::vector<favicon_base::FaviconRawBitmapData> one_favicon_bitmap_data;
1546 GenerateFaviconBitmapData(icon_url1, GetSizesSmallAndLarge(), 1544 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmallAndLarge(),
1547 &one_favicon_bitmap_data); 1545 &one_favicon_bitmap_data);
1548 1546
1549 // Add two favicons 1547 // Add two favicons
1550 backend_->SetFavicons(url1, favicon_base::FAVICON, two_favicon_bitmap_data); 1548 backend_->SetFavicons(url1, favicon_base::FAVICON, two_favicon_bitmap_data);
1551 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); 1549 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
1552 EXPECT_EQ(2u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON)); 1550 EXPECT_EQ(2u, NumIconMappingsForPageURL(url2, favicon_base::FAVICON));
1553 1551
1554 // Add one touch_icon 1552 // Add one touch_icon
1555 backend_->SetFavicons( 1553 backend_->SetFavicons(
1556 url1, favicon_base::TOUCH_ICON, one_favicon_bitmap_data); 1554 url1, favicon_base::TOUCH_ICON, one_favicon_bitmap_data);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON)); 1591 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, favicon_base::FAVICON));
1594 } 1592 }
1595 1593
1596 // Test that there is no churn in icon mappings from calling 1594 // Test that there is no churn in icon mappings from calling
1597 // SetFavicons() twice with the same |favicon_bitmap_data| parameter. 1595 // SetFavicons() twice with the same |favicon_bitmap_data| parameter.
1598 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageDuplicates) { 1596 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageDuplicates) {
1599 const GURL url("http://www.google.com/"); 1597 const GURL url("http://www.google.com/");
1600 const GURL icon_url("http://www.google.com/icon"); 1598 const GURL icon_url("http://www.google.com/icon");
1601 1599
1602 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1600 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1603 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(), 1601 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
1604 &favicon_bitmap_data); 1602 &favicon_bitmap_data);
1605 1603
1606 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data); 1604 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data);
1607 1605
1608 std::vector<IconMapping> icon_mappings; 1606 std::vector<IconMapping> icon_mappings;
1609 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1607 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1610 url, favicon_base::FAVICON, &icon_mappings)); 1608 url, favicon_base::FAVICON, &icon_mappings));
1611 EXPECT_EQ(1u, icon_mappings.size()); 1609 EXPECT_EQ(1u, icon_mappings.size());
1612 IconMappingID mapping_id = icon_mappings[0].mapping_id; 1610 IconMappingID mapping_id = icon_mappings[0].mapping_id;
1613 1611
(...skipping 10 matching lines...) Expand all
1624 } 1622 }
1625 1623
1626 // Test that calling SetFavicons() with FaviconBitmapData of different pixel 1624 // Test that calling SetFavicons() with FaviconBitmapData of different pixel
1627 // sizes than the initially passed in FaviconBitmapData deletes the no longer 1625 // sizes than the initially passed in FaviconBitmapData deletes the no longer
1628 // used favicon bitmaps. 1626 // used favicon bitmaps.
1629 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) { 1627 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) {
1630 const GURL page_url("http://www.google.com/"); 1628 const GURL page_url("http://www.google.com/");
1631 const GURL icon_url("http://www.google.com/icon"); 1629 const GURL icon_url("http://www.google.com/icon");
1632 1630
1633 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1631 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1634 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(), 1632 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
1635 &favicon_bitmap_data); 1633 &favicon_bitmap_data);
1636 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1634 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1637 1635
1638 // Test initial state. 1636 // Test initial state.
1639 std::vector<IconMapping> icon_mappings; 1637 std::vector<IconMapping> icon_mappings;
1640 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings)); 1638 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings));
1641 EXPECT_EQ(1u, icon_mappings.size()); 1639 EXPECT_EQ(1u, icon_mappings.size());
1642 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); 1640 EXPECT_EQ(icon_url, icon_mappings[0].icon_url);
1643 EXPECT_EQ(favicon_base::FAVICON, icon_mappings[0].icon_type); 1641 EXPECT_EQ(favicon_base::FAVICON, icon_mappings[0].icon_type);
1644 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id; 1642 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id;
1645 1643
1646 std::vector<FaviconBitmap> favicon_bitmaps; 1644 std::vector<FaviconBitmap> favicon_bitmaps;
1647 EXPECT_TRUE(GetSortedFaviconBitmaps(favicon_id, &favicon_bitmaps)); 1645 EXPECT_TRUE(GetSortedFaviconBitmaps(favicon_id, &favicon_bitmaps));
1648 EXPECT_EQ(2u, favicon_bitmaps.size()); 1646 EXPECT_EQ(2u, favicon_bitmaps.size());
1649 FaviconBitmapID small_bitmap_id = favicon_bitmaps[0].bitmap_id; 1647 FaviconBitmapID small_bitmap_id = favicon_bitmaps[0].bitmap_id;
1650 EXPECT_NE(0, small_bitmap_id); 1648 EXPECT_NE(0, small_bitmap_id);
1651 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmaps[0].bitmap_data)); 1649 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmaps[0].bitmap_data));
1652 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size); 1650 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size);
1653 FaviconBitmapID large_bitmap_id = favicon_bitmaps[1].bitmap_id; 1651 FaviconBitmapID large_bitmap_id = favicon_bitmaps[1].bitmap_id;
1654 EXPECT_NE(0, large_bitmap_id); 1652 EXPECT_NE(0, large_bitmap_id);
1655 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data)); 1653 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data));
1656 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size); 1654 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size);
1657 1655
1658 // Call SetFavicons() with bitmap data for only the large bitmap. Check that 1656 // Call SetFavicons() with bitmap data for only the large bitmap. Check that
1659 // the small bitmap is in fact deleted. 1657 // the small bitmap is in fact deleted.
1660 GenerateFaviconBitmapData(icon_url, GetSizesLarge(), &favicon_bitmap_data); 1658 GenerateFaviconBitmapData(icon_url, GetEdgeSizesLarge(),
1659 &favicon_bitmap_data);
1661 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1660 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1662 1661
1663 scoped_refptr<base::RefCountedMemory> bitmap_data_out; 1662 scoped_refptr<base::RefCountedMemory> bitmap_data_out;
1664 gfx::Size pixel_size_out; 1663 gfx::Size pixel_size_out;
1665 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(small_bitmap_id, 1664 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(small_bitmap_id,
1666 NULL, &bitmap_data_out, &pixel_size_out)); 1665 NULL, &bitmap_data_out, &pixel_size_out));
1667 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, 1666 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id,
1668 NULL, &bitmap_data_out, &pixel_size_out)); 1667 NULL, &bitmap_data_out, &pixel_size_out));
1669 EXPECT_TRUE(BitmapDataEqual('a', bitmap_data_out)); 1668 EXPECT_TRUE(BitmapDataEqual('a', bitmap_data_out));
1670 EXPECT_EQ(kLargeSize, pixel_size_out); 1669 EXPECT_EQ(kLargeSize, pixel_size_out);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 1763
1765 // Test that if two pages share the same FaviconID, changing the favicon for 1764 // Test that if two pages share the same FaviconID, changing the favicon for
1766 // one page does not affect the other. 1765 // one page does not affect the other.
1767 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) { 1766 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
1768 GURL icon_url("http://www.google.com/favicon.ico"); 1767 GURL icon_url("http://www.google.com/favicon.ico");
1769 GURL icon_url_new("http://www.google.com/favicon2.ico"); 1768 GURL icon_url_new("http://www.google.com/favicon2.ico");
1770 GURL page_url1("http://www.google.com"); 1769 GURL page_url1("http://www.google.com");
1771 GURL page_url2("http://www.google.ca"); 1770 GURL page_url2("http://www.google.ca");
1772 1771
1773 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1772 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1774 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(), 1773 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
1775 &favicon_bitmap_data); 1774 &favicon_bitmap_data);
1776 1775
1777 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); 1776 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
1778 1777
1779 std::vector<GURL> icon_urls; 1778 std::vector<GURL> icon_urls;
1780 icon_urls.push_back(icon_url); 1779 icon_urls.push_back(icon_url);
1781 1780
1782 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; 1781 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
1783 backend_->UpdateFaviconMappingsAndFetch(page_url2, 1782 backend_->UpdateFaviconMappingsAndFetch(page_url2,
1784 icon_urls, 1783 icon_urls,
1785 favicon_base::FAVICON, 1784 favicon_base::FAVICON,
1786 kSmallSize.width(), 1785 GetEdgeSizesSmallAndLarge(),
1787 GetScaleFactors1x2x(),
1788 &bitmap_results); 1786 &bitmap_results);
1789 1787
1790 // Check that the same FaviconID is mapped to both page URLs. 1788 // Check that the same FaviconID is mapped to both page URLs.
1791 std::vector<IconMapping> icon_mappings; 1789 std::vector<IconMapping> icon_mappings;
1792 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1790 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1793 page_url1, &icon_mappings)); 1791 page_url1, &icon_mappings));
1794 EXPECT_EQ(1u, icon_mappings.size()); 1792 EXPECT_EQ(1u, icon_mappings.size());
1795 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id; 1793 favicon_base::FaviconID favicon_id = icon_mappings[0].icon_id;
1796 EXPECT_NE(0, favicon_id); 1794 EXPECT_NE(0, favicon_id);
1797 1795
1798 icon_mappings.clear(); 1796 icon_mappings.clear();
1799 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1797 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1800 page_url2, &icon_mappings)); 1798 page_url2, &icon_mappings));
1801 EXPECT_EQ(1u, icon_mappings.size()); 1799 EXPECT_EQ(1u, icon_mappings.size());
1802 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1800 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1803 1801
1804 // Change the icon URL that |page_url1| is mapped to. 1802 // Change the icon URL that |page_url1| is mapped to.
1805 GenerateFaviconBitmapData(icon_url_new, GetSizesSmall(), 1803 GenerateFaviconBitmapData(icon_url_new, GetEdgeSizesSmall(),
1806 &favicon_bitmap_data); 1804 &favicon_bitmap_data);
1807 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); 1805 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
1808 1806
1809 // |page_url1| should map to a new FaviconID and have valid bitmap data. 1807 // |page_url1| should map to a new FaviconID and have valid bitmap data.
1810 icon_mappings.clear(); 1808 icon_mappings.clear();
1811 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1809 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1812 page_url1, &icon_mappings)); 1810 page_url1, &icon_mappings));
1813 EXPECT_EQ(1u, icon_mappings.size()); 1811 EXPECT_EQ(1u, icon_mappings.size());
1814 EXPECT_EQ(icon_url_new, icon_mappings[0].icon_url); 1812 EXPECT_EQ(icon_url_new, icon_mappings[0].icon_url);
1815 EXPECT_NE(favicon_id, icon_mappings[0].icon_id); 1813 EXPECT_NE(favicon_id, icon_mappings[0].icon_id);
(...skipping 21 matching lines...) Expand all
1837 EXPECT_EQ(3, num_broadcasted_notifications()); 1835 EXPECT_EQ(3, num_broadcasted_notifications());
1838 } 1836 }
1839 1837
1840 // Test that no notifications are broadcast as a result of calling 1838 // Test that no notifications are broadcast as a result of calling
1841 // UpdateFaviconMappingsAndFetch() for an icon URL which is already 1839 // UpdateFaviconMappingsAndFetch() for an icon URL which is already
1842 // mapped to the passed in page URL. 1840 // mapped to the passed in page URL.
1843 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { 1841 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) {
1844 GURL page_url("http://www.google.com"); 1842 GURL page_url("http://www.google.com");
1845 GURL icon_url("http://www.google.com/favicon.ico"); 1843 GURL icon_url("http://www.google.com/favicon.ico");
1846 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1844 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1847 GenerateFaviconBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data); 1845 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(),
1846 &favicon_bitmap_data);
1848 1847
1849 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1848 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1850 1849
1851 favicon_base::FaviconID icon_id = 1850 favicon_base::FaviconID icon_id =
1852 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1851 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1853 icon_url, favicon_base::FAVICON, NULL); 1852 icon_url, favicon_base::FAVICON, NULL);
1854 EXPECT_NE(0, icon_id); 1853 EXPECT_NE(0, icon_id);
1855 EXPECT_EQ(1, num_broadcasted_notifications()); 1854 EXPECT_EQ(1, num_broadcasted_notifications());
1856 1855
1857 std::vector<GURL> icon_urls; 1856 std::vector<GURL> icon_urls;
1858 icon_urls.push_back(icon_url); 1857 icon_urls.push_back(icon_url);
1859 1858
1860 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; 1859 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
1861 backend_->UpdateFaviconMappingsAndFetch(page_url, 1860 backend_->UpdateFaviconMappingsAndFetch(page_url,
1862 icon_urls, 1861 icon_urls,
1863 favicon_base::FAVICON, 1862 favicon_base::FAVICON,
1864 kSmallSize.width(), 1863 GetEdgeSizesSmallAndLarge(),
1865 GetScaleFactors1x2x(),
1866 &bitmap_results); 1864 &bitmap_results);
1867 1865
1868 EXPECT_EQ(icon_id, 1866 EXPECT_EQ(icon_id,
1869 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1867 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1870 icon_url, favicon_base::FAVICON, NULL)); 1868 icon_url, favicon_base::FAVICON, NULL));
1871 1869
1872 // No notification should have been broadcast as no icon mapping, favicon, 1870 // No notification should have been broadcast as no icon mapping, favicon,
1873 // or favicon bitmap was updated, added or removed. 1871 // or favicon bitmap was updated, added or removed.
1874 EXPECT_EQ(1, num_broadcasted_notifications()); 1872 EXPECT_EQ(1, num_broadcasted_notifications());
1875 } 1873 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1919 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1922 } 1920 }
1923 1921
1924 // Test calling MergeFavicon() when |page_url| is known to the database. 1922 // Test calling MergeFavicon() when |page_url| is known to the database.
1925 TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) { 1923 TEST_F(HistoryBackendTest, MergeFaviconPageURLInDB) {
1926 GURL page_url("http://www.google.com"); 1924 GURL page_url("http://www.google.com");
1927 GURL icon_url1("http:/www.google.com/favicon.ico"); 1925 GURL icon_url1("http:/www.google.com/favicon.ico");
1928 GURL icon_url2("http://www.google.com/favicon2.ico"); 1926 GURL icon_url2("http://www.google.com/favicon2.ico");
1929 1927
1930 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 1928 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
1931 GenerateFaviconBitmapData(icon_url1, GetSizesSmall(), 1929 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(),
1932 &favicon_bitmap_data); 1930 &favicon_bitmap_data);
1933 1931
1934 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 1932 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
1935 1933
1936 // Test initial state. 1934 // Test initial state.
1937 std::vector<IconMapping> icon_mappings; 1935 std::vector<IconMapping> icon_mappings;
1938 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1936 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1939 &icon_mappings)); 1937 &icon_mappings));
1940 EXPECT_EQ(1u, icon_mappings.size()); 1938 EXPECT_EQ(1u, icon_mappings.size());
1941 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1939 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2048 2046
2049 // Test calling MergeFavicon() when |icon_url| is known to the database but not 2047 // Test calling MergeFavicon() when |icon_url| is known to the database but not
2050 // mapped to |page_url|. 2048 // mapped to |page_url|.
2051 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { 2049 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) {
2052 GURL page_url1("http://www.google.com"); 2050 GURL page_url1("http://www.google.com");
2053 GURL page_url2("http://news.google.com"); 2051 GURL page_url2("http://news.google.com");
2054 GURL page_url3("http://maps.google.com"); 2052 GURL page_url3("http://maps.google.com");
2055 GURL icon_url("http:/www.google.com/favicon.ico"); 2053 GURL icon_url("http:/www.google.com/favicon.ico");
2056 2054
2057 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2055 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2058 GenerateFaviconBitmapData(icon_url, GetSizesSmall(), 2056 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(),
2059 &favicon_bitmap_data); 2057 &favicon_bitmap_data);
2060 2058
2061 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data); 2059 backend_->SetFavicons(page_url1, favicon_base::FAVICON, favicon_bitmap_data);
2062 2060
2063 // Test initial state. 2061 // Test initial state.
2064 std::vector<IconMapping> icon_mappings; 2062 std::vector<IconMapping> icon_mappings;
2065 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1, 2063 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1,
2066 &icon_mappings)); 2064 &icon_mappings));
2067 EXPECT_EQ(1u, icon_mappings.size()); 2065 EXPECT_EQ(1u, icon_mappings.size());
2068 EXPECT_EQ(icon_url, icon_mappings[0].icon_url); 2066 EXPECT_EQ(icon_url, icon_mappings[0].icon_url);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 } 2167 }
2170 2168
2171 // Tests that the favicon set by MergeFavicon() shows up in the result of 2169 // Tests that the favicon set by MergeFavicon() shows up in the result of
2172 // GetFaviconsForURL(). 2170 // GetFaviconsForURL().
2173 TEST_F(HistoryBackendTest, MergeFaviconShowsUpInGetFaviconsForURLResult) { 2171 TEST_F(HistoryBackendTest, MergeFaviconShowsUpInGetFaviconsForURLResult) {
2174 GURL page_url("http://www.google.com"); 2172 GURL page_url("http://www.google.com");
2175 GURL icon_url("http://www.google.com/favicon.ico"); 2173 GURL icon_url("http://www.google.com/favicon.ico");
2176 GURL merged_icon_url("http://wwww.google.com/favicon2.ico"); 2174 GURL merged_icon_url("http://wwww.google.com/favicon2.ico");
2177 2175
2178 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2176 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2179 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(), 2177 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmallAndLarge(),
2180 &favicon_bitmap_data); 2178 &favicon_bitmap_data);
2181 2179
2182 // Set some preexisting favicons for |page_url|. 2180 // Set some preexisting favicons for |page_url|.
2183 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2181 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2184 2182
2185 // Merge small favicon. 2183 // Merge small favicon.
2186 std::vector<unsigned char> data; 2184 std::vector<unsigned char> data;
2187 data.push_back('c'); 2185 data.push_back('c');
2188 scoped_refptr<base::RefCountedBytes> bitmap_data( 2186 scoped_refptr<base::RefCountedBytes> bitmap_data(
2189 new base::RefCountedBytes(data)); 2187 new base::RefCountedBytes(data));
2190 backend_->MergeFavicon(page_url, 2188 backend_->MergeFavicon(page_url,
2191 merged_icon_url, 2189 merged_icon_url,
2192 favicon_base::FAVICON, 2190 favicon_base::FAVICON,
2193 bitmap_data, 2191 bitmap_data,
2194 kSmallSize); 2192 kSmallSize);
2195 2193
2196 // Request favicon bitmaps for both 1x and 2x to simulate request done by 2194 // Request favicon bitmaps for both 1x and 2x to simulate request done by
2197 // BookmarkModel::GetFavicon(). 2195 // BookmarkModel::GetFavicon().
2198 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; 2196 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
2199 backend_->GetFaviconsForURL(page_url, 2197 backend_->GetFaviconsForURL(page_url,
2200 favicon_base::FAVICON, 2198 favicon_base::FAVICON,
2201 kSmallSize.width(), 2199 GetEdgeSizesSmallAndLarge(),
2202 GetScaleFactors1x2x(),
2203 &bitmap_results); 2200 &bitmap_results);
2204 2201
2205 EXPECT_EQ(2u, bitmap_results.size()); 2202 EXPECT_EQ(2u, bitmap_results.size());
2206 const favicon_base::FaviconRawBitmapResult& first_result = bitmap_results[0]; 2203 const favicon_base::FaviconRawBitmapResult& first_result = bitmap_results[0];
2207 const favicon_base::FaviconRawBitmapResult& result = 2204 const favicon_base::FaviconRawBitmapResult& result =
2208 (first_result.pixel_size == kSmallSize) ? first_result 2205 (first_result.pixel_size == kSmallSize) ? first_result
2209 : bitmap_results[1]; 2206 : bitmap_results[1];
2210 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data)); 2207 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data));
2211 } 2208 }
2212 2209
2213 // Tests GetFaviconsForURL with icon_types priority, 2210 // Tests GetFaviconsForURL with icon_types priority,
2214 TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) { 2211 TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) {
2215 GURL page_url("http://www.google.com"); 2212 GURL page_url("http://www.google.com");
2216 GURL icon_url("http://www.google.com/favicon.ico"); 2213 GURL icon_url("http://www.google.com/favicon.ico");
2217 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico"); 2214 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
2218 2215
2219 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2216 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2220 std::vector<gfx::Size> favicon_size; 2217 std::vector<int> favicon_size;
2221 favicon_size.push_back(gfx::Size(16, 16)); 2218 favicon_size.push_back(16);
2222 favicon_size.push_back(gfx::Size(32, 32)); 2219 favicon_size.push_back(32);
2223 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data); 2220 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
2224 ASSERT_EQ(2u, favicon_bitmap_data.size()); 2221 ASSERT_EQ(2u, favicon_bitmap_data.size());
2225 2222
2226 std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data; 2223 std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data;
2227 std::vector<gfx::Size> touch_icon_size; 2224 std::vector<int> touch_icon_size;
2228 touch_icon_size.push_back(gfx::Size(64, 64)); 2225 touch_icon_size.push_back(64);
2229 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data); 2226 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
2230 ASSERT_EQ(1u, touch_icon_bitmap_data.size()); 2227 ASSERT_EQ(1u, touch_icon_bitmap_data.size());
2231 2228
2232 // Set some preexisting favicons for |page_url|. 2229 // Set some preexisting favicons for |page_url|.
2233 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2230 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2234 backend_->SetFavicons( 2231 backend_->SetFavicons(
2235 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data); 2232 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data);
2236 2233
2237 favicon_base::FaviconRawBitmapResult result; 2234 favicon_base::FaviconRawBitmapResult result;
2238 std::vector<int> icon_types; 2235 std::vector<int> icon_types;
(...skipping 13 matching lines...) Expand all
2252 } 2249 }
2253 2250
2254 // Test the the first types of icon is returned if its size equal to the 2251 // Test the the first types of icon is returned if its size equal to the
2255 // second types icon. 2252 // second types icon.
2256 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) { 2253 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) {
2257 GURL page_url("http://www.google.com"); 2254 GURL page_url("http://www.google.com");
2258 GURL icon_url("http://www.google.com/favicon.ico"); 2255 GURL icon_url("http://www.google.com/favicon.ico");
2259 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico"); 2256 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
2260 2257
2261 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2258 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2262 std::vector<gfx::Size> favicon_size; 2259 std::vector<int> favicon_size;
2263 favicon_size.push_back(gfx::Size(16, 16)); 2260 favicon_size.push_back(16);
2264 favicon_size.push_back(gfx::Size(32, 32)); 2261 favicon_size.push_back(32);
2265 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data); 2262 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
2266 ASSERT_EQ(2u, favicon_bitmap_data.size()); 2263 ASSERT_EQ(2u, favicon_bitmap_data.size());
2267 2264
2268 std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data; 2265 std::vector<favicon_base::FaviconRawBitmapData> touch_icon_bitmap_data;
2269 std::vector<gfx::Size> touch_icon_size; 2266 std::vector<int> touch_icon_size;
2270 touch_icon_size.push_back(gfx::Size(32, 32)); 2267 touch_icon_size.push_back(32);
2271 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data); 2268 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
2272 ASSERT_EQ(1u, touch_icon_bitmap_data.size()); 2269 ASSERT_EQ(1u, touch_icon_bitmap_data.size());
2273 2270
2274 // Set some preexisting favicons for |page_url|. 2271 // Set some preexisting favicons for |page_url|.
2275 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2272 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2276 backend_->SetFavicons( 2273 backend_->SetFavicons(
2277 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data); 2274 page_url, favicon_base::TOUCH_ICON, touch_icon_bitmap_data);
2278 2275
2279 favicon_base::FaviconRawBitmapResult result; 2276 favicon_base::FaviconRawBitmapResult result;
2280 std::vector<int> icon_types; 2277 std::vector<int> icon_types;
(...skipping 13 matching lines...) Expand all
2294 EXPECT_EQ(favicon_base::FAVICON, result1.icon_type); 2291 EXPECT_EQ(favicon_base::FAVICON, result1.icon_type);
2295 } 2292 }
2296 2293
2297 // Test the favicon is returned if its size is smaller than minimal size, 2294 // Test the favicon is returned if its size is smaller than minimal size,
2298 // because it is only one available. 2295 // because it is only one available.
2299 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) { 2296 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) {
2300 GURL page_url("http://www.google.com"); 2297 GURL page_url("http://www.google.com");
2301 GURL icon_url("http://www.google.com/favicon.ico"); 2298 GURL icon_url("http://www.google.com/favicon.ico");
2302 2299
2303 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2300 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2304 std::vector<gfx::Size> favicon_size; 2301 std::vector<int> favicon_size;
2305 favicon_size.push_back(gfx::Size(16, 16)); 2302 favicon_size.push_back(16);
2306 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data); 2303 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
2307 ASSERT_EQ(1u, favicon_bitmap_data.size()); 2304 ASSERT_EQ(1u, favicon_bitmap_data.size());
2308 2305
2309 // Set preexisting favicons for |page_url|. 2306 // Set preexisting favicons for |page_url|.
2310 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2307 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2311 2308
2312 favicon_base::FaviconRawBitmapResult result; 2309 favicon_base::FaviconRawBitmapResult result;
2313 std::vector<int> icon_types; 2310 std::vector<int> icon_types;
2314 icon_types.push_back(favicon_base::FAVICON); 2311 icon_types.push_back(favicon_base::FAVICON);
2315 icon_types.push_back(favicon_base::TOUCH_ICON); 2312 icon_types.push_back(favicon_base::TOUCH_ICON);
2316 2313
2317 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result); 2314 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result);
2318 2315
2319 // Verify 16x16 icon is returned, even it small than minimal_size. 2316 // Verify 16x16 icon is returned, even it small than minimal_size.
2320 EXPECT_EQ(gfx::Size(16, 16), result.pixel_size); 2317 EXPECT_EQ(gfx::Size(16, 16), result.pixel_size);
2321 EXPECT_EQ(favicon_base::FAVICON, result.icon_type); 2318 EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
2322 } 2319 }
2323 2320
2324 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in. 2321 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in.
2325 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) { 2322 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
2326 GURL page_url1("http://www.google.com"); 2323 GURL page_url1("http://www.google.com");
2327 GURL page_url2("http://news.google.com"); 2324 GURL page_url2("http://news.google.com");
2328 GURL page_url3("http://mail.google.com"); 2325 GURL page_url3("http://mail.google.com");
2329 GURL icon_urla("http://www.google.com/favicon1.ico"); 2326 GURL icon_urla("http://www.google.com/favicon1.ico");
2330 GURL icon_urlb("http://www.google.com/favicon2.ico"); 2327 GURL icon_urlb("http://www.google.com/favicon2.ico");
2331 GURL icon_urlc("http://www.google.com/favicon3.ico"); 2328 GURL icon_urlc("http://www.google.com/favicon3.ico");
2332 2329
2333 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON. 2330 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON.
2334 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2331 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2335 GenerateFaviconBitmapData(icon_urla, GetSizesSmall(), &favicon_bitmap_data); 2332 GenerateFaviconBitmapData(icon_urla, GetEdgeSizesSmall(),
2333 &favicon_bitmap_data);
2336 backend_->SetFavicons( 2334 backend_->SetFavicons(
2337 page_url1, favicon_base::TOUCH_ICON, favicon_bitmap_data); 2335 page_url1, favicon_base::TOUCH_ICON, favicon_bitmap_data);
2338 2336
2339 // |page_url2| is mapped to |icon_urlb| and |icon_urlc| which are of type 2337 // |page_url2| is mapped to |icon_urlb| and |icon_urlc| which are of type
2340 // TOUCH_PRECOMPOSED_ICON. 2338 // TOUCH_PRECOMPOSED_ICON.
2341 GenerateFaviconBitmapData(icon_urlb, GetSizesSmall(), icon_urlc, 2339 GenerateFaviconBitmapData(icon_urlb, GetEdgeSizesSmall(), icon_urlc,
2342 GetSizesSmall(), &favicon_bitmap_data); 2340 GetEdgeSizesSmall(), &favicon_bitmap_data);
2343 backend_->SetFavicons( 2341 backend_->SetFavicons(
2344 page_url2, favicon_base::TOUCH_PRECOMPOSED_ICON, favicon_bitmap_data); 2342 page_url2, favicon_base::TOUCH_PRECOMPOSED_ICON, favicon_bitmap_data);
2345 2343
2346 std::vector<GURL> icon_urls; 2344 std::vector<GURL> icon_urls;
2347 icon_urls.push_back(icon_urla); 2345 icon_urls.push_back(icon_urla);
2348 icon_urls.push_back(icon_urlb); 2346 icon_urls.push_back(icon_urlb);
2349 icon_urls.push_back(icon_urlc); 2347 icon_urls.push_back(icon_urlc);
2350 2348
2351 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; 2349 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
2352 backend_->UpdateFaviconMappingsAndFetch( 2350 backend_->UpdateFaviconMappingsAndFetch(
2353 page_url3, 2351 page_url3,
2354 icon_urls, 2352 icon_urls,
2355 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON), 2353 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON),
2356 kSmallSize.width(), 2354 GetEdgeSizesSmallAndLarge(),
2357 GetScaleFactors1x2x(),
2358 &bitmap_results); 2355 &bitmap_results);
2359 2356
2360 // |page_url1| and |page_url2| should still be mapped to the same icon URLs. 2357 // |page_url1| and |page_url2| should still be mapped to the same icon URLs.
2361 std::vector<IconMapping> icon_mappings; 2358 std::vector<IconMapping> icon_mappings;
2362 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1, 2359 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1,
2363 &icon_mappings)); 2360 &icon_mappings));
2364 EXPECT_EQ(1u, icon_mappings.size()); 2361 EXPECT_EQ(1u, icon_mappings.size());
2365 EXPECT_EQ(icon_urla, icon_mappings[0].icon_url); 2362 EXPECT_EQ(icon_urla, icon_mappings[0].icon_url);
2366 EXPECT_EQ(favicon_base::TOUCH_ICON, icon_mappings[0].icon_type); 2363 EXPECT_EQ(favicon_base::TOUCH_ICON, icon_mappings[0].icon_type);
2367 2364
(...skipping 17 matching lines...) Expand all
2385 } 2382 }
2386 2383
2387 // Test the results of GetFaviconsFromDB() when there are no found 2384 // Test the results of GetFaviconsFromDB() when there are no found
2388 // favicons. 2385 // favicons.
2389 TEST_F(HistoryBackendTest, GetFaviconsFromDBEmpty) { 2386 TEST_F(HistoryBackendTest, GetFaviconsFromDBEmpty) {
2390 const GURL page_url("http://www.google.com/"); 2387 const GURL page_url("http://www.google.com/");
2391 2388
2392 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; 2389 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
2393 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, 2390 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url,
2394 favicon_base::FAVICON, 2391 favicon_base::FAVICON,
2395 kSmallSize.width(), 2392 GetEdgeSizesSmallAndLarge(),
2396 GetScaleFactors1x2x(),
2397 &bitmap_results)); 2393 &bitmap_results));
2398 EXPECT_TRUE(bitmap_results.empty()); 2394 EXPECT_TRUE(bitmap_results.empty());
2399 } 2395 }
2400 2396
2401 // Test the results of GetFaviconsFromDB() when there are matching favicons 2397 // Test the results of GetFaviconsFromDB() when there are matching favicons
2402 // but there are no associated favicon bitmaps. 2398 // but there are no associated favicon bitmaps.
2403 TEST_F(HistoryBackendTest, GetFaviconsFromDBNoFaviconBitmaps) { 2399 TEST_F(HistoryBackendTest, GetFaviconsFromDBNoFaviconBitmaps) {
2404 const GURL page_url("http://www.google.com/"); 2400 const GURL page_url("http://www.google.com/");
2405 const GURL icon_url("http://www.google.com/icon1"); 2401 const GURL icon_url("http://www.google.com/icon1");
2406 2402
2407 favicon_base::FaviconID icon_id = 2403 favicon_base::FaviconID icon_id =
2408 backend_->thumbnail_db_->AddFavicon(icon_url, favicon_base::FAVICON); 2404 backend_->thumbnail_db_->AddFavicon(icon_url, favicon_base::FAVICON);
2409 EXPECT_NE(0, icon_id); 2405 EXPECT_NE(0, icon_id);
2410 EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id)); 2406 EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id));
2411 2407
2412 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; 2408 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2413 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, 2409 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url,
2414 favicon_base::FAVICON, 2410 favicon_base::FAVICON,
2415 kSmallSize.width(), 2411 GetEdgeSizesSmallAndLarge(),
2416 GetScaleFactors1x2x(),
2417 &bitmap_results_out)); 2412 &bitmap_results_out));
2418 EXPECT_TRUE(bitmap_results_out.empty()); 2413 EXPECT_TRUE(bitmap_results_out.empty());
2419 } 2414 }
2420 2415
2421 // Test that GetFaviconsFromDB() returns results for the bitmaps which most 2416 // Test that GetFaviconsFromDB() returns results for the bitmaps which most
2422 // closely match the passed in desired size and scale factors. 2417 // closely match the passed in the desired pixel sizes.
2423 TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) { 2418 TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) {
2424 const GURL page_url("http://www.google.com/"); 2419 const GURL page_url("http://www.google.com/");
2425 const GURL icon_url("http://www.google.com/icon1"); 2420 const GURL icon_url("http://www.google.com/icon1");
2426 2421
2427 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2422 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2428 GenerateFaviconBitmapData(icon_url, GetSizesTinySmallAndLarge(), 2423 GenerateFaviconBitmapData(icon_url, GetEdgeSizesTinySmallAndLarge(),
2429 &favicon_bitmap_data); 2424 &favicon_bitmap_data);
2430 2425
2431 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2426 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2432 2427
2433 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; 2428 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2434 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, 2429 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
2435 favicon_base::FAVICON, 2430 favicon_base::FAVICON,
2436 kSmallSize.width(), 2431 GetEdgeSizesSmallAndLarge(),
2437 GetScaleFactors1x2x(),
2438 &bitmap_results_out)); 2432 &bitmap_results_out));
2439 2433
2440 // The bitmap data for the small and large bitmaps should be returned as their 2434 // The bitmap data for the small and large bitmaps should be returned as their
2441 // sizes match exactly. 2435 // sizes match exactly.
2442 EXPECT_EQ(2u, bitmap_results_out.size()); 2436 EXPECT_EQ(2u, bitmap_results_out.size());
2443 // No required order for results. 2437 // No required order for results.
2444 if (bitmap_results_out[0].pixel_size == kLargeSize) { 2438 if (bitmap_results_out[0].pixel_size == kLargeSize) {
2445 favicon_base::FaviconRawBitmapResult tmp_result = bitmap_results_out[0]; 2439 favicon_base::FaviconRawBitmapResult tmp_result = bitmap_results_out[0];
2446 bitmap_results_out[0] = bitmap_results_out[1]; 2440 bitmap_results_out[0] = bitmap_results_out[1];
2447 bitmap_results_out[1] = tmp_result; 2441 bitmap_results_out[1] = tmp_result;
2448 } 2442 }
2449 2443
2450 EXPECT_FALSE(bitmap_results_out[0].expired); 2444 EXPECT_FALSE(bitmap_results_out[0].expired);
2451 EXPECT_TRUE(BitmapDataEqual('b', bitmap_results_out[0].bitmap_data)); 2445 EXPECT_TRUE(BitmapDataEqual('b', bitmap_results_out[0].bitmap_data));
2452 EXPECT_EQ(kSmallSize, bitmap_results_out[0].pixel_size); 2446 EXPECT_EQ(kSmallSize, bitmap_results_out[0].pixel_size);
2453 EXPECT_EQ(icon_url, bitmap_results_out[0].icon_url); 2447 EXPECT_EQ(icon_url, bitmap_results_out[0].icon_url);
2454 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type); 2448 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type);
2455 2449
2456 EXPECT_FALSE(bitmap_results_out[1].expired); 2450 EXPECT_FALSE(bitmap_results_out[1].expired);
2457 EXPECT_TRUE(BitmapDataEqual('c', bitmap_results_out[1].bitmap_data)); 2451 EXPECT_TRUE(BitmapDataEqual('c', bitmap_results_out[1].bitmap_data));
2458 EXPECT_EQ(kLargeSize, bitmap_results_out[1].pixel_size); 2452 EXPECT_EQ(kLargeSize, bitmap_results_out[1].pixel_size);
2459 EXPECT_EQ(icon_url, bitmap_results_out[1].icon_url); 2453 EXPECT_EQ(icon_url, bitmap_results_out[1].icon_url);
2460 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[1].icon_type); 2454 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[1].icon_type);
2461 } 2455 }
2462 2456
2463 // Test that GetFaviconsFromDB() returns results from the icon URL whose 2457 // Test that GetFaviconsFromDB() returns results from the icon URL whose
2464 // bitmaps most closely match the passed in desired size and scale factors. 2458 // bitmaps most closely match the passed in desired sizes.
2465 TEST_F(HistoryBackendTest, GetFaviconsFromDBSingleIconURL) { 2459 TEST_F(HistoryBackendTest, GetFaviconsFromDBSingleIconURL) {
2466 const GURL page_url("http://www.google.com/"); 2460 const GURL page_url("http://www.google.com/");
2467 2461
2468 const GURL icon_url1("http://www.google.com/icon1"); 2462 const GURL icon_url1("http://www.google.com/icon1");
2469 const GURL icon_url2("http://www.google.com/icon2"); 2463 const GURL icon_url2("http://www.google.com/icon2");
2470 2464
2471 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2465 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2472 GenerateFaviconBitmapData(icon_url1, GetSizesSmall(), icon_url2, 2466 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(), icon_url2,
2473 GetSizesLarge(), &favicon_bitmap_data); 2467 GetEdgeSizesLarge(), &favicon_bitmap_data);
2474 2468
2475 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2469 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2476 2470
2477 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; 2471 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2478 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, 2472 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
2479 favicon_base::FAVICON, 2473 favicon_base::FAVICON,
2480 kSmallSize.width(), 2474 GetEdgeSizesSmallAndLarge(),
2481 GetScaleFactors1x2x(),
2482 &bitmap_results_out)); 2475 &bitmap_results_out));
2483 2476
2484 // The results should have results for the icon URL with the large bitmap as 2477 // The results should have results for the icon URL with the large bitmap as
2485 // downscaling is preferred to upscaling. 2478 // downscaling is preferred to upscaling.
2486 EXPECT_EQ(1u, bitmap_results_out.size()); 2479 EXPECT_EQ(1u, bitmap_results_out.size());
2487 EXPECT_EQ(kLargeSize, bitmap_results_out[0].pixel_size); 2480 EXPECT_EQ(kLargeSize, bitmap_results_out[0].pixel_size);
2488 EXPECT_EQ(icon_url2, bitmap_results_out[0].icon_url); 2481 EXPECT_EQ(icon_url2, bitmap_results_out[0].icon_url);
2489 } 2482 }
2490 2483
2491 // Test the results of GetFaviconsFromDB() when called with different 2484 // Test the results of GetFaviconsFromDB() when called with different
2492 // |icon_types|. 2485 // |icon_types|.
2493 TEST_F(HistoryBackendTest, GetFaviconsFromDBIconType) { 2486 TEST_F(HistoryBackendTest, GetFaviconsFromDBIconType) {
2494 const GURL page_url("http://www.google.com/"); 2487 const GURL page_url("http://www.google.com/");
2495 const GURL icon_url1("http://www.google.com/icon1.png"); 2488 const GURL icon_url1("http://www.google.com/icon1.png");
2496 const GURL icon_url2("http://www.google.com/icon2.png"); 2489 const GURL icon_url2("http://www.google.com/icon2.png");
2497 2490
2498 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2491 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2499 GenerateFaviconBitmapData(icon_url1, GetSizesSmall(), &favicon_bitmap_data); 2492 GenerateFaviconBitmapData(icon_url1, GetEdgeSizesSmall(),
2493 &favicon_bitmap_data);
2500 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data); 2494 backend_->SetFavicons(page_url, favicon_base::FAVICON, favicon_bitmap_data);
2501 2495
2502 GenerateFaviconBitmapData(icon_url2, GetSizesSmall(), &favicon_bitmap_data); 2496 GenerateFaviconBitmapData(
2497 icon_url2, GetEdgeSizesSmall(), &favicon_bitmap_data);
2503 backend_->SetFavicons( 2498 backend_->SetFavicons(
2504 page_url, favicon_base::TOUCH_ICON, favicon_bitmap_data); 2499 page_url, favicon_base::TOUCH_ICON, favicon_bitmap_data);
2505 2500
2506 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; 2501 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2507 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, 2502 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
2508 favicon_base::FAVICON, 2503 favicon_base::FAVICON,
2509 kSmallSize.width(), 2504 GetEdgeSizesSmallAndLarge(),
2510 GetScaleFactors1x2x(),
2511 &bitmap_results_out)); 2505 &bitmap_results_out));
2512 2506
2513 EXPECT_EQ(1u, bitmap_results_out.size()); 2507 EXPECT_EQ(1u, bitmap_results_out.size());
2514 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type); 2508 EXPECT_EQ(favicon_base::FAVICON, bitmap_results_out[0].icon_type);
2515 EXPECT_EQ(icon_url1, bitmap_results_out[0].icon_url); 2509 EXPECT_EQ(icon_url1, bitmap_results_out[0].icon_url);
2516 2510
2517 bitmap_results_out.clear(); 2511 bitmap_results_out.clear();
2518 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, 2512 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
2519 favicon_base::TOUCH_ICON, 2513 favicon_base::TOUCH_ICON,
2520 kSmallSize.width(), 2514 GetEdgeSizesSmallAndLarge(),
2521 GetScaleFactors1x2x(),
2522 &bitmap_results_out)); 2515 &bitmap_results_out));
2523 2516
2524 EXPECT_EQ(1u, bitmap_results_out.size()); 2517 EXPECT_EQ(1u, bitmap_results_out.size());
2525 EXPECT_EQ(favicon_base::TOUCH_ICON, bitmap_results_out[0].icon_type); 2518 EXPECT_EQ(favicon_base::TOUCH_ICON, bitmap_results_out[0].icon_type);
2526 EXPECT_EQ(icon_url2, bitmap_results_out[0].icon_url); 2519 EXPECT_EQ(icon_url2, bitmap_results_out[0].icon_url);
2527 } 2520 }
2528 2521
2529 // Test that GetFaviconsFromDB() correctly sets the expired flag for bitmap 2522 // Test that GetFaviconsFromDB() correctly sets the expired flag for bitmap
2530 // reults. 2523 // reults.
2531 TEST_F(HistoryBackendTest, GetFaviconsFromDBExpired) { 2524 TEST_F(HistoryBackendTest, GetFaviconsFromDBExpired) {
2532 const GURL page_url("http://www.google.com/"); 2525 const GURL page_url("http://www.google.com/");
2533 const GURL icon_url("http://www.google.com/icon.png"); 2526 const GURL icon_url("http://www.google.com/icon.png");
2534 2527
2535 std::vector<unsigned char> data; 2528 std::vector<unsigned char> data;
2536 data.push_back('a'); 2529 data.push_back('a');
2537 scoped_refptr<base::RefCountedBytes> bitmap_data( 2530 scoped_refptr<base::RefCountedBytes> bitmap_data(
2538 base::RefCountedBytes::TakeVector(&data)); 2531 base::RefCountedBytes::TakeVector(&data));
2539 base::Time last_updated = base::Time::FromTimeT(0); 2532 base::Time last_updated = base::Time::FromTimeT(0);
2540 favicon_base::FaviconID icon_id = backend_->thumbnail_db_->AddFavicon( 2533 favicon_base::FaviconID icon_id = backend_->thumbnail_db_->AddFavicon(
2541 icon_url, favicon_base::FAVICON, bitmap_data, last_updated, kSmallSize); 2534 icon_url, favicon_base::FAVICON, bitmap_data, last_updated, kSmallSize);
2542 EXPECT_NE(0, icon_id); 2535 EXPECT_NE(0, icon_id);
2543 EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id)); 2536 EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id));
2544 2537
2545 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; 2538 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2546 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, 2539 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url,
2547 favicon_base::FAVICON, 2540 favicon_base::FAVICON,
2548 kSmallSize.width(), 2541 GetEdgeSizesSmallAndLarge(),
2549 GetScaleFactors1x2x(),
2550 &bitmap_results_out)); 2542 &bitmap_results_out));
2551 2543
2552 EXPECT_EQ(1u, bitmap_results_out.size()); 2544 EXPECT_EQ(1u, bitmap_results_out.size());
2553 EXPECT_TRUE(bitmap_results_out[0].expired); 2545 EXPECT_TRUE(bitmap_results_out[0].expired);
2554 } 2546 }
2555 2547
2556 // Check that UpdateFaviconMappingsAndFetch() call back to the UI when there is 2548 // Check that UpdateFaviconMappingsAndFetch() call back to the UI when there is
2557 // no valid thumbnail database. 2549 // no valid thumbnail database.
2558 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoDB) { 2550 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoDB) {
2559 // Make the thumbnail database invalid. 2551 // Make the thumbnail database invalid.
2560 backend_->thumbnail_db_.reset(); 2552 backend_->thumbnail_db_.reset();
2561 2553
2562 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results; 2554 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results;
2563 2555
2564 backend_->UpdateFaviconMappingsAndFetch(GURL(), 2556 backend_->UpdateFaviconMappingsAndFetch(GURL(),
2565 std::vector<GURL>(), 2557 std::vector<GURL>(),
2566 favicon_base::FAVICON, 2558 favicon_base::FAVICON,
2567 kSmallSize.width(), 2559 GetEdgeSizesSmallAndLarge(),
2568 GetScaleFactors1x2x(),
2569 &bitmap_results); 2560 &bitmap_results);
2570 2561
2571 EXPECT_TRUE(bitmap_results.empty()); 2562 EXPECT_TRUE(bitmap_results.empty());
2572 } 2563 }
2573 2564
2574 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { 2565 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) {
2575 const GURL url("http://www.google.com/"); 2566 const GURL url("http://www.google.com/");
2576 const GURL same_domain_url("http://www.google.com/subdir/index.html"); 2567 const GURL same_domain_url("http://www.google.com/subdir/index.html");
2577 const GURL foreign_domain_url("http://www.not-google.com/"); 2568 const GURL foreign_domain_url("http://www.not-google.com/");
2578 const GURL icon_url("http://www.google.com/icon.png"); 2569 const GURL icon_url("http://www.google.com/icon.png");
2579 2570
2580 // Add a favicon 2571 // Add a favicon
2581 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 2572 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data;
2582 GenerateFaviconBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data); 2573 GenerateFaviconBitmapData(icon_url, GetEdgeSizesSmall(),
2574 &favicon_bitmap_data);
2583 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data); 2575 backend_->SetFavicons(url, favicon_base::FAVICON, favicon_bitmap_data);
2584 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 2576 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
2585 url, favicon_base::FAVICON, NULL)); 2577 url, favicon_base::FAVICON, NULL));
2586 2578
2587 // Validate starting state. 2579 // Validate starting state.
2588 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out; 2580 std::vector<favicon_base::FaviconRawBitmapResult> bitmap_results_out;
2589 EXPECT_TRUE(backend_->GetFaviconsFromDB(url, 2581 EXPECT_TRUE(backend_->GetFaviconsFromDB(url,
2590 favicon_base::FAVICON, 2582 favicon_base::FAVICON,
2591 kSmallSize.width(), 2583 GetEdgeSizesSmallAndLarge(),
2592 GetScaleFactors1x2x(),
2593 &bitmap_results_out)); 2584 &bitmap_results_out));
2594 EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url, 2585 EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url,
2595 favicon_base::FAVICON, 2586 favicon_base::FAVICON,
2596 kSmallSize.width(), 2587 GetEdgeSizesSmallAndLarge(),
2597 GetScaleFactors1x2x(),
2598 &bitmap_results_out)); 2588 &bitmap_results_out));
2599 EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url, 2589 EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url,
2600 favicon_base::FAVICON, 2590 favicon_base::FAVICON,
2601 kSmallSize.width(), 2591 GetEdgeSizesSmallAndLarge(),
2602 GetScaleFactors1x2x(),
2603 &bitmap_results_out)); 2592 &bitmap_results_out));
2604 2593
2605 // Same-domain cloning should work. 2594 // Same-domain cloning should work.
2606 backend_->CloneFavicons(url, same_domain_url); 2595 backend_->CloneFavicons(url, same_domain_url);
2607 EXPECT_TRUE(backend_->GetFaviconsFromDB(same_domain_url, 2596 EXPECT_TRUE(backend_->GetFaviconsFromDB(same_domain_url,
2608 favicon_base::FAVICON, 2597 favicon_base::FAVICON,
2609 kSmallSize.width(), 2598 GetEdgeSizesSmallAndLarge(),
2610 GetScaleFactors1x2x(),
2611 &bitmap_results_out)); 2599 &bitmap_results_out));
2612 2600
2613 // Foreign-domain cloning is forbidden. 2601 // Foreign-domain cloning is forbidden.
2614 backend_->CloneFavicons(url, foreign_domain_url); 2602 backend_->CloneFavicons(url, foreign_domain_url);
2615 EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url, 2603 EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url,
2616 favicon_base::FAVICON, 2604 favicon_base::FAVICON,
2617 kSmallSize.width(), 2605 GetEdgeSizesSmallAndLarge(),
2618 GetScaleFactors1x2x(),
2619 &bitmap_results_out)); 2606 &bitmap_results_out));
2620 } 2607 }
2621 2608
2622 TEST_F(HistoryBackendTest, QueryFilteredURLs) { 2609 TEST_F(HistoryBackendTest, QueryFilteredURLs) {
2623 const char* google = "http://www.google.com/"; 2610 const char* google = "http://www.google.com/";
2624 const char* yahoo = "http://www.yahoo.com/"; 2611 const char* yahoo = "http://www.yahoo.com/";
2625 const char* yahoo_sports = "http://sports.yahoo.com/"; 2612 const char* yahoo_sports = "http://sports.yahoo.com/";
2626 const char* yahoo_sports_with_article1 = 2613 const char* yahoo_sports_with_article1 =
2627 "http://sports.yahoo.com/article1.htm"; 2614 "http://sports.yahoo.com/article1.htm";
2628 const char* yahoo_sports_with_article2 = 2615 const char* yahoo_sports_with_article2 =
(...skipping 728 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 3344 // 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 3345 // at the low level that it is gone for good. The term corresponding to the
3359 // first URLRow should not be affected. 3346 // first URLRow should not be affected.
3360 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3347 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3361 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3348 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3362 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3349 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3363 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3350 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3364 } 3351 }
3365 3352
3366 } // namespace history 3353 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698