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