chromium/components/sync_device_info/device_info_sync_bridge_unittest.cc

// Copyright 2015 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/sync_device_info/device_info_sync_bridge.h"

#include <algorithm>
#include <map>
#include <set>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/mock_callback.h"
#include "base/test/simple_test_clock.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/time.h"
#include "components/sync/model/data_batch.h"
#include "components/sync/model/data_type_activation_request.h"
#include "components/sync/model/entity_change.h"
#include "components/sync/model/metadata_batch.h"
#include "components/sync/protocol/data_type_state.pb.h"
#include "components/sync/protocol/device_info_specifics.pb.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/sync_enums.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/sync/test/test_matchers.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_device_info/device_info_util.h"
#include "components/sync_device_info/local_device_info_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/ash/components/system/fake_statistics_provider.h"
#endif

namespace syncer {
namespace {

DataTypeState;
DeviceInfoSpecifics;
EntitySpecifics;
_;
AllOf;
Contains;
InvokeWithoutArgs;
IsEmpty;
IsNull;
Matcher;
NiceMock;
Not;
NotNull;
Pair;
Pointee;
Return;
SizeIs;
UnorderedElementsAre;

DeviceCountMap;
DeviceInfoList;
StorageKeyList;
RecordList;
StartCallback;
WriteBatch;

const int kLocalSuffix =;

const sync_pb::SyncEnums_DeviceType kLocalDeviceType =;
const DeviceInfo::OsType kLocalDeviceOS =;
const DeviceInfo::FormFactor kLocalDeviceFormFactor =;

MATCHER_P(HasDeviceInfo, expected, "") {}

MATCHER_P(EqualsProto, expected, "") {}

MATCHER_P(ModelEqualsSpecifics, expected_specifics, "") {}

Matcher<std::unique_ptr<EntityData>> HasSpecifics(
    const Matcher<sync_pb::EntitySpecifics>& m) {}

MATCHER_P(HasCacheGuid, cache_guid, "") {}

MATCHER(HasLastUpdatedAboutNow, "") {}

MATCHER(HasInstanceIdToken, "") {}

MATCHER(HasAnyInterestedDataTypes, "") {}

std::string CacheGuidForSuffix(int suffix) {}

std::string ClientNameForSuffix(int suffix) {}

std::string SyncUserAgentForSuffix(int suffix) {}

std::string ChromeVersionForSuffix(int suffix) {}

std::string GooglePlayServicesVersionForSuffix(int suffix) {}

std::string SigninScopedDeviceIdForSuffix(int suffix) {}

LocalDeviceNameInfo GetLocalDeviceNameInfoBlocking() {}

std::string ModelForSuffix(int suffix) {}

std::string ManufacturerForSuffix(int suffix) {}

std::string SharingVapidFcmTokenForSuffix(int suffix) {}

std::string SharingVapidP256dhForSuffix(int suffix) {}

std::string SharingVapidAuthSecretForSuffix(int suffix) {}

std::string SharingSenderIdFcmTokenForSuffix(int suffix) {}

std::string SharingChimeRepresentativeTargetIdForSuffix(int suffix) {}

std::string SharingSenderIdP256dhForSuffix(int suffix) {}

std::string SharingSenderIdAuthSecretForSuffix(int suffix) {}

sync_pb::SharingSpecificFields::EnabledFeatures SharingEnabledFeaturesForSuffix(
    int suffix) {}

std::string SyncInvalidationsInstanceIdTokenForSuffix(int suffix) {}

DataTypeSet SyncInvalidationsInterestedDataTypes() {}

DataTypeActivationRequest TestDataTypeActivationRequest(SyncMode sync_mode) {}

DeviceInfoSpecifics CreateSpecifics(
    int suffix,
    base::Time last_updated = base::Time::Now()) {}

DeviceInfoSpecifics CreateGooglePlayServicesSpecifics(int suffix) {}

DataTypeState StateWithEncryption(const std::string& encryption_key_name) {}

// Creates an EntityData around a copy of the given specifics.
EntityData SpecificsToEntity(const DeviceInfoSpecifics& specifics) {}

std::string CacheGuidToTag(const std::string& guid) {}

// Helper method to reduce duplicated code between tests. Wraps the given
// specifics objects in an EntityData and EntityChange of type ACTION_ADD, and
// returns an EntityChangeList containing them all. Order is maintained.
EntityChangeList EntityAddList(
    const std::vector<DeviceInfoSpecifics>& specifics_list) {}

std::map<std::string, sync_pb::EntitySpecifics> DataBatchToSpecificsMap(
    std::unique_ptr<DataBatch> batch) {}

class TestLocalDeviceInfoProvider : public MutableLocalDeviceInfoProvider {};  // namespace

class DeviceInfoSyncBridgeTest : public testing::Test,
                                 public DeviceInfoTracker::Observer {};

TEST_F(DeviceInfoSyncBridgeTest, BeforeSyncEnabled) {}

TEST_F(DeviceInfoSyncBridgeTest, GetClientTagNormal) {}

TEST_F(DeviceInfoSyncBridgeTest, GetClientTagEmpty) {}

TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalDataWithoutMetadata) {}

TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalMetadata) {}

