Chromium Code Reviews| Index: chrome/test/functional/chromeos_battery.py |
| =================================================================== |
| --- chrome/test/functional/chromeos_battery.py (revision 0) |
| +++ chrome/test/functional/chromeos_battery.py (revision 0) |
| @@ -0,0 +1,141 @@ |
| +#!/usr/bin/python |
| +# Copyright (c) 2011 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. |
| + |
| +import logging |
|
dtu
2011/05/27 23:33:43
Unused import. Remove.
scottc
2011/05/31 15:40:21
Done.
|
| +import os |
| +import time |
| + |
| +import pyauto_functional |
|
dtu
2011/05/27 23:33:43
Please say this:
import pyauto_functional # Must
scottc
2011/05/31 15:40:21
Done.
|
| +import pyauto |
| + |
| +from chromeos.power_strip import PowerStrip |
| + |
| +class ChromeosBattery(pyauto.PyUITest): |
| + """Tests ChromeOS Battery Status API. |
| + Preconditions: |
| + 1) Device under test (DUT) is connected to the corporate LAN |
| + LAN via Ethernet-to-USB adapter plugged into one of its |
| + USB ports. |
| + 2) AC power cable is connected to the DUT, and plugged into |
| + the IP controlled Power Switch, outlet #4, located in the |
| + Oyster Bay lab. |
| + 3) Battery is installed in the DUT, and battery is not fully |
| + discharged. |
| + |
| + Battery Info is a dictionary with keys: |
|
dtu
2011/05/27 23:33:43
You don't need to include the entire dictionary in
scottc
2011/05/31 15:40:21
Removed.
|
| + 'battery_is_present': bool |
| + 'line_power_on': bool |
| + if 'battery_is_present': |
| + 'battery_percentage': float (0 ~ 100) |
| + 'battery_fully_charged': bool |
| + if 'line_power_on': |
| + 'battery_time_to_full': int (seconds) |
| + else: |
| + 'battery_time_to_empty': int (seconds) |
| + |
| + When AC power is turn off or on, the battery will take from 2 |
| + to 60 seconds to calculate the time left. While calculating, the |
| + keys 'battery_time_to_full' and 'battery_time_to_empty' are |
| + absent. |
| + """ |
| + |
| + _OUTLET_WITH_BATTERY = '.a4' |
| + _BATTERY_CONFIG_FILE = os.path.join(pyauto.PyUITest.DataDir(), |
| + 'pyauto_private', 'chromeos', 'power', |
| + 'battery_testbed_config') |
| + |
| + def setUp(self): |
| + pyauto.PyUITest.setUp(self) |
| + self.InitPowerStrip() |
| + |
| + |
|
dtu
2011/05/27 23:33:43
One blank line between function definitions inside
scottc
2011/05/31 15:40:21
Done.
|
| + def tearDown(self): |
| + # Leave power outlet On so battery does not discharge |
| + self._power_strip.PowerOn(ChromeosBattery._OUTLET_WITH_BATTERY) |
| + pyauto.PyUITest.tearDown(self) |
| + |
| + |
| + def InitPowerStrip(self): |
| + self.assertTrue( |
| + lambda: os.path.exists(ChromeosBattery._BATTERY_CONFIG_FILE), |
| + msg = 'Power Strip configuration file does not exist.') |
| + power_config = / |
| + pyauto.PyUITest.EvalDataFrom(ChromeosBattery._BATTERY_CONFIG_FILE) |
| + self._power_strip = PowerStrip(power_config['strip_ip']) |
| + |
| + |
| + def WaitUntilBatteryTimeIsCalculated(self): |
| + battery_status = self.GetBatteryInfo() |
| + if battery_status.get('line_power_on'): |
| + time_key = 'battery_time_to_full' |
| + else: |
| + time_key = 'battery_time_to_empty' |
| + return self.WaitUntil(lambda: self.GetBatteryInfo().get(time_key) != None, |
| + timeout=60, |
| + retry_sleep=2) |
|
dtu
2011/05/27 23:33:43
Probably want to shorten the timeout and keep the
scottc
2011/05/31 15:40:21
During testing, I've seen it sometimes take up to
dtu
2011/06/01 01:09:23
Okay, in that case it is fine.
On 2011/05/31 15:4
|
| + |
| + |
| + def testBatteryChargesWhenACisOn(self): |
| + """AC power ON to CrOS device with battery.""" |
| + self._power_strip.PowerOn(ChromeosBattery._OUTLET_WITH_BATTERY) |
| + time.sleep(2) # Wait for swtich to settle |
|
dtu
2011/05/27 23:33:43
switch*
scottc
2011/05/31 15:40:21
Removed.
|
| + |
| + # Get info about charging battery |
| + self.assertTrue(self.WaitUntilBatteryTimeIsCalculated(), |
| + msg='Battery charge time was not calculated') |
| + battery_status = self.GetBatteryInfo() |
| + self.assertTrue(battery_status.get('battery_is_present'), |
| + msg='Battery is not present.') |
| + self.assertTrue(battery_status.get('line_power_on'), |
| + msg='Line power is off.') |
| + self.assertTrue(battery_status.get('battery_time_to_full') >= 0, |
| + msg='Battery charge time is negative.') |
| + |
| + |
| + def testBatteryDischargesWhenACisOff(self): |
| + """AC power OFF to CrOS device with battery.""" |
| + self._power_strip.PowerOff(ChromeosBattery._OUTLET_WITH_BATTERY) |
| + time.sleep(2) # Wait for switch to settle |
|
dtu
2011/05/27 23:33:43
Does it take some time for it to notice that the l
scottc
2011/05/31 15:40:21
Removed.
|
| + |
| + # Get info about discharging battery |
| + self.assertTrue(self.WaitUntilBatteryTimeIsCalculated(), |
| + msg='Battery discharge time was not calculated.') |
| + battery_status = self.GetBatteryInfo() |
| + self.assertTrue(battery_status.get('battery_is_present'), |
| + msg='Battery is not present.') |
| + self.assertFalse(battery_status.get('line_power_on'), |
| + msg='Line power is off.') |
| + self.assertTrue(battery_status.get('battery_time_to_empty') >= 0, |
| + msg='Battery discharge time is negative.') |
| + |
| + |
| + def testBatteryTimesAreDifferent(self): |
| + """Time until full is different than Time until empty""" |
| + # Turn AC Power ON |
| + self._power_strip.PowerOn(ChromeosBattery._OUTLET_WITH_BATTERY) |
| + time.sleep(2) |
| + |
| + # Get charging battery time to full |
| + self.WaitUntilBatteryTimeIsCalculated() |
| + battery_status = self.GetBatteryInfo() |
| + time_to_full = battery_status.get('battery_time_to_full') |
| + |
| + # Turn AC Power OFF |
| + self._power_strip.PowerOff(ChromeosBattery._OUTLET_WITH_BATTERY) |
| + time.sleep(2) |
| + |
| + # Get discharging battery time to empty |
| + self.WaitUntilBatteryTimeIsCalculated() |
| + battery_status = self.GetBatteryInfo() |
| + time_to_empty = battery_status.get('battery_time_to_empty') |
| + |
| + # Compare times |
| + self.assertNotEqual(time_to_full, time_to_empty, |
| + msg='Battery time to full equals time to empty. ' |
| + 'Though very unlikely, this is not impossible. ' |
| + 'If test failed falsely, Kris ows Scott a beer. ') |
|
dtu
2011/05/27 23:33:43
owes*
scottc
2011/05/31 15:40:21
Done.
|
| + |
| +if __name__ == '__main__': |
| + pyauto_functional.Main() |