| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 EXPECT_EQ(FAVICON, icon_type_out); | 144 EXPECT_EQ(FAVICON, icon_type_out); |
| 145 EXPECT_STREQ(kSizesSmallAndLarge.c_str(), sizes_out.c_str()); | 145 EXPECT_STREQ(kSizesSmallAndLarge.c_str(), sizes_out.c_str()); |
| 146 | 146 |
| 147 std::vector<FaviconBitmap> favicon_bitmaps_out; | 147 std::vector<FaviconBitmap> favicon_bitmaps_out; |
| 148 EXPECT_TRUE(db.GetFaviconBitmaps(icon_id, &favicon_bitmaps_out)); | 148 EXPECT_TRUE(db.GetFaviconBitmaps(icon_id, &favicon_bitmaps_out)); |
| 149 EXPECT_EQ(2u, favicon_bitmaps_out.size()); | 149 EXPECT_EQ(2u, favicon_bitmaps_out.size()); |
| 150 | 150 |
| 151 FaviconBitmap favicon_bitmap1 = favicon_bitmaps_out[0]; | 151 FaviconBitmap favicon_bitmap1 = favicon_bitmaps_out[0]; |
| 152 FaviconBitmap favicon_bitmap2 = favicon_bitmaps_out[1]; | 152 FaviconBitmap favicon_bitmap2 = favicon_bitmaps_out[1]; |
| 153 | 153 |
| 154 // Bitmaps do not need to be in particular order. | 154 // Favicon bitmaps do not need to be in particular order. |
| 155 if (favicon_bitmap1.bitmap_id == bitmap2_id) { | 155 if (favicon_bitmap1.bitmap_id == bitmap2_id) { |
| 156 FaviconBitmap tmp_favicon_bitmap = favicon_bitmap1; | 156 FaviconBitmap tmp_favicon_bitmap = favicon_bitmap1; |
| 157 favicon_bitmap1 = favicon_bitmap2; | 157 favicon_bitmap1 = favicon_bitmap2; |
| 158 favicon_bitmap2 = tmp_favicon_bitmap; | 158 favicon_bitmap2 = tmp_favicon_bitmap; |
| 159 } | 159 } |
| 160 | 160 |
| 161 EXPECT_EQ(bitmap1_id, favicon_bitmap1.bitmap_id); | 161 EXPECT_EQ(bitmap1_id, favicon_bitmap1.bitmap_id); |
| 162 EXPECT_EQ(icon_id, favicon_bitmap1.icon_id); | 162 EXPECT_EQ(icon_id, favicon_bitmap1.icon_id); |
| 163 EXPECT_EQ(time.ToTimeT(), favicon_bitmap1.last_updated.ToTimeT()); | 163 EXPECT_EQ(time.ToTimeT(), favicon_bitmap1.last_updated.ToTimeT()); |
| 164 EXPECT_EQ(data.size(), favicon_bitmap1.bitmap_data->size()); | 164 EXPECT_EQ(data.size(), favicon_bitmap1.bitmap_data->size()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 185 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 185 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 186 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 186 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 187 | 187 |
| 188 GURL url("http://google.com"); | 188 GURL url("http://google.com"); |
| 189 FaviconID id = db.AddFavicon(url, TOUCH_ICON); | 189 FaviconID id = db.AddFavicon(url, TOUCH_ICON); |
| 190 EXPECT_NE(0, id); | 190 EXPECT_NE(0, id); |
| 191 base::Time time = base::Time::Now(); | 191 base::Time time = base::Time::Now(); |
| 192 db.AddFaviconBitmap(id, favicon, time, gfx::Size()); | 192 db.AddFaviconBitmap(id, favicon, time, gfx::Size()); |
| 193 | 193 |
| 194 EXPECT_NE(0, db.AddIconMapping(url, id)); | 194 EXPECT_NE(0, db.AddIconMapping(url, id)); |
| 195 std::vector<IconMapping> icon_mapping; | 195 std::vector<IconMapping> icon_mappings; |
| 196 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 196 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mappings)); |
| 197 EXPECT_EQ(1u, icon_mapping.size()); | 197 EXPECT_EQ(1u, icon_mappings.size()); |
| 198 EXPECT_EQ(url, icon_mapping.front().page_url); | 198 EXPECT_EQ(url, icon_mappings.front().page_url); |
| 199 EXPECT_EQ(id, icon_mapping.front().icon_id); | 199 EXPECT_EQ(id, icon_mappings.front().icon_id); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST_F(ThumbnailDatabaseTest, UpdateIconMapping) { | 202 TEST_F(ThumbnailDatabaseTest, UpdateIconMapping) { |
| 203 ThumbnailDatabase db; | 203 ThumbnailDatabase db; |
| 204 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 204 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 205 db.BeginTransaction(); | 205 db.BeginTransaction(); |
| 206 | 206 |
| 207 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 207 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 208 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 208 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 209 | 209 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 247 |
| 248 FaviconID id2 = db.AddFavicon(url, FAVICON); | 248 FaviconID id2 = db.AddFavicon(url, FAVICON); |
| 249 db.AddFaviconBitmap(id2, favicon, time, gfx::Size()); | 249 db.AddFaviconBitmap(id2, favicon, time, gfx::Size()); |
| 250 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); | 250 EXPECT_TRUE(0 < db.AddIconMapping(url, id2)); |
| 251 ASSERT_NE(id, id2); | 251 ASSERT_NE(id, id2); |
| 252 | 252 |
| 253 std::vector<IconMapping> icon_mapping; | 253 std::vector<IconMapping> icon_mapping; |
| 254 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 254 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 255 ASSERT_EQ(2u, icon_mapping.size()); | 255 ASSERT_EQ(2u, icon_mapping.size()); |
| 256 EXPECT_EQ(icon_mapping.front().icon_type, TOUCH_ICON); | 256 EXPECT_EQ(icon_mapping.front().icon_type, TOUCH_ICON); |
| 257 EXPECT_TRUE(db.GetIconMappingForPageURL(url, FAVICON, NULL)); | 257 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, FAVICON, NULL)); |
| 258 | 258 |
| 259 db.DeleteIconMappings(url); | 259 db.DeleteIconMappings(url); |
| 260 | 260 |
| 261 EXPECT_FALSE(db.GetIconMappingsForPageURL(url, NULL)); | 261 EXPECT_FALSE(db.GetIconMappingsForPageURL(url, NULL)); |
| 262 EXPECT_FALSE(db.GetIconMappingForPageURL(url, FAVICON, NULL)); | 262 EXPECT_FALSE(db.GetIconMappingsForPageURL(url, FAVICON, NULL)); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURL) { | 265 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURL) { |
| 266 ThumbnailDatabase db; | 266 ThumbnailDatabase db; |
| 267 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 267 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 268 db.BeginTransaction(); | 268 db.BeginTransaction(); |
| 269 | 269 |
| 270 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 270 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 271 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 271 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 272 | 272 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 db.AddIconMapping(page_url, kept_id); | 453 db.AddIconMapping(page_url, kept_id); |
| 454 | 454 |
| 455 FaviconID new_favicon_id = | 455 FaviconID new_favicon_id = |
| 456 db.CopyFaviconAndFaviconBitmapsToTemporaryTables(kept_id); | 456 db.CopyFaviconAndFaviconBitmapsToTemporaryTables(kept_id); |
| 457 EXPECT_NE(0, new_favicon_id); | 457 EXPECT_NE(0, new_favicon_id); |
| 458 EXPECT_TRUE(db.AddToTemporaryIconMappingTable(page_url, new_favicon_id)); | 458 EXPECT_TRUE(db.AddToTemporaryIconMappingTable(page_url, new_favicon_id)); |
| 459 | 459 |
| 460 EXPECT_TRUE(db.CommitTemporaryTables()); | 460 EXPECT_TRUE(db.CommitTemporaryTables()); |
| 461 | 461 |
| 462 // Only copied data should be left. | 462 // Only copied data should be left. |
| 463 IconMapping icon_mapping; | 463 std::vector<IconMapping> icon_mappings; |
| 464 EXPECT_TRUE(db.GetIconMappingForPageURL(page_url, FAVICON, &icon_mapping)); | 464 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url, FAVICON, &icon_mappings)); |
| 465 EXPECT_EQ(new_favicon_id, icon_mapping.icon_id); | 465 EXPECT_EQ(1u, icon_mappings.size()); |
| 466 EXPECT_EQ(page_url, icon_mapping.page_url); | 466 EXPECT_EQ(new_favicon_id, icon_mappings[0].icon_id); |
| 467 EXPECT_EQ(page_url, icon_mappings[0].page_url); |
| 467 | 468 |
| 468 std::vector<FaviconBitmap> favicon_bitmaps; | 469 std::vector<FaviconBitmap> favicon_bitmaps; |
| 469 EXPECT_TRUE(db.GetFaviconBitmaps(icon_mapping.icon_id, &favicon_bitmaps)); | 470 EXPECT_TRUE(db.GetFaviconBitmaps(icon_mappings[0].icon_id, &favicon_bitmaps)); |
| 470 EXPECT_EQ(1u, favicon_bitmaps.size()); | 471 EXPECT_EQ(1u, favicon_bitmaps.size()); |
| 471 EXPECT_EQ(kLargeSize, favicon_bitmaps[0].pixel_size); | 472 EXPECT_EQ(kLargeSize, favicon_bitmaps[0].pixel_size); |
| 472 | 473 |
| 473 EXPECT_FALSE(db.GetFaviconIDForFaviconURL(unkept_url, false, NULL)); | 474 EXPECT_FALSE(db.GetFaviconIDForFaviconURL(unkept_url, false)); |
| 474 } | 475 } |
| 475 | 476 |
| 476 // Tests that deleting a favicon deletes the favicon row and favicon bitmap | 477 // Tests that deleting a favicon deletes the favicon row and favicon bitmap |
| 477 // rows from the database. | 478 // rows from the database. |
| 478 TEST_F(ThumbnailDatabaseTest, DeleteFavicon) { | 479 TEST_F(ThumbnailDatabaseTest, DeleteFavicon) { |
| 479 ThumbnailDatabase db; | 480 ThumbnailDatabase db; |
| 480 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 481 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 481 db.BeginTransaction(); | 482 db.BeginTransaction(); |
| 482 | 483 |
| 483 std::vector<unsigned char> data1(blob1, blob1 + sizeof(blob1)); | 484 std::vector<unsigned char> data1(blob1, blob1 + sizeof(blob1)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 EXPECT_NE(0, db.AddIconMapping(url, id3)); | 547 EXPECT_NE(0, db.AddIconMapping(url, id3)); |
| 547 | 548 |
| 548 icon_mapping.clear(); | 549 icon_mapping.clear(); |
| 549 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 550 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 550 | 551 |
| 551 EXPECT_EQ(url, icon_mapping.front().page_url); | 552 EXPECT_EQ(url, icon_mapping.front().page_url); |
| 552 EXPECT_EQ(id3, icon_mapping.front().icon_id); | 553 EXPECT_EQ(id3, icon_mapping.front().icon_id); |
| 553 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mapping.front().icon_type); | 554 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mapping.front().icon_type); |
| 554 } | 555 } |
| 555 | 556 |
| 557 // Test result of GetIconMappingsForPageURL when an icon type is passed in. |
| 558 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLWithIconType) { |
| 559 ThumbnailDatabase db; |
| 560 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 561 db.BeginTransaction(); |
| 562 |
| 563 GURL url("http://google.com"); |
| 564 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 565 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 566 base::Time time = base::Time::Now(); |
| 567 |
| 568 FaviconID id1 = db.AddFavicon(url, FAVICON, "0 0", favicon, time, |
| 569 gfx::Size()); |
| 570 EXPECT_NE(0, db.AddIconMapping(url, id1)); |
| 571 |
| 572 FaviconID id2 = db.AddFavicon(url, TOUCH_ICON, "0 0", favicon, time, |
| 573 gfx::Size()); |
| 574 EXPECT_NE(0, db.AddIconMapping(url, id2)); |
| 575 |
| 576 std::vector<IconMapping> icon_mappings; |
| 577 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, FAVICON | TOUCH_ICON, |
| 578 &icon_mappings)); |
| 579 EXPECT_EQ(2u, icon_mappings.size()); |
| 580 EXPECT_EQ(id2, icon_mappings[0].icon_id); |
| 581 EXPECT_EQ(id1, icon_mappings[1].icon_id); |
| 582 |
| 583 icon_mappings.clear(); |
| 584 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, TOUCH_ICON, &icon_mappings)); |
| 585 EXPECT_EQ(1u, icon_mappings.size()); |
| 586 EXPECT_EQ(id2, icon_mappings[0].icon_id); |
| 587 } |
| 588 |
| 556 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { | 589 TEST_F(ThumbnailDatabaseTest, HasMappingFor) { |
| 557 ThumbnailDatabase db; | 590 ThumbnailDatabase db; |
| 558 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 591 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 559 db.BeginTransaction(); | 592 db.BeginTransaction(); |
| 560 | 593 |
| 561 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 594 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 562 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 595 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 563 | 596 |
| 564 // Add a favicon which will have icon_mappings | 597 // Add a favicon which will have icon_mappings |
| 565 FaviconID id1 = db.AddFavicon(GURL("http://google.com"), FAVICON); | 598 FaviconID id1 = db.AddFavicon(GURL("http://google.com"), FAVICON); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 588 EXPECT_TRUE(db.HasMappingFor(id2)); | 621 EXPECT_TRUE(db.HasMappingFor(id2)); |
| 589 EXPECT_FALSE(db.HasMappingFor(id3)); | 622 EXPECT_FALSE(db.HasMappingFor(id3)); |
| 590 | 623 |
| 591 // Remove all mappings | 624 // Remove all mappings |
| 592 db.DeleteIconMappings(page_url); | 625 db.DeleteIconMappings(page_url); |
| 593 EXPECT_FALSE(db.HasMappingFor(id1)); | 626 EXPECT_FALSE(db.HasMappingFor(id1)); |
| 594 EXPECT_FALSE(db.HasMappingFor(id2)); | 627 EXPECT_FALSE(db.HasMappingFor(id2)); |
| 595 EXPECT_FALSE(db.HasMappingFor(id3)); | 628 EXPECT_FALSE(db.HasMappingFor(id3)); |
| 596 } | 629 } |
| 597 | 630 |
| 598 TEST_F(ThumbnailDatabaseTest, CloneIconMapping) { | 631 TEST_F(ThumbnailDatabaseTest, CloneIconMappings) { |
| 599 ThumbnailDatabase db; | 632 ThumbnailDatabase db; |
| 600 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 633 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 601 db.BeginTransaction(); | 634 db.BeginTransaction(); |
| 602 | 635 |
| 603 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 636 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 604 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 637 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 605 | 638 |
| 606 // Add a favicon which will have icon_mappings | 639 // Add a favicon which will have icon_mappings |
| 607 FaviconID id1 = db.AddFavicon(GURL("http://google.com"), FAVICON); | 640 FaviconID id1 = db.AddFavicon(GURL("http://google.com"), FAVICON); |
| 608 EXPECT_NE(0, id1); | 641 EXPECT_NE(0, id1); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 626 EXPECT_TRUE(db.AddIconMapping(page1_url, id2)); | 659 EXPECT_TRUE(db.AddIconMapping(page1_url, id2)); |
| 627 | 660 |
| 628 GURL page2_url("http://page2.com"); | 661 GURL page2_url("http://page2.com"); |
| 629 EXPECT_TRUE(db.AddIconMapping(page2_url, id3)); | 662 EXPECT_TRUE(db.AddIconMapping(page2_url, id3)); |
| 630 | 663 |
| 631 // Test we do nothing with existing mappings. | 664 // Test we do nothing with existing mappings. |
| 632 std::vector<IconMapping> icon_mapping; | 665 std::vector<IconMapping> icon_mapping; |
| 633 EXPECT_TRUE(db.GetIconMappingsForPageURL(page2_url, &icon_mapping)); | 666 EXPECT_TRUE(db.GetIconMappingsForPageURL(page2_url, &icon_mapping)); |
| 634 ASSERT_EQ(1U, icon_mapping.size()); | 667 ASSERT_EQ(1U, icon_mapping.size()); |
| 635 | 668 |
| 636 EXPECT_TRUE(db.CloneIconMapping(page1_url, page2_url)); | 669 EXPECT_TRUE(db.CloneIconMappings(page1_url, page2_url)); |
| 637 | 670 |
| 638 icon_mapping.clear(); | 671 icon_mapping.clear(); |
| 639 EXPECT_TRUE(db.GetIconMappingsForPageURL(page2_url, &icon_mapping)); | 672 EXPECT_TRUE(db.GetIconMappingsForPageURL(page2_url, &icon_mapping)); |
| 640 ASSERT_EQ(1U, icon_mapping.size()); | 673 ASSERT_EQ(1U, icon_mapping.size()); |
| 641 EXPECT_EQ(page2_url, icon_mapping[0].page_url); | 674 EXPECT_EQ(page2_url, icon_mapping[0].page_url); |
| 642 EXPECT_EQ(id3, icon_mapping[0].icon_id); | 675 EXPECT_EQ(id3, icon_mapping[0].icon_id); |
| 643 | 676 |
| 644 // Test we clone if the new page has no mappings. | 677 // Test we clone if the new page has no mappings. |
| 645 GURL page3_url("http://page3.com"); | 678 GURL page3_url("http://page3.com"); |
| 646 EXPECT_TRUE(db.CloneIconMapping(page1_url, page3_url)); | 679 EXPECT_TRUE(db.CloneIconMappings(page1_url, page3_url)); |
| 647 | 680 |
| 648 icon_mapping.clear(); | 681 icon_mapping.clear(); |
| 649 EXPECT_TRUE(db.GetIconMappingsForPageURL(page3_url, &icon_mapping)); | 682 EXPECT_TRUE(db.GetIconMappingsForPageURL(page3_url, &icon_mapping)); |
| 650 | 683 |
| 651 ASSERT_EQ(2U, icon_mapping.size()); | 684 ASSERT_EQ(2U, icon_mapping.size()); |
| 652 if (icon_mapping[0].icon_id == id2) | 685 if (icon_mapping[0].icon_id == id2) |
| 653 std::swap(icon_mapping[0], icon_mapping[1]); | 686 std::swap(icon_mapping[0], icon_mapping[1]); |
| 654 EXPECT_EQ(page3_url, icon_mapping[0].page_url); | 687 EXPECT_EQ(page3_url, icon_mapping[0].page_url); |
| 655 EXPECT_EQ(id1, icon_mapping[0].icon_id); | 688 EXPECT_EQ(id1, icon_mapping[0].icon_id); |
| 656 EXPECT_EQ(page3_url, icon_mapping[1].page_url); | 689 EXPECT_EQ(page3_url, icon_mapping[1].page_url); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 671 | 704 |
| 672 // Migration should be done. | 705 // Migration should be done. |
| 673 // Test one icon_mapping. | 706 // Test one icon_mapping. |
| 674 GURL page_url1 = GURL("http://google.com/"); | 707 GURL page_url1 = GURL("http://google.com/"); |
| 675 std::vector<IconMapping> icon_mappings; | 708 std::vector<IconMapping> icon_mappings; |
| 676 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url1, &icon_mappings)); | 709 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url1, &icon_mappings)); |
| 677 ASSERT_EQ(1u, icon_mappings.size()); | 710 ASSERT_EQ(1u, icon_mappings.size()); |
| 678 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); | 711 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); |
| 679 EXPECT_EQ(page_url1, icon_mappings[0].page_url); | 712 EXPECT_EQ(page_url1, icon_mappings[0].page_url); |
| 680 EXPECT_EQ(1, icon_mappings[0].icon_id); | 713 EXPECT_EQ(1, icon_mappings[0].icon_id); |
| 681 base::Time time; | 714 EXPECT_EQ(icon1, icon_mappings[0].icon_url); |
| 682 scoped_refptr<base::RefCountedMemory> out_data; | |
| 683 GURL out_icon_url; | |
| 684 ASSERT_TRUE(db.GetFavicon( | |
| 685 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url, NULL)); | |
| 686 EXPECT_EQ(icon1, out_icon_url); | |
| 687 | 715 |
| 688 // Test a page which has the same icon. | 716 // Test a page which has the same icon. |
| 689 GURL page_url3 = GURL("http://www.google.com/"); | 717 GURL page_url3 = GURL("http://www.google.com/"); |
| 690 icon_mappings.clear(); | 718 icon_mappings.clear(); |
| 691 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url3, &icon_mappings)); | 719 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url3, &icon_mappings)); |
| 692 ASSERT_EQ(1u, icon_mappings.size()); | 720 ASSERT_EQ(1u, icon_mappings.size()); |
| 693 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); | 721 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); |
| 694 EXPECT_EQ(page_url3, icon_mappings[0].page_url); | 722 EXPECT_EQ(page_url3, icon_mappings[0].page_url); |
| 695 EXPECT_EQ(1, icon_mappings[0].icon_id); | 723 EXPECT_EQ(1, icon_mappings[0].icon_id); |
| 724 EXPECT_EQ(icon1, icon_mappings[0].icon_url); |
| 696 | 725 |
| 697 // Test a icon_mapping with different IconID. | 726 // Test a icon_mapping with different IconID. |
| 698 GURL page_url2 = GURL("http://yahoo.com/"); | 727 GURL page_url2 = GURL("http://yahoo.com/"); |
| 699 icon_mappings.clear(); | 728 icon_mappings.clear(); |
| 700 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url2, &icon_mappings)); | 729 EXPECT_TRUE(db.GetIconMappingsForPageURL(page_url2, &icon_mappings)); |
| 701 ASSERT_EQ(1u, icon_mappings.size()); | 730 ASSERT_EQ(1u, icon_mappings.size()); |
| 702 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); | 731 EXPECT_EQ(FAVICON, icon_mappings[0].icon_type); |
| 703 EXPECT_EQ(page_url2, icon_mappings[0].page_url); | 732 EXPECT_EQ(page_url2, icon_mappings[0].page_url); |
| 704 EXPECT_EQ(2, icon_mappings[0].icon_id); | 733 EXPECT_EQ(2, icon_mappings[0].icon_id); |
| 705 ASSERT_TRUE(db.GetFavicon( | 734 EXPECT_EQ(icon2, icon_mappings[0].icon_url); |
| 706 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url, NULL)); | |
| 707 EXPECT_EQ(icon2, out_icon_url); | |
| 708 | 735 |
| 709 // Test a page without icon | 736 // Test a page without icon |
| 710 GURL page_url4 = GURL("http://www.google.com/blank.html"); | 737 GURL page_url4 = GURL("http://www.google.com/blank.html"); |
| 711 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL)); | 738 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL)); |
| 712 } | 739 } |
| 713 | 740 |
| 714 TEST_F(ThumbnailDatabaseTest, IconMappingEnumerator) { | 741 TEST_F(ThumbnailDatabaseTest, IconMappingEnumerator) { |
| 715 ThumbnailDatabase db; | 742 ThumbnailDatabase db; |
| 716 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); | 743 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); |
| 717 db.BeginTransaction(); | 744 db.BeginTransaction(); |
| 718 | 745 |
| 719 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 746 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 720 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 747 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 721 | 748 |
| 722 GURL url("http://google.com"); | 749 GURL url("http://google.com"); |
| 723 FaviconID touch_icon_id1 = db.AddFavicon(url, TOUCH_ICON); | 750 GURL icon_url1("http://google.com/favicon.ico"); |
| 751 FaviconID touch_icon_id1 = db.AddFavicon(icon_url1, TOUCH_ICON, |
| 752 kSizesSmallAndLarge, favicon, base::Time::Now(), kSmallSize); |
| 724 ASSERT_NE(0, touch_icon_id1); | 753 ASSERT_NE(0, touch_icon_id1); |
| 725 ASSERT_TRUE(db.AddFaviconBitmap(touch_icon_id1, favicon, base::Time::Now(), | |
| 726 gfx::Size())); | |
| 727 IconMappingID touch_mapping_id1 = db.AddIconMapping(url, touch_icon_id1); | 754 IconMappingID touch_mapping_id1 = db.AddIconMapping(url, touch_icon_id1); |
| 728 ASSERT_NE(0, touch_mapping_id1); | 755 ASSERT_NE(0, touch_mapping_id1); |
| 729 | 756 |
| 730 FaviconID favicon_id1 = db.AddFavicon(url, FAVICON); | 757 FaviconID favicon_id1 = db.AddFavicon(icon_url1, FAVICON, kSizesSmallAndLarge, |
| 758 favicon, base::Time::Now(), kSmallSize); |
| 731 ASSERT_NE(0, favicon_id1); | 759 ASSERT_NE(0, favicon_id1); |
| 732 ASSERT_TRUE(db.AddFaviconBitmap(favicon_id1, favicon, base::Time::Now(), | |
| 733 gfx::Size())); | |
| 734 IconMappingID favicon_mapping_id1 = db.AddIconMapping(url, favicon_id1); | 760 IconMappingID favicon_mapping_id1 = db.AddIconMapping(url, favicon_id1); |
| 735 ASSERT_NE(0, favicon_mapping_id1); | 761 ASSERT_NE(0, favicon_mapping_id1); |
| 736 | 762 |
| 737 GURL url2("http://chromium.org"); | 763 GURL url2("http://chromium.org"); |
| 738 FaviconID favicon_id2 = db.AddFavicon(url2, FAVICON); | 764 GURL icon_url2("http://chromium.org/favicon.ico"); |
| 765 FaviconID favicon_id2 = db.AddFavicon(icon_url2, FAVICON, kSizesSmallAndLarge, |
| 766 favicon, base::Time::Now(), kSmallSize); |
| 739 ASSERT_NE(0, favicon_id2); | 767 ASSERT_NE(0, favicon_id2); |
| 740 ASSERT_TRUE(db.AddFaviconBitmap(favicon_id2, favicon, base::Time::Now(), | |
| 741 gfx::Size())); | |
| 742 IconMappingID favicon_mapping_id2 = db.AddIconMapping(url2, favicon_id2); | 768 IconMappingID favicon_mapping_id2 = db.AddIconMapping(url2, favicon_id2); |
| 743 ASSERT_NE(0, favicon_mapping_id2); | 769 ASSERT_NE(0, favicon_mapping_id2); |
| 744 | 770 |
| 745 IconMapping icon_mapping; | 771 IconMapping icon_mapping; |
| 746 ThumbnailDatabase::IconMappingEnumerator enumerator1; | 772 ThumbnailDatabase::IconMappingEnumerator enumerator1; |
| 747 ASSERT_TRUE(db.InitIconMappingEnumerator(FAVICON, &enumerator1)); | 773 ASSERT_TRUE(db.InitIconMappingEnumerator(FAVICON, &enumerator1)); |
| 748 // There are 2 favicon mappings. | 774 // There are 2 favicon mappings. |
| 749 bool has_favicon_mapping1 = false; | 775 bool has_favicon_mapping1 = false; |
| 750 bool has_favicon_mapping2 = false; | 776 bool has_favicon_mapping2 = false; |
| 751 int mapping_count = 0; | 777 int mapping_count = 0; |
| 752 while (enumerator1.GetNextIconMapping(&icon_mapping)) { | 778 while (enumerator1.GetNextIconMapping(&icon_mapping)) { |
| 753 mapping_count++; | 779 mapping_count++; |
| 754 if (favicon_mapping_id1 == icon_mapping.mapping_id) { | 780 if (favicon_mapping_id1 == icon_mapping.mapping_id) { |
| 755 has_favicon_mapping1 = true; | 781 has_favicon_mapping1 = true; |
| 756 EXPECT_EQ(url, icon_mapping.page_url); | 782 EXPECT_EQ(url, icon_mapping.page_url); |
| 757 EXPECT_EQ(favicon_id1, icon_mapping.icon_id); | 783 EXPECT_EQ(favicon_id1, icon_mapping.icon_id); |
| 784 EXPECT_EQ(icon_url1, icon_mapping.icon_url); |
| 758 EXPECT_EQ(FAVICON, icon_mapping.icon_type); | 785 EXPECT_EQ(FAVICON, icon_mapping.icon_type); |
| 759 } else if (favicon_mapping_id2 == icon_mapping.mapping_id) { | 786 } else if (favicon_mapping_id2 == icon_mapping.mapping_id) { |
| 760 has_favicon_mapping2 = true; | 787 has_favicon_mapping2 = true; |
| 761 EXPECT_EQ(url2, icon_mapping.page_url); | 788 EXPECT_EQ(url2, icon_mapping.page_url); |
| 762 EXPECT_EQ(favicon_id2, icon_mapping.icon_id); | 789 EXPECT_EQ(favicon_id2, icon_mapping.icon_id); |
| 790 EXPECT_EQ(icon_url2, icon_mapping.icon_url); |
| 763 EXPECT_EQ(FAVICON, icon_mapping.icon_type); | 791 EXPECT_EQ(FAVICON, icon_mapping.icon_type); |
| 764 } | 792 } |
| 765 } | 793 } |
| 766 EXPECT_EQ(2, mapping_count); | 794 EXPECT_EQ(2, mapping_count); |
| 767 EXPECT_TRUE(has_favicon_mapping1); | 795 EXPECT_TRUE(has_favicon_mapping1); |
| 768 EXPECT_TRUE(has_favicon_mapping2); | 796 EXPECT_TRUE(has_favicon_mapping2); |
| 769 | 797 |
| 770 ThumbnailDatabase::IconMappingEnumerator enumerator2; | 798 ThumbnailDatabase::IconMappingEnumerator enumerator2; |
| 771 ASSERT_TRUE(db.InitIconMappingEnumerator(TOUCH_ICON, &enumerator2)); | 799 ASSERT_TRUE(db.InitIconMappingEnumerator(TOUCH_ICON, &enumerator2)); |
| 772 ASSERT_TRUE(enumerator2.GetNextIconMapping(&icon_mapping)); | 800 ASSERT_TRUE(enumerator2.GetNextIconMapping(&icon_mapping)); |
| 773 EXPECT_EQ(touch_mapping_id1, icon_mapping.mapping_id); | 801 EXPECT_EQ(touch_mapping_id1, icon_mapping.mapping_id); |
| 774 EXPECT_EQ(url, icon_mapping.page_url); | 802 EXPECT_EQ(url, icon_mapping.page_url); |
| 775 EXPECT_EQ(touch_icon_id1, icon_mapping.icon_id); | 803 EXPECT_EQ(touch_icon_id1, icon_mapping.icon_id); |
| 804 EXPECT_EQ(icon_url1, icon_mapping.icon_url); |
| 776 EXPECT_EQ(TOUCH_ICON, icon_mapping.icon_type); | 805 EXPECT_EQ(TOUCH_ICON, icon_mapping.icon_type); |
| 777 | 806 |
| 778 EXPECT_FALSE(enumerator2.GetNextIconMapping(&icon_mapping)); | 807 EXPECT_FALSE(enumerator2.GetNextIconMapping(&icon_mapping)); |
| 779 } | 808 } |
| 780 | 809 |
| 781 } // namespace history | 810 } // namespace history |
| OLD | NEW |