Chromium Code Reviews| Index: components/ukm/test_ukm_service.h |
| diff --git a/components/ukm/test_ukm_service.h b/components/ukm/test_ukm_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e7660b068031ba74460a2d07d66ae84679c2dbec |
| --- /dev/null |
| +++ b/components/ukm/test_ukm_service.h |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_UKM_TEST_UKM_SERVICE_H_ |
| +#define COMPONENTS_UKM_TEST_UKM_SERVICE_H_ |
| + |
| +#include <stddef.h> |
| +#include <memory> |
| + |
| +#include "components/metrics/test_metrics_service_client.h" |
| +#include "components/prefs/testing_pref_service.h" |
| +#include "components/ukm/ukm_pref_names.h" |
| +#include "components/ukm/ukm_service.h" |
| + |
| +namespace ukm { |
| + |
| +// Wraps an UkmService with additional accessors used for testing. |
| +class TestUkmService : public UkmService { |
| + public: |
| + TestUkmService(PrefService* pref_service); |
|
Alexei Svitkine (slow)
2017/01/25 15:35:04
explicit
oystein (OOO til 10th of July)
2017/01/25 18:38:04
Done.
|
| + ~TestUkmService() override; |
| + |
| + size_t sources_count() const { return sources_for_testing().size(); } |
| + const UkmSource* GetSource(size_t source_num) const; |
| + |
| + private: |
| + metrics::TestMetricsServiceClient test_metrics_service_client_; |
| + DISALLOW_COPY_AND_ASSIGN(TestUkmService); |
|
Alexei Svitkine (slow)
2017/01/25 15:35:04
Nit: Add an empty line above this.
oystein (OOO til 10th of July)
2017/01/25 18:38:04
Done.
|
| +}; |
| + |
| +// Convenience harness used for testing; creates a TestUkmService and |
| +// supplies it with a prefs service with a longer lifespan. |
| +class UkmServiceTestingHarness { |
| + public: |
| + UkmServiceTestingHarness(); |
| + virtual ~UkmServiceTestingHarness(); |
| + |
| + TestUkmService* test_ukm_service() const { return test_ukm_service_.get(); } |
|
Alexei Svitkine (slow)
2017/01/25 15:35:04
Return by const& since I assume it can't be null?
oystein (OOO til 10th of July)
2017/01/25 18:38:04
Done.
|
| + |
| + private: |
| + TestingPrefServiceSimple test_prefs_; |
| + std::unique_ptr<TestUkmService> test_ukm_service_; |
| +}; |
|
Alexei Svitkine (slow)
2017/01/25 15:35:04
Nit: DISALLOW_COPY_AND_ASSIGN()?
oystein (OOO til 10th of July)
2017/01/25 18:38:04
Done.
|
| + |
| +} // namespace ukm |
| + |
| +#endif // COMPONENTS_UKM_TEST_UKM_SERVICE_H_ |