Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: chrome/browser/history/expire_history_backend_unittest.cc

Issue 815983002: Topsites become keyedService based. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove extra inclusion from testing_profile.h Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/history/top_sites.h" 17 #include "chrome/browser/history/top_sites.h"
18 #include "chrome/browser/history/top_sites_factory.h"
18 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
19 #include "chrome/tools/profiles/thumbnail-inl.h" 20 #include "chrome/tools/profiles/thumbnail-inl.h"
20 #include "components/history/core/browser/expire_history_backend.h" 21 #include "components/history/core/browser/expire_history_backend.h"
21 #include "components/history/core/browser/history_backend_notifier.h" 22 #include "components/history/core/browser/history_backend_notifier.h"
22 #include "components/history/core/browser/history_database.h" 23 #include "components/history/core/browser/history_database.h"
23 #include "components/history/core/browser/thumbnail_database.h" 24 #include "components/history/core/browser/thumbnail_database.h"
24 #include "components/history/core/common/thumbnail_score.h" 25 #include "components/history/core/common/thumbnail_score.h"
25 #include "components/history/core/test/history_client_fake_bookmarks.h" 26 #include "components/history/core/test/history_client_fake_bookmarks.h"
26 #include "components/history/core/test/test_history_database.h" 27 #include "components/history/core/test/test_history_database.h"
27 #include "content/public/test/test_browser_thread.h" 28 #include "content/public/test/test_browser_thread.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 98
98 base::MessageLoopForUI message_loop_; 99 base::MessageLoopForUI message_loop_;
99 content::TestBrowserThread ui_thread_; 100 content::TestBrowserThread ui_thread_;
100 content::TestBrowserThread db_thread_; 101 content::TestBrowserThread db_thread_;
101 102
102 ExpireHistoryBackend expirer_; 103 ExpireHistoryBackend expirer_;
103 104
104 scoped_ptr<HistoryDatabase> main_db_; 105 scoped_ptr<HistoryDatabase> main_db_;
105 scoped_ptr<ThumbnailDatabase> thumb_db_; 106 scoped_ptr<ThumbnailDatabase> thumb_db_;
106 TestingProfile profile_; 107 TestingProfile profile_;
107 scoped_refptr<TopSites> top_sites_;
108 108
109 // Time at the beginning of the test, so everybody agrees what "now" is. 109 // Time at the beginning of the test, so everybody agrees what "now" is.
110 const Time now_; 110 const Time now_;
111 111
112 // Details received from HistoryObserver events. 112 // Details received from HistoryObserver events.
113 typedef std::vector<URLRows> URLsModifiedNotificationList; 113 typedef std::vector<URLRows> URLsModifiedNotificationList;
114 URLsModifiedNotificationList urls_modified_notifications_; 114 URLsModifiedNotificationList urls_modified_notifications_;
115 115
116 typedef std::vector<std::pair<bool, URLRows>> URLsDeletedNotificationList; 116 typedef std::vector<std::pair<bool, URLRows>> URLsDeletedNotificationList;
117 URLsDeletedNotificationList urls_deleted_notifications_; 117 URLsDeletedNotificationList urls_deleted_notifications_;
118 118
119 private: 119 private:
120 void SetUp() override { 120 void SetUp() override {
121 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); 121 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir());
122 122
123 base::FilePath history_name = path().Append(kHistoryFile); 123 base::FilePath history_name = path().Append(kHistoryFile);
124 main_db_.reset(new TestHistoryDatabase); 124 main_db_.reset(new TestHistoryDatabase);
125 if (main_db_->Init(history_name) != sql::INIT_OK) 125 if (main_db_->Init(history_name) != sql::INIT_OK)
126 main_db_.reset(); 126 main_db_.reset();
127 127
128 base::FilePath thumb_name = path().Append(kThumbnailFile); 128 base::FilePath thumb_name = path().Append(kThumbnailFile);
129 thumb_db_.reset(new ThumbnailDatabase(NULL)); 129 thumb_db_.reset(new ThumbnailDatabase(NULL));
130 if (thumb_db_->Init(thumb_name) != sql::INIT_OK) 130 if (thumb_db_->Init(thumb_name) != sql::INIT_OK)
131 thumb_db_.reset(); 131 thumb_db_.reset();
132 132
133 expirer_.SetDatabases(main_db_.get(), thumb_db_.get()); 133 expirer_.SetDatabases(main_db_.get(), thumb_db_.get());
134 profile_.CreateTopSites(); 134 profile_.CreateTopSites();
135 profile_.BlockUntilTopSitesLoaded(); 135 profile_.BlockUntilTopSitesLoaded();
136 top_sites_ = profile_.GetTopSites();
137 } 136 }
138 137
139 void TearDown() override { 138 void TearDown() override {
140 top_sites_ = NULL;
141 139
142 ClearLastNotifications(); 140 ClearLastNotifications();
143 141
144 expirer_.SetDatabases(NULL, NULL); 142 expirer_.SetDatabases(NULL, NULL);
145 143
146 main_db_.reset(); 144 main_db_.reset();
147 thumb_db_.reset(); 145 thumb_db_.reset();
148 } 146 }
149 147
150 // HistoryBackendNotifier: 148 // HistoryBackendNotifier:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 thumb_db_->AddIconMapping(url_row3.url(), favicon2); 212 thumb_db_->AddIconMapping(url_row3.url(), favicon2);
215 213
216 // Thumbnails for each URL. |thumbnail| takes ownership of decoded SkBitmap. 214 // Thumbnails for each URL. |thumbnail| takes ownership of decoded SkBitmap.
217 scoped_ptr<SkBitmap> thumbnail_bitmap( 215 scoped_ptr<SkBitmap> thumbnail_bitmap(
218 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); 216 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail)));
219 gfx::Image thumbnail = gfx::Image::CreateFrom1xBitmap(*thumbnail_bitmap); 217 gfx::Image thumbnail = gfx::Image::CreateFrom1xBitmap(*thumbnail_bitmap);
220 ThumbnailScore score(0.25, true, true, Time::Now()); 218 ThumbnailScore score(0.25, true, true, Time::Now());
221 219
222 Time time; 220 Time time;
223 GURL gurl; 221 GURL gurl;
224 top_sites_->SetPageThumbnail(url_row1.url(), thumbnail, score); 222 scoped_refptr<history::TopSites> top_sites =
225 top_sites_->SetPageThumbnail(url_row2.url(), thumbnail, score); 223 TopSitesFactory::GetForProfile(&profile_);
226 top_sites_->SetPageThumbnail(url_row3.url(), thumbnail, score); 224 top_sites->SetPageThumbnail(url_row1.url(), thumbnail, score);
225 top_sites->SetPageThumbnail(url_row2.url(), thumbnail, score);
226 top_sites->SetPageThumbnail(url_row3.url(), thumbnail, score);
227 227
228 // Four visits. 228 // Four visits.
229 VisitRow visit_row1; 229 VisitRow visit_row1;
230 visit_row1.url_id = url_ids[0]; 230 visit_row1.url_id = url_ids[0];
231 visit_row1.visit_time = visit_times[0]; 231 visit_row1.visit_time = visit_times[0];
232 main_db_->AddVisit(&visit_row1, SOURCE_BROWSED); 232 main_db_->AddVisit(&visit_row1, SOURCE_BROWSED);
233 233
234 VisitRow visit_row2; 234 VisitRow visit_row2;
235 visit_row2.url_id = url_ids[1]; 235 visit_row2.url_id = url_ids[1];
236 visit_row2.visit_time = visit_times[1]; 236 visit_row2.visit_time = visit_times[1];
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 296 }
297 297
298 bool ExpireHistoryTest::HasThumbnail(URLID url_id) { 298 bool ExpireHistoryTest::HasThumbnail(URLID url_id) {
299 // TODO(sky): fix this. This test isn't really valid for TopSites. For 299 // TODO(sky): fix this. This test isn't really valid for TopSites. For
300 // TopSites we should be checking URL always, not the id. 300 // TopSites we should be checking URL always, not the id.
301 URLRow info; 301 URLRow info;
302 if (!main_db_->GetURLRow(url_id, &info)) 302 if (!main_db_->GetURLRow(url_id, &info))
303 return false; 303 return false;
304 GURL url = info.url(); 304 GURL url = info.url();
305 scoped_refptr<base::RefCountedMemory> data; 305 scoped_refptr<base::RefCountedMemory> data;
306 return top_sites_->GetPageThumbnail(url, false, &data); 306 scoped_refptr<history::TopSites> top_sites =
307 TopSitesFactory::GetForProfile(&profile_);
308 return top_sites->GetPageThumbnail(url, false, &data);
307 } 309 }
308 310
309 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row, bool expired) { 311 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row, bool expired) {
310 // The passed in |row| must originate from |main_db_| so that its ID will be 312 // The passed in |row| must originate from |main_db_| so that its ID will be
311 // set to what had been in effect in |main_db_| before the deletion. 313 // set to what had been in effect in |main_db_| before the deletion.
312 ASSERT_NE(0, row.id()); 314 ASSERT_NE(0, row.id());
313 315
314 // Verify the URL no longer exists. 316 // Verify the URL no longer exists.
315 URLRow temp_row; 317 URLRow temp_row;
316 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); 318 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row));
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); 868 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1));
867 EXPECT_EQ(1U, visits.size()); 869 EXPECT_EQ(1U, visits.size());
868 } 870 }
869 871
870 // TODO(brettw) add some visits with no URL to make sure everything is updated 872 // TODO(brettw) add some visits with no URL to make sure everything is updated
871 // properly. Have the visits also refer to nonexistent FTS rows. 873 // properly. Have the visits also refer to nonexistent FTS rows.
872 // 874 //
873 // Maybe also refer to invalid favicons. 875 // Maybe also refer to invalid favicons.
874 876
875 } // namespace history 877 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/top_sites/top_sites_apitest.cc ('k') | chrome/browser/history/history_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698