xref: /aosp_15_r20/external/cronet/base/test/power_monitor_test_utils.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2022 The Chromium Authors
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 BASE_TEST_POWER_MONITOR_TEST_UTILS_H_
6 #define BASE_TEST_POWER_MONITOR_TEST_UTILS_H_
7 
8 #include <optional>
9 
10 #include "base/functional/callback.h"
11 #include "base/power_monitor/battery_level_provider.h"
12 #include "base/power_monitor/sampling_event_source.h"
13 
14 namespace base::test {
15 
16 class TestSamplingEventSource : public SamplingEventSource {
17  public:
18   TestSamplingEventSource();
19   ~TestSamplingEventSource() override;
20 
21   bool Start(SamplingEventCallback callback) override;
22 
23   void SimulateEvent();
24 
25  private:
26   SamplingEventCallback sampling_event_callback_;
27 };
28 
29 class TestBatteryLevelProvider : public base::BatteryLevelProvider {
30  public:
31   TestBatteryLevelProvider();
32   void GetBatteryState(
33       base::OnceCallback<
34           void(const std::optional<base::BatteryLevelProvider::BatteryState>&)>
35           callback) override;
36 
37   void SetBatteryState(
38       std::optional<base::BatteryLevelProvider::BatteryState> battery_state);
39 
40   static base::BatteryLevelProvider::BatteryState CreateBatteryState(
41       int battery_count = 1,
42       bool is_external_power_connected = false,
43       int charge_percent = 100);
44 
45  private:
46   std::optional<base::BatteryLevelProvider::BatteryState> battery_state_;
47 };
48 
49 }  // namespace base::test
50 
51 #endif  // BASE_TEST_POWER_MONITOR_TEST_UTILS_H_
52