Upload upstream chromium 114.0.5735.31
[platform/framework/web/chromium-efl.git] / components / ukm / ukm_test_helper.h
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.
4
5 #ifndef COMPONENTS_UKM_UKM_TEST_HELPER_H_
6 #define COMPONENTS_UKM_UKM_TEST_HELPER_H_
7
8 #include <memory>
9
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"
15
16 namespace ukm {
17
18 // Helper class that provides access to UkmService internals. This class is a
19 // friend of UkmService and UkmRecorderImpl.
20 class UkmTestHelper {
21  public:
22   explicit UkmTestHelper(UkmService* ukm_service);
23   ~UkmTestHelper() = default;
24
25   // Returns true if |ukm_service_| records extensions.
26   bool IsExtensionRecordingEnabled() const;
27
28   // Returns true if |ukm_service_| has recording enabled.
29   bool IsRecordingEnabled() const;
30
31   // Returns true if |ukm_service_| if the following feature is enabled:
32   // kReportUserNoisedUserBirthYearAndGender.
33   static bool IsReportUserNoisedUserBirthYearAndGenderEnabled();
34
35   // Returns |ukm_service_|'s client ID.
36   uint64_t GetClientId();
37
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();
41
42   // Returns the UkmSource corresponding to |source_id|, if present; otherwise,
43   // returns nullptr.
44   UkmSource* GetSource(SourceId source_id);
45
46   // Returns true if |ukm_service_| has a source corresponding to |source_id|.
47   bool HasSource(SourceId source_id);
48
49   // Returns true if UkmSource denoted by |source_id| is marked as obsolete.
50   bool IsSourceObsolete(SourceId source_id);
51
52   // Adds a dummy source with |source_id| to |ukm_service_|.
53   void RecordSourceForTesting(SourceId source_id);
54
55   // Creates a log and stores it in |ukm_service_|'s UnsentLogStore.
56   void BuildAndStoreLog();
57
58   // Returns true if |ukm_service_| has logs to send.
59   bool HasUnsentLogs();
60
61   // Adds MSBB consent to the UkmService.
62   void SetMsbbConsent();
63
64  private:
65   const raw_ptr<UkmService, DanglingUntriaged> ukm_service_;
66 };
67
68 }  // namespace ukm
69
70 #endif  // COMPONENTS_UKM_UKM_TEST_HELPER_H_