OLD | NEW |
---|---|
(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 EXPECT_EQ(default_status.charging, status.charging); | |
20 EXPECT_EQ(default_status.chargingTime, status.chargingTime); | |
21 EXPECT_EQ(default_status.dischargingTime, status.dischargingTime); | |
22 EXPECT_EQ(default_status.level, status.level); | |
23 } | |
24 | |
25 TEST(BatteryStatusManagerLinuxTest, ChargingHalfFull) { | |
26 base::DictionaryValue dictionary; | |
27 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING); | |
28 dictionary.SetDouble("TimeToFull", 0); | |
29 dictionary.SetDouble("Percentage", 50); | |
30 blink::WebBatteryStatus status; | |
31 ComputeWebBatteryStatus(dictionary, status); | |
32 EXPECT_EQ(true, status.charging); | |
33 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); | |
34 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); | |
35 EXPECT_EQ(0.5, status.level); | |
36 } | |
37 | |
38 TEST(BatteryStatusManagerLinuxTest, ChargingTimeToFull) { | |
39 base::DictionaryValue dictionary; | |
40 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING); | |
41 dictionary.SetDouble("TimeToFull", 100.f); | |
42 dictionary.SetDouble("Percentage", 1); | |
43 blink::WebBatteryStatus status; | |
44 ComputeWebBatteryStatus(dictionary, status); | |
45 EXPECT_EQ(true, status.charging); | |
46 EXPECT_EQ(100, status.chargingTime); | |
47 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); | |
48 EXPECT_EQ(.01, status.level); | |
49 } | |
50 | |
51 TEST(BatteryStatusManagerLinuxTest, FullyCharged) { | |
52 base::DictionaryValue dictionary; | |
53 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_FULL); | |
54 dictionary.SetDouble("TimeToFull", 100); | |
55 dictionary.SetDouble("TimeToEmpty", 200); | |
56 dictionary.SetDouble("Percentage", 100); | |
57 blink::WebBatteryStatus status; | |
58 ComputeWebBatteryStatus(dictionary, status); | |
59 EXPECT_EQ(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); | |
63 } | |
64 | |
65 TEST(BatteryStatusManagerLinuxTest, Discharging) { | |
66 base::DictionaryValue dictionary; | |
67 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING); | |
68 dictionary.SetDouble("TimeToFull", 0); | |
69 dictionary.SetDouble("TimeToEmpty", 200); | |
70 dictionary.SetDouble("Percentage", 90); | |
mlamouri (slow - plz ping)
2014/08/07 16:17:05
Could you add a similar test with no TimeToEmpty.
timvolodine
2014/08/08 18:46:45
Done.
| |
71 blink::WebBatteryStatus status; | |
72 ComputeWebBatteryStatus(dictionary, status); | |
73 EXPECT_EQ(false, status.charging); | |
74 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); | |
75 EXPECT_EQ(200, status.dischargingTime); | |
76 EXPECT_EQ(.9, status.level); | |
77 } | |
78 | |
mlamouri (slow - plz ping)
2014/08/07 16:17:05
Could you add some tests for STATE_UNKWNOWN and ST
timvolodine
2014/08/08 18:46:45
Done.
| |
79 } // namespace | |
80 | |
mlamouri (slow - plz ping)
2014/08/07 16:17:05
Also, it would be greate to add some empty lines i
timvolodine
2014/08/08 18:46:45
Done.
| |
81 } // namespace content | |
OLD | NEW |