OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_UKM_TEST_UKM_SERVICE_H_ | 5 #ifndef COMPONENTS_UKM_TEST_UKM_SERVICE_H_ |
6 #define COMPONENTS_UKM_TEST_UKM_SERVICE_H_ | 6 #define COMPONENTS_UKM_TEST_UKM_SERVICE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "components/metrics/test_metrics_service_client.h" | 11 #include "components/metrics/test_metrics_service_client.h" |
12 #include "components/prefs/testing_pref_service.h" | 12 #include "components/prefs/testing_pref_service.h" |
13 #include "components/ukm/ukm_pref_names.h" | 13 #include "components/ukm/ukm_pref_names.h" |
14 #include "components/ukm/ukm_service.h" | 14 #include "components/ukm/ukm_service.h" |
15 | 15 |
16 namespace ukm { | 16 namespace ukm { |
17 | 17 |
18 // Wraps an UkmService with additional accessors used for testing. | 18 // Wraps an UkmService with additional accessors used for testing. |
19 class TestUkmService : public UkmService { | 19 class TestUkmService : public UkmService { |
20 public: | 20 public: |
21 explicit TestUkmService(PrefService* pref_service); | 21 explicit TestUkmService(PrefService* pref_service); |
22 ~TestUkmService() override; | 22 ~TestUkmService() override; |
23 | 23 |
24 size_t sources_count() const { return sources_for_testing().size(); } | 24 size_t sources_count() const { return sources_for_testing().size(); } |
25 const std::map<int32_t, std::unique_ptr<UkmSource>>& GetSources() const; | 25 const std::map<int32_t, std::unique_ptr<UkmSource>>& GetSources() const; |
26 const UkmSource* GetSourceForUrl(const char* url) const; | 26 const UkmSource* GetSourceForUrl(const char* url) const; |
| 27 const UkmSource* GetSourceForSourceId(int32_t source_id) const; |
27 | 28 |
28 size_t entries_count() const { return entries_for_testing().size(); } | 29 size_t entries_count() const { return entries_for_testing().size(); } |
29 const UkmEntry* GetEntry(size_t entry_num) const; | 30 const UkmEntry* GetEntry(size_t entry_num) const; |
| 31 const UkmEntry* GetEntryForEntryName(const char* entry_name) const; |
30 | 32 |
31 private: | 33 private: |
32 metrics::TestMetricsServiceClient test_metrics_service_client_; | 34 metrics::TestMetricsServiceClient test_metrics_service_client_; |
33 | 35 |
34 DISALLOW_COPY_AND_ASSIGN(TestUkmService); | 36 DISALLOW_COPY_AND_ASSIGN(TestUkmService); |
35 }; | 37 }; |
36 | 38 |
37 // Convenience harness used for testing; creates a TestUkmService and | 39 // Convenience harness used for testing; creates a TestUkmService and |
38 // supplies it with a prefs service with a longer lifespan. | 40 // supplies it with a prefs service with a longer lifespan. |
39 class UkmServiceTestingHarness { | 41 class UkmServiceTestingHarness { |
40 public: | 42 public: |
41 UkmServiceTestingHarness(); | 43 UkmServiceTestingHarness(); |
42 virtual ~UkmServiceTestingHarness(); | 44 virtual ~UkmServiceTestingHarness(); |
43 | 45 |
44 TestUkmService* test_ukm_service() { return test_ukm_service_.get(); } | 46 TestUkmService* test_ukm_service() { return test_ukm_service_.get(); } |
45 | 47 |
46 private: | 48 private: |
47 TestingPrefServiceSimple test_prefs_; | 49 TestingPrefServiceSimple test_prefs_; |
48 std::unique_ptr<TestUkmService> test_ukm_service_; | 50 std::unique_ptr<TestUkmService> test_ukm_service_; |
49 | 51 |
50 DISALLOW_COPY_AND_ASSIGN(UkmServiceTestingHarness); | 52 DISALLOW_COPY_AND_ASSIGN(UkmServiceTestingHarness); |
51 }; | 53 }; |
52 | 54 |
53 } // namespace ukm | 55 } // namespace ukm |
54 | 56 |
55 #endif // COMPONENTS_UKM_TEST_UKM_SERVICE_H_ | 57 #endif // COMPONENTS_UKM_TEST_UKM_SERVICE_H_ |
OLD | NEW |