1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_UKM_UKM_TEST_HELPER_H_
6 #define COMPONENTS_UKM_UKM_TEST_HELPER_H_
10 #include "base/memory/raw_ptr.h"
11 #include "components/ukm/ukm_service.h"
12 #include "services/metrics/public/cpp/ukm_source.h"
13 #include "services/metrics/public/cpp/ukm_source_id.h"
14 #include "third_party/metrics_proto/ukm/report.pb.h"
18 // Helper class that provides access to UkmService internals. This class is a
19 // friend of UkmService and UkmRecorderImpl.
22 explicit UkmTestHelper(UkmService* ukm_service);
23 ~UkmTestHelper() = default;
25 // Returns true if |ukm_service_| records extensions.
26 bool IsExtensionRecordingEnabled() const;
28 // Returns true if |ukm_service_| has recording enabled.
29 bool IsRecordingEnabled() const;
31 // Returns true if |ukm_service_| if the following feature is enabled:
32 // kReportUserNoisedUserBirthYearAndGender.
33 static bool IsReportUserNoisedUserBirthYearAndGenderEnabled();
35 // Returns |ukm_service_|'s client ID.
36 uint64_t GetClientId();
38 // Creates and returns a UKM report if there are unsent logs from which a
39 // report can be generated. Returns nullptr otherwise.
40 std::unique_ptr<Report> GetUkmReport();
42 // Returns the UkmSource corresponding to |source_id|, if present; otherwise,
44 UkmSource* GetSource(SourceId source_id);
46 // Returns true if |ukm_service_| has a source corresponding to |source_id|.
47 bool HasSource(SourceId source_id);
49 // Returns true if UkmSource denoted by |source_id| is marked as obsolete.
50 bool IsSourceObsolete(SourceId source_id);
52 // Adds a dummy source with |source_id| to |ukm_service_|.
53 void RecordSourceForTesting(SourceId source_id);
55 // Creates a log and stores it in |ukm_service_|'s UnsentLogStore.
56 void BuildAndStoreLog();
58 // Returns true if |ukm_service_| has logs to send.
61 // Adds MSBB consent to the UkmService.
62 void SetMsbbConsent();
65 const raw_ptr<UkmService, DanglingUntriaged> ukm_service_;
70 #endif // COMPONENTS_UKM_UKM_TEST_HELPER_H_