| 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 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 ['foo.bar'] * 256 + ['foo.ba']): | 816 ['foo.bar'] * 256 + ['foo.ba']): |
| 817 with self.assertRaises(device_errors.AdbShellCommandFailedError) as ec: | 817 with self.assertRaises(device_errors.AdbShellCommandFailedError) as ec: |
| 818 self.device._RunPipedShellCommand('ps | grep foo') | 818 self.device._RunPipedShellCommand('ps | grep foo') |
| 819 self.assertIs(None, ec.exception.status) | 819 self.assertIs(None, ec.exception.status) |
| 820 | 820 |
| 821 | 821 |
| 822 @mock.patch('time.sleep', mock.Mock()) | 822 @mock.patch('time.sleep', mock.Mock()) |
| 823 class DeviceUtilsKillAllTest(DeviceUtilsTest): | 823 class DeviceUtilsKillAllTest(DeviceUtilsTest): |
| 824 | 824 |
| 825 def testKillAll_noMatchingProcessesFailure(self): | 825 def testKillAll_noMatchingProcessesFailure(self): |
| 826 with self.assertCall(self.call.device.GetPids('test_process'), {}): | 826 with self.assertCall(self.call.device._GetProcessPidPairs('test_process'), |
| 827 []): |
| 827 with self.assertRaises(device_errors.CommandFailedError): | 828 with self.assertRaises(device_errors.CommandFailedError): |
| 828 self.device.KillAll('test_process') | 829 self.device.KillAll('test_process') |
| 829 | 830 |
| 830 def testKillAll_noMatchingProcessesQuiet(self): | 831 def testKillAll_noMatchingProcessesQuiet(self): |
| 831 with self.assertCall(self.call.device.GetPids('test_process'), {}): | 832 with self.assertCall(self.call.device._GetProcessPidPairs('test_process'), |
| 833 []): |
| 832 self.assertEqual(0, self.device.KillAll('test_process', quiet=True)) | 834 self.assertEqual(0, self.device.KillAll('test_process', quiet=True)) |
| 833 | 835 |
| 834 def testKillAll_nonblocking(self): | 836 def testKillAll_nonblocking(self): |
| 835 with self.assertCalls( | 837 with self.assertCalls( |
| 836 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), | 838 (self.call.device._GetProcessPidPairs('some.process'), |
| 839 [('some.process', '1234')]), |
| 837 (self.call.adb.Shell('kill -9 1234'), '')): | 840 (self.call.adb.Shell('kill -9 1234'), '')): |
| 838 self.assertEquals( | 841 self.assertEquals( |
| 839 1, self.device.KillAll('some.process', blocking=False)) | 842 1, self.device.KillAll('some.process', blocking=False)) |
| 840 | 843 |
| 841 def testKillAll_blocking(self): | 844 def testKillAll_blocking(self): |
| 842 with self.assertCalls( | 845 with self.assertCalls( |
| 843 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), | 846 (self.call.device._GetProcessPidPairs('some.process'), |
| 847 [('some.process', '1234')]), |
| 844 (self.call.adb.Shell('kill -9 1234'), ''), | 848 (self.call.adb.Shell('kill -9 1234'), ''), |
| 845 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), | 849 (self.call.device._GetProcessPidPairs('some.process'), |
| 846 (self.call.device.GetPids('some.process'), [])): | 850 [('some.process', '1234')]), |
| 851 (self.call.device._GetProcessPidPairs('some.process'), [])): |
| 847 self.assertEquals( | 852 self.assertEquals( |
| 848 1, self.device.KillAll('some.process', blocking=True)) | 853 1, self.device.KillAll('some.process', blocking=True)) |
| 849 | 854 |
| 850 def testKillAll_root(self): | 855 def testKillAll_root(self): |
| 851 with self.assertCalls( | 856 with self.assertCalls( |
| 852 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), | 857 (self.call.device._GetProcessPidPairs('some.process'), |
| 858 [('some.process', '1234')]), |
| 853 (self.call.device.NeedsSU(), True), | 859 (self.call.device.NeedsSU(), True), |
| 854 (self.call.adb.Shell("su -c sh -c 'kill -9 1234'"), '')): | 860 (self.call.adb.Shell("su -c sh -c 'kill -9 1234'"), '')): |
| 855 self.assertEquals( | 861 self.assertEquals( |
| 856 1, self.device.KillAll('some.process', as_root=True)) | 862 1, self.device.KillAll('some.process', as_root=True)) |
| 857 | 863 |
| 858 def testKillAll_sigterm(self): | 864 def testKillAll_sigterm(self): |
| 859 with self.assertCalls( | 865 with self.assertCalls( |
| 860 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), | 866 (self.call.device._GetProcessPidPairs('some.process'), |
| 867 [('some.process', '1234')]), |
| 861 (self.call.adb.Shell('kill -15 1234'), '')): | 868 (self.call.adb.Shell('kill -15 1234'), '')): |
| 862 self.assertEquals( | 869 self.assertEquals( |
| 863 1, self.device.KillAll('some.process', signum=device_signal.SIGTERM)) | 870 1, self.device.KillAll('some.process', signum=device_signal.SIGTERM)) |
| 864 | 871 |
| 872 def testKillAll_multipleInstances(self): |
| 873 with self.assertCalls( |
| 874 (self.call.device._GetProcessPidPairs('some.process'), |
| 875 [('some.process', '1234'), ('some.process', '4567')]), |
| 876 (self.call.adb.Shell('kill -15 1234 4567'), '')): |
| 877 self.assertEquals( |
| 878 2, self.device.KillAll('some.process', signum=device_signal.SIGTERM)) |
| 879 |
| 865 | 880 |
| 866 class DeviceUtilsStartActivityTest(DeviceUtilsTest): | 881 class DeviceUtilsStartActivityTest(DeviceUtilsTest): |
| 867 | 882 |
| 868 def testStartActivity_actionOnly(self): | 883 def testStartActivity_actionOnly(self): |
| 869 test_intent = intent.Intent(action='android.intent.action.VIEW') | 884 test_intent = intent.Intent(action='android.intent.action.VIEW') |
| 870 with self.assertCall( | 885 with self.assertCall( |
| 871 self.call.adb.Shell('am start ' | 886 self.call.adb.Shell('am start ' |
| 872 '-a android.intent.action.VIEW'), | 887 '-a android.intent.action.VIEW'), |
| 873 'Starting: Intent { act=android.intent.action.VIEW }'): | 888 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 874 self.device.StartActivity(test_intent) | 889 self.device.StartActivity(test_intent) |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 devices = device_utils.DeviceUtils.HealthyDevices() | 1851 devices = device_utils.DeviceUtils.HealthyDevices() |
| 1837 self.assertEquals(1, len(devices)) | 1852 self.assertEquals(1, len(devices)) |
| 1838 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) | 1853 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) |
| 1839 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) | 1854 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) |
| 1840 | 1855 |
| 1841 | 1856 |
| 1842 if __name__ == '__main__': | 1857 if __name__ == '__main__': |
| 1843 logging.getLogger().setLevel(logging.DEBUG) | 1858 logging.getLogger().setLevel(logging.DEBUG) |
| 1844 unittest.main(verbosity=2) | 1859 unittest.main(verbosity=2) |
| 1845 | 1860 |
| OLD | NEW |