chromium/components/saved_tab_groups/saved_tab_group_sync_bridge_unittest.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// Discard orphaned tabs after 30 days if the associated group cannot be found.
constexpr base::TimeDelta kDiscardOrphanedTabsThreshold =;

// Forwards SavedTabGroupModel's observer notifications to the bridge.
class ModelObserverForwarder : public SavedTabGroupModelObserver {};

// Do not check update times for specifics as adding tabs to a group through the
// bridge will change the update times for the group object.
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) {}

}  // anonymous namespace

// // Verifies the sync bridge correctly passes/merges data in to the model.
class SavedTabGroupSyncBridgeTest : public ::testing::Test {};

// Verify that when we add data into the sync bridge the SavedTabGroupModel will
// reflect those changes.
TEST_F(SavedTabGroupSyncBridgeTest, MergeFullSyncData) {}

TEST_F(SavedTabGroupSyncBridgeTest, ConflictResolutionForTabGroup) {}

TEST_F(SavedTabGroupSyncBridgeTest, ConflictResolutionForTab) {}

// Verify merging with preexisting data in the model merges the correct
// elements.
TEST_F(SavedTabGroupSyncBridgeTest, MergeFullSyncDataWithExistingData) {}

// Verify that on sign-out, the groups created before sign-in are locally
// deleted.
TEST_F(SavedTabGroupSyncBridgeTest,
       DisableSyncLocallyRemovesGroupsCreatedBeforeSignIn) {}

// Verify orphaned tabs (tabs missing their group) are added into the correct
// group in the model once the group arrives.
TEST_F(SavedTabGroupSyncBridgeTest, OrphanedTabAddedIntoGroupWhenFound) {}

// Verify orphaned tabs (tabs missing their group) that have not been updated
// for 30 days are discarded and not added into the model.
TEST_F(SavedTabGroupSyncBridgeTest, OprhanedTabDiscardedAfter30Days) {}

// Verify orphaned tabs (tabs missing their group) that have not been updated
// for 30 days and have a group are not discarded.
TEST_F(SavedTabGroupSyncBridgeTest, OprhanedTabGroupFoundAfter30Days) {}

// Verify that when we add data into the sync bridge the SavedTabGroupModel
// will reflect those changes.
TEST_F(SavedTabGroupSyncBridgeTest, AddSyncData) {}

// Verify that ACTION_UPDATE performs the same as ACTION_ADD initially and that
// the model reflects the updated group data after subsequent calls.
TEST_F(SavedTabGroupSyncBridgeTest, UpdateSyncData) {}

// Verify that the correct elements are removed when ACTION_DELETE is called.
TEST_F(SavedTabGroupSyncBridgeTest, DeleteSyncData) {}

// Verify that the deleted elements are processed last. We process deleted
// elements last for consistency since the ordering of messages is not
// guaranteed.
TEST_F(SavedTabGroupSyncBridgeTest, DeleteSyncDataProcessedLast) {}

// Verify that locally added groups call add all group data to the processor.
TEST_F(SavedTabGroupSyncBridgeTest, AddGroupLocally) {}

// Verify that local ID change events aren't passed to the processor.
TEST_F(SavedTabGroupSyncBridgeTest, LocalIdChanged) {}

// Verify that locally removed groups removes the group from the processor
// and leaves the tabs without an associated group.
TEST_F(SavedTabGroupSyncBridgeTest, RemoveGroupLocally) {}

// Verify that locally updated groups add all group data to the processor.
TEST_F(SavedTabGroupSyncBridgeTest, UpdateGroupLocally) {}

// Verify duplicate tab added from sync is merged with the correct tab and not
// added again to the model.
TEST_F(SavedTabGroupSyncBridgeTest, AddTabFromSync) {}

// Verify that locally added tabs call put on the processor.
TEST_F(SavedTabGroupSyncBridgeTest, AddTabLocally) {}

// Verify that locally removed tabs remove the correct tabs from the processor.
TEST_F(SavedTabGroupSyncBridgeTest, RemoveTabLocally) {}

// Verify that locally updated tabs update the correct tabs in the processor.
TEST_F(SavedTabGroupSyncBridgeTest, UpdateTabLocally) {}

// Verify that locally reordered tabs updates all tabs in the group.
TEST_F(SavedTabGroupSyncBridgeTest, ReorderTabsInGroupLocally) {}

// Verify that locally reordered tabs updates all tabs in the group.
TEST_F(SavedTabGroupSyncBridgeTest, ReorderGroupLocally) {}

// Verify that pulling the cache guid works.
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) {}

}  // namespace tab_groups