chromium/components/metrics/demographics/demographic_metrics_provider_unittest.cc

// Copyright 2019 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/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 {};

// Profile client for testing that gets fake Profile information and services.
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>(
      /*number_of_profiles=*/1,
      SYNC_FEATURE_DISABLED_ON_CHROMEOS_ASH_VIA_DASHBOARD);

  // Run demographics provider.
  DemographicMetricsProvider provider(
      std::move(client), MetricsLogUploader::MetricServiceType::UMA);
  ChromeUserMetricsExtension uma_proto;
  provider.ProvideSyncedUserNoisedBirthYearAndGender(&uma_proto);

  // Expect the proto fields to be not set and left to default.
  EXPECT_FALSE(uma_proto.user_demographics().has_birth_year());
  EXPECT_FALSE(uma_proto.user_demographics().has_gender());

  // Verify histograms.
  histogram.ExpectUniqueSample("UMA.UserDemographics.Status",
                               UserDemographicsStatus::kSyncNotEnabled, 1);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

TEST(DemographicMetricsProviderTest,
     ProvideSyncedUserNoisedBirthYearAndGender_SyncNotEnabled) {}

TEST(DemographicMetricsProviderTest,
     ProvideSyncedUserNoisedBirthYearAndGender_FeatureDisabled) {}

TEST(DemographicMetricsProviderTest,
     ProvideSyncedUserNoisedBirthYearAndGender_NotExactlyOneProfile) {}

TEST(DemographicMetricsProviderTest,
     ProvideSyncedUserNoisedBirthYearAndGender_NoUserDemographics) {}

TEST(DemographicMetricsProviderTest,
     ProvideSyncedUserNoisedBirthYearAndGenderToUkmReport) {}

}  // namespace
}  // namespace metrics