TEST_F(DeviceInfoSyncBridgeTest, TestWithLocalDataAndMetadata) {}

TEST_F(DeviceInfoSyncBridgeTest, TestWithMultipleLocalDataAndMetadata) {}

TEST_F(DeviceInfoSyncBridgeTest, GetData) {}

TEST_F(DeviceInfoSyncBridgeTest, GetDataMissing) {}

TEST_F(DeviceInfoSyncBridgeTest, GetAllData) {}

TEST_F(DeviceInfoSyncBridgeTest, ApplyIncrementalSyncChangesEmpty) {}

TEST_F(DeviceInfoSyncBridgeTest, ApplyIncrementalSyncChangesInMemory) {}

TEST_F(DeviceInfoSyncBridgeTest, ApplyIncrementalSyncChangesStore) {}

TEST_F(DeviceInfoSyncBridgeTest, ApplyIncrementalSyncChangesWithLocalGuid) {}

TEST_F(DeviceInfoSyncBridgeTest, ApplyDeleteNonexistent) {}

TEST_F(DeviceInfoSyncBridgeTest, MergeEmpty) {}

TEST_F(DeviceInfoSyncBridgeTest, MergeLocalGuid) {}

TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevices) {}

TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithOverlappingTime) {}

TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithNonOverlappingTime) {}

TEST_F(DeviceInfoSyncBridgeTest,
       CountActiveDevicesWithNonOverlappingTimeAndDistinctType) {}

TEST_F(DeviceInfoSyncBridgeTest, CountActiveDevicesWithMalformedTimestamps) {}

TEST_F(DeviceInfoSyncBridgeTest,
       ShouldFilterOutNonChromeClientsFromDeviceTracker) {}

TEST_F(DeviceInfoSyncBridgeTest, SendLocalData) {}

TEST_F(DeviceInfoSyncBridgeTest, ApplyDisableSyncChanges) {}

TEST_F(DeviceInfoSyncBridgeTest, ExpireOldEntriesUponStartup) {}

TEST_F(DeviceInfoSyncBridgeTest, RefreshLocalDeviceInfo) {}

TEST_F(DeviceInfoSyncBridgeTest, DeviceNameForTransportOnlySyncMode) {}

TEST_F(DeviceInfoSyncBridgeTest, DeviceNameForFullSyncMode) {}

// Tests local client name when device is initially synced with transport only
// sync mode, but the sync mode is not available after restart since it is not
// persisted.
TEST_F(DeviceInfoSyncBridgeTest,
       DeviceNameForTransportOnlySyncMode_RestartBridge) {}

// Tests local client name when device is initially synced with full sync mode,
// but the sync mode is not available after restart since it is not persisted.
TEST_F(DeviceInfoSyncBridgeTest, DeviceNameForFullSyncMode_RestartBridge) {}

TEST_F(DeviceInfoSyncBridgeTest, RefreshLocalDeviceNameForSyncModeToggle) {}

TEST_F(DeviceInfoSyncBridgeTest, ShouldSendInvalidationFields) {}

TEST_F(DeviceInfoSyncBridgeTest,
       ShouldNotifyWhenAdditionalInterestedDataTypesSynced) {}

TEST_F(DeviceInfoSyncBridgeTest,
       ShouldNotNotifyWithoutAdditionalInterestedDataTypes) {}

// This test mimics the case when OnSyncStarting is called before the metadata
// is loaded from the storage.
TEST_F(DeviceInfoSyncBridgeTest,
       ShouldCleanUpMetadataOnInvalidCacheGuidAfterReadMetadata) {}

// This test mimics the opposite case when OnSyncStarting is called after the
// metadata is loaded from the storage.
TEST_F(DeviceInfoSyncBridgeTest,
       ShouldCleanUpMetadataOnInvalidCacheGuidAfterSyncStarting) {}

TEST_F(DeviceInfoSyncBridgeTest, ShouldInvokeCallbackOnReadAllMetadata) {}

TEST_F(DeviceInfoSyncBridgeTest, ShouldRemoveDeviceInfoOnTombstone) {}

TEST_F(DeviceInfoSyncBridgeTest,
       ShouldReuploadOnceAfterLocalDeviceInfoTombstone) {}

TEST_F(DeviceInfoSyncBridgeTest, ShouldForceLocalDeviceInfoUpload) {}

TEST_F(DeviceInfoSyncBridgeTest, ShouldNotUploadRecentLocalDeviceUponStartup) {}

TEST_F(DeviceInfoSyncBridgeTest, ShouldUploadOutdatedLocalDeviceInfo) {}

TEST_F(DeviceInfoSyncBridgeTest, ShouldDeriveOsFromDeviceType) {}

}  // namespace

}  // namespace syncer