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

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

Issue 945883003: [Android] Convert battery utilities to DeviceUtils. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 'Rss': 101, 1375 'Rss': 101,
1376 'Pss': 102, 1376 'Pss': 102,
1377 'Shared_Clean': 103, 1377 'Shared_Clean': 103,
1378 'Shared_Dirty': 104, 1378 'Shared_Dirty': 104,
1379 'Private_Clean': 105, 1379 'Private_Clean': 105,
1380 'Private_Dirty': 106, 1380 'Private_Dirty': 106,
1381 }, 1381 },
1382 self.device.GetMemoryUsageForPid(4321)) 1382 self.device.GetMemoryUsageForPid(4321))
1383 1383
1384 1384
1385 class DeviceUtilsGetBatteryInfoTest(DeviceUtilsTest):
1386 def testGetBatteryInfo_normal(self):
1387 with self.assertCall(
1388 self.call.device.RunShellCommand(
1389 ['dumpsys', 'battery'], check_return=True),
1390 [
1391 'Current Battery Service state:',
1392 ' AC powered: false',
1393 ' USB powered: true',
1394 ' level: 100',
1395 ' temperature: 321',
1396 ]):
1397 self.assertEquals(
1398 {
1399 'AC powered': 'false',
1400 'USB powered': 'true',
1401 'level': '100',
1402 'temperature': '321',
1403 },
1404 self.device.GetBatteryInfo())
1405
1406
1407 def testGetBatteryInfo_nothing(self):
1408 with self.assertCall(
1409 self.call.device.RunShellCommand(
1410 ['dumpsys', 'battery'], check_return=True), []):
1411 self.assertEquals({}, self.device.GetBatteryInfo())
1412
1413
1414 class DeviceUtilsGetUsbChargingTest(DeviceUtilsTest):
1415 def testGetUsbCharging_true(self):
1416 with self.assertCall(
1417 self.call.device.GetBatteryInfo(), {'USB powered': 'true'}):
1418 self.assertTrue(self.device.GetUsbCharging())
1419
1420 def testGetUsbCharging_false(self):
1421 with self.assertCall(
1422 self.call.device.GetBatteryInfo(), {'USB powered': 'false'}):
1423 self.assertFalse(self.device.GetUsbCharging())
1424
1425 def testGetUsbCharging_unknown(self):
1426 with self.assertCall(
1427 self.call.device.GetBatteryInfo(), {'AC powered': 'true'}):
1428 self.assertFalse(self.device.GetUsbCharging())
1429
1430
1431 class DeviceUtilsSetUsbChargingTest(DeviceUtilsTest):
1432
1433 @mock.patch('time.sleep', mock.Mock())
1434 def testSetUsbCharging_enabled(self):
1435 with self.assertCalls(
1436 (self.call.device.FileExists(mock.ANY), True),
1437 (self.call.device.RunShellCommand(mock.ANY), []),
1438 (self.call.device.GetUsbCharging(), False),
1439 (self.call.device.RunShellCommand(mock.ANY), []),
1440 (self.call.device.GetUsbCharging(), True)):
1441 self.device.SetUsbCharging(True)
1442
1443 def testSetUsbCharging_alreadyEnabled(self):
1444 with self.assertCalls(
1445 (self.call.device.FileExists(mock.ANY), True),
1446 (self.call.device.RunShellCommand(mock.ANY), []),
1447 (self.call.device.GetUsbCharging(), True)):
1448 self.device.SetUsbCharging(True)
1449
1450 @mock.patch('time.sleep', mock.Mock())
1451 def testSetUsbCharging_disabled(self):
1452 with self.assertCalls(
1453 (self.call.device.FileExists(mock.ANY), True),
1454 (self.call.device.RunShellCommand(mock.ANY), []),
1455 (self.call.device.GetUsbCharging(), True),
1456 (self.call.device.RunShellCommand(mock.ANY), []),
1457 (self.call.device.GetUsbCharging(), False)):
1458 self.device.SetUsbCharging(False)
1459
1460
1461
1385 class DeviceUtilsStrTest(DeviceUtilsTest): 1462 class DeviceUtilsStrTest(DeviceUtilsTest):
1386 1463
1387 def testStr_returnsSerial(self): 1464 def testStr_returnsSerial(self):
1388 with self.assertCalls( 1465 with self.assertCalls(
1389 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): 1466 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')):
1390 self.assertEqual('0123456789abcdef', str(self.device)) 1467 self.assertEqual('0123456789abcdef', str(self.device))
1391 1468
1392 1469
1393 class DeviceUtilsParallelTest(mock_calls.TestCase): 1470 class DeviceUtilsParallelTest(mock_calls.TestCase):
1394 1471
(...skipping 13 matching lines...) Expand all
1408 with self.assertCall( 1485 with self.assertCall(
1409 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []): 1486 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []):
1410 with self.assertRaises(device_errors.NoDevicesError): 1487 with self.assertRaises(device_errors.NoDevicesError):
1411 device_utils.DeviceUtils.parallel() 1488 device_utils.DeviceUtils.parallel()
1412 1489
1413 1490
1414 if __name__ == '__main__': 1491 if __name__ == '__main__':
1415 logging.getLogger().setLevel(logging.DEBUG) 1492 logging.getLogger().setLevel(logging.DEBUG)
1416 unittest.main(verbosity=2) 1493 unittest.main(verbosity=2)
1417 1494
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