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

Unified Diff: chrome/browser/history/top_sites_impl_unittest.cc

Issue 441623002: Eliminate sending NOTIFICATION_TOP_SITES_* from TopSites (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix incorrect parmeter being passed in notification Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/history/top_sites_impl.cc ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/top_sites_impl_unittest.cc
diff --git a/chrome/browser/history/top_sites_impl_unittest.cc b/chrome/browser/history/top_sites_impl_unittest.cc
index 044f3bc2eeb80839338cf3ff56497ae1b95c572f..9cd07aa5a3915d7d87ae1b4331f5f78b6dd9e4d9 100644
--- a/chrome/browser/history/top_sites_impl_unittest.cc
+++ b/chrome/browser/history/top_sites_impl_unittest.cc
@@ -8,15 +8,19 @@
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/cancelable_task_tracker.h"
+#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_db_task.h"
+#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/history_unittest_base.h"
+#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/history/top_sites_cache.h"
#include "chrome/browser/history/top_sites_impl.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/browser/notification_service.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -25,6 +29,44 @@
using content::BrowserThread;
+class TestTopSitesObserver : public history::TopSitesObserver {
+ public:
+ explicit TestTopSitesObserver(Profile* profile, history::TopSites* top_sites);
+ virtual ~TestTopSitesObserver();
+ // TopSitesObserver:
+ virtual void TopSitesLoaded(history::TopSites* top_sites) OVERRIDE;
+ virtual void TopSitesChanged(history::TopSites* top_sites) OVERRIDE;
+
+ private:
+ Profile* profile_;
+ history::TopSites* top_sites_;
+};
+
+TestTopSitesObserver::~TestTopSitesObserver() {
+ top_sites_->RemoveObserver(this);
+}
+
+TestTopSitesObserver::TestTopSitesObserver(Profile* profile,
+ history::TopSites* top_sites)
+ : profile_(profile), top_sites_(top_sites) {
+ DCHECK(top_sites_);
+ top_sites_->AddObserver(this);
+}
+
+void TestTopSitesObserver::TopSitesLoaded(history::TopSites* top_sites) {
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_TOP_SITES_LOADED,
+ content::Source<Profile>(profile_),
+ content::Details<history::TopSites>(top_sites));
+}
+
+void TestTopSitesObserver::TopSitesChanged(history::TopSites* top_sites) {
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_TOP_SITES_CHANGED,
+ content::Source<Profile>(profile_),
+ content::NotificationService::NoDetails());
+}
+
namespace history {
namespace {
@@ -140,12 +182,13 @@ class TopSitesImplTest : public HistoryUnitTestBase {
profile_.reset(new TestingProfile);
if (CreateHistoryAndTopSites()) {
ASSERT_TRUE(profile_->CreateHistoryService(false, false));
- profile_->CreateTopSites();
+ CreateTopSitesAndObserver();
profile_->BlockUntilTopSitesLoaded();
}
}
virtual void TearDown() {
+ top_sites_observer_.reset();
profile_.reset();
}
@@ -281,7 +324,7 @@ class TopSitesImplTest : public HistoryUnitTestBase {
// Recreates top sites. This forces top sites to reread from the db.
void RecreateTopSitesAndBlock() {
// Recreate TopSites and wait for it to load.
- profile()->CreateTopSites();
+ CreateTopSitesAndObserver();
// As history already loaded we have to fake this call.
profile()->BlockUntilTopSitesLoaded();
}
@@ -326,12 +369,21 @@ class TopSitesImplTest : public HistoryUnitTestBase {
top_sites()->thread_safe_cache_->SetTopSites(empty);
}
+ void CreateTopSitesAndObserver() {
+ if (top_sites_observer_)
+ top_sites_observer_.reset();
+
+ profile_->CreateTopSites();
+ top_sites_observer_.reset(
+ new TestTopSitesObserver(profile_.get(), profile_->GetTopSites()));
+ }
+
private:
base::MessageLoopForUI message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_;
scoped_ptr<TestingProfile> profile_;
-
+ scoped_ptr<TestTopSitesObserver> top_sites_observer_;
// To cancel HistoryService tasks.
base::CancelableTaskTracker history_tracker_;
@@ -982,7 +1034,7 @@ TEST_F(TopSitesImplTest, GetUpdateDelay) {
// has loaded.
TEST_F(TopSitesImplTest, NotifyCallbacksWhenLoaded) {
// Recreate top sites. It won't be loaded now.
- profile()->CreateTopSites();
+ CreateTopSitesAndObserver();
EXPECT_FALSE(IsTopSitesLoaded());
@@ -1023,7 +1075,7 @@ TEST_F(TopSitesImplTest, NotifyCallbacksWhenLoaded) {
SetTopSites(pages);
// Recreate top sites. It won't be loaded now.
- profile()->CreateTopSites();
+ CreateTopSitesAndObserver();
EXPECT_FALSE(IsTopSitesLoaded());
@@ -1068,7 +1120,7 @@ TEST_F(TopSitesImplTest, NotifyCallbacksWhenLoaded) {
// Makes sure canceled requests are not notified.
TEST_F(TopSitesImplTest, CancelingRequestsForTopSites) {
// Recreate top sites. It won't be loaded now.
- profile()->CreateTopSites();
+ CreateTopSitesAndObserver();
EXPECT_FALSE(IsTopSitesLoaded());
« no previous file with comments | « chrome/browser/history/top_sites_impl.cc ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698