Commit 6f03093b authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

Revert "[Sync] Support FCM Invalidations in Sync browser tests"

This reverts commit 5f47f6e7.

Reason for revert: Reverting some CLs that are suspect for causing
flakiness in the tests

Original change's description:
> [Sync] Support FCM Invalidations in Sync browser tests
> 
> Change-Id: I43de31210a0e52a39f2b0017e08994ccf1207714
> Bug: 985287
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1745997
> Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
> Reviewed-by: Marc Treib <treib@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#689571}

TBR=treib@chromium.org,mamir@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 985287
Change-Id: Idacca73b390e5fe88fa5a658991c5e3f9c611cab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1774924Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691572}
parent dd6b3c84
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sync/test/integration/fake_server_invalidation_sender.h"
#include "chrome/browser/profiles/profile.h"
#include "components/invalidation/impl/fcm_network_handler.h"
namespace fake_server {
namespace {
const char kInvalidationsFCMAppId[] = "com.google.chrome.fcm.invalidations";
} // namespace
FakeServerInvalidationSender::FakeServerInvalidationSender(
const std::string& client_id,
bool self_notify,
base::RepeatingCallback<syncer::FCMNetworkHandler*()>
fcm_network_handler_getter)
: client_id_(client_id),
self_notify_(self_notify),
fcm_network_handler_getter_(fcm_network_handler_getter) {}
FakeServerInvalidationSender::~FakeServerInvalidationSender() {}
void FakeServerInvalidationSender::OnCommit(
const std::string& committer_id,
syncer::ModelTypeSet committed_model_types) {
if (!self_notify_ && client_id_ == committer_id) {
return;
}
syncer::FCMNetworkHandler* fcm_network_handler =
fcm_network_handler_getter_.Run();
// If there is no FCM network handler registered for this profile, there is
// nothing to do. This could be the case during test Setup phase because the
// FCM network handlers get assigned in SetupInvalidations() which happens
// after SetupSync().
if (fcm_network_handler == nullptr) {
return;
}
// For each of the committed model types, pass a message to the FCM Network
// Handler to simulate a message from the GCMDriver.
for (syncer::ModelType type : committed_model_types) {
std::string notification_type;
bool result = RealModelTypeToNotificationType(type, &notification_type);
// We shouldn't ever get commits for non-protocol types.
DCHECK(result);
gcm::IncomingMessage message;
// Client doesn't parse the payload.
message.data["payload"] = "any_payload";
// version doesn't matter, it's not used in the client.
message.data["version"] = "1234567890";
// The public topic name should be stored in the external name field.
message.data["external_name"] = notification_type;
// The private topic name is stored in the sender_id field.
message.sender_id =
"/topics/private/" + notification_type + "-topic_server_user_id";
fcm_network_handler->OnMessage(kInvalidationsFCMAppId, message);
}
}
} // namespace fake_server
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_FAKE_SERVER_INVALIDATION_SENDER_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_FAKE_SERVER_INVALIDATION_SENDER_H_
#include "base/macros.h"
#include "components/sync/base/model_type.h"
#include "components/sync/test/fake_server/fake_server.h"
namespace syncer {
class FCMNetworkHandler;
}
namespace fake_server {
// This class is observing changes to the fake server, and sends invalidations
// to different clients upon commits. Sent invalidation follows the same format
// expected by the FCM invalidations framework.
class FakeServerInvalidationSender : public FakeServer::Observer {
public:
FakeServerInvalidationSender(
const std::string& client_id,
bool self_notify,
base::RepeatingCallback<syncer::FCMNetworkHandler*()>
fcm_network_handler_getter);
~FakeServerInvalidationSender() override;
// FakeServer::Observer implementation.
void OnCommit(const std::string& committer_id,
syncer::ModelTypeSet committed_model_types) override;
private:
const std::string client_id_;
const bool self_notify_;
const base::RepeatingCallback<syncer::FCMNetworkHandler*()>
fcm_network_handler_getter_;
DISALLOW_COPY_AND_ASSIGN(FakeServerInvalidationSender);
};
} // namespace fake_server
#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_FAKE_SERVER_INVALIDATION_SENDER_H_
......@@ -19,7 +19,6 @@
#include "build/build_config.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/invalidation/profile_invalidation_provider_factory.h"
#include "chrome/browser/net/system_network_context_manager.h"
......@@ -29,6 +28,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/test/integration/fake_server_invalidation_service.h"
#include "chrome/browser/sync/test/integration/p2p_sync_refresher.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
......@@ -46,23 +46,14 @@
#include "chrome/test/base/search_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/gcm_driver/gcm_profile_service.h"
#include "components/invalidation/impl/fake_invalidation_service.h"
#include "components/invalidation/impl/fcm_invalidation_service.h"
#include "components/invalidation/impl/fcm_network_handler.h"
#include "components/invalidation/impl/invalidation_prefs.h"
#include "components/invalidation/impl/invalidation_switches.h"
#include "components/invalidation/impl/per_user_topic_registration_manager.h"
#include "components/invalidation/impl/profile_identity_provider.h"
#include "components/invalidation/impl/profile_invalidation_provider.h"
#include "components/invalidation/public/invalidation_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/os_crypt/os_crypt_mocker.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/search_engines/template_url_service.h"
#include "components/sync/base/invalidation_helper.h"
#include "components/sync/base/sync_base_switches.h"
#include "components/sync/driver/profile_sync_service.h"
#include "components/sync/driver/sync_driver_switches.h"
#include "components/sync/driver/sync_user_settings.h"
......@@ -78,7 +69,6 @@
#include "net/base/port_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/data_decoder/public/cpp/safe_json_parser.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "url/gurl.h"
......@@ -106,8 +96,6 @@ const char kSyncPasswordForTest[] = "sync-password-for-test";
} // namespace switches
namespace {
// Sender ID coming from the Firebase console.
const char kInvalidationGCMSenderId[] = "8181035976";
void SetURLLoaderFactoryForTest(
Profile* profile,
......@@ -124,58 +112,6 @@ void SetURLLoaderFactoryForTest(
account_manager->SetUrlLoaderFactoryForTests(url_loader_factory);
#endif // defined(OS_CHROMEOS)
}
class FakePerUserTopicRegistrationManager
: public syncer::PerUserTopicRegistrationManager {
public:
explicit FakePerUserTopicRegistrationManager(PrefService* local_state)
: syncer::PerUserTopicRegistrationManager(
/*identity_provider=*/nullptr,
/*pref_service=*/local_state,
/*url_loader_factory=*/nullptr,
base::BindRepeating(&data_decoder::SafeJsonParser::Parse, nullptr),
/*project_id*/ kInvalidationGCMSenderId,
/*migrate_prefs=*/false) {}
~FakePerUserTopicRegistrationManager() override = default;
void UpdateRegisteredTopics(const syncer::Topics& topics,
const std::string& instance_id_token) override {}
private:
DISALLOW_COPY_AND_ASSIGN(FakePerUserTopicRegistrationManager);
};
std::unique_ptr<syncer::FCMNetworkHandler> CreateFCMNetworkHandler(
Profile* profile,
std::map<const Profile*, syncer::FCMNetworkHandler*>*
profile_to_fcm_network_handler_map,
gcm::GCMDriver* gcm_driver,
instance_id::InstanceIDDriver* instance_id_driver,
const std::string& sender_id,
const std::string& app_id) {
auto handler = std::make_unique<syncer::FCMNetworkHandler>(
gcm_driver, instance_id_driver, sender_id, app_id);
(*profile_to_fcm_network_handler_map)[profile] = handler.get();
return handler;
}
std::unique_ptr<syncer::PerUserTopicRegistrationManager>
CreatePerUserTopicRegistrationManager(
invalidation::IdentityProvider* identity_provider,
PrefService* local_state,
network::mojom::URLLoaderFactory* url_loader_factory,
const syncer::ParseJSONCallback& parse_json,
const std::string& project_id,
bool migrate_prefs) {
return std::make_unique<FakePerUserTopicRegistrationManager>(local_state);
}
syncer::FCMNetworkHandler* GetFCMNetworkHandler(
const Profile* profile,
std::map<const Profile*, syncer::FCMNetworkHandler*>*
profile_to_fcm_network_handler_map) {
auto it = profile_to_fcm_network_handler_map->find(profile);
return it != profile_to_fcm_network_handler_map->end() ? it->second : nullptr;
}
// Helper class to ensure a profile is registered before the manager is
// notified of creation.
......@@ -224,17 +160,23 @@ class EncryptionChecker : public SingleClientStatusChangeChecker {
std::string GetDebugMessage() const override { return "Encryption"; }
};
} // namespace
instance_id::InstanceID* SyncTest::FakeInstanceIDDriver::GetInstanceID(
const std::string& app_id) {
return &fake_instance_id_;
std::unique_ptr<invalidation::InvalidationService> CreateInvalidationService(
const std::string& sender_id) {
return std::make_unique<fake_server::FakeServerInvalidationService>();
}
bool SyncTest::FakeInstanceIDDriver::ExistsInstanceID(
const std::string& app_id) const {
return true;
std::unique_ptr<KeyedService> BuildFakeServerProfileInvalidationProvider(
content::BrowserContext* context) {
Profile* profile = static_cast<Profile*>(context);
return std::make_unique<invalidation::ProfileInvalidationProvider>(
std::make_unique<fake_server::FakeServerInvalidationService>(),
std::make_unique<invalidation::ProfileIdentityProvider>(
IdentityManagerFactory::GetForProfile(profile)),
base::BindRepeating(&CreateInvalidationService));
}
} // namespace
SyncTest::SyncTest(TestType test_type)
: test_type_(test_type),
server_type_(SERVER_TYPE_UNDECIDED),
......@@ -568,7 +510,7 @@ bool SyncTest::SetupClients() {
profile_delegates_.resize(num_clients_ + 1); // + 1 for the verifier.
clients_.resize(num_clients_);
sync_refreshers_.resize(num_clients_);
fake_server_invalidation_observers_.resize(num_clients_);
fake_server_invalidation_services_.resize(num_clients_);
if (create_gaia_account_at_runtime_) {
if (!UsingExternalServers()) {
......@@ -670,8 +612,7 @@ void SyncTest::InitializeProfile(int index, Profile* profile) {
}
void SyncTest::DisableNotificationsForClient(int index) {
fake_server_->RemoveObserver(
fake_server_invalidation_observers_[index].get());
fake_server_->RemoveObserver(fake_server_invalidation_services_[index]);
}
void SyncTest::SetEncryptionPassphraseForClient(int index,
......@@ -702,41 +643,26 @@ void SyncTest::SetUpInvalidations(int index) {
break;
case IN_PROCESS_FAKE_SERVER: {
const std::string client_id = "Client " + base::NumberToString(index);
// Listen for fake server changes.
fake_server_invalidation_observers_[index] =
std::make_unique<fake_server::FakeServerInvalidationSender>(
client_id, TestUsesSelfNotifications(),
base::BindRepeating(&GetFCMNetworkHandler, GetProfile(index),
&profile_to_fcm_network_handler_map_));
fake_server_->AddObserver(
fake_server_invalidation_observers_[index].get());
// Store in prefs the mapping between public and private topics names. In
// real clients, those are stored upon registration with the
// per-user-topic server. The pref name is defined in
// per_user_topic_registration_manager.cc.
DictionaryPrefUpdate update(
GetProfile(index)->GetPrefs(),
"invalidation.per_sender_registered_for_invalidation");
update->SetDictionary(kInvalidationGCMSenderId,
std::make_unique<base::DictionaryValue>());
for (syncer::ModelType model_type :
GetSyncService(index)->GetPreferredDataTypes()) {
std::string notification_type;
if (!RealModelTypeToNotificationType(model_type, &notification_type)) {
continue;
}
update->FindDictKey(kInvalidationGCMSenderId)
->SetKey(notification_type,
base::Value("/private/" + notification_type +
"-topic_server_user_id"));
}
DictionaryPrefUpdate update_client_id(
GetProfile(index)->GetPrefs(),
invalidation::prefs::kInvalidationClientIDCache);
update_client_id->SetString(kInvalidationGCMSenderId, client_id);
KeyedService* test_factory =
invalidation::ProfileInvalidationProviderFactory::GetInstance()
->SetTestingFactoryAndUse(
GetProfile(index),
base::BindRepeating(
&BuildFakeServerProfileInvalidationProvider));
invalidation::InvalidationService* invalidation_service =
static_cast<invalidation::ProfileInvalidationProvider*>(test_factory)
->GetInvalidationService();
auto* fake_invalidation_service =
static_cast<fake_server::FakeServerInvalidationService*>(
invalidation_service);
fake_server_->AddObserver(fake_invalidation_service);
if (TestUsesSelfNotifications())
fake_invalidation_service->EnableSelfNotifications();
else
fake_invalidation_service->DisableSelfNotifications();
fake_server_invalidation_services_[index] = fake_invalidation_service;
break;
}
case SERVER_TYPE_UNDECIDED:
......@@ -915,9 +841,10 @@ void SyncTest::TearDownOnMainThread() {
init_browser_count - browsers_.size());
if (fake_server_.get()) {
for (const std::unique_ptr<fake_server::FakeServerInvalidationSender>&
observer : fake_server_invalidation_observers_) {
fake_server_->RemoveObserver(observer.get());
std::vector<fake_server::FakeServerInvalidationService*>::const_iterator it;
for (it = fake_server_invalidation_services_.begin();
it != fake_server_invalidation_services_.end(); ++it) {
fake_server_->RemoveObserver(*it);
}
}
......@@ -926,67 +853,6 @@ void SyncTest::TearDownOnMainThread() {
configuration_refresher_.reset();
}
void SyncTest::SetUpInProcessBrowserTestFixture() {
will_create_browser_context_services_subscription_ =
BrowserContextDependencyManager::GetInstance()
->RegisterWillCreateBrowserContextServicesCallbackForTesting(
base::BindRepeating(&SyncTest::OnWillCreateBrowserContextServices,
base::Unretained(this)));
}
void SyncTest::OnWillCreateBrowserContextServices(
content::BrowserContext* context) {
invalidation::ProfileInvalidationProviderFactory::GetInstance()
->SetTestingFactory(
context,
base::BindRepeating(&SyncTest::CreateProfileInvalidationProvider,
&profile_to_fcm_network_handler_map_,
&fake_instance_id_driver_));
}
// static
std::unique_ptr<KeyedService> SyncTest::CreateProfileInvalidationProvider(
std::map<const Profile*, syncer::FCMNetworkHandler*>*
profile_to_fcm_network_handler_map,
instance_id::InstanceIDDriver* instance_id_driver,
content::BrowserContext* context) {
Profile* profile = Profile::FromBrowserContext(context);
gcm::GCMProfileService* gcm_profile_service =
gcm::GCMProfileServiceFactory::GetForProfile(profile);
auto profile_identity_provider =
std::make_unique<invalidation::ProfileIdentityProvider>(
IdentityManagerFactory::GetForProfile(profile));
auto fcm_invalidation_service =
std::make_unique<invalidation::FCMInvalidationService>(
profile_identity_provider.get(),
base::BindRepeating(&CreateFCMNetworkHandler, profile,
profile_to_fcm_network_handler_map,
gcm_profile_service->driver(),
instance_id_driver),
base::BindRepeating(
&CreatePerUserTopicRegistrationManager,
profile_identity_provider.get(), profile->GetPrefs(),
base::RetainedRef(
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetURLLoaderFactoryForBrowserProcess()
.get()),
base::BindRepeating(&data_decoder::SafeJsonParser::Parse,
nullptr)),
instance_id_driver, profile->GetPrefs(), kInvalidationGCMSenderId);
fcm_invalidation_service->Init();
return std::make_unique<invalidation::ProfileInvalidationProvider>(
std::move(fcm_invalidation_service), std::move(profile_identity_provider),
/*custom_sender_invalidation_service_factory=*/
base::BindRepeating(
[](const std::string&)
-> std::unique_ptr<invalidation::InvalidationService> {
return std::make_unique<invalidation::FakeInvalidationService>();
}));
}
void SyncTest::SetUpOnMainThread() {
// Start up a sync test server if one is needed and setup mock gaia responses.
// Note: This must be done prior to the call to SetupClients() because we want
......
......@@ -16,11 +16,8 @@
#include "chrome/browser/extensions/install_verifier.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/test/integration/configuration_refresher.h"
#include "chrome/browser/sync/test/integration/fake_server_invalidation_sender.h"
#include "chrome/common/buildflags.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/gcm_driver/instance_id/instance_id.h"
#include "components/gcm_driver/instance_id/instance_id_driver.h"
#include "components/sync/base/model_type.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/test/fake_server/fake_server.h"
......@@ -62,6 +59,7 @@ class ScopedTempDir;
namespace fake_server {
class FakeServer;
class FakeServerInvalidationService;
} // namespace fake_server
namespace syncer {
......@@ -94,55 +92,6 @@ class SyncTest : public InProcessBrowserTest {
// in-process (bypassing HTTP calls).
};
class FakeInstanceID : public instance_id::InstanceID {
public:
FakeInstanceID()
: instance_id::InstanceID("FakeAppId", /*gcm_driver = */ nullptr) {}
~FakeInstanceID() override = default;
void GetID(const GetIDCallback& callback) override {}
void GetCreationTime(const GetCreationTimeCallback& callback) override {}
void GetToken(const std::string& authorized_entity,
const std::string& scope,
const std::map<std::string, std::string>& options,
std::set<Flags> flags,
GetTokenCallback callback) override {}
void ValidateToken(const std::string& authorized_entity,
const std::string& scope,
const std::string& token,
const ValidateTokenCallback& callback) override {}
void DeleteToken(const std::string& authorized_entity,
const std::string& scope,
DeleteTokenCallback callback) override {}
protected:
void DeleteTokenImpl(const std::string& authorized_entity,
const std::string& scope,
DeleteTokenCallback callback) override {}
void DeleteIDImpl(DeleteIDCallback callback) override {}
private:
DISALLOW_COPY_AND_ASSIGN(FakeInstanceID);
};
class FakeInstanceIDDriver : public instance_id::InstanceIDDriver {
public:
FakeInstanceIDDriver()
: instance_id::InstanceIDDriver(/*gcm_driver=*/nullptr) {}
~FakeInstanceIDDriver() override = default;
instance_id::InstanceID* GetInstanceID(const std::string& app_id) override;
void RemoveInstanceID(const std::string& app_id) override {}
bool ExistsInstanceID(const std::string& app_id) const override;
private:
FakeInstanceID fake_instance_id_;
DISALLOW_COPY_AND_ASSIGN(FakeInstanceIDDriver);
};
// A SyncTest must be associated with a particular test type.
explicit SyncTest(TestType test_type);
......@@ -279,9 +228,6 @@ class SyncTest : public InProcessBrowserTest {
// BrowserTestBase implementation:
void SetUpOnMainThread() override;
void TearDownOnMainThread() override;
void SetUpInProcessBrowserTestFixture() override;
void OnWillCreateBrowserContextServices(content::BrowserContext* context);
virtual void BeforeSetupClient(int index);
......@@ -348,12 +294,6 @@ class SyncTest : public InProcessBrowserTest {
Profile* profile,
Profile::CreateStatus status);
static std::unique_ptr<KeyedService> CreateProfileInvalidationProvider(
std::map<const Profile*, syncer::FCMNetworkHandler*>*
profile_to_fcm_network_handler_map,
instance_id::InstanceIDDriver* instance_id_driver,
content::BrowserContext* context);
// Helper to Profile::CreateProfile that handles path creation, setting up
// preexisting pref files, and registering the created profile as a testing
// profile.
......@@ -469,25 +409,14 @@ class SyncTest : public InProcessBrowserTest {
// notifications of this activity to its peer sync clients.
std::vector<std::unique_ptr<P2PSyncRefresher>> sync_refreshers_;
// Owns the FakeServerInvalidationSender for each profile.
std::vector<std::unique_ptr<fake_server::FakeServerInvalidationSender>>
fake_server_invalidation_observers_;
// Maps a profile to the corresponding FCMNetworkHandler. Contains one entry
// per profile. It is used to simulate an incoming FCM messages to different
// profiles within the FakeServerInvalidationSender.
std::map<const Profile*, syncer::FCMNetworkHandler*>
profile_to_fcm_network_handler_map_;
FakeInstanceIDDriver fake_instance_id_driver_;
// Collection of pointers to FakeServerInvalidation objects for each
// profile.
std::vector<fake_server::FakeServerInvalidationService*>
fake_server_invalidation_services_;
// Triggers a GetUpdates via refresh after a configuration.
std::unique_ptr<ConfigurationRefresher> configuration_refresher_;
std::unique_ptr<
base::CallbackList<void(content::BrowserContext*)>::Subscription>
will_create_browser_context_services_subscription_;
// Sync profile against which changes to individual profiles are verified.
// We don't need a corresponding verifier sync client because the contents
// of the verifier profile are strictly local, and are not meant to be
......
......@@ -5814,8 +5814,6 @@ if (!is_android && !is_fuchsia) {
"../browser/sync/test/integration/extension_settings_helper.h",
"../browser/sync/test/integration/extensions_helper.cc",
"../browser/sync/test/integration/extensions_helper.h",
"../browser/sync/test/integration/fake_server_invalidation_sender.cc",
"../browser/sync/test/integration/fake_server_invalidation_sender.h",
"../browser/sync/test/integration/fake_server_invalidation_service.cc",
"../browser/sync/test/integration/fake_server_invalidation_service.h",
"../browser/sync/test/integration/fake_server_match_status_checker.cc",
......
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