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

Side by Side Diff: device/battery/battery_status_manager_linux_unittest.cc

Issue 457933002: Replace Chrome IPC with Mojo IPC for querying BatteryStatus service Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/battery_status/battery_status_manager_linux.h" 5 #include "device/battery/battery_status_manager_linux.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace content { 10 namespace device {
11 11
12 namespace { 12 namespace {
13 13
14 TEST(BatteryStatusManagerLinuxTest, EmptyDictionary) { 14 TEST(BatteryStatusManagerLinuxTest, EmptyDictionary) {
15 base::DictionaryValue dictionary; 15 base::DictionaryValue dictionary;
16 blink::WebBatteryStatus default_status; 16 BatteryStatus default_status;
17 blink::WebBatteryStatus status = ComputeWebBatteryStatus(dictionary); 17 BatteryStatus status = ComputeWebBatteryStatus(dictionary);
18 18
19 EXPECT_EQ(default_status.charging, status.charging); 19 EXPECT_EQ(default_status.charging, status.charging);
20 EXPECT_EQ(default_status.chargingTime, status.chargingTime); 20 EXPECT_EQ(default_status.charging_time, status.charging_time);
21 EXPECT_EQ(default_status.dischargingTime, status.dischargingTime); 21 EXPECT_EQ(default_status.discharging_time, status.discharging_time);
22 EXPECT_EQ(default_status.level, status.level); 22 EXPECT_EQ(default_status.level, status.level);
23 } 23 }
24 24
25 TEST(BatteryStatusManagerLinuxTest, ChargingHalfFull) { 25 TEST(BatteryStatusManagerLinuxTest, ChargingHalfFull) {
26 base::DictionaryValue dictionary; 26 base::DictionaryValue dictionary;
27 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING); 27 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING);
28 dictionary.SetDouble("TimeToFull", 0); 28 dictionary.SetDouble("TimeToFull", 0);
29 dictionary.SetDouble("Percentage", 50); 29 dictionary.SetDouble("Percentage", 50);
30 30
31 blink::WebBatteryStatus status = ComputeWebBatteryStatus(dictionary); 31 BatteryStatus status = ComputeWebBatteryStatus(dictionary);
32 32
33 EXPECT_TRUE(status.charging); 33 EXPECT_TRUE(status.charging);
34 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); 34 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.charging_time);
35 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); 35 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.discharging_time);
36 EXPECT_EQ(0.5, status.level); 36 EXPECT_EQ(0.5, status.level);
37 } 37 }
38 38
39 TEST(BatteryStatusManagerLinuxTest, ChargingTimeToFull) { 39 TEST(BatteryStatusManagerLinuxTest, ChargingTimeToFull) {
40 base::DictionaryValue dictionary; 40 base::DictionaryValue dictionary;
41 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING); 41 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING);
42 dictionary.SetDouble("TimeToFull", 100.f); 42 dictionary.SetDouble("TimeToFull", 100.f);
43 dictionary.SetDouble("Percentage", 1); 43 dictionary.SetDouble("Percentage", 1);
44 44
45 blink::WebBatteryStatus status = ComputeWebBatteryStatus(dictionary); 45 BatteryStatus status = ComputeWebBatteryStatus(dictionary);
46 46
47 EXPECT_TRUE(status.charging); 47 EXPECT_TRUE(status.charging);
48 EXPECT_EQ(100, status.chargingTime); 48 EXPECT_EQ(100, status.charging_time);
49 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); 49 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.discharging_time);
50 EXPECT_EQ(.01, status.level); 50 EXPECT_EQ(.01, status.level);
51 } 51 }
52 52
53 TEST(BatteryStatusManagerLinuxTest, FullyCharged) { 53 TEST(BatteryStatusManagerLinuxTest, FullyCharged) {
54 base::DictionaryValue dictionary; 54 base::DictionaryValue dictionary;
55 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_FULL); 55 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_FULL);
56 dictionary.SetDouble("TimeToFull", 100); 56 dictionary.SetDouble("TimeToFull", 100);
57 dictionary.SetDouble("TimeToEmpty", 200); 57 dictionary.SetDouble("TimeToEmpty", 200);
58 dictionary.SetDouble("Percentage", 100); 58 dictionary.SetDouble("Percentage", 100);
59 59
60 blink::WebBatteryStatus status = ComputeWebBatteryStatus(dictionary); 60 BatteryStatus status = ComputeWebBatteryStatus(dictionary);
61 61
62 EXPECT_TRUE(status.charging); 62 EXPECT_TRUE(status.charging);
63 EXPECT_EQ(0, status.chargingTime); 63 EXPECT_EQ(0, status.charging_time);
64 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); 64 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.discharging_time);
65 EXPECT_EQ(1, status.level); 65 EXPECT_EQ(1, status.level);
66 } 66 }
67 67
68 TEST(BatteryStatusManagerLinuxTest, Discharging) { 68 TEST(BatteryStatusManagerLinuxTest, Discharging) {
69 base::DictionaryValue dictionary; 69 base::DictionaryValue dictionary;
70 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING); 70 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING);
71 dictionary.SetDouble("TimeToFull", 0); 71 dictionary.SetDouble("TimeToFull", 0);
72 dictionary.SetDouble("TimeToEmpty", 200); 72 dictionary.SetDouble("TimeToEmpty", 200);
73 dictionary.SetDouble("Percentage", 90); 73 dictionary.SetDouble("Percentage", 90);
74 74
75 blink::WebBatteryStatus status = ComputeWebBatteryStatus(dictionary); 75 BatteryStatus status = ComputeWebBatteryStatus(dictionary);
76 76
77 EXPECT_FALSE(status.charging); 77 EXPECT_FALSE(status.charging);
78 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); 78 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.charging_time);
79 EXPECT_EQ(200, status.dischargingTime); 79 EXPECT_EQ(200, status.discharging_time);
80 EXPECT_EQ(.9, status.level); 80 EXPECT_EQ(.9, status.level);
81 } 81 }
82 82
83 TEST(BatteryStatusManagerLinuxTest, DischargingTimeToEmptyUnknown) { 83 TEST(BatteryStatusManagerLinuxTest, DischargingTimeToEmptyUnknown) {
84 base::DictionaryValue dictionary; 84 base::DictionaryValue dictionary;
85 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING); 85 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING);
86 dictionary.SetDouble("TimeToFull", 0); 86 dictionary.SetDouble("TimeToFull", 0);
87 dictionary.SetDouble("TimeToEmpty", 0); 87 dictionary.SetDouble("TimeToEmpty", 0);
88 dictionary.SetDouble("Percentage", 90); 88 dictionary.SetDouble("Percentage", 90);
89 89
90 blink::WebBatteryStatus status = ComputeWebBatteryStatus(dictionary); 90 BatteryStatus status = ComputeWebBatteryStatus(dictionary);
91 91
92 EXPECT_FALSE(status.charging); 92 EXPECT_FALSE(status.charging);
93 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); 93 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.charging_time);
94 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); 94 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.discharging_time);
95 EXPECT_EQ(.9, status.level); 95 EXPECT_EQ(.9, status.level);
96 } 96 }
97 97
98 TEST(BatteryStatusManagerLinuxTest, DeviceStateUnknown) { 98 TEST(BatteryStatusManagerLinuxTest, DeviceStateUnknown) {
99 base::DictionaryValue dictionary; 99 base::DictionaryValue dictionary;
100 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_UNKNOWN); 100 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_UNKNOWN);
101 dictionary.SetDouble("TimeToFull", 0); 101 dictionary.SetDouble("TimeToFull", 0);
102 dictionary.SetDouble("TimeToEmpty", 0); 102 dictionary.SetDouble("TimeToEmpty", 0);
103 dictionary.SetDouble("Percentage", 50); 103 dictionary.SetDouble("Percentage", 50);
104 104
105 blink::WebBatteryStatus status = ComputeWebBatteryStatus(dictionary); 105 BatteryStatus status = ComputeWebBatteryStatus(dictionary);
106 106
107 EXPECT_TRUE(status.charging); 107 EXPECT_TRUE(status.charging);
108 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); 108 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.charging_time);
109 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); 109 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.discharging_time);
110 EXPECT_EQ(.5, status.level); 110 EXPECT_EQ(.5, status.level);
111 } 111 }
112 112
113 TEST(BatteryStatusManagerLinuxTest, DeviceStateEmpty) { 113 TEST(BatteryStatusManagerLinuxTest, DeviceStateEmpty) {
114 base::DictionaryValue dictionary; 114 base::DictionaryValue dictionary;
115 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_EMPTY); 115 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_EMPTY);
116 dictionary.SetDouble("TimeToFull", 0); 116 dictionary.SetDouble("TimeToFull", 0);
117 dictionary.SetDouble("TimeToEmpty", 0); 117 dictionary.SetDouble("TimeToEmpty", 0);
118 dictionary.SetDouble("Percentage", 0); 118 dictionary.SetDouble("Percentage", 0);
119 119
120 blink::WebBatteryStatus status = ComputeWebBatteryStatus(dictionary); 120 BatteryStatus status = ComputeWebBatteryStatus(dictionary);
121 121
122 EXPECT_FALSE(status.charging); 122 EXPECT_FALSE(status.charging);
123 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); 123 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.charging_time);
124 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); 124 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.discharging_time);
125 EXPECT_EQ(0, status.level); 125 EXPECT_EQ(0, status.level);
126 } 126 }
127 127
128 TEST(BatteryStatusManagerLinuxTest, LevelRoundedToThreeSignificantDigits) { 128 TEST(BatteryStatusManagerLinuxTest, LevelRoundedToThreeSignificantDigits) {
129 base::DictionaryValue dictionary; 129 base::DictionaryValue dictionary;
130 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING); 130 dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING);
131 dictionary.SetDouble("Percentage", 14.56); 131 dictionary.SetDouble("Percentage", 14.56);
132 132
133 blink::WebBatteryStatus status = ComputeWebBatteryStatus(dictionary); 133 BatteryStatus status = ComputeWebBatteryStatus(dictionary);
134 134
135 EXPECT_FALSE(status.charging); 135 EXPECT_FALSE(status.charging);
136 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); 136 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.charging_time);
137 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); 137 EXPECT_EQ(std::numeric_limits<double>::infinity(), status.discharging_time);
138 EXPECT_EQ(0.15, status.level); 138 EXPECT_EQ(0.15, status.level);
139 } 139 }
140 140
141 } // namespace 141 } // namespace
142 142
143 } // namespace content 143 } // namespace device
OLDNEW
« no previous file with comments | « device/battery/battery_status_manager_linux.cc ('k') | device/battery/battery_status_manager_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698