#include <string>
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/sync/device_info_sync_service_factory.h"
#include "chrome/browser/sync/test/integration/bookmarks_helper.h"
#include "chrome/browser/sync/test/integration/device_info_helper.h"
#include "chrome/browser/sync/test/integration/sync_service_impl_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/features.h"
#include "components/sync/base/time.h"
#include "components/sync/protocol/device_info_specifics.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/sync.pb.h"
#include "components/sync/protocol/sync_entity.pb.h"
#include "components/sync/protocol/sync_enums.pb.h"
#include "components/sync/test/fake_server.h"
#include "components/sync/test/fake_server_http_post_provider.h"
#include "components/sync_device_info/device_info.h"
#include "components/sync_device_info/device_info_sync_service.h"
#include "components/sync_device_info/device_info_tracker.h"
#include "components/sync_device_info/device_info_util.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace {
HasCacheGuid;
HasSharingFields;
DataType;
DataTypeSet;
AllOf;
Contains;
ElementsAre;
IsEmpty;
IsSupersetOf;
Not;
UnorderedElementsAre;
MATCHER(HasFullHardwareClass, "") { … }
MATCHER(IsFullHardwareClassEmpty, "") { … }
MATCHER_P(ModelEntryHasCacheGuid, expected_cache_guid, "") { … }
MATCHER_P(HasInterestedDataType, expected_data_type, "") { … }
std::string CacheGuidForSuffix(int suffix) { … }
std::string ClientNameForSuffix(int suffix) { … }
std::string SyncUserAgentForSuffix(int suffix) { … }
std::string ChromeVersionForSuffix(int suffix) { … }
std::string SigninScopedDeviceIdForSuffix(int suffix) { … }
DataTypeSet DefaultInterestedDataTypes() { … }
sync_pb::DeviceInfoSpecifics CreateSpecifics(
int suffix,
const std::string& fcm_registration_token,
const DataTypeSet& interested_data_types) { … }
sync_pb::DeviceInfoSpecifics CreateSpecifics(int suffix) { … }
class DeviceInfoCommitChecker : public SingleClientStatusChangeChecker { … };
class SingleClientDeviceInfoSyncTest : public SyncTest { … };
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
UmaEnabledSetFullHardwareClass) {
bool uma_enabled = true;
ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(
&uma_enabled);
ASSERT_TRUE(SetupSync());
EXPECT_THAT(fake_server_->GetSyncEntitiesByDataType(syncer::DEVICE_INFO),
Contains(HasFullHardwareClass()));
ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr);
}
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
UmaDisabledFullHardwareClassEmpty) {
bool uma_enabled = false;
ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(
&uma_enabled);
ASSERT_TRUE(SetupSync());
EXPECT_THAT(fake_server_->GetSyncEntitiesByDataType(syncer::DEVICE_INFO),
Contains(IsFullHardwareClassEmpty()));
ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr);
}
#else
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
UmaEnabledFullHardwareClassOnNonChromeOS) { … }
#endif
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest, CommitLocalDevice) { … }
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest, DownloadRemoteDevices) { … }
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
DownloadRemoteDeviceWithoutChromeVersion) { … }
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
DownloadRemoteDeviceWithNewVersionFieldOnly) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_CommitLocalDevice_TransportOnly …
#else
#define MAYBE_CommitLocalDevice_TransportOnly …
#endif
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
MAYBE_CommitLocalDevice_TransportOnly) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_DownloadRemoteDevices_TransportOnly …
#else
#define MAYBE_DownloadRemoteDevices_TransportOnly …
#endif
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
MAYBE_DownloadRemoteDevices_TransportOnly) { … }
#endif
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
ShouldSetTheOnlyClientFlag) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientDeviceInfoSyncTest,
ShouldSetTheOnlyClientFlagForStandaloneInvalidationsOnly) { … }
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
ShouldSetTheOnlyClientFlagForDataType) { … }
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
ShouldNotProvideTheOnlyClientFlag) { … }
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
ShouldNotPopulateTheOnlyClientWhenDeviceInfoUpdated) { … }
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
ShouldReuploadLocalDeviceIfRemovedFromServer) { … }
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
ShouldRetryDeviceInfoCommitOnAuthError) { … }
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
PRE_ShouldNotSendDeviceInfoAfterBrowserRestart) { … }
IN_PROC_BROWSER_TEST_F(SingleClientDeviceInfoSyncTest,
ShouldNotSendDeviceInfoAfterBrowserRestart) { … }
#endif
}