| Index: chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
|
| diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
|
| index a6868662fe8ee8323db97b415c96b45d82617135..b94dbc9c66bb32eabdfbffde89b4f41c9ec00850 100644
|
| --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
|
| +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
|
| @@ -2,6 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include <string>
|
| +#include <utility>
|
| #include <vector>
|
|
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -24,6 +26,7 @@
|
| #include "chrome/browser/history/history_types.h"
|
| #include "chrome/browser/invalidation/fake_invalidation_service.h"
|
| #include "chrome/browser/invalidation/invalidation_service_factory.h"
|
| +#include "chrome/browser/prefs/pref_service_syncable.h"
|
| #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
|
| #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
|
| #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
|
| @@ -39,7 +42,9 @@
|
| #include "chrome/browser/sync/profile_sync_service_factory.h"
|
| #include "chrome/browser/sync/profile_sync_test_util.h"
|
| #include "chrome/browser/sync/test_profile_sync_service.h"
|
| +#include "chrome/test/base/testing_browser_process.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| +#include "chrome/test/base/testing_profile_manager.h"
|
| #include "components/keyed_service/content/refcounted_browser_context_keyed_service.h"
|
| #include "components/signin/core/browser/signin_manager.h"
|
| #include "components/sync_driver/data_type_error_handler_mock.h"
|
| @@ -68,6 +73,9 @@ using testing::SetArgumentPointee;
|
| using testing::_;
|
|
|
| namespace {
|
| +
|
| +const char kTestProfileName[] = "test-profile";
|
| +
|
| // Visits with this timestamp are treated as expired.
|
| static const int EXPIRED_VISIT = -1;
|
|
|
| @@ -180,22 +188,31 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
|
| }
|
|
|
| protected:
|
| - ProfileSyncServiceTypedUrlTest() {
|
| + ProfileSyncServiceTypedUrlTest()
|
| + : profile_manager_(TestingBrowserProcess::GetGlobal()) {
|
| history_thread_.reset(new Thread("history"));
|
| }
|
|
|
| virtual void SetUp() {
|
| AbstractProfileSyncServiceTest::SetUp();
|
| - TestingProfile::Builder builder;
|
| - builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
|
| - BuildAutoIssuingFakeProfileOAuth2TokenService);
|
| - profile_ = builder.Build().Pass();
|
| + ASSERT_TRUE(profile_manager_.SetUp());
|
| + TestingProfile::TestingFactories testing_factories;
|
| + testing_factories.push_back(std::make_pair(
|
| + ProfileOAuth2TokenServiceFactory::GetInstance(),
|
| + BuildAutoIssuingFakeProfileOAuth2TokenService));
|
| + profile_ = profile_manager_.CreateTestingProfile(
|
| + kTestProfileName,
|
| + scoped_ptr<PrefServiceSyncable>(),
|
| + base::UTF8ToUTF16(kTestProfileName),
|
| + 0,
|
| + std::string(),
|
| + testing_factories);
|
| invalidation::InvalidationServiceFactory::GetInstance()->SetTestingFactory(
|
| - profile_.get(), invalidation::FakeInvalidationService::Build);
|
| + profile_, invalidation::FakeInvalidationService::Build);
|
| history_backend_ = new HistoryBackendMock();
|
| history_service_ = static_cast<HistoryServiceMock*>(
|
| HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
|
| - profile_.get(), BuildHistoryService));
|
| + profile_, BuildHistoryService));
|
| EXPECT_CALL((*history_service_), ScheduleDBTask(_, _))
|
| .WillRepeatedly(RunTaskOnDBThread(history_thread_.get(),
|
| history_backend_.get()));
|
| @@ -206,27 +223,25 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
|
| EXPECT_CALL((*history_service_), Shutdown())
|
| .WillOnce(ShutdownHistoryService(history_thread_.release(),
|
| history_service_));
|
| - profile_.reset();
|
| + profile_ = NULL;
|
| + profile_manager_.DeleteTestingProfile(kTestProfileName);
|
| AbstractProfileSyncServiceTest::TearDown();
|
| }
|
|
|
| TypedUrlModelAssociator* StartSyncService(const base::Closure& callback) {
|
| TypedUrlModelAssociator* model_associator = NULL;
|
| if (!sync_service_) {
|
| - SigninManagerBase* signin =
|
| - SigninManagerFactory::GetForProfile(profile_.get());
|
| + SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_);
|
| signin->SetAuthenticatedUsername("test");
|
| - sync_service_ = TestProfileSyncService::BuildAutoStartAsyncInit(
|
| - profile_.get(), callback);
|
| + sync_service_ = TestProfileSyncService::BuildAutoStartAsyncInit(profile_,
|
| + callback);
|
| ProfileSyncComponentsFactoryMock* components =
|
| sync_service_->components_factory_mock();
|
| TypedUrlDataTypeController* data_type_controller =
|
| - new TypedUrlDataTypeController(components,
|
| - profile_.get(),
|
| - sync_service_);
|
| + new TypedUrlDataTypeController(components, profile_, sync_service_);
|
|
|
| EXPECT_CALL(*components, CreateTypedUrlSyncComponents(_, _, _)).
|
| - WillOnce(MakeTypedUrlSyncComponents(profile_.get(),
|
| + WillOnce(MakeTypedUrlSyncComponents(profile_,
|
| sync_service_,
|
| history_backend_.get(),
|
| data_type_controller,
|
| @@ -236,7 +251,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
|
| WillOnce(ReturnNewDataTypeManager());
|
|
|
| ProfileOAuth2TokenService* oauth2_token_service =
|
| - ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get());
|
| + ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
|
| oauth2_token_service->UpdateCredentials("test", "oauth2_login_token");
|
|
|
| sync_service_->RegisterDataTypeController(data_type_controller);
|
| @@ -317,8 +332,8 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
|
| }
|
|
|
| scoped_ptr<Thread> history_thread_;
|
| -
|
| - scoped_ptr<TestingProfile> profile_;
|
| + TestingProfileManager profile_manager_;
|
| + TestingProfile* profile_;
|
| scoped_refptr<HistoryBackendMock> history_backend_;
|
| HistoryServiceMock* history_service_;
|
| browser_sync::DataTypeErrorHandlerMock error_handler_;
|
| @@ -569,7 +584,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAdd) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLsModifiedDetails>(&details));
|
|
|
| history::URLRows new_sync_entries;
|
| @@ -600,7 +615,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddWithBlank) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLsModifiedDetails>(&details));
|
|
|
| std::vector<history::URLRow> new_sync_entries;
|
| @@ -638,7 +653,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdate) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLsModifiedDetails>(&details));
|
|
|
| history::URLRows new_sync_entries;
|
| @@ -667,7 +682,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeAddFromVisit) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLVisitedDetails>(&details));
|
|
|
| history::URLRows new_sync_entries;
|
| @@ -706,7 +721,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeUpdateFromVisit) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLVisitedDetails>(&details));
|
|
|
| history::URLRows new_sync_entries;
|
| @@ -747,7 +762,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLVisitedDetails>(&details));
|
|
|
| GetTypedUrlsFromSyncDB(&new_sync_entries);
|
| @@ -764,7 +779,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) {
|
| details.row = twelve_visits;
|
| details.transition = content::PAGE_TRANSITION_TYPED;
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLVisitedDetails>(&details));
|
| GetTypedUrlsFromSyncDB(&new_sync_entries);
|
| // Should be no changes to the sync DB from this notification.
|
| @@ -779,7 +794,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserIgnoreChangeUpdateFromVisit) {
|
| details.row = twenty_visits;
|
| details.transition = content::PAGE_TRANSITION_TYPED;
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URL_VISITED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLVisitedDetails>(&details));
|
| GetTypedUrlsFromSyncDB(&new_sync_entries);
|
| ASSERT_EQ(1U, new_sync_entries.size());
|
| @@ -814,7 +829,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemove) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLsDeletedDetails>(&changes));
|
|
|
| history::URLRows new_sync_entries;
|
| @@ -853,7 +868,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemoveArchive) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLsDeletedDetails>(&changes));
|
|
|
| history::URLRows new_sync_entries;
|
| @@ -893,7 +908,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, ProcessUserChangeRemoveAll) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLsDeletedDetails>(&changes));
|
|
|
| GetTypedUrlsFromSyncDB(&new_sync_entries);
|
| @@ -1012,7 +1027,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreLocalFileURL) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLsModifiedDetails>(&details));
|
|
|
| history::URLRows new_sync_entries;
|
| @@ -1066,7 +1081,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreLocalhostURL) {
|
| scoped_refptr<ThreadNotifier> notifier(
|
| new ThreadNotifier(history_thread_.get()));
|
| notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
|
| - content::Source<Profile>(profile_.get()),
|
| + content::Source<Profile>(profile_),
|
| content::Details<history::URLsModifiedDetails>(&details));
|
|
|
| history::URLRows new_sync_entries;
|
|
|