#include "components/sync_sessions/session_sync_bridge.h"
#include <map>
#include <utility>
#include <vector>
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/engine/commit_and_get_updates_types.h"
#include "components/sync/engine/data_type_activation_response.h"
#include "components/sync/model/client_tag_based_data_type_processor.h"
#include "components/sync/model/data_batch.h"
#include "components/sync/model/data_type_activation_request.h"
#include "components/sync/model/data_type_sync_bridge.h"
#include "components/sync/model/metadata_batch.h"
#include "components/sync/model/metadata_change_list.h"
#include "components/sync/protocol/data_type_state.pb.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/protocol/session_specifics.pb.h"
#include "components/sync/protocol/sync_enums.pb.h"
#include "components/sync/service/sync_prefs.h"
#include "components/sync/test/data_type_store_test_util.h"
#include "components/sync/test/mock_commit_queue.h"
#include "components/sync/test/mock_data_type_local_change_processor.h"
#include "components/sync/test/test_matchers.h"
#include "components/sync_sessions/mock_sync_sessions_client.h"
#include "components/sync_sessions/session_sync_prefs.h"
#include "components/sync_sessions/test_matchers.h"
#include "components/sync_sessions/test_synced_window_delegates_getter.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace sync_sessions {
namespace {
SessionSpecifics;
CommitResponseDataList;
DataBatch;
EntityChangeList;
EntityData;
FailedCommitResponseDataList;
IsEmptyMetadataBatch;
MetadataBatch;
MockDataTypeLocalChangeProcessor;
_;
AtLeast;
ElementsAre;
Eq;
IsEmpty;
IsNull;
Not;
NotNull;
Pair;
Pointee;
Return;
SaveArg;
SizeIs;
UnorderedElementsAre;
WithArg;
const char kAccountId[] = …;
const char kLocalCacheGuid[] = …;
MATCHER_P(EntityDataHasSpecifics, session_specifics_matcher, "") { … }
sync_pb::DataTypeState GetDataTypeStateWithInitialSyncDone() { … }
syncer::EntityData SpecificsToEntity(const sync_pb::SessionSpecifics& specifics,
base::Time mtime = base::Time::Now()) { … }
syncer::UpdateResponseData SpecificsToUpdateResponse(
const sync_pb::SessionSpecifics& specifics,
base::Time mtime = base::Time::Now()) { … }
std::map<std::string, std::unique_ptr<EntityData>> BatchToEntityDataMap(
std::unique_ptr<DataBatch> batch) { … }
syncer::UpdateResponseData CreateTombstone(const std::string& client_tag) { … }
syncer::CommitResponseData CreateSuccessResponse(
const std::string& client_tag) { … }
sync_pb::SessionSpecifics CreateHeaderSpecificsWithOneTab(
const std::string& session_tag,
int window_id,
int tab_id) { … }
sync_pb::SessionSpecifics CreateTabSpecifics(const std::string& session_tag,
int window_id,
int tab_id,
int tab_node_id,
const std::string& url) { … }
class SessionSyncBridgeTest : public ::testing::Test { … };
TEST_F(SessionSyncBridgeTest, ShouldCallModelReadyToSyncWhenSyncEnabled) { … }
TEST_F(SessionSyncBridgeTest, ShouldDeferLocalEventDueToSessionRestore) { … }
TEST_F(SessionSyncBridgeTest, ShouldCreateHeaderByDefault) { … }
TEST_F(SessionSyncBridgeTest, ShouldExposeInitialLocalTabsToProcessor) { … }
TEST_F(SessionSyncBridgeTest, ShouldReportLocalTabCreation) { … }
TEST_F(SessionSyncBridgeTest, ShouldNotUpdatePlaceholderTabsDuringRestore) { … }
TEST_F(SessionSyncBridgeTest,
ShouldIgnoreUnsyncablePlaceholderTabDuringRestore) { … }
TEST_F(SessionSyncBridgeTest, ShouldRestoreTabbedDataIfNoWindowsDuringStartup) { … }
TEST_F(SessionSyncBridgeTest, ShouldPreserveTabbedDataIfCustomTabOnlyFound) { … }
TEST_F(SessionSyncBridgeTest, ShouldPreserveTabbedDataIfNewCustomTabAlsoFound) { … }
TEST_F(SessionSyncBridgeTest, ShouldAssociateIfCustomTabOnlyOnStartup) { … }
TEST_F(SessionSyncBridgeTest, ShouldExposeTabbedWindowAfterCustomTabOnly) { … }
TEST_F(SessionSyncBridgeTest, ShouldRecycleTabNodeAfterCommitCompleted) { … }
TEST_F(SessionSyncBridgeTest, ShouldRestoreLocalSessionWithFreedTab) { … }
TEST_F(SessionSyncBridgeTest, ShouldDisableSyncAndReenable) { … }
TEST_F(SessionSyncBridgeTest, ShouldMergeForeignSession) { … }
TEST_F(SessionSyncBridgeTest, ShouldTriggerNotificationWithoutRemoteData) { … }
TEST_F(SessionSyncBridgeTest, ShouldNotExposeForeignHeaderWithoutTabs) { … }
TEST_F(SessionSyncBridgeTest, ShouldNotExposeClosedTabsAfterRestart) { … }
TEST_F(SessionSyncBridgeTest, ShouldHandleRemoteDeletion) { … }
TEST_F(SessionSyncBridgeTest, ShouldIgnoreRemoteDeletionOfLocalTab) { … }
TEST_F(SessionSyncBridgeTest, ShouldIgnoreRemoteDeletionOfLocalPlaceholderTab) { … }
TEST_F(SessionSyncBridgeTest, ShouldNotRestoreLocalSessionWithoutMetadata) { … }
TEST_F(SessionSyncBridgeTest, ShouldDeleteForeignSessionFromUI) { … }
TEST_F(SessionSyncBridgeTest, ShouldIgnoreLocalSessionDeletionFromUI) { … }
TEST_F(SessionSyncBridgeTest, ShouldNotBroadcastUpdatesIfEmpty) { … }
TEST_F(SessionSyncBridgeTest, ShouldDoGarbageCollection) { … }
TEST_F(SessionSyncBridgeTest, ShouldReturnBrowserTypeInGetData) { … }
}
}