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

Side by Side Diff: build/android/pylib/device/device_utils_test.py

Issue 963093002: [Android] Check for AC and wireless charging when determining charging state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Unit tests for the contents of device_utils.py (mostly DeviceUtils). 7 Unit tests for the contents of device_utils.py (mostly DeviceUtils).
8 """ 8 """
9 9
10 # pylint: disable=C0321 10 # pylint: disable=C0321
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 self.device.GetBatteryInfo()) 1404 self.device.GetBatteryInfo())
1405 1405
1406 1406
1407 def testGetBatteryInfo_nothing(self): 1407 def testGetBatteryInfo_nothing(self):
1408 with self.assertCall( 1408 with self.assertCall(
1409 self.call.device.RunShellCommand( 1409 self.call.device.RunShellCommand(
1410 ['dumpsys', 'battery'], check_return=True), []): 1410 ['dumpsys', 'battery'], check_return=True), []):
1411 self.assertEquals({}, self.device.GetBatteryInfo()) 1411 self.assertEquals({}, self.device.GetBatteryInfo())
1412 1412
1413 1413
1414 class DeviceUtilsGetUsbChargingTest(DeviceUtilsTest): 1414 class DeviceUtilsGetChargingTest(DeviceUtilsTest):
1415 def testGetUsbCharging_true(self): 1415 def testGetCharging_usb(self):
1416 with self.assertCall( 1416 with self.assertCall(
1417 self.call.device.GetBatteryInfo(), {'USB powered': 'true'}): 1417 self.call.device.GetBatteryInfo(), {'USB powered': 'true'}):
1418 self.assertTrue(self.device.GetUsbCharging()) 1418 self.assertTrue(self.device.GetCharging())
1419 1419
1420 def testGetUsbCharging_false(self): 1420 def testGetCharging_usbFalse(self):
1421 with self.assertCall( 1421 with self.assertCall(
1422 self.call.device.GetBatteryInfo(), {'USB powered': 'false'}): 1422 self.call.device.GetBatteryInfo(), {'USB powered': 'false'}):
1423 self.assertFalse(self.device.GetUsbCharging()) 1423 self.assertFalse(self.device.GetCharging())
1424 1424
1425 def testGetUsbCharging_unknown(self): 1425 def testGetCharging_ac(self):
1426 with self.assertCall( 1426 with self.assertCall(
1427 self.call.device.GetBatteryInfo(), {'AC powered': 'true'}): 1427 self.call.device.GetBatteryInfo(), {'AC powered': 'true'}):
1428 self.assertFalse(self.device.GetUsbCharging()) 1428 self.assertTrue(self.device.GetCharging())
1429
1430 def testGetCharging_wireless(self):
1431 with self.assertCall(
1432 self.call.device.GetBatteryInfo(), {'Wireless powered': 'true'}):
1433 self.assertTrue(self.device.GetCharging())
1434
1435 def testGetCharging_unknown(self):
1436 with self.assertCall(
1437 self.call.device.GetBatteryInfo(), {'level': '42'}):
1438 self.assertFalse(self.device.GetCharging())
1429 1439
1430 1440
1431 class DeviceUtilsSetUsbChargingTest(DeviceUtilsTest): 1441 class DeviceUtilsSetChargingTest(DeviceUtilsTest):
1432 1442
1433 @mock.patch('time.sleep', mock.Mock()) 1443 @mock.patch('time.sleep', mock.Mock())
1434 def testSetUsbCharging_enabled(self): 1444 def testSetCharging_enabled(self):
1435 with self.assertCalls( 1445 with self.assertCalls(
1436 (self.call.device.FileExists(mock.ANY), True), 1446 (self.call.device.FileExists(mock.ANY), True),
1437 (self.call.device.RunShellCommand(mock.ANY), []), 1447 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
1438 (self.call.device.GetUsbCharging(), False), 1448 (self.call.device.GetCharging(), False),
1439 (self.call.device.RunShellCommand(mock.ANY), []), 1449 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
1440 (self.call.device.GetUsbCharging(), True)): 1450 (self.call.device.GetCharging(), True)):
1441 self.device.SetUsbCharging(True) 1451 self.device.SetCharging(True)
1442 1452
1443 def testSetUsbCharging_alreadyEnabled(self): 1453 def testSetCharging_alreadyEnabled(self):
1444 with self.assertCalls( 1454 with self.assertCalls(
1445 (self.call.device.FileExists(mock.ANY), True), 1455 (self.call.device.FileExists(mock.ANY), True),
1446 (self.call.device.RunShellCommand(mock.ANY), []), 1456 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
1447 (self.call.device.GetUsbCharging(), True)): 1457 (self.call.device.GetCharging(), True)):
1448 self.device.SetUsbCharging(True) 1458 self.device.SetCharging(True)
1449 1459
1450 @mock.patch('time.sleep', mock.Mock()) 1460 @mock.patch('time.sleep', mock.Mock())
1451 def testSetUsbCharging_disabled(self): 1461 def testSetCharging_disabled(self):
1452 with self.assertCalls( 1462 with self.assertCalls(
1453 (self.call.device.FileExists(mock.ANY), True), 1463 (self.call.device.FileExists(mock.ANY), True),
1454 (self.call.device.RunShellCommand(mock.ANY), []), 1464 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
1455 (self.call.device.GetUsbCharging(), True), 1465 (self.call.device.GetCharging(), True),
1456 (self.call.device.RunShellCommand(mock.ANY), []), 1466 (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
1457 (self.call.device.GetUsbCharging(), False)): 1467 (self.call.device.GetCharging(), False)):
1458 self.device.SetUsbCharging(False) 1468 self.device.SetCharging(False)
1459 1469
1460 1470
1461 1471
1462 class DeviceUtilsStrTest(DeviceUtilsTest): 1472 class DeviceUtilsStrTest(DeviceUtilsTest):
1463 1473
1464 def testStr_returnsSerial(self): 1474 def testStr_returnsSerial(self):
1465 with self.assertCalls( 1475 with self.assertCalls(
1466 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): 1476 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')):
1467 self.assertEqual('0123456789abcdef', str(self.device)) 1477 self.assertEqual('0123456789abcdef', str(self.device))
1468 1478
(...skipping 16 matching lines...) Expand all
1485 with self.assertCall( 1495 with self.assertCall(
1486 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []): 1496 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []):
1487 with self.assertRaises(device_errors.NoDevicesError): 1497 with self.assertRaises(device_errors.NoDevicesError):
1488 device_utils.DeviceUtils.parallel() 1498 device_utils.DeviceUtils.parallel()
1489 1499
1490 1500
1491 if __name__ == '__main__': 1501 if __name__ == '__main__':
1492 logging.getLogger().setLevel(logging.DEBUG) 1502 logging.getLogger().setLevel(logging.DEBUG)
1493 unittest.main(verbosity=2) 1503 unittest.main(verbosity=2)
1494 1504
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698