Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: content/browser/battery_status/battery_status_manager_linux_unittest.cc

Issue 436683002: Battery Status API: implementation for Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix BUILD.gn Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "content/browser/battery_status/battery_status_manager_linux.h"
6
7 #include "base/values.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace content {
11
12 namespace {
13
14 TEST(BatteryStatusManagerLinuxTest, EmptyDictionary) {
15 base::DictionaryValue dictionary;
16 blink::WebBatteryStatus status;
17 blink::WebBatteryStatus default_status;
18 ComputeWebBatteryStatus(dictionary, status);
19
20 EXPECT_EQ(default_status.charging, status.charging);
21 EXPECT_EQ(default_status.chargingTime, status.chargingTime);
22 EXPECT_EQ(default_status.dischargingTime, status.dischargingTime);
23 EXPECT_EQ(default_status.level, status.level);
24 }
25
26 TEST(BatteryStatusManagerLinuxTest, ChargingHalfFull) {
27 base::DictionaryValue dictionary;
28 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING);
29 dictionary.SetDouble("TimeToFull", 0);
30 dictionary.SetDouble("Percentage", 50);
31
32 blink::WebBatteryStatus status;
33 ComputeWebBatteryStatus(dictionary, status);
34
35 EXPECT_EQ(true, status.charging);
36 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime);
37 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime);
38 EXPECT_EQ(0.5, status.level);
39 }
40
41 TEST(BatteryStatusManagerLinuxTest, ChargingTimeToFull) {
42 base::DictionaryValue dictionary;
43 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING);
44 dictionary.SetDouble("TimeToFull", 100.f);
45 dictionary.SetDouble("Percentage", 1);
46
47 blink::WebBatteryStatus status;
48 ComputeWebBatteryStatus(dictionary, status);
49
50 EXPECT_EQ(true, status.charging);
51 EXPECT_EQ(100, status.chargingTime);
52 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime);
53 EXPECT_EQ(.01, status.level);
54 }
55
56 TEST(BatteryStatusManagerLinuxTest, FullyCharged) {
57 base::DictionaryValue dictionary;
58 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_FULL);
59 dictionary.SetDouble("TimeToFull", 100);
60 dictionary.SetDouble("TimeToEmpty", 200);
61 dictionary.SetDouble("Percentage", 100);
62
63 blink::WebBatteryStatus status;
64 ComputeWebBatteryStatus(dictionary, status);
65
66 EXPECT_EQ(true, status.charging);
67 EXPECT_EQ(0, status.chargingTime);
68 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime);
69 EXPECT_EQ(1, status.level);
70 }
71
72 TEST(BatteryStatusManagerLinuxTest, Discharging) {
73 base::DictionaryValue dictionary;
74 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING);
75 dictionary.SetDouble("TimeToFull", 0);
76 dictionary.SetDouble("TimeToEmpty", 200);
77 dictionary.SetDouble("Percentage", 90);
78
79 blink::WebBatteryStatus status;
80 ComputeWebBatteryStatus(dictionary, status);
81
82 EXPECT_EQ(false, status.charging);
83 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime);
84 EXPECT_EQ(200, status.dischargingTime);
85 EXPECT_EQ(.9, status.level);
86 }
87
88 TEST(BatteryStatusManagerLinuxTest, DischargingTimeToEmptyUnknown) {
89 base::DictionaryValue dictionary;
90 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING);
91 dictionary.SetDouble("TimeToFull", 0);
92 dictionary.SetDouble("TimeToEmpty", 0);
93 dictionary.SetDouble("Percentage", 90);
94
95 blink::WebBatteryStatus status;
96 ComputeWebBatteryStatus(dictionary, status);
97
98 EXPECT_EQ(false, status.charging);
99 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime);
100 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime);
101 EXPECT_EQ(.9, status.level);
102 }
103
104 TEST(BatteryStatusManagerLinuxTest, DeviceStateUnknown) {
105 base::DictionaryValue dictionary;
106 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_UNKNOWN);
107 dictionary.SetDouble("TimeToFull", 0);
108 dictionary.SetDouble("TimeToEmpty", 0);
109 dictionary.SetDouble("Percentage", 50);
110
111 blink::WebBatteryStatus status;
112 ComputeWebBatteryStatus(dictionary, status);
113
114 EXPECT_EQ(true, status.charging);
115 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime);
116 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime);
117 EXPECT_EQ(.5, status.level);
118 }
119
120 TEST(BatteryStatusManagerLinuxTest, DeviceStateEmpty) {
121 base::DictionaryValue dictionary;
122 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_EMPTY);
123 dictionary.SetDouble("TimeToFull", 0);
124 dictionary.SetDouble("TimeToEmpty", 0);
125 dictionary.SetDouble("Percentage", 0);
126
127 blink::WebBatteryStatus status;
128 ComputeWebBatteryStatus(dictionary, status);
129
130 EXPECT_EQ(false, status.charging);
131 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime);
132 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime);
133 EXPECT_EQ(0, status.level);
134 }
135
136 TEST(BatteryStatusManagerLinuxTest, LevelRoundedToThreeSignificantDigits) {
137 base::DictionaryValue dictionary;
138 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING);
139 dictionary.SetDouble("Percentage", 14.36);
140
141 blink::WebBatteryStatus status;
142 ComputeWebBatteryStatus(dictionary, status);
143
144 EXPECT_EQ(false, status.charging);
145 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime);
146 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime);
147 EXPECT_EQ(0.144, status.level);
148 }
149
150 } // namespace
151
152 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698