#include "components/saved_tab_groups/saved_tab_group_sync_bridge.h"
#include <algorithm>
#include <cstddef>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ref.h"
#include "base/scoped_observation.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_file_util.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/testing_pref_service.h"
#include "components/saved_tab_groups/features.h"
#include "components/saved_tab_groups/pref_names.h"
#include "components/saved_tab_groups/saved_tab_group.h"
#include "components/saved_tab_groups/saved_tab_group_model.h"
#include "components/saved_tab_groups/saved_tab_group_model_observer.h"
#include "components/saved_tab_groups/saved_tab_group_tab.h"
#include "components/saved_tab_groups/saved_tab_group_test_utils.h"
#include "components/sync/engine/commit_queue.h"
#include "components/sync/model/conflict_resolution.h"
#include "components/sync/model/data_batch.h"
#include "components/sync/model/data_type_store.h"
#include "components/sync/model/data_type_store_service_impl.h"
#include "components/sync/model/entity_change.h"
#include "components/sync/model/metadata_batch.h"
#include "components/sync/model/metadata_change_list.h"
#include "components/sync/model/mutable_data_batch.h"
#include "components/sync/protocol/entity_data.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/saved_tab_group_specifics.pb.h"
#include "components/sync/test/data_type_store_test_util.h"
#include "components/sync/test/mock_data_type_local_change_processor.h"
#include "components/tab_groups/tab_group_color.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/tab_groups/tab_group_visual_data.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
ConflictResolution;
EntityData;
_;
namespace tab_groups {
namespace {
constexpr base::TimeDelta kDiscardOrphanedTabsThreshold = …;
class ModelObserverForwarder : public SavedTabGroupModelObserver { … };
bool AreGroupSpecificsEqual(const sync_pb::SavedTabGroupSpecifics& sp1,
const sync_pb::SavedTabGroupSpecifics& sp2) { … }
bool AreSavedTabGroupsEqual(const SavedTabGroup& group1,
const SavedTabGroup& group2) { … }
bool AreTabSpecificsEqual(const sync_pb::SavedTabGroupSpecifics& sp1,
const sync_pb::SavedTabGroupSpecifics& sp2) { … }
bool AreSavedTabGroupTabsEqual(const SavedTabGroupTab& tab1,
const SavedTabGroupTab& tab2) { … }
syncer::EntityData CreateEntityData(sync_pb::SavedTabGroupSpecifics specific) { … }
std::unique_ptr<syncer::EntityChange> CreateEntityChange(
sync_pb::SavedTabGroupSpecifics specific,
syncer::EntityChange::ChangeType change_type) { … }
syncer::EntityChangeList CreateEntityChangeListFromGroup(
const SavedTabGroup& group,
syncer::EntityChange::ChangeType change_type) { … }
}
class SavedTabGroupSyncBridgeTest : public ::testing::Test { … };
TEST_F(SavedTabGroupSyncBridgeTest, MergeFullSyncData) { … }
TEST_F(SavedTabGroupSyncBridgeTest, ConflictResolutionForTabGroup) { … }
TEST_F(SavedTabGroupSyncBridgeTest, ConflictResolutionForTab) { … }
TEST_F(SavedTabGroupSyncBridgeTest, MergeFullSyncDataWithExistingData) { … }
TEST_F(SavedTabGroupSyncBridgeTest,
DisableSyncLocallyRemovesGroupsCreatedBeforeSignIn) { … }
TEST_F(SavedTabGroupSyncBridgeTest, OrphanedTabAddedIntoGroupWhenFound) { … }
TEST_F(SavedTabGroupSyncBridgeTest, OprhanedTabDiscardedAfter30Days) { … }
TEST_F(SavedTabGroupSyncBridgeTest, OprhanedTabGroupFoundAfter30Days) { … }
TEST_F(SavedTabGroupSyncBridgeTest, AddSyncData) { … }
TEST_F(SavedTabGroupSyncBridgeTest, UpdateSyncData) { … }
TEST_F(SavedTabGroupSyncBridgeTest, DeleteSyncData) { … }
TEST_F(SavedTabGroupSyncBridgeTest, DeleteSyncDataProcessedLast) { … }
TEST_F(SavedTabGroupSyncBridgeTest, AddGroupLocally) { … }
TEST_F(SavedTabGroupSyncBridgeTest, LocalIdChanged) { … }
TEST_F(SavedTabGroupSyncBridgeTest, RemoveGroupLocally) { … }
TEST_F(SavedTabGroupSyncBridgeTest, UpdateGroupLocally) { … }
TEST_F(SavedTabGroupSyncBridgeTest, AddTabFromSync) { … }
TEST_F(SavedTabGroupSyncBridgeTest, AddTabLocally) { … }
TEST_F(SavedTabGroupSyncBridgeTest, RemoveTabLocally) { … }
TEST_F(SavedTabGroupSyncBridgeTest, UpdateTabLocally) { … }
TEST_F(SavedTabGroupSyncBridgeTest, ReorderTabsInGroupLocally) { … }
TEST_F(SavedTabGroupSyncBridgeTest, ReorderGroupLocally) { … }
TEST_F(SavedTabGroupSyncBridgeTest, Group) { … }
class SavedTabGroupSyncBridgeMigrationTest
: public SavedTabGroupSyncBridgeTest { … };
TEST_F(
SavedTabGroupSyncBridgeMigrationTest,
MigrateSpecificsToSavedTabGroupData_OldToNewFormat_Success_OneGroup_VerifyNewRecord) { … }
TEST_F(
SavedTabGroupSyncBridgeMigrationTest,
MigrateSpecificsToSavedTabGroupData_OldToNewFormat_Success_OneGroupWithOneTab) { … }
TEST_F(SavedTabGroupSyncBridgeMigrationTest,
MigrateSpecificsToSavedTabGroupData_CorruptedData) { … }
TEST_F(SavedTabGroupSyncBridgeMigrationTest,
SavedTabGroupSyncBridgeMigrationTest_AlreadyMigrated) { … }
TEST_F(SavedTabGroupSyncBridgeMigrationTest,
SavedTabGroupSyncBridgeMigrationTest_NewFormatBeforeMigration) { … }
TEST_F(
SavedTabGroupSyncBridgeMigrationTest,
MigrateSpecificsToSavedTabGroupData_AlreadyNewFormatBeforeMigration_Success_OneGroupWithOneTab) { … }
}