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