Index: chrome/browser/browsing_data/history_counter_browsertest.cc |
diff --git a/chrome/browser/browsing_data/history_counter_browsertest.cc b/chrome/browser/browsing_data/history_counter_browsertest.cc |
index 1366efa53c8c271f3a1a7c5ae0b66273d79cd372..17d025affa8ec94cc6feb3962f200929ca40926c 100644 |
--- a/chrome/browser/browsing_data/history_counter_browsertest.cc |
+++ b/chrome/browser/browsing_data/history_counter_browsertest.cc |
@@ -2,13 +2,16 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/browsing_data/history_counter.h" |
+#include "components/browsing_data/core/counters/history_counter.h" |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
#include "base/run_loop.h" |
#include "chrome/browser/history/history_service_factory.h" |
#include "chrome/browser/history/web_history_service_factory.h" |
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
#include "chrome/browser/signin/signin_manager_factory.h" |
+#include "chrome/browser/sync/profile_sync_service_factory.h" |
#include "chrome/browser/sync/test/integration/sync_test.h" |
#include "chrome/browser/ui/browser.h" |
#include "components/browser_sync/browser/profile_sync_service.h" |
@@ -38,14 +41,15 @@ class HistoryCounterTest : public SyncTest { |
void SetUpOnMainThread() override { |
time_ = base::Time::Now(); |
- service_ = HistoryServiceFactory::GetForProfileWithoutCreating( |
+ history_service_ = HistoryServiceFactory::GetForProfileWithoutCreating( |
browser()->profile()); |
+ |
SetHistoryDeletionPref(true); |
SetDeletionPeriodPref(browsing_data::EVERYTHING); |
} |
void AddVisit(const std::string url) { |
- service_->AddPage(GURL(url), time_, history::SOURCE_BROWSED); |
+ history_service_->AddPage(GURL(url), time_, history::SOURCE_BROWSED); |
} |
const base::Time& GetCurrentTime() { |
@@ -86,8 +90,9 @@ class HistoryCounterTest : public SyncTest { |
finished_ = result->Finished(); |
if (finished_) { |
- HistoryCounter::HistoryResult* history_result = |
- static_cast<HistoryCounter::HistoryResult*>(result.get()); |
+ browsing_data::HistoryCounter::HistoryResult* history_result = |
+ static_cast<browsing_data::HistoryCounter::HistoryResult*>( |
+ result.get()); |
local_result_ = history_result->Value(); |
has_synced_visits_ = history_result->has_synced_visits(); |
@@ -111,9 +116,15 @@ class HistoryCounterTest : public SyncTest { |
CountingFinishedSinceLastAsked(); |
} |
+ history::WebHistoryService* GetWebHistoryService(Profile* profile) { |
+ return WebHistoryServiceFactory::GetForProfile(profile); |
+ } |
+ |
+ history::HistoryService* GetHistoryService() { return history_service_; } |
+ |
private: |
std::unique_ptr<base::RunLoop> run_loop_; |
- history::HistoryService* service_; |
+ history::HistoryService* history_service_; |
base::Time time_; |
bool finished_; |
@@ -147,7 +158,12 @@ IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DuplicateVisits) { |
Profile* profile = browser()->profile(); |
- HistoryCounter counter(profile); |
+ browsing_data::HistoryCounter counter( |
+ GetHistoryService(), |
+ base::Bind(&HistoryCounterTest::GetWebHistoryService, |
+ base::Unretained(this), base::Unretained(profile)), |
+ ProfileSyncServiceFactory::GetForProfile(profile)); |
+ |
counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
base::Unretained(this))); |
counter.Restart(); |
@@ -165,7 +181,12 @@ IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) { |
Profile* profile = browser()->profile(); |
- HistoryCounter counter(profile); |
+ browsing_data::HistoryCounter counter( |
+ GetHistoryService(), |
+ base::Bind(&HistoryCounterTest::GetWebHistoryService, |
+ base::Unretained(this), base::Unretained(profile)), |
+ ProfileSyncServiceFactory::GetForProfile(profile)); |
+ |
counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
base::Unretained(this))); |
SetHistoryDeletionPref(true); |
@@ -182,7 +203,12 @@ IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefIsFalse) { |
Profile* profile = browser()->profile(); |
- HistoryCounter counter(profile); |
+ browsing_data::HistoryCounter counter( |
+ GetHistoryService(), |
+ base::Bind(&HistoryCounterTest::GetWebHistoryService, |
+ base::Unretained(this), base::Unretained(profile)), |
+ ProfileSyncServiceFactory::GetForProfile(profile)); |
+ |
counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
base::Unretained(this))); |
counter.Restart(); |
@@ -216,7 +242,12 @@ IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) { |
Profile* profile = browser()->profile(); |
- HistoryCounter counter(profile); |
+ browsing_data::HistoryCounter counter( |
+ GetHistoryService(), |
+ base::Bind(&HistoryCounterTest::GetWebHistoryService, |
+ base::Unretained(this), base::Unretained(profile)), |
+ ProfileSyncServiceFactory::GetForProfile(profile)); |
+ |
counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
base::Unretained(this))); |
@@ -247,19 +278,25 @@ IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) { |
// for testing. |
Profile* profile = browser()->profile(); |
- std::unique_ptr<history::FakeWebHistoryService> service( |
+ std::unique_ptr<history::FakeWebHistoryService> web_history_service( |
new history::FakeWebHistoryService( |
ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
SigninManagerFactory::GetForProfile(profile), |
profile->GetRequestContext())); |
- HistoryCounter counter(profile); |
- counter.SetWebHistoryServiceForTesting(service.get()); |
+ browsing_data::HistoryCounter counter( |
+ GetHistoryService(), |
+ base::Bind(&HistoryCounterTest::GetWebHistoryService, |
+ base::Unretained(this), |
+ base::Unretained(profile)), |
+ ProfileSyncServiceFactory::GetForProfile(profile)); |
+ |
+ counter.SetWebHistoryServiceForTesting(web_history_service.get()); |
counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
base::Unretained(this))); |
// No entries locally and no entries in Sync. |
- service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
+ web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
counter.Restart(); |
WaitForCounting(); |
EXPECT_EQ(0u, GetLocalResult()); |
@@ -268,19 +305,19 @@ IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) { |
// No entries locally. There are some entries in Sync, but they are out of the |
// time range. |
SetDeletionPeriodPref(browsing_data::LAST_HOUR); |
- service->AddSyncedVisit( |
+ web_history_service->AddSyncedVisit( |
"www.google.com", GetCurrentTime() - base::TimeDelta::FromHours(2)); |
- service->AddSyncedVisit( |
+ web_history_service->AddSyncedVisit( |
"www.chrome.com", GetCurrentTime() - base::TimeDelta::FromHours(2)); |
- service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
+ web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
counter.Restart(); |
WaitForCounting(); |
EXPECT_EQ(0u, GetLocalResult()); |
EXPECT_FALSE(HasSyncedVisits()); |
// No entries locally, but some entries in Sync. |
- service->AddSyncedVisit("www.google.com", GetCurrentTime()); |
- service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
+ web_history_service->AddSyncedVisit("www.google.com", GetCurrentTime()); |
+ web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
counter.Restart(); |
WaitForCounting(); |
EXPECT_EQ(0u, GetLocalResult()); |
@@ -288,16 +325,16 @@ IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) { |
// To err on the safe side, if the server request fails, we assume that there |
// might be some items on the server. |
- service->SetupFakeResponse(true /* success */, |
- net::HTTP_INTERNAL_SERVER_ERROR); |
+ web_history_service->SetupFakeResponse(true /* success */, |
+ net::HTTP_INTERNAL_SERVER_ERROR); |
counter.Restart(); |
WaitForCounting(); |
EXPECT_EQ(0u, GetLocalResult()); |
EXPECT_TRUE(HasSyncedVisits()); |
// Same when the entire query fails. |
- service->SetupFakeResponse(false /* success */, |
- net::HTTP_INTERNAL_SERVER_ERROR); |
+ web_history_service->SetupFakeResponse(false /* success */, |
+ net::HTTP_INTERNAL_SERVER_ERROR); |
counter.Restart(); |
WaitForCounting(); |
EXPECT_EQ(0u, GetLocalResult()); |
@@ -306,15 +343,15 @@ IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) { |
// Nonzero local count, nonempty sync. |
AddVisit("https://www.google.com"); |
AddVisit("https://www.chrome.com"); |
- service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
+ web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
counter.Restart(); |
WaitForCounting(); |
EXPECT_EQ(2u, GetLocalResult()); |
EXPECT_TRUE(HasSyncedVisits()); |
// Nonzero local count, empty sync. |
- service->ClearSyncedVisits(); |
- service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
+ web_history_service->ClearSyncedVisits(); |
+ web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
counter.Restart(); |
WaitForCounting(); |
EXPECT_EQ(2u, GetLocalResult()); |
@@ -332,12 +369,21 @@ IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DISABLED_RestartOnSyncChange) { |
Profile* profile = GetProfile(kFirstProfileIndex); |
// Set up the fake web history service and the counter. |
+ |
std::unique_ptr<history::FakeWebHistoryService> web_history_service( |
new history::FakeWebHistoryService( |
- ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()), |
- SigninManagerFactory::GetForProfile(browser()->profile()), |
- browser()->profile()->GetRequestContext())); |
- HistoryCounter counter(profile); |
+ ProfileOAuth2TokenServiceFactory::GetForProfile( |
+ browser()->profile()), |
+ SigninManagerFactory::GetForProfile(browser()->profile()), |
+ browser()->profile()->GetRequestContext())); |
+ |
+ browsing_data::HistoryCounter counter( |
+ GetHistoryService(), |
+ base::Bind(&HistoryCounterTest::GetWebHistoryService, |
+ base::Unretained(this), |
+ base::Unretained(profile)), |
+ sync_service); |
+ |
counter.SetWebHistoryServiceForTesting(web_history_service.get()); |
counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
base::Unretained(this))); |