| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_RAPPOR_TEST_RAPPOR_SERVICE_H_ | 5 #ifndef COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_ |
| 6 #define COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_ | 6 #define COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "components/prefs/testing_pref_service.h" | 15 #include "components/prefs/testing_pref_service.h" |
| 16 #include "components/rappor/rappor_service.h" | 16 #include "components/rappor/rappor_service_impl.h" |
| 17 #include "components/rappor/test_log_uploader.h" | 17 #include "components/rappor/test_log_uploader.h" |
| 18 | 18 |
| 19 namespace rappor { | 19 namespace rappor { |
| 20 | 20 |
| 21 // This class duplicates the functionality of Sample, with a cohort initialized | 21 // This class duplicates the functionality of Sample, with a cohort initialized |
| 22 // always to 0. It keeps a shadow object around which copies every flag field | 22 // always to 0. It keeps a shadow object around which copies every flag field |
| 23 // and string field set on the Sample. | 23 // and string field set on the Sample. |
| 24 class TestSample : public Sample { | 24 class TestSample : public Sample { |
| 25 public: | 25 public: |
| 26 TestSample(RapporType type); | 26 TestSample(RapporType type); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 44 | 44 |
| 45 Shadow GetShadow() { return shadow_; } | 45 Shadow GetShadow() { return shadow_; } |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 Shadow shadow_; | 48 Shadow shadow_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // This class provides a simple instance that can be instantiated by tests | 51 // This class provides a simple instance that can be instantiated by tests |
| 52 // and examined to check that metrics were recorded. It assumes the most | 52 // and examined to check that metrics were recorded. It assumes the most |
| 53 // permissive settings so that any metric can be recorded. | 53 // permissive settings so that any metric can be recorded. |
| 54 class TestRapporService : public RapporService { | 54 class TestRapporServiceImpl : public RapporServiceImpl { |
| 55 public: | 55 public: |
| 56 TestRapporService(); | 56 TestRapporServiceImpl(); |
| 57 | 57 |
| 58 ~TestRapporService() override; | 58 ~TestRapporServiceImpl() override; |
| 59 | 59 |
| 60 // RapporService: | 60 // RapporServiceImpl: |
| 61 std::unique_ptr<Sample> CreateSample(RapporType type) override; | 61 std::unique_ptr<Sample> CreateSample(RapporType type) override; |
| 62 void RecordSampleObj(const std::string& metric_name, | |
| 63 std::unique_ptr<Sample> sample) override; | |
| 64 void RecordSample(const std::string& metric_name, | 62 void RecordSample(const std::string& metric_name, |
| 65 RapporType type, | 63 std::unique_ptr<Sample> sample) override; |
| 66 const std::string& sample) override; | 64 void RecordSampleString(const std::string& metric_name, |
| 65 RapporType type, |
| 66 const std::string& sample) override; |
| 67 | 67 |
| 68 // Gets the number of reports that would be uploaded by this service. | 68 // Gets the number of reports that would be uploaded by this service. |
| 69 // This also clears the internal map of metrics as a biproduct, so if | 69 // This also clears the internal map of metrics as a biproduct, so if |
| 70 // comparing numbers of reports, the comparison should be from the last time | 70 // comparing numbers of reports, the comparison should be from the last time |
| 71 // GetReportsCount() was called (not from the beginning of the test). | 71 // GetReportsCount() was called (not from the beginning of the test). |
| 72 int GetReportsCount(); | 72 int GetReportsCount(); |
| 73 | 73 |
| 74 // Gets the reports proto that would be uploaded. | 74 // Gets the reports proto that would be uploaded. |
| 75 // This clears the internal map of metrics. | 75 // This clears the internal map of metrics. |
| 76 void GetReports(RapporReports* reports); | 76 void GetReports(RapporReports* reports); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 122 |
| 123 // Holds a weak ref to the uploader_ object. | 123 // Holds a weak ref to the uploader_ object. |
| 124 TestLogUploader* test_uploader_; | 124 TestLogUploader* test_uploader_; |
| 125 | 125 |
| 126 // The last scheduled log rotation. | 126 // The last scheduled log rotation. |
| 127 base::TimeDelta next_rotation_; | 127 base::TimeDelta next_rotation_; |
| 128 | 128 |
| 129 // Sets this to true to mock incognito state. | 129 // Sets this to true to mock incognito state. |
| 130 bool is_incognito_; | 130 bool is_incognito_; |
| 131 | 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(TestRapporService); | 132 DISALLOW_COPY_AND_ASSIGN(TestRapporServiceImpl); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 } // namespace rappor | 135 } // namespace rappor |
| 136 | 136 |
| 137 #endif // COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_ | 137 #endif // COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_ |
| OLD | NEW |