Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 17 #include "chrome/browser/history/history_backend.h" | 17 #include "chrome/browser/history/history_backend.h" |
| 18 #include "chrome/browser/history/history_notifications.h" | 18 #include "chrome/browser/history/history_notifications.h" |
| 19 #include "chrome/browser/history/in_memory_history_backend.h" | 19 #include "chrome/browser/history/in_memory_history_backend.h" |
| 20 #include "chrome/browser/history/in_memory_database.h" | 20 #include "chrome/browser/history/in_memory_database.h" |
| 21 #include "chrome/browser/history/top_sites.h" | 21 #include "chrome/browser/history/top_sites.h" |
|
sky
2011/01/13 16:55:52
You should be able to remove this now.
satorux1
2011/01/14 07:36:46
Done.
| |
| 22 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/notification_details.h" | 24 #include "chrome/common/notification_details.h" |
| 25 #include "chrome/common/notification_source.h" | 25 #include "chrome/common/notification_source.h" |
| 26 #include "chrome/common/thumbnail_score.h" | 26 #include "chrome/common/thumbnail_score.h" |
| 27 #include "chrome/tools/profiles/thumbnail-inl.h" | 27 #include "chrome/tools/profiles/thumbnail-inl.h" |
| 28 #include "gfx/codec/jpeg_codec.h" | 28 #include "gfx/codec/jpeg_codec.h" |
| 29 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 31 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 // There should still be visits. | 408 // There should still be visits. |
| 409 visits.clear(); | 409 visits.clear(); |
| 410 backend_->db_->GetVisitsForURL(row1_id, &visits); | 410 backend_->db_->GetVisitsForURL(row1_id, &visits); |
| 411 EXPECT_EQ(1U, visits.size()); | 411 EXPECT_EQ(1U, visits.size()); |
| 412 | 412 |
| 413 // The favicon should still be valid. | 413 // The favicon should still be valid. |
| 414 EXPECT_EQ(favicon1, | 414 EXPECT_EQ(favicon1, |
| 415 backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url1)); | 415 backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url1)); |
| 416 } | 416 } |
| 417 | 417 |
| 418 TEST_F(HistoryBackendTest, GetPageThumbnailAfterRedirects) { | |
| 419 ASSERT_TRUE(backend_.get()); | |
| 420 if (history::TopSites::IsEnabled()) | |
| 421 return; | |
| 422 | |
| 423 const char* base_url = "http://mail"; | |
| 424 const char* thumbnail_url = "http://mail.google.com"; | |
| 425 const char* first_chain[] = { | |
| 426 base_url, | |
| 427 thumbnail_url, | |
| 428 NULL | |
| 429 }; | |
| 430 AddRedirectChain(first_chain, 0); | |
| 431 | |
| 432 // Add a thumbnail for the end of that redirect chain. | |
| 433 scoped_ptr<SkBitmap> thumbnail( | |
| 434 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); | |
| 435 backend_->SetPageThumbnail(GURL(thumbnail_url), *thumbnail, | |
| 436 ThumbnailScore(0.25, true, true)); | |
| 437 | |
| 438 // Write a second URL chain so that if you were to simply check what | |
| 439 // "http://mail" redirects to, you wouldn't see the URL that has | |
| 440 // contains the thumbnail. | |
| 441 const char* second_chain[] = { | |
| 442 base_url, | |
| 443 "http://mail.google.com/somewhere/else", | |
| 444 NULL | |
| 445 }; | |
| 446 AddRedirectChain(second_chain, 1); | |
| 447 | |
| 448 // Now try to get the thumbnail for the base url. It shouldn't be | |
| 449 // distracted by the second chain and should return the thumbnail | |
| 450 // attached to thumbnail_url_. | |
| 451 scoped_refptr<RefCountedBytes> data; | |
| 452 backend_->GetPageThumbnailDirectly(GURL(base_url), &data); | |
| 453 | |
| 454 EXPECT_TRUE(data.get()); | |
| 455 } | |
| 456 | |
| 457 // Tests a handful of assertions for a navigation with a type of | 418 // Tests a handful of assertions for a navigation with a type of |
| 458 // KEYWORD_GENERATED. | 419 // KEYWORD_GENERATED. |
| 459 TEST_F(HistoryBackendTest, KeywordGenerated) { | 420 TEST_F(HistoryBackendTest, KeywordGenerated) { |
| 460 ASSERT_TRUE(backend_.get()); | 421 ASSERT_TRUE(backend_.get()); |
| 461 | 422 |
| 462 GURL url("http://google.com"); | 423 GURL url("http://google.com"); |
| 463 | 424 |
| 464 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); | 425 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); |
| 465 scoped_refptr<HistoryAddPageArgs> request( | 426 scoped_refptr<HistoryAddPageArgs> request( |
| 466 new HistoryAddPageArgs(url, visit_time, NULL, 0, GURL(), | 427 new HistoryAddPageArgs(url, visit_time, NULL, 0, GURL(), |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 | 570 |
| 610 // Fetch the row information about stripped url from history db. | 571 // Fetch the row information about stripped url from history db. |
| 611 VisitVector visits; | 572 VisitVector visits; |
| 612 URLID row_id = backend_->db_->GetRowForURL(stripped_url, NULL); | 573 URLID row_id = backend_->db_->GetRowForURL(stripped_url, NULL); |
| 613 backend_->db_->GetVisitsForURL(row_id, &visits); | 574 backend_->db_->GetVisitsForURL(row_id, &visits); |
| 614 | 575 |
| 615 // Check if stripped url is stored in database. | 576 // Check if stripped url is stored in database. |
| 616 ASSERT_EQ(1U, visits.size()); | 577 ASSERT_EQ(1U, visits.size()); |
| 617 } | 578 } |
| 618 | 579 |
| 619 TEST_F(HistoryBackendTest, DeleteThumbnailsDatabaseTest) { | |
| 620 if (history::TopSites::IsEnabled()) | |
| 621 return; | |
| 622 | |
| 623 EXPECT_TRUE(backend_->thumbnail_db_->NeedsMigrationToTopSites()); | |
| 624 backend_->delegate_->StartTopSitesMigration(); | |
| 625 EXPECT_FALSE(backend_->thumbnail_db_->NeedsMigrationToTopSites()); | |
| 626 } | |
| 627 | |
| 628 TEST_F(HistoryBackendTest, AddPageVisitSource) { | 580 TEST_F(HistoryBackendTest, AddPageVisitSource) { |
| 629 ASSERT_TRUE(backend_.get()); | 581 ASSERT_TRUE(backend_.get()); |
| 630 | 582 |
| 631 GURL url("http://www.google.com"); | 583 GURL url("http://www.google.com"); |
| 632 | 584 |
| 633 // Clear all history. | 585 // Clear all history. |
| 634 backend_->DeleteAllHistory(); | 586 backend_->DeleteAllHistory(); |
| 635 | 587 |
| 636 // Assume visiting the url from an externsion. | 588 // Assume visiting the url from an externsion. |
| 637 backend_->AddPageVisit(url, base::Time::Now(), 0, PageTransition::TYPED, | 589 backend_->AddPageVisit(url, base::Time::Now(), 0, PageTransition::TYPED, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 | 784 |
| 833 // Check visit_source table is created and empty. | 785 // Check visit_source table is created and empty. |
| 834 s.Assign(db.GetUniqueStatement( | 786 s.Assign(db.GetUniqueStatement( |
| 835 "SELECT name FROM sqlite_master WHERE name=\"visit_source\"")); | 787 "SELECT name FROM sqlite_master WHERE name=\"visit_source\"")); |
| 836 ASSERT_TRUE(s.Step()); | 788 ASSERT_TRUE(s.Step()); |
| 837 s.Assign(db.GetUniqueStatement("SELECT * FROM visit_source LIMIT 10")); | 789 s.Assign(db.GetUniqueStatement("SELECT * FROM visit_source LIMIT 10")); |
| 838 EXPECT_FALSE(s.Step()); | 790 EXPECT_FALSE(s.Step()); |
| 839 } | 791 } |
| 840 | 792 |
| 841 } // namespace history | 793 } // namespace history |
| OLD | NEW |