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 // History unit tests come in two flavors: | 5 // History unit tests come in two flavors: |
| 6 // | 6 // |
| 7 // 1. The more complicated style is that the unit test creates a full history | 7 // 1. The more complicated style is that the unit test creates a full history |
| 8 // service. This spawns a background thread for the history backend, and | 8 // service. This spawns a background thread for the history backend, and |
| 9 // all communication is asynchronous. This is useful for testing more | 9 // all communication is asynchronous. This is useful for testing more |
| 10 // complicated things or end-to-end behavior. | 10 // complicated things or end-to-end behavior. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 #include "base/utf_string_conversions.h" | 38 #include "base/utf_string_conversions.h" |
| 39 #include "chrome/browser/download/download_item.h" | 39 #include "chrome/browser/download/download_item.h" |
| 40 #include "chrome/browser/history/download_create_info.h" | 40 #include "chrome/browser/history/download_create_info.h" |
| 41 #include "chrome/browser/history/history.h" | 41 #include "chrome/browser/history/history.h" |
| 42 #include "chrome/browser/history/history_backend.h" | 42 #include "chrome/browser/history/history_backend.h" |
| 43 #include "chrome/browser/history/history_database.h" | 43 #include "chrome/browser/history/history_database.h" |
| 44 #include "chrome/browser/history/history_notifications.h" | 44 #include "chrome/browser/history/history_notifications.h" |
| 45 #include "chrome/browser/history/in_memory_database.h" | 45 #include "chrome/browser/history/in_memory_database.h" |
| 46 #include "chrome/browser/history/in_memory_history_backend.h" | 46 #include "chrome/browser/history/in_memory_history_backend.h" |
| 47 #include "chrome/browser/history/page_usage_data.h" | 47 #include "chrome/browser/history/page_usage_data.h" |
| 48 #include "chrome/browser/history/top_sites.h" | 48 #include "chrome/browser/history/top_sites.h" |
|
sky
2011/01/13 16:55:52
Can this be removed now?
satorux1
2011/01/14 07:36:46
Done.
| |
| 49 #include "chrome/common/chrome_paths.h" | 49 #include "chrome/common/chrome_paths.h" |
| 50 #include "chrome/common/notification_details.h" | 50 #include "chrome/common/notification_details.h" |
| 51 #include "chrome/common/notification_source.h" | 51 #include "chrome/common/notification_source.h" |
| 52 #include "chrome/common/thumbnail_score.h" | 52 #include "chrome/common/thumbnail_score.h" |
| 53 #include "chrome/tools/profiles/thumbnail-inl.h" | 53 #include "chrome/tools/profiles/thumbnail-inl.h" |
| 54 #include "gfx/codec/jpeg_codec.h" | 54 #include "gfx/codec/jpeg_codec.h" |
| 55 #include "testing/gtest/include/gtest/gtest.h" | 55 #include "testing/gtest/include/gtest/gtest.h" |
| 56 #include "third_party/skia/include/core/SkBitmap.h" | 56 #include "third_party/skia/include/core/SkBitmap.h" |
| 57 | 57 |
| 58 using base::Time; | 58 using base::Time; |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 MessageLoop::current()->Run(); | 675 MessageLoop::current()->Run(); |
| 676 | 676 |
| 677 // Make sure we still have one segment. | 677 // Make sure we still have one segment. |
| 678 ASSERT_EQ(1U, page_usage_data_->size()); | 678 ASSERT_EQ(1U, page_usage_data_->size()); |
| 679 EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url); | 679 EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url); |
| 680 | 680 |
| 681 // However, the score should have increased. | 681 // However, the score should have increased. |
| 682 EXPECT_GT(page_usage_data_[0]->GetScore(), 5.0); | 682 EXPECT_GT(page_usage_data_[0]->GetScore(), 5.0); |
| 683 } | 683 } |
| 684 | 684 |
| 685 // This just tests history system -> thumbnail database integration, the actual | |
| 686 // thumbnail tests are in its own file. | |
| 687 TEST_F(HistoryTest, Thumbnails) { | |
| 688 if (history::TopSites::IsEnabled()) | |
| 689 return; // TopSitesTest replaces this. | |
| 690 | |
| 691 scoped_refptr<HistoryService> history(new HistoryService); | |
| 692 history_service_ = history; | |
| 693 ASSERT_TRUE(history->Init(history_dir_, NULL)); | |
| 694 | |
| 695 scoped_ptr<SkBitmap> thumbnail( | |
| 696 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); | |
| 697 static const double boringness = 0.25; | |
| 698 | |
| 699 const GURL url("http://www.google.com/thumbnail_test/"); | |
| 700 // Must be visited before adding a thumbnail. | |
| 701 history->AddPage(url, history::SOURCE_BROWSED); | |
| 702 history->SetPageThumbnail(url, *thumbnail, | |
| 703 ThumbnailScore(boringness, true, true)); | |
| 704 | |
| 705 // Make sure we get the correct thumbnail data. | |
| 706 EXPECT_TRUE(history->GetPageThumbnail(url, &consumer_, | |
| 707 NewCallback(static_cast<HistoryTest*>(this), | |
| 708 &HistoryTest::OnThumbnailDataAvailable))); | |
| 709 thumbnail_data_.clear(); | |
| 710 MessageLoop::current()->Run(); | |
| 711 // Make sure we got a valid JPEG back. This isn't equivalent to | |
| 712 // being correct, but when we're roundtripping through JPEG | |
| 713 // compression and we don't have a similarity measure. | |
| 714 EXPECT_TRUE(thumbnail_data_.size()); | |
| 715 scoped_ptr<SkBitmap> decoded_thumbnail( | |
| 716 gfx::JPEGCodec::Decode(&thumbnail_data_[0], thumbnail_data_.size())); | |
| 717 EXPECT_TRUE(decoded_thumbnail.get()); | |
| 718 | |
| 719 // Request a nonexistent thumbnail and make sure we get | |
| 720 // a callback and no data. | |
| 721 EXPECT_TRUE(history->GetPageThumbnail(GURL("http://asdfasdf.com/"), | |
| 722 &consumer_, | |
| 723 NewCallback(static_cast<HistoryTest*>(this), | |
| 724 &HistoryTest::OnThumbnailDataAvailable))); | |
| 725 thumbnail_data_.clear(); | |
| 726 MessageLoop::current()->Run(); | |
| 727 EXPECT_EQ(0U, thumbnail_data_.size()); | |
| 728 | |
| 729 // Request the thumbnail and cancel the request.. | |
| 730 got_thumbnail_callback_ = false; | |
| 731 thumbnail_data_.clear(); | |
| 732 HistoryService::Handle handle = history->GetPageThumbnail(url, &consumer_, | |
| 733 NewCallback(static_cast<HistoryTest*>(this), | |
| 734 &HistoryTest::OnThumbnailDataAvailable)); | |
| 735 EXPECT_TRUE(handle); | |
| 736 | |
| 737 history->CancelRequest(handle); | |
| 738 | |
| 739 // We create a task with a timeout so we can make sure we don't get and | |
| 740 // data in that time. | |
| 741 class QuitMessageLoop : public Task { | |
| 742 public: | |
| 743 virtual void Run() { | |
| 744 MessageLoop::current()->Quit(); | |
| 745 } | |
| 746 }; | |
| 747 MessageLoop::current()->PostDelayedTask(FROM_HERE, new QuitMessageLoop, 2000); | |
| 748 MessageLoop::current()->Run(); | |
| 749 EXPECT_FALSE(got_thumbnail_callback_); | |
| 750 } | |
| 751 | |
| 752 TEST_F(HistoryTest, MostVisitedURLs) { | 685 TEST_F(HistoryTest, MostVisitedURLs) { |
| 753 scoped_refptr<HistoryService> history(new HistoryService); | 686 scoped_refptr<HistoryService> history(new HistoryService); |
| 754 history_service_ = history; | 687 history_service_ = history; |
| 755 ASSERT_TRUE(history->Init(history_dir_, NULL)); | 688 ASSERT_TRUE(history->Init(history_dir_, NULL)); |
| 756 | 689 |
| 757 const GURL url0("http://www.google.com/url0/"); | 690 const GURL url0("http://www.google.com/url0/"); |
| 758 const GURL url1("http://www.google.com/url1/"); | 691 const GURL url1("http://www.google.com/url1/"); |
| 759 const GURL url2("http://www.google.com/url2/"); | 692 const GURL url2("http://www.google.com/url2/"); |
| 760 const GURL url3("http://www.google.com/url3/"); | 693 const GURL url3("http://www.google.com/url3/"); |
| 761 const GURL url4("http://www.google.com/url4/"); | 694 const GURL url4("http://www.google.com/url4/"); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 history_service_ = history; | 865 history_service_ = history; |
| 933 history->ScheduleDBTask(task.get(), &request_consumer); | 866 history->ScheduleDBTask(task.get(), &request_consumer); |
| 934 request_consumer.CancelAllRequests(); | 867 request_consumer.CancelAllRequests(); |
| 935 CleanupHistoryService(); | 868 CleanupHistoryService(); |
| 936 // WARNING: history has now been deleted. | 869 // WARNING: history has now been deleted. |
| 937 history = NULL; | 870 history = NULL; |
| 938 ASSERT_FALSE(task->done_invoked); | 871 ASSERT_FALSE(task->done_invoked); |
| 939 } | 872 } |
| 940 | 873 |
| 941 } // namespace history | 874 } // namespace history |
| OLD | NEW |