xref: /aosp_15_r20/external/cronet/base/power_monitor/power_monitor_device_source_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2020 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 #include "base/power_monitor/power_monitor_device_source.h"
6 
7 #if BUILDFLAG(IS_ANDROID)
8 #include <android/api-level.h>
9 #endif
10 
11 #include "base/logging.h"
12 #include "base/power_monitor/power_monitor.h"
13 #include "base/power_monitor/power_monitor_source.h"
14 #include "build/build_config.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 
17 using DeviceThermalState = base::PowerThermalObserver::DeviceThermalState;
18 
19 namespace base {
20 
21 class PowerMonitorDeviceSourceTest : public testing::Test {
22  public:
23   PowerMonitorDeviceSourceTest() = default;
24   ~PowerMonitorDeviceSourceTest() override = default;
25 
GetCurrentThermalState()26   DeviceThermalState GetCurrentThermalState() {
27     return power_monitor_device_source_.GetCurrentThermalState();
28   }
29 
30   PowerMonitorDeviceSource power_monitor_device_source_;
31 };
32 
TEST_F(PowerMonitorDeviceSourceTest,GetCurrentThermalState)33 TEST_F(PowerMonitorDeviceSourceTest, GetCurrentThermalState) {
34   const DeviceThermalState current_state = GetCurrentThermalState();
35 #if BUILDFLAG(IS_MAC)
36   // We cannot make assumptions on |current_state|. Print it out to use the var.
37   DVLOG(1) << PowerMonitorSource::DeviceThermalStateToString(current_state);
38 #elif BUILDFLAG(IS_ANDROID)
39   if (android_get_device_api_level() >= __ANDROID_API_Q__) {
40     EXPECT_NE(current_state, DeviceThermalState::kUnknown);
41   } else {
42     EXPECT_EQ(current_state, DeviceThermalState::kUnknown);
43   }
44 #else
45   EXPECT_EQ(current_state, DeviceThermalState::kUnknown);
46 #endif
47 }
48 
49 }  // namespace base
50