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

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

Issue 815983002: Topsites become keyedService based. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years, 12 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/task/cancelable_task_tracker.h" 9 #include "base/task/cancelable_task_tracker.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 TestTopSitesObserver::TestTopSitesObserver(Profile* profile, 48 TestTopSitesObserver::TestTopSitesObserver(Profile* profile,
49 history::TopSites* top_sites) 49 history::TopSites* top_sites)
50 : profile_(profile), top_sites_(top_sites) { 50 : profile_(profile), top_sites_(top_sites) {
51 DCHECK(top_sites_); 51 DCHECK(top_sites_);
52 top_sites_->AddObserver(this); 52 top_sites_->AddObserver(this);
53 } 53 }
54 54
55 void TestTopSitesObserver::TopSitesLoaded(history::TopSites* top_sites) { 55 void TestTopSitesObserver::TopSitesLoaded(history::TopSites* top_sites) {
56 content::NotificationService::current()->Notify( 56 content::NotificationService::current()->Notify(
57 chrome::NOTIFICATION_TOP_SITES_LOADED, 57 chrome::NOTIFICATION_TOP_SITES_LOADED, content::Source<Profile>(profile_),
58 content::Source<Profile>(profile_),
59 content::Details<history::TopSites>(top_sites)); 58 content::Details<history::TopSites>(top_sites));
60 } 59 }
61 60
62 void TestTopSitesObserver::TopSitesChanged(history::TopSites* top_sites) { 61 void TestTopSitesObserver::TopSitesChanged(history::TopSites* top_sites) {
63 content::NotificationService::current()->Notify( 62 content::NotificationService::current()->Notify(
64 chrome::NOTIFICATION_TOP_SITES_CHANGED, 63 chrome::NOTIFICATION_TOP_SITES_CHANGED,
65 content::Source<Profile>(profile_), 64 content::Source<Profile>(profile_),
66 content::NotificationService::NoDetails()); 65 content::NotificationService::NoDetails());
67 } 66 }
68 67
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // Waits for top sites to finish processing a task. This is useful if you need 228 // Waits for top sites to finish processing a task. This is useful if you need
230 // to wait until top sites finishes processing a task. 229 // to wait until top sites finishes processing a task.
231 void WaitForTopSites() { 230 void WaitForTopSites() {
232 top_sites()->backend_->DoEmptyRequest( 231 top_sites()->backend_->DoEmptyRequest(
233 base::Bind(&TopSitesImplTest::QuitCallback, base::Unretained(this)), 232 base::Bind(&TopSitesImplTest::QuitCallback, base::Unretained(this)),
234 &top_sites_tracker_); 233 &top_sites_tracker_);
235 base::MessageLoop::current()->Run(); 234 base::MessageLoop::current()->Run();
236 } 235 }
237 236
238 TopSitesImpl* top_sites() { 237 TopSitesImpl* top_sites() {
239 return static_cast<TopSitesImpl*>(profile_->GetTopSites()); 238 return static_cast<TopSitesImpl*>(
239 TopSitesServiceFactory::GetForProfile(profile_));
sdefresne 2014/12/29 09:48:14 nit: TopSitesServiceFactory::GetForProfile(profile
Jitu( very slow this week) 2014/12/30 10:09:03 Done.
240 } 240 }
241 TestingProfile* profile() {return profile_.get();} 241 TestingProfile* profile() {return profile_.get();}
242 HistoryService* history_service() { 242 HistoryService* history_service() {
243 return HistoryServiceFactory::GetForProfile(profile_.get(), 243 return HistoryServiceFactory::GetForProfile(profile_.get(),
244 Profile::EXPLICIT_ACCESS); 244 Profile::EXPLICIT_ACCESS);
245 } 245 }
246 246
247 MostVisitedURLList GetPrepopulatePages() { 247 MostVisitedURLList GetPrepopulatePages() {
248 return top_sites()->GetPrepopulatePages(); 248 return top_sites()->GetPrepopulatePages();
249 } 249 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 void EmptyThreadSafeCache() { 362 void EmptyThreadSafeCache() {
363 base::AutoLock lock(top_sites()->lock_); 363 base::AutoLock lock(top_sites()->lock_);
364 MostVisitedURLList empty; 364 MostVisitedURLList empty;
365 top_sites()->thread_safe_cache_->SetTopSites(empty); 365 top_sites()->thread_safe_cache_->SetTopSites(empty);
366 } 366 }
367 367
368 void CreateTopSitesAndObserver() { 368 void CreateTopSitesAndObserver() {
369 if (top_sites_observer_) 369 if (top_sites_observer_)
370 top_sites_observer_.reset(); 370 top_sites_observer_.reset();
371 371
372 profile_->CreateTopSites(); 372 profile_->CreateTopSitesService();
373 top_sites_observer_.reset( 373 top_sites_observer_.reset(
374 new TestTopSitesObserver(profile_.get(), profile_->GetTopSites())); 374 new TestTopSitesObserver(profile_.get(), TopSitesServiceFactory::GetForP rofile(profile_));
375 } 375 }
376 376
377 private: 377 private:
378 base::MessageLoopForUI message_loop_; 378 base::MessageLoopForUI message_loop_;
379 content::TestBrowserThread ui_thread_; 379 content::TestBrowserThread ui_thread_;
380 content::TestBrowserThread db_thread_; 380 content::TestBrowserThread db_thread_;
381 scoped_ptr<TestingProfile> profile_; 381 scoped_ptr<TestingProfile> profile_;
382 scoped_ptr<TestTopSitesObserver> top_sites_observer_; 382 scoped_ptr<TestTopSitesObserver> top_sites_observer_;
383 // To cancel HistoryService tasks. 383 // To cancel HistoryService tasks.
384 base::CancelableTaskTracker history_tracker_; 384 base::CancelableTaskTracker history_tracker_;
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize()); 1682 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize());
1683 orig_thumbnail.lockPixels(); 1683 orig_thumbnail.lockPixels();
1684 thumbnail.lockPixels(); 1684 thumbnail.lockPixels();
1685 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(), 1685 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(),
1686 orig_thumbnail.getSize())); 1686 orig_thumbnail.getSize()));
1687 thumbnail.unlockPixels(); 1687 thumbnail.unlockPixels();
1688 orig_thumbnail.unlockPixels(); 1688 orig_thumbnail.unlockPixels();
1689 } 1689 }
1690 1690
1691 } // namespace history 1691 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698