| 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 <string> | 6 #include <string> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "chrome/browser/history/expire_history_backend.h" | 18 #include "chrome/browser/history/expire_history_backend.h" |
| 19 #include "chrome/browser/history/history_details.h" | 19 #include "chrome/browser/history/history_details.h" |
| 20 #include "chrome/browser/history/top_sites.h" | 20 #include "chrome/browser/history/top_sites.h" |
| 21 #include "chrome/browser/history/top_sites_factory.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 22 #include "chrome/tools/profiles/thumbnail-inl.h" | 23 #include "chrome/tools/profiles/thumbnail-inl.h" |
| 23 #include "components/history/core/browser/history_backend_notifier.h" | 24 #include "components/history/core/browser/history_backend_notifier.h" |
| 24 #include "components/history/core/browser/history_database.h" | 25 #include "components/history/core/browser/history_database.h" |
| 25 #include "components/history/core/browser/thumbnail_database.h" | 26 #include "components/history/core/browser/thumbnail_database.h" |
| 26 #include "components/history/core/common/thumbnail_score.h" | 27 #include "components/history/core/common/thumbnail_score.h" |
| 27 #include "components/history/core/test/history_client_fake_bookmarks.h" | 28 #include "components/history/core/test/history_client_fake_bookmarks.h" |
| 28 #include "components/history/core/test/test_history_database.h" | 29 #include "components/history/core/test/test_history_database.h" |
| 29 #include "content/public/test/test_browser_thread.h" | 30 #include "content/public/test/test_browser_thread.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 101 |
| 101 base::MessageLoopForUI message_loop_; | 102 base::MessageLoopForUI message_loop_; |
| 102 content::TestBrowserThread ui_thread_; | 103 content::TestBrowserThread ui_thread_; |
| 103 content::TestBrowserThread db_thread_; | 104 content::TestBrowserThread db_thread_; |
| 104 | 105 |
| 105 ExpireHistoryBackend expirer_; | 106 ExpireHistoryBackend expirer_; |
| 106 | 107 |
| 107 scoped_ptr<HistoryDatabase> main_db_; | 108 scoped_ptr<HistoryDatabase> main_db_; |
| 108 scoped_ptr<ThumbnailDatabase> thumb_db_; | 109 scoped_ptr<ThumbnailDatabase> thumb_db_; |
| 109 TestingProfile profile_; | 110 TestingProfile profile_; |
| 110 scoped_refptr<TopSites> top_sites_; | |
| 111 | 111 |
| 112 // Time at the beginning of the test, so everybody agrees what "now" is. | 112 // Time at the beginning of the test, so everybody agrees what "now" is. |
| 113 const Time now_; | 113 const Time now_; |
| 114 | 114 |
| 115 // Notifications intended to be broadcast, we can check these values to make | 115 // Notifications intended to be broadcast, we can check these values to make |
| 116 // sure that the deletor is doing the correct broadcasts. We own the details | 116 // sure that the deletor is doing the correct broadcasts. We own the details |
| 117 // pointers. | 117 // pointers. |
| 118 typedef std::vector< std::pair<int, HistoryDetails*> > | 118 typedef std::vector< std::pair<int, HistoryDetails*> > |
| 119 NotificationList; | 119 NotificationList; |
| 120 NotificationList notifications_; | 120 NotificationList notifications_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 135 main_db_.reset(); | 135 main_db_.reset(); |
| 136 | 136 |
| 137 base::FilePath thumb_name = path().Append(kThumbnailFile); | 137 base::FilePath thumb_name = path().Append(kThumbnailFile); |
| 138 thumb_db_.reset(new ThumbnailDatabase(NULL)); | 138 thumb_db_.reset(new ThumbnailDatabase(NULL)); |
| 139 if (thumb_db_->Init(thumb_name) != sql::INIT_OK) | 139 if (thumb_db_->Init(thumb_name) != sql::INIT_OK) |
| 140 thumb_db_.reset(); | 140 thumb_db_.reset(); |
| 141 | 141 |
| 142 expirer_.SetDatabases(main_db_.get(), thumb_db_.get()); | 142 expirer_.SetDatabases(main_db_.get(), thumb_db_.get()); |
| 143 profile_.CreateTopSites(); | 143 profile_.CreateTopSites(); |
| 144 profile_.BlockUntilTopSitesLoaded(); | 144 profile_.BlockUntilTopSitesLoaded(); |
| 145 top_sites_ = profile_.GetTopSites(); | |
| 146 } | 145 } |
| 147 | 146 |
| 148 void TearDown() override { | 147 void TearDown() override { |
| 149 top_sites_ = NULL; | |
| 150 | 148 |
| 151 ClearLastNotifications(); | 149 ClearLastNotifications(); |
| 152 | 150 |
| 153 expirer_.SetDatabases(NULL, NULL); | 151 expirer_.SetDatabases(NULL, NULL); |
| 154 | 152 |
| 155 main_db_.reset(); | 153 main_db_.reset(); |
| 156 thumb_db_.reset(); | 154 thumb_db_.reset(); |
| 157 } | 155 } |
| 158 | 156 |
| 159 // HistoryBackendNotifier: | 157 // HistoryBackendNotifier: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 thumb_db_->AddIconMapping(url_row3.url(), favicon2); | 221 thumb_db_->AddIconMapping(url_row3.url(), favicon2); |
| 224 | 222 |
| 225 // Thumbnails for each URL. |thumbnail| takes ownership of decoded SkBitmap. | 223 // Thumbnails for each URL. |thumbnail| takes ownership of decoded SkBitmap. |
| 226 scoped_ptr<SkBitmap> thumbnail_bitmap( | 224 scoped_ptr<SkBitmap> thumbnail_bitmap( |
| 227 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); | 225 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); |
| 228 gfx::Image thumbnail = gfx::Image::CreateFrom1xBitmap(*thumbnail_bitmap); | 226 gfx::Image thumbnail = gfx::Image::CreateFrom1xBitmap(*thumbnail_bitmap); |
| 229 ThumbnailScore score(0.25, true, true, Time::Now()); | 227 ThumbnailScore score(0.25, true, true, Time::Now()); |
| 230 | 228 |
| 231 Time time; | 229 Time time; |
| 232 GURL gurl; | 230 GURL gurl; |
| 233 top_sites_->SetPageThumbnail(url_row1.url(), thumbnail, score); | 231 scoped_refptr<history::TopSites> top_sites = |
| 234 top_sites_->SetPageThumbnail(url_row2.url(), thumbnail, score); | 232 TopSitesFactory::GetForProfile(&profile_); |
| 235 top_sites_->SetPageThumbnail(url_row3.url(), thumbnail, score); | 233 top_sites->SetPageThumbnail(url_row1.url(), thumbnail, score); |
| 234 top_sites->SetPageThumbnail(url_row2.url(), thumbnail, score); |
| 235 top_sites->SetPageThumbnail(url_row3.url(), thumbnail, score); |
| 236 | 236 |
| 237 // Four visits. | 237 // Four visits. |
| 238 VisitRow visit_row1; | 238 VisitRow visit_row1; |
| 239 visit_row1.url_id = url_ids[0]; | 239 visit_row1.url_id = url_ids[0]; |
| 240 visit_row1.visit_time = visit_times[0]; | 240 visit_row1.visit_time = visit_times[0]; |
| 241 main_db_->AddVisit(&visit_row1, SOURCE_BROWSED); | 241 main_db_->AddVisit(&visit_row1, SOURCE_BROWSED); |
| 242 | 242 |
| 243 VisitRow visit_row2; | 243 VisitRow visit_row2; |
| 244 visit_row2.url_id = url_ids[1]; | 244 visit_row2.url_id = url_ids[1]; |
| 245 visit_row2.visit_time = visit_times[1]; | 245 visit_row2.visit_time = visit_times[1]; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool ExpireHistoryTest::HasThumbnail(URLID url_id) { | 307 bool ExpireHistoryTest::HasThumbnail(URLID url_id) { |
| 308 // TODO(sky): fix this. This test isn't really valid for TopSites. For | 308 // TODO(sky): fix this. This test isn't really valid for TopSites. For |
| 309 // TopSites we should be checking URL always, not the id. | 309 // TopSites we should be checking URL always, not the id. |
| 310 URLRow info; | 310 URLRow info; |
| 311 if (!main_db_->GetURLRow(url_id, &info)) | 311 if (!main_db_->GetURLRow(url_id, &info)) |
| 312 return false; | 312 return false; |
| 313 GURL url = info.url(); | 313 GURL url = info.url(); |
| 314 scoped_refptr<base::RefCountedMemory> data; | 314 scoped_refptr<base::RefCountedMemory> data; |
| 315 return top_sites_->GetPageThumbnail(url, false, &data); | 315 scoped_refptr<history::TopSites> top_sites = |
| 316 TopSitesFactory::GetForProfile(&profile_); |
| 317 return top_sites->GetPageThumbnail(url, false, &data); |
| 316 } | 318 } |
| 317 | 319 |
| 318 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row, bool expired) { | 320 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row, bool expired) { |
| 319 // The passed in |row| must originate from |main_db_| so that its ID will be | 321 // The passed in |row| must originate from |main_db_| so that its ID will be |
| 320 // set to what had been in effect in |main_db_| before the deletion. | 322 // set to what had been in effect in |main_db_| before the deletion. |
| 321 ASSERT_NE(0, row.id()); | 323 ASSERT_NE(0, row.id()); |
| 322 | 324 |
| 323 // Verify the URL no longer exists. | 325 // Verify the URL no longer exists. |
| 324 URLRow temp_row; | 326 URLRow temp_row; |
| 325 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); | 327 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); | 877 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); |
| 876 EXPECT_EQ(1U, visits.size()); | 878 EXPECT_EQ(1U, visits.size()); |
| 877 } | 879 } |
| 878 | 880 |
| 879 // TODO(brettw) add some visits with no URL to make sure everything is updated | 881 // TODO(brettw) add some visits with no URL to make sure everything is updated |
| 880 // properly. Have the visits also refer to nonexistent FTS rows. | 882 // properly. Have the visits also refer to nonexistent FTS rows. |
| 881 // | 883 // |
| 882 // Maybe also refer to invalid favicons. | 884 // Maybe also refer to invalid favicons. |
| 883 | 885 |
| 884 } // namespace history | 886 } // namespace history |
| OLD | NEW |