#include "components/sync/engine/data_type_worker.h"
#include <stdint.h>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/features.h"
#include "components/sync/base/unique_position.h"
#include "components/sync/engine/cancelation_signal.h"
#include "components/sync/engine/commit_contribution.h"
#include "components/sync/engine/cycle/entity_change_metric_recording.h"
#include "components/sync/engine/cycle/status_controller.h"
#include "components/sync/protocol/autofill_specifics.pb.h"
#include "components/sync/protocol/data_type_state.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/password_sharing_invitation_specifics.pb.h"
#include "components/sync/protocol/password_specifics.pb.h"
#include "components/sync/protocol/sync.pb.h"
#include "components/sync/protocol/sync_entity.pb.h"
#include "components/sync/protocol/webauthn_credential_specifics.pb.h"
#include "components/sync/test/fake_cryptographer.h"
#include "components/sync/test/mock_data_type_processor.h"
#include "components/sync/test/mock_invalidation.h"
#include "components/sync/test/mock_invalidation_tracker.h"
#include "components/sync/test/mock_nudge_handler.h"
#include "components/sync/test/single_type_mock_server.h"
#include "components/sync/test/trackable_mock_invalidation.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
Time;
DataTypeState;
EntitySpecifics;
SyncEntity;
ElementsAre;
IsNull;
NotNull;
SizeIs;
UnorderedElementsAre;
namespace syncer {
namespace {
const char kEncryptionKeyNamePrefix[] = …;
const char kTag1[] = …;
const char kTag2[] = …;
const char kTag3[] = …;
const char kValue1[] = …;
const char kValue2[] = …;
const char kValue3[] = …;
EntitySpecifics GenerateSpecifics(const std::string& tag,
const std::string& value) { … }
std::string GetNthKeyName(int n) { … }
sync_pb::EntitySpecifics EncryptPasswordSpecificsWithNthKey(
int n,
const sync_pb::PasswordSpecificsData& unencrypted_password) { … }
sync_pb::CrossUserSharingPublicKey PublicKeyToProto(
const CrossUserSharingPublicPrivateKeyPair& key_pair,
uint32_t version) { … }
sync_pb::IncomingPasswordSharingInvitationSpecifics
CreateIncomingPasswordSharingInvitation(const std::string& invitation_guid,
const std::string& signon_realm,
const std::string& username_value,
const std::string& password_value,
const std::string& sender_name,
uint32_t recipient_key_version,
FakeCryptographer* cryptographer) { … }
ClientTagHash GeneratePreferenceTagHash(const std::string& tag) { … }
MATCHER_P(HasPreferenceClientTag,
expected_tag,
base::StringPrintf(
"expected_tag: %s, hash: %s",
expected_tag,
GeneratePreferenceTagHash(expected_tag).value().c_str())) { … }
}
class DataTypeWorkerTest : public ::testing::Test { … };
TEST_F(DataTypeWorkerTest, SimpleCommit) { … }
TEST_F(DataTypeWorkerTest, SimpleDelete) { … }
TEST_F(DataTypeWorkerTest, SendInitialSyncDone) { … }
TEST_F(DataTypeWorkerTest, TwoNewItemsCommittedSeparately) { … }
TEST_F(DataTypeWorkerTest, ReceiveUpdates) { … }
TEST_F(DataTypeWorkerTest,
ReceiveUpdates_ShouldNotPopulateUpdatedTypesOnTombstone) { … }
TEST_F(DataTypeWorkerTest, ReceiveUpdates_NoDuplicateHash) { … }
TEST_F(DataTypeWorkerTest, ReceiveUpdates_DuplicateHashWithinPartialUpdate) { … }
TEST_F(DataTypeWorkerTest, ReceiveUpdates_DuplicateHashAcrossPartialUpdates) { … }
TEST_F(DataTypeWorkerTest,
ReceiveUpdates_EmptyHashNotConsideredDuplicateIfForDistinctServerIds) { … }
TEST_F(DataTypeWorkerTest, ReceiveUpdates_MultipleDuplicateHashes) { … }
TEST_F(DataTypeWorkerTest,
ReceiveUpdates_DuplicateClientTagHashesForDistinctServerIds) { … }
TEST_F(DataTypeWorkerTest,
ReceiveUpdates_DuplicateOriginatorClientIdForDistinctServerIds) { … }
TEST_F(
DataTypeWorkerTest,
ReceiveUpdates_DuplicateOriginatorClientIdForDistinctOriginatorCacheGuids) { … }
TEST_F(DataTypeWorkerTest, ReceiveMultiPartUpdates) { … }
TEST_F(DataTypeWorkerTest, EmptyUpdates) { … }
TEST_F(DataTypeWorkerTest, EncryptedCommit) { … }
TEST_F(DataTypeWorkerTest, EncryptedDelete) { … }
TEST_F(DataTypeWorkerTest, EncryptionBlocksUpdates) { … }
TEST_F(DataTypeWorkerTest, EncryptionBlocksCommits) { … }
TEST_F(DataTypeWorkerTest, ReceiveDecryptableEntities) { … }
TEST_F(DataTypeWorkerTest,
ReceiveDecryptableEntitiesShouldWaitTillKeyArrives) { … }
TEST_F(DataTypeWorkerTest, InitializeWithCryptographer) { … }
TEST_F(DataTypeWorkerTest, InitializeWithPendingCryptographer) { … }
TEST_F(DataTypeWorkerTest, FirstInitializeWithCryptographer) { … }
TEST_F(DataTypeWorkerTest, CryptographerDuringInitialization) { … }
TEST_F(DataTypeWorkerTest, ReceiveUndecryptableEntries) { … }
TEST_F(DataTypeWorkerTest, OverwriteUndecryptableUpdateWithDecryptableOne) { … }
TEST_F(DataTypeWorkerTest, ReceiveCorruptEncryption) { … }
TEST_F(DataTypeWorkerTest, DecryptUpdateIfPossibleDespiteEncryptionDisabled) { … }
TEST_F(DataTypeWorkerTest, IgnoreUpdatesEncryptedWithKeysMissingForTooLong) { … }
TEST_F(DataTypeWorkerTest, DisconnectProcessorFromSyncTest) { … }
TEST_F(DataTypeWorkerTest, RecreateDeletedEntity) { … }
TEST_F(DataTypeWorkerTest, CommitOnly) { … }
TEST_F(DataTypeWorkerTest, ShouldPropagateCommitFailure) { … }
TEST_F(DataTypeWorkerTest, ShouldKeepGcDirectiveDuringSyncCycle) { … }
TEST_F(DataTypeWorkerTest, ShouldCleanUpPendingUpdatesOnGcDirective) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
NonBookmarkNorWalletSucceeds) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest, BookmarkTombstone) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
BookmarkWithUniquePositionInSyncEntity) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
BookmarkWithPositionInParent) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
BookmarkWithInsertAfterItemId) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
BookmarkWithMissingPositionFallsBackToRandom) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest, BookmarkWithGUID) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest, BookmarkWithMissingGUID) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
BookmarkWithMissingGUIDAndInvalidOCII) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
WalletDataWithMissingClientTagHash) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
OfferDataWithMissingClientTagHash) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
WebAuthnCredentialWithLegacyClientTagHash) { … }
TEST(DataTypeWorkerPopulateUpdateResponseDataTest,
WebAuthnCredentialWithLegacyClientTagHashForDeletion) { … }
class GetLocalChangesRequestTest : public testing::Test { … };
GetLocalChangesRequestTest::GetLocalChangesRequestTest()
: … { … }
GetLocalChangesRequestTest::~GetLocalChangesRequestTest() = default;
void GetLocalChangesRequestTest::SetUp() { … }
void GetLocalChangesRequestTest::TearDown() { … }
scoped_refptr<GetLocalChangesRequest>
GetLocalChangesRequestTest::MakeRequest() { … }
void GetLocalChangesRequestTest::BlockingWaitForResponseOrCancelation(
scoped_refptr<GetLocalChangesRequest> request,
CancelationSignal* cancelation_signal) { … }
void GetLocalChangesRequestTest::ScheduleBlockingWait(
scoped_refptr<GetLocalChangesRequest> request,
CancelationSignal* cancelation_signal) { … }
TEST_F(GetLocalChangesRequestTest, CancelationSignaledBeforeRequest) { … }
TEST_F(GetLocalChangesRequestTest, CancelationSignaledAfterRequest) { … }
TEST_F(GetLocalChangesRequestTest, SuccessfulRequest) { … }
class DataTypeWorkerPasswordsTest : public DataTypeWorkerTest { … };
TEST_F(DataTypeWorkerPasswordsTest, PasswordCommit) { … }
TEST_F(DataTypeWorkerPasswordsTest, PasswordCommitWithCustomPassphrase) { … }
TEST_F(DataTypeWorkerPasswordsTest, ReceiveDecryptablePasswordEntities) { … }
TEST_F(DataTypeWorkerPasswordsTest,
ReceiveDecryptablePasswordShouldWaitTillKeyArrives) { … }
TEST_F(DataTypeWorkerPasswordsTest, ReceiveUndecryptablePasswordEntries) { … }
TEST_F(DataTypeWorkerPasswordsTest, ReceiveCorruptedPasswordEntities) { … }
class DataTypeWorkerBookmarksTest : public DataTypeWorkerTest { … };
TEST_F(DataTypeWorkerBookmarksTest, CanDecryptUpdateWithMissingBookmarkGUID) { … }
TEST_F(DataTypeWorkerBookmarksTest,
CanDecryptUpdateWithMissingBookmarkGUIDAndInvalidOCII) { … }
TEST_F(DataTypeWorkerBookmarksTest,
CannotDecryptUpdateWithMissingBookmarkGUID) { … }
TEST_F(DataTypeWorkerBookmarksTest,
CannotDecryptUpdateWithMissingBookmarkGUIDAndInvalidOCII) { … }
TEST_F(DataTypeWorkerTest, ShouldNotHaveLocalChangesOnSuccessfulLastCommit) { … }
TEST_F(DataTypeWorkerTest, ShouldHaveLocalChangesOnCommitFailure) { … }
TEST_F(DataTypeWorkerTest, ShouldHaveLocalChangesOnSuccessfulNotLastCommit) { … }
TEST_F(DataTypeWorkerTest, ShouldHaveLocalChangesWhenNudgedWhileInFlight) { … }
TEST_F(DataTypeWorkerTest, ShouldHaveLocalChangesWhenContributedMaxEntities) { … }
TEST_F(DataTypeWorkerPasswordsTest,
ShouldIgnoreTheEncryptedNotesBackupWhenNotesInPasswordSpecificsData) { … }
TEST_F(DataTypeWorkerPasswordsTest,
ShouldUseTheEncryptedNotesBackupWhenMissingInPasswordSpecificsData) { … }
TEST_F(DataTypeWorkerPasswordsTest, ShouldEmitUnsetWhenNoNotesInUpdate) { … }
TEST_F(DataTypeWorkerPasswordsTest, ShouldEmitNotesBackupCorrupted) { … }
TEST_F(DataTypeWorkerPasswordsTest, ShouldPopulatePasswordNotesBackup) { … }
TEST_F(DataTypeWorkerPasswordsTest,
ShouldPopulatePasswordNotesBackupWhenNoLocalNotes) { … }
TEST_F(DataTypeWorkerTest, LoadInvalidations) { … }
TEST_F(DataTypeWorkerTest, StoreInvalidationsCallCount) { … }
TEST_F(DataTypeWorkerTest, HintCoalescing) { … }
TEST_F(DataTypeWorkerTest, DataTypeStateAfterApplyUpdates) { … }
TEST_F(DataTypeWorkerTest, DropHintsLocally_OneAtATime) { … }
TEST_F(DataTypeWorkerTest, DropHintsAtServer_Alone) { … }
TEST_F(DataTypeWorkerTest, DropHintsAtServer_WithOtherInvalidations) { … }
TEST_F(DataTypeWorkerTest, ShouldEncryptOutgoingPasswordSharingInvitation) { … }
class DataTypeWorkerIncomingPasswordSharingInvitationTest
: public DataTypeWorkerTest { … };
TEST_F(DataTypeWorkerIncomingPasswordSharingInvitationTest,
ShouldDecryptIncomingPasswordSharingInvitation) { … }
TEST_F(DataTypeWorkerIncomingPasswordSharingInvitationTest,
ShouldIgnoreCorruptedInvitation) { … }
class DataTypeWorkerAckTrackingTest : public DataTypeWorkerTest { … };
TEST_F(DataTypeWorkerAckTrackingTest, SimpleAcknowledgement) { … }
TEST_F(DataTypeWorkerAckTrackingTest, ManyAcknowledgements) { … }
TEST_F(DataTypeWorkerAckTrackingTest, OverflowAndRecover) { … }
TEST_F(DataTypeWorkerAckTrackingTest, UnknownVersionFromServer_Simple) { … }
TEST_F(DataTypeWorkerAckTrackingTest, UnknownVersionFromServer_Complex) { … }
TEST_F(DataTypeWorkerAckTrackingTest, AckInvalidationsAddedDuringSyncCycle) { … }
TEST_F(DataTypeWorkerAckTrackingTest, MultipleGetUpdates) { … }
class DataTypeWorkerHistoryTest : public DataTypeWorkerTest { … };
TEST_F(DataTypeWorkerHistoryTest, AppliesPartialUpdateImmediately) { … }
TEST_F(DataTypeWorkerHistoryTest, KeepsInitialSyncMarkedAsDone) { … }
class DataTypeWorkerSharedTabGroupDataTest : public DataTypeWorkerTest { … };
TEST_F(DataTypeWorkerSharedTabGroupDataTest,
ShouldClearUpdatesForInactiveCollaborationsDuringSyncCycle) { … }
}