| 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 std::map<int32_t, std::unique_ptr<UkmSource>>& GetSources() const; | |
| 26 const UkmSource* GetSourceForUrl(const char* url) const; | |
| 27 const UkmSource* GetSourceForSourceId(int32_t source_id) const; | |
| 28 | |
| 29 size_t entries_count() const { return entries_for_testing().size(); } | |
| 30 const UkmEntry* GetEntry(size_t entry_num) const; | |
| 31 const UkmEntry* GetEntryForEntryName(const char* entry_name) const; | |
| 32 | |
| 33 private: | |
| 34 metrics::TestMetricsServiceClient test_metrics_service_client_; | |
| 35 | |
| 36 DISALLOW_COPY_AND_ASSIGN(TestUkmService); | |
| 37 }; | |
| 38 | |
| 39 // Convenience harness used for testing; creates a TestUkmService and | |
| 40 // supplies it with a prefs service with a longer lifespan. | |
| 41 class UkmServiceTestingHarness { | |
| 42 public: | |
| 43 UkmServiceTestingHarness(); | |
| 44 virtual ~UkmServiceTestingHarness(); | |
| 45 | |
| 46 TestUkmService* test_ukm_service() { return test_ukm_service_.get(); } | |
| 47 | |
| 48 private: | |
| 49 TestingPrefServiceSimple test_prefs_; | |
| 50 std::unique_ptr<TestUkmService> test_ukm_service_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(UkmServiceTestingHarness); | |
| 53 }; | |
| 54 | |
| 55 } // namespace ukm | |
| 56 | |
| 57 #endif // COMPONENTS_UKM_TEST_UKM_SERVICE_H_ | |
| OLD | NEW |