Commit 6295d700 authored by Paula Vidas's avatar Paula Vidas Committed by Commit Bot

[SyncInvalidations] Add integration tests for sync invalidations.

This CL adds tests that check if interested data types and FCM token are
included in device info when relevant feature flags are enabled.

For now, FakeInstanceID::GetToken() always returns the same token, but
that will be changed when FakeServerSyncInvalidationsSender is added.

Bug: 1135167
Change-Id: Ide98c9371ad788be804342899b6a561ef2b30e41
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450150
Commit-Queue: Paula Vidas <paulavidas@google.com>
Reviewed-by: default avatarRushan Suleymanov <rushans@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815523}
parent eedc26c6
// Copyright 2020 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 "base/test/scoped_feature_list.h"
#include "chrome/browser/sync/sync_invalidations_service_factory.h"
#include "chrome/browser/sync/test/integration/device_info_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "components/sync/base/model_type.h"
#include "components/sync/invalidations/switches.h"
#include "components/sync/invalidations/sync_invalidations_service.h"
#include "components/sync/protocol/sync.pb.h"
#include "content/public/test/browser_test.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
using testing::AllOf;
using testing::ElementsAre;
using testing::Not;
using testing::NotNull;
MATCHER_P(HasInterestedDataTypes, expected_data_types, "") {
syncer::ModelTypeSet data_types;
for (const int field_number : arg.specifics()
.device_info()
.invalidation_fields()
.interested_data_type_ids()) {
syncer::ModelType data_type =
syncer::GetModelTypeFromSpecificsFieldNumber(field_number);
if (!syncer::IsRealDataType(data_type)) {
return false;
}
data_types.Put(data_type);
}
return data_types == expected_data_types;
}
MATCHER(HasInstanceIdToken, "") {
return arg.specifics()
.device_info()
.invalidation_fields()
.has_instance_id_token();
}
MATCHER_P(HasInstanceIdToken, expected_token, "") {
return arg.specifics()
.device_info()
.invalidation_fields()
.instance_id_token() == expected_token;
}
class SingleClientWithSyncSendInterestedDataTypesTest : public SyncTest {
public:
SingleClientWithSyncSendInterestedDataTypesTest() : SyncTest(SINGLE_CLIENT) {
override_features_.InitWithFeatures(
/*enabled_features=*/{switches::kSyncSendInterestedDataTypes},
/*disabled_features=*/{
switches::kUseSyncInvalidations,
switches::kUseSyncInvalidationsForWalletAndOffer});
}
~SingleClientWithSyncSendInterestedDataTypesTest() override = default;
private:
base::test::ScopedFeatureList override_features_;
DISALLOW_COPY_AND_ASSIGN(SingleClientWithSyncSendInterestedDataTypesTest);
};
IN_PROC_BROWSER_TEST_F(SingleClientWithSyncSendInterestedDataTypesTest,
SendInterestedDataTypesAsPartOfDeviceInfo) {
ASSERT_TRUE(SetupSync());
syncer::SyncInvalidationsService* sync_invalidations_service =
SyncInvalidationsServiceFactory::GetForProfile(GetProfile(0));
ASSERT_THAT(sync_invalidations_service, NotNull());
syncer::ModelTypeSet interested_data_types =
sync_invalidations_service->GetInterestedDataTypes();
// Check that some "standard" data types are included.
EXPECT_TRUE(
interested_data_types.HasAll({syncer::NIGORI, syncer::BOOKMARKS}));
// Wallet and Offer data types are excluded unless
// kUseSyncInvalidationsForWalletAndOffer is also enabled.
EXPECT_FALSE(interested_data_types.Has(syncer::AUTOFILL_WALLET_DATA));
EXPECT_FALSE(interested_data_types.Has(syncer::AUTOFILL_WALLET_OFFER));
// The local device should eventually be committed to the server.
// The InstanceID token should only be uploaded if kUseSyncInvalidations is
// also enabled.
EXPECT_TRUE(
ServerDeviceInfoMatchChecker(
GetFakeServer(),
ElementsAre(AllOf(HasInterestedDataTypes(interested_data_types),
Not(HasInstanceIdToken()))))
.Wait());
}
class SingleClientWithUseSyncInvalidationsTest : public SyncTest {
public:
SingleClientWithUseSyncInvalidationsTest() : SyncTest(SINGLE_CLIENT) {
override_features_.InitWithFeatures(
/*enabled_features=*/{switches::kSyncSendInterestedDataTypes,
switches::kUseSyncInvalidations},
/*disabled_features=*/{
switches::kUseSyncInvalidationsForWalletAndOffer});
}
~SingleClientWithUseSyncInvalidationsTest() override = default;
private:
base::test::ScopedFeatureList override_features_;
DISALLOW_COPY_AND_ASSIGN(SingleClientWithUseSyncInvalidationsTest);
};
IN_PROC_BROWSER_TEST_F(SingleClientWithUseSyncInvalidationsTest,
SendInterestedDataTypesAndFCMTokenAsPartOfDeviceInfo) {
ASSERT_TRUE(SetupSync());
syncer::SyncInvalidationsService* sync_invalidations_service =
SyncInvalidationsServiceFactory::GetForProfile(GetProfile(0));
ASSERT_THAT(sync_invalidations_service, NotNull());
syncer::ModelTypeSet interested_data_types =
sync_invalidations_service->GetInterestedDataTypes();
std::string fcm_token = sync_invalidations_service->GetFCMRegistrationToken();
// Check that some "standard" data types are included.
EXPECT_TRUE(
interested_data_types.HasAll({syncer::NIGORI, syncer::BOOKMARKS}));
// Wallet and Offer data types are excluded unless
// kUseSyncInvalidationsForWalletAndOffer is also enabled.
EXPECT_FALSE(interested_data_types.Has(syncer::AUTOFILL_WALLET_DATA));
EXPECT_FALSE(interested_data_types.Has(syncer::AUTOFILL_WALLET_OFFER));
EXPECT_FALSE(fcm_token.empty());
// The local device should eventually be committed to the server.
EXPECT_TRUE(
ServerDeviceInfoMatchChecker(
GetFakeServer(),
ElementsAre(AllOf(HasInterestedDataTypes(interested_data_types),
HasInstanceIdToken(fcm_token))))
.Wait());
}
class SingleClientWithUseSyncInvalidationsForWalletAndOfferTest
: public SyncTest {
public:
SingleClientWithUseSyncInvalidationsForWalletAndOfferTest()
: SyncTest(SINGLE_CLIENT) {
override_features_.InitWithFeatures(
/*enabled_features=*/{switches::kSyncSendInterestedDataTypes,
switches::kUseSyncInvalidations,
switches::kUseSyncInvalidationsForWalletAndOffer},
/*disabled_features=*/{});
}
~SingleClientWithUseSyncInvalidationsForWalletAndOfferTest() override =
default;
private:
base::test::ScopedFeatureList override_features_;
DISALLOW_COPY_AND_ASSIGN(
SingleClientWithUseSyncInvalidationsForWalletAndOfferTest);
};
IN_PROC_BROWSER_TEST_F(
SingleClientWithUseSyncInvalidationsForWalletAndOfferTest,
SendInterestedDataTypesAndFCMTokenAsPartOfDeviceInfo) {
ASSERT_TRUE(SetupSync());
syncer::SyncInvalidationsService* sync_invalidations_service =
SyncInvalidationsServiceFactory::GetForProfile(GetProfile(0));
ASSERT_THAT(sync_invalidations_service, NotNull());
syncer::ModelTypeSet interested_data_types =
sync_invalidations_service->GetInterestedDataTypes();
std::string fcm_token = sync_invalidations_service->GetFCMRegistrationToken();
// Check that some "standard" data types are included.
EXPECT_TRUE(
interested_data_types.HasAll({syncer::NIGORI, syncer::BOOKMARKS}));
// Wallet data type should be included by default if
// kUseSyncInvalidationsForWalletAndOffer is enabled.
EXPECT_TRUE(interested_data_types.Has(syncer::AUTOFILL_WALLET_DATA));
EXPECT_FALSE(fcm_token.empty());
// The local device should eventually be committed to the server.
EXPECT_TRUE(
ServerDeviceInfoMatchChecker(
GetFakeServer(),
ElementsAre(AllOf(HasInterestedDataTypes(interested_data_types),
HasInstanceIdToken(fcm_token))))
.Wait());
}
} // namespace
......@@ -216,6 +216,16 @@ class SyncProfileDelegate : public Profile::Delegate {
} // namespace
void SyncTest::FakeInstanceID::GetToken(
const std::string& authorized_entity,
const std::string& scope,
base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags,
GetTokenCallback callback) {
std::move(callback).Run("token", instance_id::InstanceID::Result::SUCCESS);
}
instance_id::InstanceID* SyncTest::FakeInstanceIDDriver::GetInstanceID(
const std::string& app_id) {
return &fake_instance_id_;
......
......@@ -117,7 +117,7 @@ class SyncTest : public PlatformBrowserTest {
base::TimeDelta time_to_live,
const std::map<std::string, std::string>& options,
std::set<Flags> flags,
GetTokenCallback callback) override {}
GetTokenCallback callback) override;
void ValidateToken(const std::string& authorized_entity,
const std::string& scope,
......
......@@ -6962,6 +6962,7 @@ if (!is_fuchsia && !is_android) {
"../browser/sync/test/integration/single_client_sessions_sync_test.cc",
"../browser/sync/test/integration/single_client_sharing_message_sync_test.cc",
"../browser/sync/test/integration/single_client_standalone_transport_sync_test.cc",
"../browser/sync/test/integration/single_client_sync_invalidations_test.cc",
"../browser/sync/test/integration/single_client_themes_sync_test.cc",
"../browser/sync/test/integration/single_client_typed_urls_sync_test.cc",
"../browser/sync/test/integration/single_client_user_consents_sync_test.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