ServiceWorker: Consolidate version manipulation functions in SWProviderContext
[chromium-blink-merge.git] / components / rappor / test_rappor_service.h
blobee437420b87f6844323e8ee94f2f307a46b87a42
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_
6 #define COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_
8 #include <string>
10 #include "base/prefs/testing_pref_service.h"
11 #include "components/rappor/rappor_service.h"
12 #include "components/rappor/test_log_uploader.h"
14 namespace rappor {
16 // This class provides a simple instance that can be instantiated by tests
17 // and examined to check that metrics were recorded. It assumes the most
18 // permissive settings so that any metric can be recorded.
19 class TestRapporService : public RapporService {
20 public:
21 TestRapporService();
23 ~TestRapporService() override;
25 // Gets the number of reports that would be uploaded by this service.
26 // This also clears the internal map of metrics as a biproduct, so if
27 // comparing numbers of reports, the comparison should be from the last time
28 // GetReportsCount() was called (not from the beginning of the test).
29 int GetReportsCount();
31 // Gets the reports proto that would be uploaded.
32 // This clears the internal map of metrics.
33 void GetReports(RapporReports* reports);
35 void set_is_incognito(bool is_incognito) { is_incognito_ = is_incognito; }
37 TestingPrefServiceSimple* test_prefs() { return &test_prefs_; }
39 TestLogUploader* test_uploader() { return test_uploader_; }
41 base::TimeDelta next_rotation() { return next_rotation_; }
43 protected:
44 // Cancels the next call to OnLogInterval.
45 void CancelNextLogRotation() override;
47 // Schedules the next call to OnLogInterval.
48 void ScheduleNextLogRotation(base::TimeDelta interval) override;
50 private:
51 TestingPrefServiceSimple test_prefs_;
53 // Holds a weak ref to the uploader_ object.
54 TestLogUploader* test_uploader_;
56 // The last scheduled log rotation.
57 base::TimeDelta next_rotation_;
59 // Sets this to true to mock incognito state.
60 bool is_incognito_;
62 DISALLOW_COPY_AND_ASSIGN(TestRapporService);
65 } // namespace rappor
67 #endif // COMPONENTS_RAPPOR_TEST_RAPPOR_SERVICE_H_