#include "components/sync/model/client_tag_based_data_type_processor.h"
#include <stddef.h>
#include <stdint.h>
#include <optional>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/protobuf_matchers.h"
#include "base/test/task_environment.h"
#include "base/threading/platform_thread.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/deletion_origin.h"
#include "components/sync/base/sync_mode.h"
#include "components/sync/base/unique_position.h"
#include "components/sync/engine/commit_and_get_updates_types.h"
#include "components/sync/engine/data_type_activation_response.h"
#include "components/sync/model/conflict_resolution.h"
#include "components/sync/model/data_type_activation_request.h"
#include "components/sync/model/processor_entity.h"
#include "components/sync/model/type_entities_count.h"
#include "components/sync/protocol/data_type_state.pb.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/unique_position.pb.h"
#include "components/sync/test/fake_data_type_sync_bridge.h"
#include "components/sync/test/mock_data_type_worker.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
namespace {
EqualsProto;
DataTypeState;
EntityMetadata;
EntitySpecifics;
Not;
NotNull;
const char kDefaultAuthenticatedAccountId[] = …;
const char kKey1[] = …;
const char kKey2[] = …;
const char kKey3[] = …;
const char kKey4[] = …;
const char kKey5[] = …;
const char kValue1[] = …;
const char kValue2[] = …;
const char kValue3[] = …;
const char kCacheGuid[] = …;
const EntitySpecifics kEmptySpecifics;
ClientTagHash GetHash(DataType type, const std::string& key) { … }
ClientTagHash GetPrefHash(const std::string& key) { … }
ClientTagHash GetSharedTabHash(const std::string& key) { … }
EntitySpecifics GeneratePrefSpecifics(const std::string& key,
const std::string& value) { … }
EntitySpecifics GenerateUserEventSpecifics(int64_t event_time_usec,
int64_t navigation_id) { … }
EntitySpecifics GenerateSharedTabSpecifics(
std::string guid,
sync_pb::UniquePosition unique_position) { … }
std::unique_ptr<EntityData> GenerateEntityData(
DataType type,
const std::string& key,
const EntitySpecifics& specifics) { … }
std::unique_ptr<EntityData> GeneratePrefEntityData(const std::string& key,
const std::string& value) { … }
std::unique_ptr<EntityData> GenerateSharedTabGroupEntityData(
const std::string& guid,
sync_pb::UniquePosition unique_position) { … }
EntitySpecifics WritePrefItem(FakeDataTypeSyncBridge* bridge,
const std::string& key,
const std::string& value) { … }
const std::string& GetPrefValue(const EntityData& entity_data) { … }
EntitySpecifics WriteUserEventItem(FakeDataTypeSyncBridge* bridge,
int64_t event_time,
int64_t navigation_id) { … }
void CaptureCommitRequest(CommitRequestDataList* dst,
CommitRequestDataList&& src) { … }
void CaptureTypeEntitiesCount(TypeEntitiesCount* dst,
const TypeEntitiesCount& count) { … }
sync_pb::UniquePosition ExtractUniquePositionFromSharedTab(
const sync_pb::EntitySpecifics& specifics) { … }
class TestDataTypeSyncBridge : public FakeDataTypeSyncBridge { … };
}
class ClientTagBasedDataTypeProcessorTest : public ::testing::Test { … };
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldExposeNewlyTrackedAccountId) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldExposePreviouslyTrackedAccountId) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldExposeNewlyTrackedAccountIdIfChanged) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldExposeNewlyAddedInvalidations) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldExposeNewlyTrackedCacheGuid) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldExposePreviouslyTrackedCacheGuid) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldMergeLocalAndRemoteChanges) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldExposePossiblyTrimmedRemoteSpecifics) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldFilterOutInitialTombstones) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldFilterOutInitialRootNodes) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldApplyIncrementalUpdates) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldReportErrorDuringActivation) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldReportErrorDuringMerge) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldDeferErrorsBeforeStart) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldHandleSynchronousDataLoad) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldLoadPendingDelete) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotQueueAnotherCommitIfAlreadyCommitted) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldCommitLocalCreation) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
CommitShouldOverwriteExistingItem) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldReportErrorApplyingAck) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldOverrideFieldsForLocalUpdate) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldCommitLocalUpdate) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldCommitLocalUpdateBeforeCreationAck) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldIgnoreRedundantLocalUpdate) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldReportErrorApplyingUpdate) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldCommitLocalDeletion) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotCommitLocalDeletionOfUncommittedEntity) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldHandleLocalDeletionDuringLocalCreationCommit) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldProcessRemoteDeletion) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldIgnoreLocalDeletionOfUnknownEntity) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldRetryCommitAfterServerError) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldRetryCommitAfterFullCommitFailure) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldTruncateLocalChangesToMaxSize) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldHandleTwoIndependentItems) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotTreatMatchingChangesAsConflict) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResolveConflictToLocalVersion) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResolveConflictToLocalUndeletion) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResolveConflictToRemoteUndeletion) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResolveConflictToRemoteUndeletionWithUpdateStorageKey) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResolveConflictToRemoteVersion) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResolveConflictToRemoteDeletion) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldDisconnectAndReconnect) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldStopAndKeepMetadata) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldStopAndClearMetadata) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotClearBridgeMetadataPriorToMergeFullSyncData) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldReencryptCommitsWithNewKey) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldHandleErrorWhileReencrypting) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldReencryptUpdatesWithNewKey) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResolveConflictToLocalDuringReencryption) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResolveConflictToRemoteDuringReencryption) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldHandleConflictWhileLoadingForReencryption) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldIgnoreLocalEncryptionChange) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldDropRemoteUpdatesWithoutClientTags) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldReportEphemeralConfigurationTime) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldReportPersistentConfigurationTime) { … }
class FullUpdateClientTagBasedDataTypeProcessorTest
: public ClientTagBasedDataTypeProcessorTest { … };
TEST_F(FullUpdateClientTagBasedDataTypeProcessorTest,
ShouldApplyGarbageCollectionByVersionFullUpdate) { … }
TEST_F(FullUpdateClientTagBasedDataTypeProcessorTest,
ShouldReportEphemeralConfigurationTimeOnlyForFirstFullUpdate) { … }
TEST_F(FullUpdateClientTagBasedDataTypeProcessorTest,
ShouldReportErrorForUnsupportedIncrementalUpdate) { … }
TEST_F(FullUpdateClientTagBasedDataTypeProcessorTest,
ShouldProcessEmptyUpdate) { … }
TEST_F(FullUpdateClientTagBasedDataTypeProcessorTest,
ShouldProcessInitialUpdate) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldIgnoreRemoteEncryption) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldIgnoreRemoteEncryptionInterleaved) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldUpdateStorageKey) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldReencryptDatatypeWithoutStorageKeySupport) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldUntrackEntity) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldUntrackEntityForStorageKey) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldIgnoreUntrackEntityForInexistentStorageKey) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldUntrackEntityForClientTagHash) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotApplyGarbageCollectionByVersion) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldDeleteMetadataWhenCacheGuidMismatch) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldDeleteMetadataWhenDataTypeIdMismatch) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldClearOrphanMetadataInGetLocalChangesWhenDataIsMissing) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotReportOrphanMetadataInGetLocalChangesWhenDataIsPresent) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldRecordNumUnsyncedEntitiesOnModelReady) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldDeleteItemAndRecreaeItWithDifferentStorageKey) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldPropagateFailedCommitItemsToBridgeWhenCommitCompleted) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotPropagateFailedCommitAttemptToBridgeWhenNoFailedItems) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldPropagateFullCommitFailure) { … }
class CommitOnlyClientTagBasedDataTypeProcessorTest
: public ClientTagBasedDataTypeProcessorTest { … };
TEST_F(CommitOnlyClientTagBasedDataTypeProcessorTest,
ShouldExposeNewlyTrackedAccountId) { … }
TEST_F(CommitOnlyClientTagBasedDataTypeProcessorTest,
ShouldExposePreviouslyTrackedAccountId) { … }
TEST_F(CommitOnlyClientTagBasedDataTypeProcessorTest,
ShouldCallMergeWhenSyncEnabled) { … }
TEST_F(CommitOnlyClientTagBasedDataTypeProcessorTest,
ShouldNotCallMergeAfterRestart) { … }
TEST_F(CommitOnlyClientTagBasedDataTypeProcessorTest,
ShouldCommitAndDeleteWhenAcked) { … }
TEST_F(CommitOnlyClientTagBasedDataTypeProcessorTest,
ShouldTrackUnsyncedChangesAfterPartialCommit) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldResetOnInvalidCacheGuid) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldResetOnInvalidDataTypeId) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResetForEntityMetadataWithoutInitialSyncDone) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotResetWhenInitialSyncPartiallyDone) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldResetForDuplicateClientTagHash) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotProcessInvalidRemoteIncrementalUpdate) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotProcessInvalidRemoteFullUpdate) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotReportErrorAfterOnSyncStopping) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotInvokeBridgeOnSyncStartingFromOnSyncStopping) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest, ShouldClearMetadataIfStopped) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldClearMetadataIfStoppedUponModelReadyToSync) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldClearMetadataWhileStoppedUponModelReadyToSyncWithoutEntities) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotClearMetadataIfNotStopped) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotClearMetadataIfStoppedIfNotTracking) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotClearMetadataIfStoppedWithoutMetadataInitially) { … }
TEST_F(ClientTagBasedDataTypeProcessorTest,
ShouldNotClearMetadataIfStoppedUponModelReadyToSyncWithoutMetadata) { … }
class PasswordsClientTagBasedDataTypeProcessorTest
: public ClientTagBasedDataTypeProcessorTest { … };
TEST_F(PasswordsClientTagBasedDataTypeProcessorTest,
ShouldSetPasswordsRedownloadedForNotesFlag) { … }
class ClientTagBasedDataTypeProcessorWithUniquePositionTest
: public ClientTagBasedDataTypeProcessorTest { … };
TEST_F(ClientTagBasedDataTypeProcessorWithUniquePositionTest,
ShouldProcessUniquePositionForNewEntity) { … }
TEST_F(ClientTagBasedDataTypeProcessorWithUniquePositionTest,
ShouldUpdateUniquePositionForExistingEntity) { … }
TEST_F(ClientTagBasedDataTypeProcessorWithUniquePositionTest,
ShouldUpdateUniquePositionAfterDeletion) { … }
TEST_F(ClientTagBasedDataTypeProcessorWithUniquePositionTest,
ShouldStoreRemoteUniquePositionOnFullUpdate) { … }
TEST_F(ClientTagBasedDataTypeProcessorWithUniquePositionTest,
ShouldGenerateUniquePositionForInitialEntity) { … }
TEST_F(ClientTagBasedDataTypeProcessorWithUniquePositionTest,
ShouldGenerateUniquePositionsBeforeAndAfter) { … }
TEST_F(ClientTagBasedDataTypeProcessorWithUniquePositionTest,
ShouldGenerateUniquePositionBetween) { … }
TEST_F(ClientTagBasedDataTypeProcessorWithUniquePositionTest,
ShouldReturnUniquePosition) { … }
}