#include "components/sync/service/sync_service_impl.h"
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/prefs/testing_pref_service.h"
#include "components/signin/public/base/signin_pref_names.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/signin/public/identity_manager/primary_account_mutator.h"
#include "components/sync/base/command_line_switches.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/features.h"
#include "components/sync/base/pref_names.h"
#include "components/sync/base/sync_util.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/engine/nigori/key_derivation_params.h"
#include "components/sync/engine/sync_status.h"
#include "components/sync/service/sync_service_observer.h"
#include "components/sync/service/sync_token_status.h"
#include "components/sync/service/trusted_vault_synthetic_field_trial.h"
#include "components/sync/test/fake_data_type_controller.h"
#include "components/sync/test/fake_sync_engine.h"
#include "components/sync/test/fake_sync_engine_factory.h"
#include "components/sync/test/mock_data_type_local_data_batch_uploader.h"
#include "components/sync/test/sync_client_mock.h"
#include "components/sync/test/sync_service_impl_bundle.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/trusted_vault/test/fake_trusted_vault_client.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
_;
AllOf;
AnyNumber;
AtLeast;
ByMove;
Eq;
Invoke;
IsEmpty;
IsNull;
Not;
NotNull;
Pair;
Return;
UnorderedElementsAre;
namespace syncer {
namespace {
constexpr char kTestUser[] = …;
struct FakeControllerInitParams { … };
MATCHER_P(ContainsDataType, type, "") { … }
MATCHER_P(IsValidFieldTrialGroupWithName, expected_name, "") { … }
SyncCycleSnapshot MakeDefaultSyncCycleSnapshot() { … }
class MockSyncServiceObserver : public SyncServiceObserver { … };
class TestSyncServiceObserver : public SyncServiceObserver { … };
class SyncServiceImplTest : public ::testing::Test { … };
TEST_F(SyncServiceImplTest, InitialState) { … }
TEST_F(SyncServiceImplTest, SuccessfulInitialization) { … }
TEST_F(SyncServiceImplTest, SuccessfulLocalBackendInitialization) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplTest, NeedsConfirmation) { … }
#endif
TEST_F(SyncServiceImplTest, DataTypesForTransportMode) { … }
TEST_F(SyncServiceImplTest, SetupInProgress) { … }
TEST_F(SyncServiceImplTest, DisabledByPolicyBeforeInit) { … }
TEST_F(SyncServiceImplTest, DisabledByPolicyBeforeInitThenPolicyRemoved) { … }
TEST_F(SyncServiceImplTest, DisabledByPolicyAfterInit) { … }
TEST_F(SyncServiceImplTest, AbortedByShutdown) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplTest, EarlySignOut) { … }
#endif
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplTest, SignOutDisablesSyncTransportAndSyncFeature) { … }
TEST_F(SyncServiceImplTest,
SignOutClearsSyncTransportDataAndSyncTheFeaturePrefs) { … }
TEST_F(SyncServiceImplTest,
SignOutDuringTransportModeClearsTransportDataAndAccountStorageOptIn) { … }
#endif
TEST_F(
SyncServiceImplTest,
AddressesSyncShouldBeDisabledForNewlySigninUsersWithAlreadyCustomPassphraseSet) { … }
TEST_F(
SyncServiceImplTest,
AddressesSyncShouldNotBeDisabledForSignedInUsersWithNewlyCustomPassphraseSet) { … }
TEST_F(SyncServiceImplTest, GetSyncTokenStatus) { … }
TEST_F(SyncServiceImplTest, RevokeAccessTokenFromTokenService) { … }
TEST_F(SyncServiceImplTest, CredentialsRejectedByClient_StopSync) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplTest, SignOutRevokeAccessToken) { … }
#endif
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplTest, ClearTransportDataOnInitializeWhenSignedOut) { … }
#endif
TEST_F(SyncServiceImplTest, DashboardResetTwiceDoesNotCrash) { … }
TEST_F(SyncServiceImplTest, CredentialErrorReturned) { … }
TEST_F(SyncServiceImplTest,
TransportIsDisabledIfBothAuthErrorAndDisableReason) { … }
TEST_F(SyncServiceImplTest, CredentialErrorClearsOnNewToken) { … }
TEST_F(SyncServiceImplTest, DisableSyncFlag) { … }
TEST_F(SyncServiceImplTest, NoDisableSyncFlag) { … }
TEST_F(SyncServiceImplTest, ResetLocalSyncData) { … }
TEST_F(SyncServiceImplTest, DisableSyncOnClient) { … }
TEST_F(SyncServiceImplTest,
DisableSyncOnClientLogsPassphraseTypeForNotMyBirthday) { … }
TEST_F(SyncServiceImplTest,
DisableSyncOnClientLogsPassphraseTypeForEncryptionObsolete) { … }
TEST_F(SyncServiceImplTest, DisableSyncOnClientClearsPassphrasePrefForAccount) { … }
TEST_F(SyncServiceImplTest,
DisableSyncOnClientClearsPassphrasePrefForSyncingAccount) { … }
TEST_F(SyncServiceImplTest, EncryptionObsoleteClearsPassphrasePrefForAccount) { … }
TEST_F(SyncServiceImplTest, LocalBackendUnimpactedByPolicy) { … }
TEST_F(SyncServiceImplTest, ConfigureDataTypeManagerReason) { … }
TEST_F(SyncServiceImplTest, ShouldProvideDisableReasonsAfterShutdown) { … }
TEST_F(SyncServiceImplTest, ShouldSendDataTypesToSyncInvalidationsService) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(SyncServiceImplTest,
ShouldSendDataTypesToSyncInvalidationsServiceInTransportMode) { … }
#else
TEST_F(SyncServiceImplTest,
ShouldSendDataTypesToSyncInvalidationsServiceInTransportModeAsh) {
SignInWithSyncConsent();
std::vector<FakeControllerInitParams> params;
params.emplace_back(BOOKMARKS, false);
params.emplace_back(DEVICE_INFO, true);
InitializeService(std::move(params));
base::RunLoop().RunUntilIdle();
EXPECT_CALL(*sync_invalidations_service(),
SetInterestedDataTypes(AllOf(ContainsDataType(NIGORI),
Not(ContainsDataType(BOOKMARKS)),
ContainsDataType(DEVICE_INFO))));
SyncProtocolError client_cmd;
client_cmd.action = DISABLE_SYNC_ON_CLIENT;
service()->OnActionableProtocolError(client_cmd);
base::RunLoop().RunUntilIdle();
ASSERT_FALSE(service()->IsSyncFeatureActive());
EXPECT_TRUE(engine()->started_handling_invalidations());
}
#endif
TEST_F(SyncServiceImplTest, ShouldEnableAndDisableInvalidationsForSessions) { … }
TEST_F(SyncServiceImplTest, ShouldNotSubscribeToProxyTypes) { … }
TEST_F(SyncServiceImplTest, ShouldNotSubscribeToFailedTypes) { … }
TEST_F(SyncServiceImplTest, ShouldNotSubscribeToStopAndClearDataTypes) { … }
TEST_F(SyncServiceImplTest, ShouldSubscribeToStopAndKeepDataTypes) { … }
TEST_F(SyncServiceImplTest, ShouldUnsubscribeWhenStopAndClear) { … }
TEST_F(SyncServiceImplTest, ShouldUnsubscribeOnTypeFailure) { … }
TEST_F(SyncServiceImplTest,
ShouldActivateSyncInvalidationsServiceWhenSyncIsInitialized) { … }
TEST_F(SyncServiceImplTest,
ShouldNotStartListeningInvalidationsWhenLocalSyncEnabled) { … }
TEST_F(SyncServiceImplTest,
ShouldNotStopListeningPermanentlyOnShutdownBrowserAndKeepData) { … }
TEST_F(SyncServiceImplTest, ShouldStopListeningPermanentlyOnDashboardReset) { … }
TEST_F(SyncServiceImplTest, ShouldCallStopUponResetEngineIfAlreadyShutDown) { … }
TEST_F(SyncServiceImplTest, ShouldReturnErrorDownloadStatus) { … }
TEST_F(SyncServiceImplTest, ShouldReturnErrorDownloadStatusWhenSyncDisabled) { … }
TEST_F(SyncServiceImplTest, ShouldReturnWaitingDownloadStatus) { … }
TEST_F(SyncServiceImplTest, ShouldReturnErrorWhenDataTypeDisabled) { … }
TEST_F(SyncServiceImplTest, ShouldWaitUntilNoInvalidations) { … }
TEST_F(SyncServiceImplTest, ShouldWaitForInitializedInvalidations) { … }
TEST_F(SyncServiceImplTest, ShouldWaitForPollRequest) { … }
TEST_F(SyncServiceImplTest, ShouldReturnErrorOnSyncPaused) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(
SyncServiceImplTest,
GetTypesWithPendingDownloadForInitialSyncDuringFirstSyncInTransportMode) { … }
TEST_F(SyncServiceImplTest,
GetTypesWithPendingDownloadForInitialSyncDuringFirstSync) { … }
#endif
TEST_F(SyncServiceImplTest,
GetTypesWithPendingDownloadForInitialSyncDuringNthSync) { … }
TEST_F(SyncServiceImplTest, EarlyCallToGetTypesWithUnsyncedDataShouldNotCrash) { … }
TEST_F(SyncServiceImplTest,
ShouldOnlyForwardEnabledTypesUponGetLocalDataDescriptions) { … }
TEST_F(SyncServiceImplTest,
ShouldNotForwardTypesWithErrorUponGetLocalDataDescriptions) { … }
TEST_F(SyncServiceImplTest,
ShouldNotForwardUponGetLocalDataDescriptionsIfSyncDisabled) { … }
TEST_F(SyncServiceImplTest,
ShouldReturnEmptyUponGetLocalDataDescriptionsForSignedOutUsers) { … }
TEST_F(SyncServiceImplTest,
ShouldReturnEmptyUponGetLocalDataDescriptionsForSyncingUsers) { … }
TEST_F(SyncServiceImplTest, ShouldJoinLocalDataDescriptionsForDifferentTypes) { … }
TEST_F(SyncServiceImplTest,
ShouldOnlyForwardEnabledTypesUponTriggerLocalDataMigration) { … }
TEST_F(SyncServiceImplTest,
ShouldNotForwardTypesWithErrorUponTriggerLocalDataMigration) { … }
TEST_F(SyncServiceImplTest,
ShouldNotForwardUponTriggerLocalDataMigrationIfSyncDisabled) { … }
TEST_F(SyncServiceImplTest,
ShouldDoNothingUponTriggerLocalDataMigrationForNotSignedInUsers) { … }
TEST_F(SyncServiceImplTest,
ShouldDoNothingUponTriggerLocalDataMigrationForSyncingUsers) { … }
TEST_F(SyncServiceImplTest, ShouldRecordLocalDataMigrationRequests) { … }
TEST_F(SyncServiceImplTest, ShouldNotifyOnManagedPrefDisabled) { … }
TEST_F(SyncServiceImplTest, ShouldCacheTrustedVaultAutoUpgradeDebugInfo) { … }
}
}