| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <set> | 5 #include <set> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // backend directly. Most of the history backend functions are tested by the | 38 // backend directly. Most of the history backend functions are tested by the |
| 39 // history unit test. Because of the elaborate callbacks involved, this is no | 39 // history unit test. Because of the elaborate callbacks involved, this is no |
| 40 // harder than calling it directly for many things. | 40 // harder than calling it directly for many things. |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // data we'll put into the thumbnail database | 44 // data we'll put into the thumbnail database |
| 45 static const unsigned char blob1[] = | 45 static const unsigned char blob1[] = |
| 46 "12346102356120394751634516591348710478123649165419234519234512349134"; | 46 "12346102356120394751634516591348710478123649165419234519234512349134"; |
| 47 | 47 |
| 48 const gfx::Size kFaviconRegularSize = gfx::Size(16, 16); |
| 49 const gfx::Size kFaviconLargeSize = gfx::Size(32, 32); |
| 50 |
| 51 const gfx::Size kFavicon1xSize = gfx::Size(16, 16); |
| 52 const gfx::Size kFavicon2xSize = gfx::Size(32, 32); |
| 53 |
| 48 } // namepace | 54 } // namepace |
| 49 | 55 |
| 50 namespace history { | 56 namespace history { |
| 51 | 57 |
| 52 class HistoryBackendTest; | 58 class HistoryBackendTest; |
| 53 | 59 |
| 54 // This must be a separate object since HistoryBackend manages its lifetime. | 60 // This must be a separate object since HistoryBackend manages its lifetime. |
| 55 // This just forwards the messages we're interested in to the test object. | 61 // This just forwards the messages we're interested in to the test object. |
| 56 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { | 62 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { |
| 57 public: | 63 public: |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 URLID id = backend_->db()->GetRowForURL(url, &row); | 197 URLID id = backend_->db()->GetRowForURL(url, &row); |
| 192 VisitVector visits; | 198 VisitVector visits; |
| 193 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); | 199 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); |
| 194 return visits[0].transition; | 200 return visits[0].transition; |
| 195 } | 201 } |
| 196 | 202 |
| 197 FilePath getTestDir() { | 203 FilePath getTestDir() { |
| 198 return test_dir_; | 204 return test_dir_; |
| 199 } | 205 } |
| 200 | 206 |
| 201 FaviconID GetFavicon(const GURL& url, IconType icon_type) { | 207 FaviconID GetFaviconIDForPageURL(const GURL& page_url, IconType icon_type) { |
| 202 IconMapping icon_mapping; | 208 std::vector<IconMapping> icon_mappings; |
| 203 if (backend_->thumbnail_db_->GetIconMappingForPageURL(url, icon_type, | 209 if (backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type, |
| 204 &icon_mapping)) | 210 &icon_mappings)) |
| 205 return icon_mapping.icon_id; | 211 return icon_mappings[0].icon_id; |
| 206 else | 212 else |
| 207 return 0; | 213 return 0; |
| 208 } | 214 } |
| 209 | 215 |
| 216 FaviconID GetFaviconIDForIconURL(const GURL& icon_url, IconType icon_type) { |
| 217 std::vector<FaviconIDAndSize> favicon_id_size_listing; |
| 218 backend_->thumbnail_db_->GetFaviconIDsForFaviconURL( |
| 219 icon_url, icon_type, &favicon_id_size_listing); |
| 220 if (favicon_id_size_listing.size() > 0) |
| 221 return favicon_id_size_listing[0].icon_id; |
| 222 else |
| 223 return 0; |
| 224 } |
| 225 |
| 226 bool HasFaviconMapping(const GURL& page_url, |
| 227 const gfx::Size& pixel_size, |
| 228 int icon_types) { |
| 229 std::vector<IconMapping> icon_mappings; |
| 230 backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_types, |
| 231 &icon_mappings); |
| 232 for (size_t i = 0; i < icon_mappings.size(); ++i) { |
| 233 if (icon_mappings[i].icon_pixel_size == pixel_size) |
| 234 return true; |
| 235 } |
| 236 return false; |
| 237 } |
| 238 |
| 210 BookmarkModel bookmark_model_; | 239 BookmarkModel bookmark_model_; |
| 211 | 240 |
| 212 protected: | 241 protected: |
| 213 bool loaded_; | 242 bool loaded_; |
| 214 | 243 |
| 215 private: | 244 private: |
| 216 friend class HistoryBackendTestDelegate; | 245 friend class HistoryBackendTestDelegate; |
| 217 | 246 |
| 218 // testing::Test | 247 // testing::Test |
| 219 virtual void SetUp() { | 248 virtual void SetUp() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 315 |
| 287 TEST_F(HistoryBackendTest, DeleteAll) { | 316 TEST_F(HistoryBackendTest, DeleteAll) { |
| 288 ASSERT_TRUE(backend_.get()); | 317 ASSERT_TRUE(backend_.get()); |
| 289 | 318 |
| 290 // Add two favicons, use the characters '1' and '2' for the image data. Note | 319 // Add two favicons, use the characters '1' and '2' for the image data. Note |
| 291 // that we do these in the opposite order. This is so the first one gets ID | 320 // that we do these in the opposite order. This is so the first one gets ID |
| 292 // 2 autoassigned to the database, which will change when the other one is | 321 // 2 autoassigned to the database, which will change when the other one is |
| 293 // deleted. This way we can test that updating works properly. | 322 // deleted. This way we can test that updating works properly. |
| 294 GURL favicon_url1("http://www.google.com/favicon.ico"); | 323 GURL favicon_url1("http://www.google.com/favicon.ico"); |
| 295 GURL favicon_url2("http://news.google.com/favicon.ico"); | 324 GURL favicon_url2("http://news.google.com/favicon.ico"); |
| 296 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2, | 325 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon( |
| 297 FAVICON); | 326 favicon_url2, kFaviconRegularSize, FAVICON); |
| 298 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, | 327 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( |
| 299 FAVICON); | 328 favicon_url1, kFaviconRegularSize, FAVICON); |
| 300 | 329 |
| 301 std::vector<unsigned char> data; | 330 std::vector<unsigned char> data; |
| 302 data.push_back('1'); | 331 data.push_back('1'); |
| 303 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, | 332 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, |
| 304 new base::RefCountedBytes(data), Time::Now())); | 333 new base::RefCountedBytes(data), Time::Now())); |
| 305 | 334 |
| 306 data[0] = '2'; | 335 data[0] = '2'; |
| 307 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( | 336 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( |
| 308 favicon2, new base::RefCountedBytes(data), Time::Now())); | 337 favicon2, new base::RefCountedBytes(data), Time::Now())); |
| 309 | 338 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 ASSERT_EQ(0U, all_visits.size()); | 425 ASSERT_EQ(0U, all_visits.size()); |
| 397 | 426 |
| 398 // All thumbnails should be deleted. | 427 // All thumbnails should be deleted. |
| 399 std::vector<unsigned char> out_data; | 428 std::vector<unsigned char> out_data; |
| 400 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), | 429 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), |
| 401 &out_data)); | 430 &out_data)); |
| 402 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); | 431 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); |
| 403 | 432 |
| 404 // We should have a favicon for the first URL only. We look them up by favicon | 433 // We should have a favicon for the first URL only. We look them up by favicon |
| 405 // URL since the IDs may hav changed. | 434 // URL since the IDs may hav changed. |
| 406 FaviconID out_favicon1 = backend_->thumbnail_db_-> | 435 FaviconID out_favicon1 = GetFaviconIDForIconURL(favicon_url1, FAVICON); |
| 407 GetFaviconIDForFaviconURL(favicon_url1, FAVICON, NULL); | |
| 408 EXPECT_TRUE(out_favicon1); | 436 EXPECT_TRUE(out_favicon1); |
| 409 FaviconID out_favicon2 = backend_->thumbnail_db_-> | 437 FaviconID out_favicon2 = GetFaviconIDForIconURL(favicon_url2, FAVICON); |
| 410 GetFaviconIDForFaviconURL(favicon_url2, FAVICON, NULL); | |
| 411 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; | 438 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; |
| 412 | 439 |
| 413 // The remaining URL should still reference the same favicon, even if its | 440 // The remaining URL should still reference the same favicon, even if its |
| 414 // ID has changed. | 441 // ID has changed. |
| 415 EXPECT_EQ(out_favicon1, GetFavicon(outrow1.url(), FAVICON)); | 442 EXPECT_EQ(out_favicon1, GetFaviconIDForPageURL(outrow1.url(), FAVICON)); |
| 416 | 443 |
| 417 // The first URL should still be bookmarked. | 444 // The first URL should still be bookmarked. |
| 418 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); | 445 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); |
| 419 | 446 |
| 420 // The full text database should have no data. | 447 // The full text database should have no data. |
| 421 std::vector<TextDatabase::Match> text_matches; | 448 std::vector<TextDatabase::Match> text_matches; |
| 422 Time first_time_searched; | 449 Time first_time_searched; |
| 423 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), | 450 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), |
| 424 QueryOptions(), | 451 QueryOptions(), |
| 425 &text_matches, | 452 &text_matches, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), | 505 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), |
| 479 QueryOptions(), | 506 QueryOptions(), |
| 480 &text_matches, | 507 &text_matches, |
| 481 &first_time_searched); | 508 &first_time_searched); |
| 482 EXPECT_EQ(0U, text_matches.size()); | 509 EXPECT_EQ(0U, text_matches.size()); |
| 483 } | 510 } |
| 484 | 511 |
| 485 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { | 512 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { |
| 486 GURL favicon_url1("http://www.google.com/favicon.ico"); | 513 GURL favicon_url1("http://www.google.com/favicon.ico"); |
| 487 GURL favicon_url2("http://news.google.com/favicon.ico"); | 514 GURL favicon_url2("http://news.google.com/favicon.ico"); |
| 488 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2, | 515 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon( |
| 489 FAVICON); | 516 favicon_url2, kFaviconRegularSize, FAVICON); |
| 490 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, | 517 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( |
| 491 FAVICON); | 518 favicon_url1, kFaviconRegularSize, FAVICON); |
| 492 | 519 |
| 493 std::vector<unsigned char> data; | 520 std::vector<unsigned char> data; |
| 494 data.push_back('1'); | 521 data.push_back('1'); |
| 495 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( | 522 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( |
| 496 favicon1, new base::RefCountedBytes(data), Time::Now())); | 523 favicon1, new base::RefCountedBytes(data), Time::Now())); |
| 497 | 524 |
| 498 data[0] = '2'; | 525 data[0] = '2'; |
| 499 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( | 526 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( |
| 500 favicon2, new base::RefCountedBytes(data), Time::Now())); | 527 favicon2, new base::RefCountedBytes(data), Time::Now())); |
| 501 | 528 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 527 // the visits. | 554 // the visits. |
| 528 backend_->expirer_.DeleteURL(row2.url()); | 555 backend_->expirer_.DeleteURL(row2.url()); |
| 529 | 556 |
| 530 // Make sure url 2 is still valid, but has no visits. | 557 // Make sure url 2 is still valid, but has no visits. |
| 531 URLRow tmp_url_row; | 558 URLRow tmp_url_row; |
| 532 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL)); | 559 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL)); |
| 533 VisitVector visits; | 560 VisitVector visits; |
| 534 backend_->db_->GetVisitsForURL(row2_id, &visits); | 561 backend_->db_->GetVisitsForURL(row2_id, &visits); |
| 535 EXPECT_EQ(0U, visits.size()); | 562 EXPECT_EQ(0U, visits.size()); |
| 536 // The favicon should still be valid. | 563 // The favicon should still be valid. |
| 537 EXPECT_EQ(favicon2, | 564 EXPECT_EQ(favicon2, GetFaviconIDForIconURL(favicon_url2, FAVICON)); |
| 538 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url2, | |
| 539 FAVICON, | |
| 540 NULL)); | |
| 541 | 565 |
| 542 // Unstar row2. | 566 // Unstar row2. |
| 543 bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row2.url()); | 567 bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row2.url()); |
| 544 | 568 |
| 545 // Tell the backend it was unstarred. We have to explicitly do this as | 569 // Tell the backend it was unstarred. We have to explicitly do this as |
| 546 // BookmarkModel isn't wired up to the backend during testing. | 570 // BookmarkModel isn't wired up to the backend during testing. |
| 547 std::set<GURL> unstarred_urls; | 571 std::set<GURL> unstarred_urls; |
| 548 unstarred_urls.insert(row2.url()); | 572 unstarred_urls.insert(row2.url()); |
| 549 backend_->URLsNoLongerBookmarked(unstarred_urls); | 573 backend_->URLsNoLongerBookmarked(unstarred_urls); |
| 550 | 574 |
| 551 // The URL should no longer exist. | 575 // The URL should no longer exist. |
| 552 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row)); | 576 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row)); |
| 553 // And the favicon should be deleted. | 577 // And the favicon should be deleted. |
| 554 EXPECT_EQ(0, | 578 EXPECT_EQ(0, GetFaviconIDForIconURL(favicon_url2, FAVICON)); |
| 555 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url2, | |
| 556 FAVICON, | |
| 557 NULL)); | |
| 558 | 579 |
| 559 // Unstar row 1. | 580 // Unstar row 1. |
| 560 bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row1.url()); | 581 bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row1.url()); |
| 561 // Tell the backend it was unstarred. We have to explicitly do this as | 582 // Tell the backend it was unstarred. We have to explicitly do this as |
| 562 // BookmarkModel isn't wired up to the backend during testing. | 583 // BookmarkModel isn't wired up to the backend during testing. |
| 563 unstarred_urls.clear(); | 584 unstarred_urls.clear(); |
| 564 unstarred_urls.insert(row1.url()); | 585 unstarred_urls.insert(row1.url()); |
| 565 backend_->URLsNoLongerBookmarked(unstarred_urls); | 586 backend_->URLsNoLongerBookmarked(unstarred_urls); |
| 566 | 587 |
| 567 // The URL should still exist (because there were visits). | 588 // The URL should still exist (because there were visits). |
| 568 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL)); | 589 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL)); |
| 569 | 590 |
| 570 // There should still be visits. | 591 // There should still be visits. |
| 571 visits.clear(); | 592 visits.clear(); |
| 572 backend_->db_->GetVisitsForURL(row1_id, &visits); | 593 backend_->db_->GetVisitsForURL(row1_id, &visits); |
| 573 EXPECT_EQ(1U, visits.size()); | 594 EXPECT_EQ(1U, visits.size()); |
| 574 | 595 |
| 575 // The favicon should still be valid. | 596 // The favicon should still be valid. |
| 576 EXPECT_EQ(favicon1, | 597 EXPECT_EQ(favicon1, GetFaviconIDForIconURL(favicon_url1, FAVICON)); |
| 577 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url1, | |
| 578 FAVICON, | |
| 579 NULL)); | |
| 580 } | 598 } |
| 581 | 599 |
| 582 // Tests a handful of assertions for a navigation with a type of | 600 // Tests a handful of assertions for a navigation with a type of |
| 583 // KEYWORD_GENERATED. | 601 // KEYWORD_GENERATED. |
| 584 TEST_F(HistoryBackendTest, KeywordGenerated) { | 602 TEST_F(HistoryBackendTest, KeywordGenerated) { |
| 585 ASSERT_TRUE(backend_.get()); | 603 ASSERT_TRUE(backend_.get()); |
| 586 | 604 |
| 587 GURL url("http://google.com"); | 605 GURL url("http://google.com"); |
| 588 | 606 |
| 589 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); | 607 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 AddClientRedirect(url_b, url_c, true, base::Time(), | 673 AddClientRedirect(url_b, url_c, true, base::Time(), |
| 656 &transition1, &transition2); | 674 &transition1, &transition2); |
| 657 EXPECT_FALSE(transition1 & content::PAGE_TRANSITION_CHAIN_END); | 675 EXPECT_FALSE(transition1 & content::PAGE_TRANSITION_CHAIN_END); |
| 658 EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END); | 676 EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END); |
| 659 } | 677 } |
| 660 | 678 |
| 661 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { | 679 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { |
| 662 // Setup test data - two Urls in the history, one with favicon assigned and | 680 // Setup test data - two Urls in the history, one with favicon assigned and |
| 663 // one without. | 681 // one without. |
| 664 GURL favicon_url1("http://www.google.com/favicon.ico"); | 682 GURL favicon_url1("http://www.google.com/favicon.ico"); |
| 665 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, | 683 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( |
| 666 FAVICON); | 684 favicon_url1, kFaviconRegularSize, FAVICON); |
| 667 std::vector<unsigned char> data; | 685 std::vector<unsigned char> data; |
| 668 data.push_back('1'); | 686 data.push_back('1'); |
| 669 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, | 687 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, |
| 670 base::RefCountedBytes::TakeVector(&data), Time::Now())); | 688 base::RefCountedBytes::TakeVector(&data), Time::Now())); |
| 671 URLRow row1(GURL("http://www.google.com/")); | 689 URLRow row1(GURL("http://www.google.com/")); |
| 672 row1.set_visit_count(1); | 690 row1.set_visit_count(1); |
| 673 row1.set_last_visit(Time::Now()); | 691 row1.set_last_visit(Time::Now()); |
| 674 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); | 692 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); |
| 675 | 693 |
| 676 URLRow row2(GURL("http://news.google.com/")); | 694 URLRow row2(GURL("http://news.google.com/")); |
| 677 row2.set_visit_count(1); | 695 row2.set_visit_count(1); |
| 678 row2.set_last_visit(Time::Now()); | 696 row2.set_last_visit(Time::Now()); |
| 679 URLRows rows; | 697 URLRows rows; |
| 680 rows.push_back(row1); | 698 rows.push_back(row1); |
| 681 rows.push_back(row2); | 699 rows.push_back(row2); |
| 682 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); | 700 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); |
| 683 URLRow url_row1, url_row2; | 701 URLRow url_row1, url_row2; |
| 684 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); | 702 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); |
| 685 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); | 703 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); |
| 686 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == 0); | 704 EXPECT_FALSE(GetFaviconIDForPageURL(row1.url(), FAVICON) == 0); |
| 687 EXPECT_TRUE(GetFavicon(row2.url(), FAVICON) == 0); | 705 EXPECT_TRUE(GetFaviconIDForPageURL(row2.url(), FAVICON) == 0); |
| 688 | 706 |
| 689 // Now provide one imported favicon for both URLs already in the registry. | 707 // Now provide one imported favicon for both URLs already in the registry. |
| 690 // The new favicon should only be used with the URL that doesn't already have | 708 // The new favicon should only be used with the URL that doesn't already have |
| 691 // a favicon. | 709 // a favicon. |
| 692 std::vector<history::ImportedFaviconUsage> favicons; | 710 std::vector<history::ImportedFaviconUsage> favicons; |
| 693 history::ImportedFaviconUsage favicon; | 711 history::ImportedFaviconUsage favicon; |
| 694 favicon.favicon_url = GURL("http://news.google.com/favicon.ico"); | 712 favicon.favicon_url = GURL("http://news.google.com/favicon.ico"); |
| 695 favicon.png_data.push_back('2'); | 713 favicon.png_data.push_back('2'); |
| 696 favicon.urls.insert(row1.url()); | 714 favicon.urls.insert(row1.url()); |
| 697 favicon.urls.insert(row2.url()); | 715 favicon.urls.insert(row2.url()); |
| 698 favicons.push_back(favicon); | 716 favicons.push_back(favicon); |
| 699 backend_->SetImportedFavicons(favicons); | 717 backend_->SetImportedFavicons(favicons); |
| 700 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); | 718 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); |
| 701 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); | 719 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); |
| 702 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == 0); | 720 EXPECT_FALSE(GetFaviconIDForPageURL(row1.url(), FAVICON) == 0); |
| 703 EXPECT_FALSE(GetFavicon(row2.url(), FAVICON) == 0); | 721 EXPECT_FALSE(GetFaviconIDForPageURL(row2.url(), FAVICON) == 0); |
| 704 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == | 722 EXPECT_FALSE(GetFaviconIDForPageURL(row1.url(), FAVICON) == |
| 705 GetFavicon(row2.url(), FAVICON)); | 723 GetFaviconIDForPageURL(row2.url(), FAVICON)); |
| 706 | 724 |
| 707 // A URL should not be added to history (to store favicon), if | 725 // A URL should not be added to history (to store favicon), if |
| 708 // the URL is not bookmarked. | 726 // the URL is not bookmarked. |
| 709 GURL url3("http://mail.google.com"); | 727 GURL url3("http://mail.google.com"); |
| 710 favicons.clear(); | 728 favicons.clear(); |
| 711 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); | 729 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); |
| 712 favicon.png_data.push_back('3'); | 730 favicon.png_data.push_back('3'); |
| 713 favicon.urls.insert(url3); | 731 favicon.urls.insert(url3); |
| 714 favicons.push_back(favicon); | 732 favicons.push_back(favicon); |
| 715 backend_->SetImportedFavicons(favicons); | 733 backend_->SetImportedFavicons(favicons); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 backend_->db_->AddURL(url_info2); | 1096 backend_->db_->AddURL(url_info2); |
| 1079 | 1097 |
| 1080 history::RedirectList redirects; | 1098 history::RedirectList redirects; |
| 1081 redirects.push_back(url2); | 1099 redirects.push_back(url2); |
| 1082 redirects.push_back(url1); | 1100 redirects.push_back(url1); |
| 1083 backend_->recent_redirects_.Put(url1, redirects); | 1101 backend_->recent_redirects_.Put(url1, redirects); |
| 1084 | 1102 |
| 1085 const GURL icon_url("http://www.google.com/icon"); | 1103 const GURL icon_url("http://www.google.com/icon"); |
| 1086 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1104 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 1087 // Add a favicon | 1105 // Add a favicon |
| 1088 backend_->SetFavicon( | 1106 backend_->SetFavicon(url1, |
| 1089 url1, icon_url, base::RefCountedBytes::TakeVector(&data), FAVICON); | 1107 icon_url, |
| 1090 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1108 base::RefCountedBytes::TakeVector(&data), |
| 1091 url1, FAVICON, NULL)); | 1109 kFaviconRegularSize, |
| 1092 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1110 FAVICON); |
| 1093 url2, FAVICON, NULL)); | 1111 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconRegularSize, FAVICON)); |
| 1112 EXPECT_TRUE(HasFaviconMapping(url2, kFaviconRegularSize, FAVICON)); |
| 1094 | 1113 |
| 1095 // Add a touch_icon | 1114 // Add a touch_icon |
| 1096 backend_->SetFavicon( | 1115 backend_->SetFavicon(url1, |
| 1097 url1, icon_url, base::RefCountedBytes::TakeVector(&data), TOUCH_ICON); | 1116 icon_url, |
| 1098 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1117 base::RefCountedBytes::TakeVector(&data), |
| 1099 url1, TOUCH_ICON, NULL)); | 1118 kFaviconRegularSize, |
| 1100 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1119 TOUCH_ICON); |
| 1101 url2, TOUCH_ICON, NULL)); | 1120 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconRegularSize, TOUCH_ICON)); |
| 1102 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1121 EXPECT_TRUE(HasFaviconMapping(url2, kFaviconRegularSize, TOUCH_ICON)); |
| 1103 url1, FAVICON, NULL)); | 1122 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconRegularSize, FAVICON)); |
| 1123 |
| 1124 // Add a large touch icon |
| 1125 backend_->SetFavicon(url1, |
| 1126 icon_url, |
| 1127 base::RefCountedBytes::TakeVector(&data), |
| 1128 kFaviconLargeSize, |
| 1129 TOUCH_ICON); |
| 1130 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconLargeSize, TOUCH_ICON)); |
| 1131 EXPECT_TRUE(HasFaviconMapping(url2, kFaviconLargeSize, TOUCH_ICON)); |
| 1132 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconRegularSize, TOUCH_ICON)); |
| 1133 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconRegularSize, FAVICON)); |
| 1104 | 1134 |
| 1105 // Add a TOUCH_PRECOMPOSED_ICON | 1135 // Add a TOUCH_PRECOMPOSED_ICON |
| 1106 backend_->SetFavicon(url1, | 1136 backend_->SetFavicon(url1, |
| 1107 icon_url, | 1137 icon_url, |
| 1108 base::RefCountedBytes::TakeVector(&data), | 1138 base::RefCountedBytes::TakeVector(&data), |
| 1139 kFaviconRegularSize, |
| 1109 TOUCH_PRECOMPOSED_ICON); | 1140 TOUCH_PRECOMPOSED_ICON); |
| 1110 // The touch_icon was replaced. | 1141 // The small touch_icon was replaced. |
| 1111 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1142 EXPECT_FALSE(HasFaviconMapping(url1, kFaviconRegularSize, TOUCH_ICON)); |
| 1112 url1, TOUCH_ICON, NULL)); | 1143 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconLargeSize, TOUCH_ICON)); |
| 1113 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1144 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconRegularSize, FAVICON)); |
| 1114 url1, FAVICON, NULL)); | 1145 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconRegularSize, |
| 1115 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1146 TOUCH_PRECOMPOSED_ICON)); |
| 1116 url1, TOUCH_PRECOMPOSED_ICON, NULL)); | 1147 EXPECT_TRUE(HasFaviconMapping(url2, kFaviconRegularSize, |
| 1117 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1148 TOUCH_PRECOMPOSED_ICON)); |
| 1118 url2, TOUCH_PRECOMPOSED_ICON, NULL)); | |
| 1119 | 1149 |
| 1120 // Add a touch_icon | 1150 // Add a touch_icon |
| 1121 backend_->SetFavicon( | 1151 backend_->SetFavicon(url1, |
| 1122 url1, icon_url, base::RefCountedBytes::TakeVector(&data), TOUCH_ICON); | 1152 icon_url, |
| 1123 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1153 base::RefCountedBytes::TakeVector(&data), |
| 1124 url1, TOUCH_ICON, NULL)); | 1154 kFaviconRegularSize, |
| 1125 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1155 TOUCH_ICON); |
| 1126 url1, FAVICON, NULL)); | 1156 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconRegularSize, TOUCH_ICON)); |
| 1157 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconLargeSize, TOUCH_ICON)); |
| 1158 EXPECT_TRUE(HasFaviconMapping(url1, kFaviconRegularSize, FAVICON)); |
| 1127 // The TOUCH_PRECOMPOSED_ICON was replaced. | 1159 // The TOUCH_PRECOMPOSED_ICON was replaced. |
| 1128 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1160 EXPECT_FALSE(HasFaviconMapping(url1, kFaviconRegularSize, |
| 1129 url1, TOUCH_PRECOMPOSED_ICON, NULL)); | 1161 TOUCH_PRECOMPOSED_ICON)); |
| 1130 | 1162 |
| 1131 // Add a favicon | 1163 // Add a favicon |
| 1132 const GURL icon_url2("http://www.google.com/icon2"); | 1164 const GURL icon_url2("http://www.google.com/icon2"); |
| 1133 backend_->SetFavicon( | 1165 backend_->SetFavicon(url1, |
| 1134 url1, icon_url2, base::RefCountedBytes::TakeVector(&data), FAVICON); | 1166 icon_url2, |
| 1135 FaviconID icon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 1167 base::RefCountedBytes::TakeVector(&data), |
| 1136 icon_url2, FAVICON, NULL); | 1168 kFaviconRegularSize, |
| 1137 EXPECT_NE(0, icon_id); | 1169 FAVICON); |
| 1138 std::vector<IconMapping> icon_mapping; | 1170 FaviconID icon_id2 = GetFaviconIDForIconURL(icon_url2, FAVICON); |
| 1171 EXPECT_NE(icon_id2, 0); |
| 1172 std::vector<IconMapping> icon_mappings; |
| 1139 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1173 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 1140 url1, &icon_mapping)); | 1174 url1, FAVICON, &icon_mappings)); |
| 1141 // The old icon was replaced. | 1175 EXPECT_EQ(1u, icon_mappings.size()); |
| 1142 EXPECT_TRUE(icon_mapping.size() > 1); | 1176 EXPECT_EQ(icon_id2, icon_mappings[0].icon_id); |
| 1143 EXPECT_EQ(icon_id, icon_mapping[1].icon_id); | 1177 } |
| 1178 |
| 1179 TEST_F(HistoryBackendTest, ExceedPageFaviconLimit) { |
| 1180 const GURL page_url("http://www.google.com"); |
| 1181 const GURL icon_url("http://www.google.com/icon"); |
| 1182 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 1183 |
| 1184 int size = 10; |
| 1185 size_t num_to_insert = kMaxFaviconsPerPage + 1; |
| 1186 for (size_t i = 0; i < num_to_insert; ++i) { |
| 1187 backend_->SetFavicon(page_url, |
| 1188 icon_url, |
| 1189 base::RefCountedBytes::TakeVector(&data), |
| 1190 gfx::Size(size, size), |
| 1191 FAVICON); |
| 1192 size++; |
| 1193 } |
| 1194 |
| 1195 std::vector<IconMapping> icon_mappings; |
| 1196 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 1197 page_url, &icon_mappings)); |
| 1198 EXPECT_EQ(kMaxFaviconsPerPage, icon_mappings.size()); |
| 1144 } | 1199 } |
| 1145 | 1200 |
| 1146 TEST_F(HistoryBackendTest, AddOrUpdateIconMapping) { | 1201 TEST_F(HistoryBackendTest, AddOrUpdateIconMapping) { |
| 1147 // Test the same icon and page mapping will not be added twice. other case | 1202 // Test the same icon and page mapping will not be added twice. other case |
| 1148 // should be covered in TEST_F(HistoryBackendTest, SetFaviconMapping) | 1203 // should be covered in TEST_F(HistoryBackendTest, SetFaviconMapping) |
| 1149 const GURL url("http://www.google.com/"); | 1204 const GURL url("http://www.google.com/"); |
| 1150 const GURL icon_url("http://www.google.com/icon"); | 1205 const GURL icon_url("http://www.google.com/icon"); |
| 1151 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1206 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 1152 | 1207 |
| 1153 backend_->SetFavicon( | 1208 backend_->SetFavicon(url, icon_url, |
| 1154 url, icon_url, base::RefCountedBytes::TakeVector(&data), FAVICON); | 1209 base::RefCountedBytes::TakeVector(&data), kFaviconRegularSize, FAVICON); |
| 1155 FaviconID icon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 1210 FaviconID icon_id = GetFaviconIDForIconURL(icon_url, FAVICON); |
| 1156 icon_url, FAVICON, NULL); | |
| 1157 | 1211 |
| 1158 // Add the same mapping | 1212 // Add the same mapping |
| 1159 FaviconID replaced; | 1213 FaviconID replaced; |
| 1160 EXPECT_FALSE(backend_->AddOrUpdateIconMapping( | 1214 EXPECT_FALSE(backend_->AddOrUpdateIconMapping( |
| 1161 url, icon_id, FAVICON, &replaced)); | 1215 url, icon_id, kFaviconRegularSize, FAVICON, &replaced)); |
| 1162 EXPECT_EQ(0, replaced); | 1216 EXPECT_EQ(0, replaced); |
| 1163 | 1217 |
| 1164 std::vector<IconMapping> icon_mapping; | 1218 std::vector<IconMapping> icon_mapping; |
| 1165 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1219 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 1166 url, &icon_mapping)); | 1220 url, &icon_mapping)); |
| 1167 EXPECT_EQ(1u, icon_mapping.size()); | 1221 EXPECT_EQ(1u, icon_mapping.size()); |
| 1168 } | 1222 } |
| 1169 | 1223 |
| 1170 TEST_F(HistoryBackendTest, GetFaviconForURL) { | 1224 TEST_F(HistoryBackendTest, GetFaviconForURL) { |
| 1171 // This test will add a fav icon and touch icon for the same URL | 1225 // This test will add a fav icon and touch icon for the same URL |
| 1172 // and check the behaviour of backend's GetFaviconForURL implementation. | 1226 // and check the behaviour of backend's GetFaviconForURL implementation. |
| 1173 const GURL url("http://www.google.com/"); | 1227 const GURL url("http://www.google.com/"); |
| 1174 const GURL icon_url("http://www.google.com/icon"); | 1228 const GURL icon_url("http://www.google.com/icon"); |
| 1229 |
| 1175 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1230 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 1176 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 1231 scoped_refptr<base::RefCountedBytes> bytes( |
| 1232 new base::RefCountedBytes(data)); |
| 1177 // Used for testing the icon data after getting from DB | 1233 // Used for testing the icon data after getting from DB |
| 1178 std::string blob_data(bytes->front(), | 1234 std::string blob_data(bytes->front(), |
| 1179 bytes->front() + bytes->size()); | 1235 bytes->front() + bytes->size()); |
| 1180 | 1236 |
| 1181 // Add a favicon | 1237 // Add a favicon |
| 1182 backend_->SetFavicon( | 1238 backend_->SetFavicon( |
| 1183 url, icon_url, bytes.get(), FAVICON); | 1239 url, icon_url, bytes.get(), kFavicon1xSize, FAVICON); |
| 1184 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1240 EXPECT_TRUE(HasFaviconMapping(url, kFavicon1xSize, FAVICON)); |
| 1185 url, FAVICON, NULL)); | |
| 1186 | 1241 |
| 1187 // Add a touch_icon | 1242 // Add a small touch_icon |
| 1188 backend_->SetFavicon( | 1243 backend_->SetFavicon( |
| 1189 url, icon_url, bytes.get(), TOUCH_ICON); | 1244 url, icon_url, bytes.get(), kFavicon1xSize, TOUCH_ICON); |
| 1190 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1245 EXPECT_TRUE(HasFaviconMapping(url, kFavicon1xSize, TOUCH_ICON)); |
| 1191 url, TOUCH_ICON, NULL)); | |
| 1192 | 1246 |
| 1193 // Test the Fav icon for this URL. | 1247 // Add a large touch icon |
| 1248 backend_->SetFavicon( |
| 1249 url, icon_url, bytes.get(), kFavicon2xSize, TOUCH_ICON); |
| 1250 EXPECT_TRUE(HasFaviconMapping(url, kFavicon2xSize, TOUCH_ICON)); |
| 1251 |
| 1252 // Test the Fav small icon for this URL. |
| 1194 FaviconData favicon; | 1253 FaviconData favicon; |
| 1195 ASSERT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, &favicon)); | 1254 ASSERT_TRUE(backend_->GetFaviconFromDB(url, kFavicon1xSize, FAVICON, |
| 1196 std::string favicon_data( | 1255 &favicon)); |
| 1197 favicon.image_data->front(), | 1256 std::string favicon_data_1x( |
| 1198 favicon.image_data->front() + favicon.image_data->size()); | 1257 favicon.bitmap_data->front(), |
| 1258 favicon.bitmap_data->front() + favicon.bitmap_data->size()); |
| 1199 | 1259 |
| 1200 EXPECT_EQ(FAVICON, favicon.icon_type); | 1260 EXPECT_EQ(FAVICON, favicon.icon_type); |
| 1201 EXPECT_EQ(icon_url, favicon.icon_url); | 1261 EXPECT_EQ(icon_url, favicon.icon_url); |
| 1202 EXPECT_EQ(blob_data, favicon_data); | 1262 EXPECT_EQ(blob_data, favicon_data_1x); |
| 1263 EXPECT_EQ(kFavicon1xSize, favicon.requested_size); |
| 1203 | 1264 |
| 1204 // Test the touch icon for this URL. | 1265 // Test falling back to small icon if the large one is not present. |
| 1205 ASSERT_TRUE(backend_->GetFaviconFromDB(url, TOUCH_ICON, &favicon)); | 1266 ASSERT_TRUE(backend_->GetFaviconFromDB(url, kFavicon2xSize, FAVICON, |
| 1206 std::string touchicon_data( | 1267 &favicon)); |
| 1207 favicon.image_data->front(), | 1268 std::string favicon_data_2x( |
| 1208 favicon.image_data->front() + favicon.image_data->size()); | 1269 favicon.bitmap_data->front(), |
| 1270 favicon.bitmap_data->front() + favicon.bitmap_data->size()); |
| 1271 |
| 1272 EXPECT_EQ(FAVICON, favicon.icon_type); |
| 1273 EXPECT_EQ(icon_url, favicon.icon_url); |
| 1274 EXPECT_EQ(blob_data, favicon_data_2x); |
| 1275 EXPECT_EQ(kFavicon1xSize, favicon.requested_size); |
| 1276 |
| 1277 // Test the small touch icon for this URL. |
| 1278 ASSERT_TRUE(backend_->GetFaviconFromDB(url, kFavicon1xSize, TOUCH_ICON, |
| 1279 &favicon)); |
| 1280 std::string touchicon_1x_data( |
| 1281 favicon.bitmap_data->front(), |
| 1282 favicon.bitmap_data->front() + favicon.bitmap_data->size()); |
| 1209 | 1283 |
| 1210 EXPECT_EQ(TOUCH_ICON, favicon.icon_type); | 1284 EXPECT_EQ(TOUCH_ICON, favicon.icon_type); |
| 1211 EXPECT_EQ(icon_url, favicon.icon_url); | 1285 EXPECT_EQ(icon_url, favicon.icon_url); |
| 1212 EXPECT_EQ(blob_data, touchicon_data); | 1286 EXPECT_EQ(blob_data, touchicon_1x_data); |
| 1287 EXPECT_EQ(kFavicon1xSize, favicon.requested_size); |
| 1288 |
| 1289 // Test the large touch icon for this URL. |
| 1290 ASSERT_TRUE(backend_->GetFaviconFromDB(url, kFavicon2xSize, TOUCH_ICON, |
| 1291 &favicon)); |
| 1292 std::string touchicon_2x_data( |
| 1293 favicon.bitmap_data->front(), |
| 1294 favicon.bitmap_data->front() + favicon.bitmap_data->size()); |
| 1295 |
| 1296 EXPECT_EQ(TOUCH_ICON, favicon.icon_type); |
| 1297 EXPECT_EQ(icon_url, favicon.icon_url); |
| 1298 EXPECT_EQ(blob_data, touchicon_2x_data); |
| 1299 EXPECT_EQ(kFavicon2xSize, favicon.requested_size); |
| 1213 } | 1300 } |
| 1214 | 1301 |
| 1215 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { | 1302 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { |
| 1216 const GURL url("http://www.google.com/"); | 1303 const GURL url("http://www.google.com/"); |
| 1217 const GURL icon_url("http://www.google.com/icon"); | 1304 const GURL icon_url("http://www.google.com/icon"); |
| 1218 const GURL same_domain_url("http://www.google.com/subdir/index.html"); | 1305 const GURL same_domain_url("http://www.google.com/subdir/index.html"); |
| 1219 const GURL foreign_domain_url("http://www.not-google.com/"); | 1306 const GURL foreign_domain_url("http://www.not-google.com/"); |
| 1220 | 1307 |
| 1221 // Add a favicon | 1308 // Add a favicon |
| 1222 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1309 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
| 1223 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 1310 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
| 1224 backend_->SetFavicon( | 1311 backend_->SetFavicon( |
| 1225 url, icon_url, bytes.get(), FAVICON); | 1312 url, icon_url, bytes.get(), kFaviconRegularSize, FAVICON); |
| 1226 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1313 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 1227 url, FAVICON, NULL)); | 1314 url, FAVICON, NULL)); |
| 1228 | 1315 |
| 1229 // Validate starting state. | 1316 // Validate starting state. |
| 1230 FaviconData favicon; | 1317 FaviconData favicon; |
| 1231 EXPECT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, &favicon)); | 1318 EXPECT_TRUE(backend_->GetFaviconFromDB(url, kFaviconRegularSize, FAVICON, |
| 1232 EXPECT_FALSE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, &favicon)); | 1319 &favicon)); |
| 1320 EXPECT_FALSE(backend_->GetFaviconFromDB(same_domain_url, |
| 1321 kFaviconRegularSize, FAVICON, &favicon)); |
| 1233 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, | 1322 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, |
| 1234 FAVICON, &favicon)); | 1323 kFaviconRegularSize, FAVICON, &favicon)); |
| 1235 | 1324 |
| 1236 // Same-domain cloning should work. | 1325 // Same-domain cloning should work. |
| 1237 backend_->CloneFavicon(url, same_domain_url); | 1326 backend_->CloneFavicon(url, same_domain_url); |
| 1238 EXPECT_TRUE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, &favicon)); | 1327 EXPECT_TRUE(backend_->GetFaviconFromDB(same_domain_url, kFaviconRegularSize, |
| 1328 FAVICON, &favicon)); |
| 1239 | 1329 |
| 1240 // Foreign-domain cloning is forbidden. | 1330 // Foreign-domain cloning is forbidden. |
| 1241 backend_->CloneFavicon(url, foreign_domain_url); | 1331 backend_->CloneFavicon(url, foreign_domain_url); |
| 1242 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, | 1332 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, |
| 1243 FAVICON, &favicon)); | 1333 kFaviconRegularSize, FAVICON, &favicon)); |
| 1244 } | 1334 } |
| 1245 | 1335 |
| 1246 TEST_F(HistoryBackendTest, QueryFilteredURLs) { | 1336 TEST_F(HistoryBackendTest, QueryFilteredURLs) { |
| 1247 const char* google = "http://www.google.com/"; | 1337 const char* google = "http://www.google.com/"; |
| 1248 const char* yahoo = "http://www.yahoo.com/"; | 1338 const char* yahoo = "http://www.yahoo.com/"; |
| 1249 const char* yahoo_sports = "http://sports.yahoo.com/"; | 1339 const char* yahoo_sports = "http://sports.yahoo.com/"; |
| 1250 const char* yahoo_sports_with_article1 = | 1340 const char* yahoo_sports_with_article1 = |
| 1251 "http://sports.yahoo.com/article1.htm"; | 1341 "http://sports.yahoo.com/article1.htm"; |
| 1252 const char* yahoo_sports_with_article2 = | 1342 const char* yahoo_sports_with_article2 = |
| 1253 "http://sports.yahoo.com/article2.htm"; | 1343 "http://sports.yahoo.com/article2.htm"; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 | 1657 |
| 1568 backend_->DeleteURL(url); | 1658 backend_->DeleteURL(url); |
| 1569 backend_->AddPageNoVisitForBookmark(url, string16()); | 1659 backend_->AddPageNoVisitForBookmark(url, string16()); |
| 1570 backend_->GetURL(url, &row); | 1660 backend_->GetURL(url, &row); |
| 1571 EXPECT_EQ(url, row.url()); | 1661 EXPECT_EQ(url, row.url()); |
| 1572 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); | 1662 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); |
| 1573 EXPECT_EQ(0, row.visit_count()); | 1663 EXPECT_EQ(0, row.visit_count()); |
| 1574 } | 1664 } |
| 1575 | 1665 |
| 1576 } // namespace history | 1666 } // namespace history |
| OLD | NEW |