Commit ad8ec178 authored by Paula Vidas's avatar Paula Vidas Committed by Commit Bot

[SyncInvalidations] Add testing SyncInvalidationsService factory.

The FakeInstanceIDDriver needs to be used in sync invalidations tests.

Bug: 1135167
Change-Id: Ifa5c38ea18317d7b99635fee6ee12e129bf4dda8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2455646Reviewed-by: default avatarRushan Suleymanov <rushans@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Paula Vidas <paulavidas@google.com>
Cr-Commit-Position: refs/heads/master@{#815072}
parent 12605744
......@@ -29,6 +29,7 @@
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/sync_invalidations_service_factory.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
......@@ -60,6 +61,8 @@
#include "components/sync/driver/sync_user_settings.h"
#include "components/sync/engine/sync_engine_switches.h"
#include "components/sync/engine_impl/sync_scheduler_impl.h"
#include "components/sync/invalidations/switches.h"
#include "components/sync/invalidations/sync_invalidations_service_impl.h"
#include "components/sync/protocol/sync.pb.h"
#include "components/sync/test/fake_server/fake_server_network_resources.h"
#include "content/public/browser/navigation_entry.h"
......@@ -937,7 +940,7 @@ void SyncTest::OnWillCreateBrowserContextServices(
if (UsingExternalServers()) {
// DO NOTHING. External live sync servers use GCM to notify profiles of
// any invalidations in sync'ed data. No need to provide a testing
// factory the ProfileInvalidationProvider.
// factory for ProfileInvalidationProvider and SyncInvalidationsService.
return;
}
invalidation::ProfileInvalidationProviderFactory::GetInstance()
......@@ -946,6 +949,9 @@ void SyncTest::OnWillCreateBrowserContextServices(
base::BindRepeating(&SyncTest::CreateProfileInvalidationProvider,
&profile_to_fcm_network_handler_map_,
&fake_instance_id_driver_));
SyncInvalidationsServiceFactory::GetInstance()->SetTestingFactory(
context, base::BindRepeating(&SyncTest::CreateSyncInvalidationsService,
&fake_instance_id_driver_));
}
// static
......@@ -989,6 +995,22 @@ std::unique_ptr<KeyedService> SyncTest::CreateProfileInvalidationProvider(
}));
}
// static
std::unique_ptr<KeyedService> SyncTest::CreateSyncInvalidationsService(
instance_id::InstanceIDDriver* instance_id_driver,
content::BrowserContext* context) {
if (!base::FeatureList::IsEnabled(switches::kSyncSendInterestedDataTypes)) {
return nullptr;
}
Profile* profile = Profile::FromBrowserContext(context);
gcm::GCMDriver* gcm_driver =
gcm::GCMProfileServiceFactory::GetForProfile(profile)->driver();
return std::make_unique<syncer::SyncInvalidationsServiceImpl>(
gcm_driver, instance_id_driver);
}
void SyncTest::ResetSyncForPrimaryAccount() {
if (UsingExternalServers()) {
base::ScopedAllowBlockingForTesting allow_blocking;
......
......@@ -360,6 +360,10 @@ class SyncTest : public PlatformBrowserTest {
instance_id::InstanceIDDriver* instance_id_driver,
content::BrowserContext* context);
static std::unique_ptr<KeyedService> CreateSyncInvalidationsService(
instance_id::InstanceIDDriver* instance_id_driver,
content::BrowserContext* context);
// Helper to Profile::CreateProfile that handles path creation. It creates
// a profile then registers it as a testing profile.
Profile* MakeTestProfile(base::FilePath profile_path, int index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment