OLD | NEW |
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 Loading... |
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(['dumpsys', 'battery']), |
| 1389 [ |
| 1390 'Current Battery Service state:', |
| 1391 ' AC powered: false', |
| 1392 ' USB powered: true', |
| 1393 ' level: 100', |
| 1394 ' temperature: 321', |
| 1395 ]): |
| 1396 self.assertEquals( |
| 1397 { |
| 1398 'AC powered': 'false', |
| 1399 'USB powered': 'true', |
| 1400 'level': '100', |
| 1401 'temperature': '321', |
| 1402 }, |
| 1403 self.device.GetBatteryInfo()) |
| 1404 |
| 1405 |
| 1406 def testGetBatteryInfo_nothing(self): |
| 1407 with self.assertCall( |
| 1408 self.call.device.RunShellCommand(['dumpsys', 'battery']), []): |
| 1409 self.assertEquals({}, self.device.GetBatteryInfo()) |
| 1410 |
| 1411 |
| 1412 class DeviceUtilsGetUsbChargingTest(DeviceUtilsTest): |
| 1413 def testGetUsbCharging_true(self): |
| 1414 with self.assertCall( |
| 1415 self.call.device.GetBatteryInfo(), {'USB powered': 'true'}): |
| 1416 self.assertTrue(self.device.GetUsbCharging()) |
| 1417 |
| 1418 def testGetUsbCharging_false(self): |
| 1419 with self.assertCall( |
| 1420 self.call.device.GetBatteryInfo(), {'USB powered': 'false'}): |
| 1421 self.assertFalse(self.device.GetUsbCharging()) |
| 1422 |
| 1423 def testGetUsbCharging_unknown(self): |
| 1424 with self.assertCall( |
| 1425 self.call.device.GetBatteryInfo(), {'AC powered': 'true'}): |
| 1426 self.assertFalse(self.device.GetUsbCharging()) |
| 1427 |
| 1428 |
| 1429 class DeviceUtilsSetUsbChargingTest(DeviceUtilsTest): |
| 1430 def testSetUsbCharging_enabled(self): |
| 1431 with self.assertCalls( |
| 1432 (self.call.device.FileExists(mock.ANY), True), |
| 1433 (self.call.device.GetUsbCharging(), False), |
| 1434 (self.call.device.RunShellCommand(mock.ANY), []), |
| 1435 (self.call.device.GetUsbCharging(), True)): |
| 1436 self.device.SetUsbCharging(True) |
| 1437 |
| 1438 def testSetUsbCharging_alreadyEnabled(self): |
| 1439 with self.assertCalls( |
| 1440 (self.call.device.FileExists(mock.ANY), True), |
| 1441 (self.call.device.GetUsbCharging(), True)): |
| 1442 self.device.SetUsbCharging(True) |
| 1443 |
| 1444 def testSetUsbCharging_disabled(self): |
| 1445 with self.assertCalls( |
| 1446 (self.call.device.FileExists(mock.ANY), True), |
| 1447 (self.call.device.GetUsbCharging(), True), |
| 1448 (self.call.device.RunShellCommand(mock.ANY), []), |
| 1449 (self.call.device.GetUsbCharging(), False)): |
| 1450 self.device.SetUsbCharging(False) |
| 1451 |
| 1452 |
| 1453 |
1385 class DeviceUtilsStrTest(DeviceUtilsTest): | 1454 class DeviceUtilsStrTest(DeviceUtilsTest): |
1386 | 1455 |
1387 def testStr_returnsSerial(self): | 1456 def testStr_returnsSerial(self): |
1388 with self.assertCalls( | 1457 with self.assertCalls( |
1389 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): | 1458 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): |
1390 self.assertEqual('0123456789abcdef', str(self.device)) | 1459 self.assertEqual('0123456789abcdef', str(self.device)) |
1391 | 1460 |
1392 | 1461 |
1393 class DeviceUtilsParallelTest(mock_calls.TestCase): | 1462 class DeviceUtilsParallelTest(mock_calls.TestCase): |
1394 | 1463 |
1395 def testParallel_default(self): | 1464 def testParallel_default(self): |
1396 test_serials = ['0123456789abcdef', 'fedcba9876543210'] | 1465 test_serials = ['0123456789abcdef', 'fedcba9876543210'] |
1397 with self.assertCall( | 1466 with self.assertCall( |
1398 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), | 1467 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), |
1399 [_AdbWrapperMock(serial) for serial in test_serials]): | 1468 [_AdbWrapperMock(serial) for serial in test_serials]): |
1400 parallel_devices = device_utils.DeviceUtils.parallel() | 1469 parallel_devices = device_utils.DeviceUtils.parallel() |
1401 for serial, device in zip(test_serials, parallel_devices.pGet(None)): | 1470 for serial, device in zip(test_serials, parallel_devices.pGet(None)): |
1402 self.assertTrue( | 1471 self.assertTrue( |
1403 isinstance(device, device_utils.DeviceUtils) | 1472 isinstance(device, device_utils.DeviceUtils) |
1404 and serial == str(device), | 1473 and serial == str(device), |
1405 'Expected a DeviceUtils object with serial %s' % serial) | 1474 'Expected a DeviceUtils object with serial %s' % serial) |
1406 | 1475 |
1407 | 1476 |
1408 if __name__ == '__main__': | 1477 if __name__ == '__main__': |
1409 logging.getLogger().setLevel(logging.DEBUG) | 1478 logging.getLogger().setLevel(logging.DEBUG) |
1410 unittest.main(verbosity=2) | 1479 unittest.main(verbosity=2) |
1411 | 1480 |
OLD | NEW |