#include "components/saved_tab_groups/shared_tab_group_data_sync_bridge.h"
#include <array>
#include <initializer_list>
#include <memory>
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ref.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/test/bind.h"
#include "base/test/protobuf_matchers.h"
#include "base/test/task_environment.h"
#include "base/uuid.h"
#include "components/prefs/testing_pref_service.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/base/client_tag_hash.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/unique_position.h"
#include "components/sync/model/data_batch.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/protocol/entity_data.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/shared_tab_group_data_specifics.pb.h"
#include "components/sync/protocol/unique_position.pb.h"
#include "components/sync/test/data_type_store_test_util.h"
#include "components/sync/test/mock_data_type_local_change_processor.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace tab_groups {
void PrintTo(const SavedTabGroupTab& tab, std::ostream* os) { … }
namespace {
EqualsProto;
_;
ElementsAre;
Eq;
Invoke;
Pointee;
Return;
SizeIs;
UnorderedElementsAre;
WithArg;
MATCHER_P3(HasSharedGroupMetadata, title, color, collaboration_id, "") { … }
MATCHER_P2(HasTabMetadata, title, url, "") { … }
MATCHER_P3(HasGroupEntityData, title, color, collaboration_id, "") { … }
MATCHER_P3(HasTabEntityData, title, url, collaboration_id, "") { … }
MATCHER_P2(HasTabEntityDataWithPosition, title, unique_position, "") { … }
std::string StorageKeyForTab(const SavedTabGroupTab& tab) { … }
MATCHER_P(HasClientTagHashForTab, tab, "") { … }
class MockTabGroupModelObserver : public SavedTabGroupModelObserver { … };
class ModelObserverForwarder : public SavedTabGroupModelObserver { … };
sync_pb::SharedTabGroupDataSpecifics MakeTabGroupSpecifics(
const std::string& title,
sync_pb::SharedTabGroup::Color color) { … }
sync_pb::SharedTabGroupDataSpecifics MakeTabSpecifics(
const std::string& title,
const GURL& url,
const base::Uuid& group_id,
const syncer::UniquePosition& unique_position) { … }
syncer::EntityData CreateEntityData(
const sync_pb::SharedTabGroupDataSpecifics& specifics,
const std::string& collaboration_id) { … }
std::unique_ptr<syncer::EntityChange> CreateAddEntityChange(
const sync_pb::SharedTabGroupDataSpecifics& specifics,
const std::string& collaboration_id) { … }
std::unique_ptr<syncer::EntityChange> CreateUpdateEntityChange(
const sync_pb::SharedTabGroupDataSpecifics& specifics,
const std::string& collaboration_id) { … }
std::vector<syncer::EntityData> ExtractEntityDataFromBatch(
std::unique_ptr<syncer::DataBatch> batch) { … }
sync_pb::EntityMetadata CreateMetadata(std::string collaboration_id) { … }
syncer::UniquePosition GenerateRandomUniquePosition() { … }
class SharedTabGroupDataSyncBridgeTest : public testing::Test { … };
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldReturnClientTag) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldCallModelReadyToSync) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldAddRemoteGroupsAtInitialSync) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldAddRemoteTabsAtInitialSync) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldAddRemoteGroupsAtIncrementalUpdate) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldAddRemoteTabsAtIncrementalUpdate) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldUpdateExistingGroupOnIncrementalUpdate) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldUpdateExistingTabOnIncrementalUpdate) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldDeleteExistingGroupOnIncrementalUpdate) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldDeleteExistingTabOnIncrementalUpdate) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldCheckValidEntities) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldRemoveLocalGroupsOnDisableSync) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldNotifyObserversOnDisableSync) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldReturnGroupDataForCommit) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldReturnTabDataForCommit) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldReturnAllDataForDebugging) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldSendToSyncNewGroupWithTabs) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldSendToSyncUpdatedGroupMetadata) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldSendToSyncNewLocalTab) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldSendToSyncRemovedLocalTab) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldSendToSyncUpdatedLocalTab) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldSendToSyncRemovedLocalGroup) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldReloadDataOnBrowserRestart) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldReturnUniquePositionFromTabSpecifics) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldReturnEmptyUniquePositionFromGroupSpecifics) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldGenerateUniquePositionsWhenGroupAddedLocally) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldGenerateUniquePositionForInitialTabEntity) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldGenerateUniquePositionForNewTabBefore) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldGenerateUniquePositionForNewTabAfter) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest,
ShouldGenerateUniquePositionForNewTabBetween) { … }
TEST_F(SharedTabGroupDataSyncBridgeTest, ShouldUpdatePositionOnRemoteUpdate) { … }
constexpr size_t kNumTabsForOrderTest = …;
class SharedTabGroupDataSyncBridgeRemoteUpdateOrderTest
: public SharedTabGroupDataSyncBridgeTest,
public testing::WithParamInterface<
std::array<size_t, kNumTabsForOrderTest>> { … };
TEST_P(SharedTabGroupDataSyncBridgeRemoteUpdateOrderTest,
ShouldAddRemoteTabsInCorrectOrder) { … }
INSTANTIATE_TEST_SUITE_P(…);
}
}