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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 329 |
330 def testGetApplicationPath_fails(self): | 330 def testGetApplicationPath_fails(self): |
331 with self.assertCalls( | 331 with self.assertCalls( |
332 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), | 332 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), |
333 (self.call.adb.Shell('pm path android'), | 333 (self.call.adb.Shell('pm path android'), |
334 self.CommandError('ERROR. Is package manager running?\n'))): | 334 self.CommandError('ERROR. Is package manager running?\n'))): |
335 with self.assertRaises(device_errors.CommandFailedError): | 335 with self.assertRaises(device_errors.CommandFailedError): |
336 self.device.GetApplicationPath('android') | 336 self.device.GetApplicationPath('android') |
337 | 337 |
338 | 338 |
| 339 class DeviceUtilsGetApplicationDataDirectoryTest(DeviceUtilsTest): |
| 340 |
| 341 def testGetApplicationDataDirectory_exists(self): |
| 342 with self.assertCall( |
| 343 self.call.device._RunPipedShellCommand( |
| 344 'pm dump foo.bar.baz | grep dataDir='), |
| 345 ['dataDir=/data/data/foo.bar.baz']): |
| 346 self.assertEquals( |
| 347 '/data/data/foo.bar.baz', |
| 348 self.device.GetApplicationDataDirectory('foo.bar.baz')) |
| 349 |
| 350 def testGetApplicationDataDirectory_notExists(self): |
| 351 with self.assertCall( |
| 352 self.call.device._RunPipedShellCommand( |
| 353 'pm dump foo.bar.baz | grep dataDir='), |
| 354 self.ShellError()): |
| 355 self.assertIsNone(self.device.GetApplicationDataDirectory('foo.bar.baz')) |
| 356 |
| 357 |
339 @mock.patch('time.sleep', mock.Mock()) | 358 @mock.patch('time.sleep', mock.Mock()) |
340 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): | 359 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): |
341 | 360 |
342 def testWaitUntilFullyBooted_succeedsNoWifi(self): | 361 def testWaitUntilFullyBooted_succeedsNoWifi(self): |
343 with self.assertCalls( | 362 with self.assertCalls( |
344 self.call.adb.WaitForDevice(), | 363 self.call.adb.WaitForDevice(), |
345 # sd_card_ready | 364 # sd_card_ready |
346 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), | 365 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), |
347 (self.call.adb.Shell('test -d /fake/storage/path'), ''), | 366 (self.call.adb.Shell('test -d /fake/storage/path'), ''), |
348 # pm_ready | 367 # pm_ready |
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 devices = device_utils.DeviceUtils.HealthyDevices() | 1719 devices = device_utils.DeviceUtils.HealthyDevices() |
1701 self.assertEquals(1, len(devices)) | 1720 self.assertEquals(1, len(devices)) |
1702 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) | 1721 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) |
1703 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) | 1722 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) |
1704 | 1723 |
1705 | 1724 |
1706 if __name__ == '__main__': | 1725 if __name__ == '__main__': |
1707 logging.getLogger().setLevel(logging.DEBUG) | 1726 logging.getLogger().setLevel(logging.DEBUG) |
1708 unittest.main(verbosity=2) | 1727 unittest.main(verbosity=2) |
1709 | 1728 |
OLD | NEW |