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