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 #include "content/browser/battery_status/battery_status_manager_win.h"
7 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(BatteryStatusManagerWinTest
, ACLineStatusOffline
) {
14 SYSTEM_POWER_STATUS win_status
;
15 win_status
.ACLineStatus
= WIN_AC_LINE_STATUS_OFFLINE
;
16 win_status
.BatteryLifePercent
= 100;
17 win_status
.BatteryLifeTime
= 200;
19 blink::WebBatteryStatus status
= ComputeWebBatteryStatus(win_status
);
20 EXPECT_FALSE(status
.charging
);
21 EXPECT_EQ(std::numeric_limits
<double>::infinity(), status
.chargingTime
);
22 EXPECT_EQ(200, status
.dischargingTime
);
23 EXPECT_EQ(1, status
.level
);
26 TEST(BatteryStatusManagerWinTest
, ACLineStatusOfflineDischargingTimeUnknown
) {
27 SYSTEM_POWER_STATUS win_status
;
28 win_status
.ACLineStatus
= WIN_AC_LINE_STATUS_OFFLINE
;
29 win_status
.BatteryLifePercent
= 100;
30 win_status
.BatteryLifeTime
= (DWORD
)-1;
32 blink::WebBatteryStatus status
= ComputeWebBatteryStatus(win_status
);
33 EXPECT_FALSE(status
.charging
);
34 EXPECT_EQ(std::numeric_limits
<double>::infinity(), status
.chargingTime
);
35 EXPECT_EQ(std::numeric_limits
<double>::infinity(), status
.dischargingTime
);
36 EXPECT_EQ(1, status
.level
);
39 TEST(BatteryStatusManagerWinTest
, ACLineStatusOnline
) {
40 SYSTEM_POWER_STATUS win_status
;
41 win_status
.ACLineStatus
= WIN_AC_LINE_STATUS_ONLINE
;
42 win_status
.BatteryLifePercent
= 50;
43 win_status
.BatteryLifeTime
= 200;
45 blink::WebBatteryStatus status
= ComputeWebBatteryStatus(win_status
);
46 EXPECT_TRUE(status
.charging
);
47 EXPECT_EQ(std::numeric_limits
<double>::infinity(), status
.chargingTime
);
48 EXPECT_EQ(std::numeric_limits
<double>::infinity(), status
.dischargingTime
);
49 EXPECT_EQ(.5, status
.level
);
52 TEST(BatteryStatusManagerWinTest
, ACLineStatusOnlineFullBattery
) {
53 SYSTEM_POWER_STATUS win_status
;
54 win_status
.ACLineStatus
= WIN_AC_LINE_STATUS_ONLINE
;
55 win_status
.BatteryLifePercent
= 100;
56 win_status
.BatteryLifeTime
= 200;
58 blink::WebBatteryStatus status
= ComputeWebBatteryStatus(win_status
);
59 EXPECT_TRUE(status
.charging
);
60 EXPECT_EQ(0, status
.chargingTime
);
61 EXPECT_EQ(std::numeric_limits
<double>::infinity(), status
.dischargingTime
);
62 EXPECT_EQ(1, status
.level
);
65 TEST(BatteryStatusManagerWinTest
, ACLineStatusUnknown
) {
66 SYSTEM_POWER_STATUS win_status
;
67 win_status
.ACLineStatus
= WIN_AC_LINE_STATUS_UNKNOWN
;
68 win_status
.BatteryLifePercent
= 50;
69 win_status
.BatteryLifeTime
= 200;
71 blink::WebBatteryStatus status
= ComputeWebBatteryStatus(win_status
);
72 EXPECT_TRUE(status
.charging
);
73 EXPECT_EQ(std::numeric_limits
<double>::infinity(), status
.chargingTime
);
74 EXPECT_EQ(std::numeric_limits
<double>::infinity(), status
.dischargingTime
);
75 EXPECT_EQ(.5, status
.level
);
80 } // namespace content