Commit 1369d34f authored by mlamouri@chromium.org's avatar mlamouri@chromium.org

BatteryStatus: fix chargingTime() to follow the specification.

If the battery status is unknown, the charging time should be
0 instead of Infinity. The reason being that in that case, the
battery status is reflected as a plugged and fully charged battery.

BUG=122593

Review URL: https://codereview.chromium.org/203693003

git-svn-id: svn://svn.chromium.org/blink/trunk@170338 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d54325ae
......@@ -2,7 +2,7 @@ This test prints the default battery status values.
Charging Status: Charging
Charging Time: Infinity
Charging Time: 0
Discharging Time: Infinity
......
......@@ -42,7 +42,7 @@ PASS window.cached_navigator.userAgent is ''
PASS window.cached_navigator.vendor is window.navigator.vendor
PASS window.cached_navigator.vendorSub is ''
FAIL window.cached_navigator_battery.charging should be false. Was true.
FAIL window.cached_navigator_battery.chargingTime should be 0. Was Infinity.
PASS window.cached_navigator_battery.chargingTime is 0
FAIL window.cached_navigator_battery.dischargingTime should be 0. Was Infinity.
FAIL window.cached_navigator_battery.level should be 0. Was 1.
PASS window.cached_navigator_battery.onchargingchange is null
......
......@@ -42,7 +42,7 @@ PASS window.cached_navigator.userAgent is ''
PASS window.cached_navigator.vendor is window.navigator.vendor
PASS window.cached_navigator.vendorSub is ''
FAIL window.cached_navigator_battery.charging should be false. Was true.
FAIL window.cached_navigator_battery.chargingTime should be 0. Was Infinity.
PASS window.cached_navigator_battery.chargingTime is 0
FAIL window.cached_navigator_battery.dischargingTime should be 0. Was Infinity.
FAIL window.cached_navigator_battery.level should be 0. Was 1.
PASS window.cached_navigator_battery.onchargingchange is null
......
......@@ -42,7 +42,7 @@ PASS window.cached_navigator.userAgent is ''
PASS window.cached_navigator.vendor is window.navigator.vendor
PASS window.cached_navigator.vendorSub is ''
FAIL window.cached_navigator_battery.charging should be false. Was true.
FAIL window.cached_navigator_battery.chargingTime should be 0. Was Infinity.
PASS window.cached_navigator_battery.chargingTime is 0
FAIL window.cached_navigator_battery.dischargingTime should be 0. Was Infinity.
FAIL window.cached_navigator_battery.level should be 0. Was 1.
PASS window.cached_navigator_battery.onchargingchange is null
......
......@@ -40,7 +40,7 @@ PASS childWindow.navigator.appCodeName is window.navigator.appCodeName
PASS childWindow.navigator.appName is window.navigator.appName
PASS childWindow.navigator.appVersion is ''
FAIL childWindow.navigator.battery.charging should be false. Was true.
FAIL childWindow.navigator.battery.chargingTime should be 0. Was Infinity.
PASS childWindow.navigator.battery.chargingTime is 0
FAIL childWindow.navigator.battery.dischargingTime should be 0. Was Infinity.
FAIL childWindow.navigator.battery.level should be 0. Was 1.
PASS childWindow.navigator.battery.onchargingchange is null
......
......@@ -34,9 +34,16 @@ bool BatteryManager::charging()
double BatteryManager::chargingTime()
{
if (!m_batteryStatus || !m_batteryStatus->charging())
if (!m_batteryStatus)
return 0;
if (!m_batteryStatus->charging())
return std::numeric_limits<double>::infinity();
// The spec requires that if level == 1.0, chargingTime == 0 but this has to
// be implement by the backend. Adding this assert will help enforcing it.
ASSERT(level() != 1.0 && m_batteryStatus->chargingTime() == 0.0);
return m_batteryStatus->chargingTime();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment