Chromium Code Reviews| Index: content/browser/battery_status/battery_status_manager_linux_unittest.cc | 
| diff --git a/content/browser/battery_status/battery_status_manager_linux_unittest.cc b/content/browser/battery_status/battery_status_manager_linux_unittest.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..57ff0a04c5288424b09a055018a49a61ffe5a4ed | 
| --- /dev/null | 
| +++ b/content/browser/battery_status/battery_status_manager_linux_unittest.cc | 
| @@ -0,0 +1,81 @@ | 
| +// Copyright 2014 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "content/browser/battery_status/battery_status_manager_linux.h" | 
| + | 
| +#include "base/values.h" | 
| +#include "testing/gtest/include/gtest/gtest.h" | 
| + | 
| +namespace content { | 
| + | 
| +namespace { | 
| + | 
| +TEST(BatteryStatusManagerLinuxTest, EmptyDictionary) { | 
| + base::DictionaryValue dictionary; | 
| + blink::WebBatteryStatus status; | 
| + blink::WebBatteryStatus default_status; | 
| + ComputeWebBatteryStatus(dictionary, status); | 
| + EXPECT_EQ(default_status.charging, status.charging); | 
| + EXPECT_EQ(default_status.chargingTime, status.chargingTime); | 
| + EXPECT_EQ(default_status.dischargingTime, status.dischargingTime); | 
| + EXPECT_EQ(default_status.level, status.level); | 
| +} | 
| + | 
| +TEST(BatteryStatusManagerLinuxTest, ChargingHalfFull) { | 
| + base::DictionaryValue dictionary; | 
| + dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING); | 
| + dictionary.SetDouble("TimeToFull", 0); | 
| + dictionary.SetDouble("Percentage", 50); | 
| + blink::WebBatteryStatus status; | 
| + ComputeWebBatteryStatus(dictionary, status); | 
| + EXPECT_EQ(true, status.charging); | 
| + EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); | 
| + EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); | 
| + EXPECT_EQ(0.5, status.level); | 
| +} | 
| + | 
| +TEST(BatteryStatusManagerLinuxTest, ChargingTimeToFull) { | 
| + base::DictionaryValue dictionary; | 
| + dictionary.SetDouble("State", UPOWER_DEVICE_STATE_CHARGING); | 
| + dictionary.SetDouble("TimeToFull", 100.f); | 
| + dictionary.SetDouble("Percentage", 1); | 
| + blink::WebBatteryStatus status; | 
| + ComputeWebBatteryStatus(dictionary, status); | 
| + EXPECT_EQ(true, status.charging); | 
| + EXPECT_EQ(100, status.chargingTime); | 
| + EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); | 
| + EXPECT_EQ(.01, status.level); | 
| +} | 
| + | 
| +TEST(BatteryStatusManagerLinuxTest, FullyCharged) { | 
| + base::DictionaryValue dictionary; | 
| + dictionary.SetDouble("State", UPOWER_DEVICE_STATE_FULL); | 
| + dictionary.SetDouble("TimeToFull", 100); | 
| + dictionary.SetDouble("TimeToEmpty", 200); | 
| + dictionary.SetDouble("Percentage", 100); | 
| + blink::WebBatteryStatus status; | 
| + ComputeWebBatteryStatus(dictionary, status); | 
| + EXPECT_EQ(true, status.charging); | 
| + EXPECT_EQ(0, status.chargingTime); | 
| + EXPECT_EQ(std::numeric_limits<double>::infinity(), status.dischargingTime); | 
| + EXPECT_EQ(1, status.level); | 
| +} | 
| + | 
| +TEST(BatteryStatusManagerLinuxTest, Discharging) { | 
| + base::DictionaryValue dictionary; | 
| + dictionary.SetDouble("State", UPOWER_DEVICE_STATE_DISCHARGING); | 
| + dictionary.SetDouble("TimeToFull", 0); | 
| + dictionary.SetDouble("TimeToEmpty", 200); | 
| + 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.
 
 | 
| + blink::WebBatteryStatus status; | 
| + ComputeWebBatteryStatus(dictionary, status); | 
| + EXPECT_EQ(false, status.charging); | 
| + EXPECT_EQ(std::numeric_limits<double>::infinity(), status.chargingTime); | 
| + EXPECT_EQ(200, status.dischargingTime); | 
| + EXPECT_EQ(.9, status.level); | 
| +} | 
| + | 
| 
 
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.
 
 | 
| +} // namespace | 
| + | 
| 
 
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.
 
 | 
| +} // namespace content |