#include "components/metrics/demographics/demographic_metrics_provider.h"
#include <memory>
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "components/metrics/demographics/user_demographics.h"
#include "components/metrics/metrics_log_uploader.h"
#include "components/sync/base/features.h"
#include "components/sync/service/sync_prefs.h"
#include "components/sync/test/test_sync_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
#include "third_party/metrics_proto/ukm/report.pb.h"
namespace metrics {
namespace {
constexpr int kTestBirthYear = …;
constexpr UserDemographicsProto::Gender kTestGender = …;
enum TestSyncServiceState { … };
class TestProfileClient : public DemographicMetricsProvider::ProfileClient { … };
TEST(DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_FeatureEnabled) { … }
TEST(DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_NoSyncService) { … }
TEST(DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_SyncEnabledButPaused) { … }
TEST(
DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_SyncFeatureDisabledButPreferencesEnabled_WithSyncToSignin) { … }
TEST(
DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_SyncFeatureDisabledButPreferencesEnabled_WithoutSyncToSignin) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST(
DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_SyncFeatureDisabledOnChromeOsAshViaSyncDashboard) {
base::HistogramTester histogram;
auto client = std::make_unique<TestProfileClient>(
1,
SYNC_FEATURE_DISABLED_ON_CHROMEOS_ASH_VIA_DASHBOARD);
DemographicMetricsProvider provider(
std::move(client), MetricsLogUploader::MetricServiceType::UMA);
ChromeUserMetricsExtension uma_proto;
provider.ProvideSyncedUserNoisedBirthYearAndGender(&uma_proto);
EXPECT_FALSE(uma_proto.user_demographics().has_birth_year());
EXPECT_FALSE(uma_proto.user_demographics().has_gender());
histogram.ExpectUniqueSample("UMA.UserDemographics.Status",
UserDemographicsStatus::kSyncNotEnabled, 1);
}
#endif
TEST(DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_SyncNotEnabled) { … }
TEST(DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_FeatureDisabled) { … }
TEST(DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_NotExactlyOneProfile) { … }
TEST(DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGender_NoUserDemographics) { … }
TEST(DemographicMetricsProviderTest,
ProvideSyncedUserNoisedBirthYearAndGenderToUkmReport) { … }
}
}