Bug 705084 - Part A - Add kDefaultRemainingTime and add guards to make sure backends are correct. r=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Thu, 01 Dec 2011 11:49:42 +0100
changeset 82713 fc7d25349c101087deb4a922b6bf8bbc467eece9
parent 82712 7b22bc7c9847c82e3a943b9cb00175540e6c88d8
child 82714 197c9ea3fb2a0391ffd66cb06f2faed89b48ab21
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs705084
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 705084 - Part A - Add kDefaultRemainingTime and add guards to make sure backends are correct. r=sicking
dom/battery/BatteryManager.cpp
dom/battery/Constants.h
dom/battery/test/test_battery_basics.html
--- a/dom/battery/BatteryManager.cpp
+++ b/dom/battery/BatteryManager.cpp
@@ -82,17 +82,17 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetWrapperCache)
 
 NS_IMPL_ADDREF_INHERITED(BatteryManager, nsDOMEventTargetWrapperCache)
 NS_IMPL_RELEASE_INHERITED(BatteryManager, nsDOMEventTargetWrapperCache)
 
 BatteryManager::BatteryManager()
   : mLevel(kDefaultLevel)
   , mCharging(kDefaultCharging)
-  , mRemainingTime(kUnknownRemainingTime)
+  , mRemainingTime(kDefaultRemainingTime)
 {
 }
 
 BatteryManager::~BatteryManager()
 {
   if (mListenerManager) {
     mListenerManager->Disconnect();
   }
@@ -186,16 +186,24 @@ BatteryManager::DispatchTrustedEventToSe
 }
 
 void
 BatteryManager::UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo)
 {
   mLevel = aBatteryInfo.level();
   mCharging = aBatteryInfo.charging();
   mRemainingTime = aBatteryInfo.remainingTime();
+
+  // Add some guards to make sure the values are coherent.
+  if (mLevel == 1.0 && mCharging == true &&
+      mRemainingTime != kDefaultRemainingTime) {
+    mRemainingTime = kDefaultRemainingTime;
+    NS_ERROR("Battery API: When charging and level at 1.0, remaining time "
+             "should be 0. Please fix your backend!");
+  }
 }
 
 void
 BatteryManager::Notify(const hal::BatteryInformation& aBatteryInfo)
 {
   double previousLevel = mLevel;
   bool previousCharging = mCharging;
   double previousRemainingTime = mRemainingTime;
--- a/dom/battery/Constants.h
+++ b/dom/battery/Constants.h
@@ -43,15 +43,16 @@
  * It's not part of BatteryManager.h to prevent those backends to include it.
  */
 namespace mozilla {
 namespace dom {
 namespace battery {
 
   static const double kDefaultLevel         = 1.0;
   static const bool   kDefaultCharging      = true;
+  static const double kDefaultRemainingTime = 0;
   static const double kUnknownRemainingTime = -1;
 
 } // namespace battery
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_battery_Constants_h__
--- a/dom/battery/test/test_battery_basics.html
+++ b/dom/battery/test/test_battery_basics.html
@@ -21,14 +21,14 @@ ok(!("BatteryManager" in window), "Batte
 ok(("MozBatteryManager" in window), "MozBatteryManager should be visible");
 
 ok('mozBattery' in navigator, "navigator.mozBattery should exist");
 
 var battery = navigator.mozBattery;
 is(battery.level, 1.0, "Default battery level should be 1.0");
 is(battery.charging, true, "Default charging value should be true");
 is(battery.dischargingTime, Infinity, "Default dischargingTime should be Inifinity");
-is(battery.chargingTime, Infinity, "Default chargingTime should be Inifinity");
+is(battery.chargingTime, 0, "Default chargingTime should be 0");
 
 </script>
 </pre>
 </body>
 </html>