OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_UKM_TEST_UKM_SERVICE_H_ |
| 6 #define COMPONENTS_UKM_TEST_UKM_SERVICE_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <memory> |
| 10 |
| 11 #include "components/metrics/test_metrics_service_client.h" |
| 12 #include "components/prefs/testing_pref_service.h" |
| 13 #include "components/ukm/ukm_pref_names.h" |
| 14 #include "components/ukm/ukm_service.h" |
| 15 |
| 16 namespace ukm { |
| 17 |
| 18 // Wraps an UkmService with additional accessors used for testing. |
| 19 class TestUkmService : public UkmService { |
| 20 public: |
| 21 explicit TestUkmService(PrefService* pref_service); |
| 22 ~TestUkmService() override; |
| 23 |
| 24 size_t sources_count() const { return sources_for_testing().size(); } |
| 25 const UkmSource* GetSource(size_t source_num) const; |
| 26 |
| 27 private: |
| 28 metrics::TestMetricsServiceClient test_metrics_service_client_; |
| 29 |
| 30 DISALLOW_COPY_AND_ASSIGN(TestUkmService); |
| 31 }; |
| 32 |
| 33 // Convenience harness used for testing; creates a TestUkmService and |
| 34 // supplies it with a prefs service with a longer lifespan. |
| 35 class UkmServiceTestingHarness { |
| 36 public: |
| 37 UkmServiceTestingHarness(); |
| 38 virtual ~UkmServiceTestingHarness(); |
| 39 |
| 40 const TestUkmService& test_ukm_service() const { |
| 41 return *test_ukm_service_.get(); |
| 42 } |
| 43 |
| 44 private: |
| 45 TestingPrefServiceSimple test_prefs_; |
| 46 std::unique_ptr<TestUkmService> test_ukm_service_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(UkmServiceTestingHarness); |
| 49 }; |
| 50 |
| 51 } // namespace ukm |
| 52 |
| 53 #endif // COMPONENTS_UKM_TEST_UKM_SERVICE_H_ |
OLD | NEW |