| 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=protected-access | 10 # pylint: disable=protected-access |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 self.device.Install( | 594 self.device.Install( |
| 595 '/fake/test/app.apk', retries=0, permissions=['p1', 'p2']) | 595 '/fake/test/app.apk', retries=0, permissions=['p1', 'p2']) |
| 596 | 596 |
| 597 def testInstall_priorInstall(self): | 597 def testInstall_priorInstall(self): |
| 598 APK_PATH = '/fake/test/app.apk' | 598 APK_PATH = '/fake/test/app.apk' |
| 599 with self.assertCalls( | 599 with self.assertCalls( |
| 600 (mock.call.devil.android.apk_helper.GetPackageName(APK_PATH), | 600 (mock.call.devil.android.apk_helper.GetPackageName(APK_PATH), |
| 601 'test.package'), | 601 'test.package'), |
| 602 (self.call.device._GetApplicationPathsInternal('test.package'), | 602 (self.call.device._GetApplicationPathsInternal('test.package'), |
| 603 ['/fake/data/app/test.package.apk']), | 603 ['/fake/data/app/test.package.apk']), |
| 604 self.call.adb.Uninstall('test.package', False), | 604 self.call.device.Uninstall('test.package'), |
| 605 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): | 605 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): |
| 606 self.device.Install('/fake/test/app.apk', retries=0, permissions=[]) | 606 self.device.Install('/fake/test/app.apk', retries=0, permissions=[]) |
| 607 | 607 |
| 608 def testInstall_differentPriorInstall_reinstall(self): | 608 def testInstall_differentPriorInstall_reinstall(self): |
| 609 with self.assertCalls( | 609 with self.assertCalls( |
| 610 (mock.call.devil.android.apk_helper.GetPackageName( | 610 (mock.call.devil.android.apk_helper.GetPackageName( |
| 611 '/fake/test/app.apk'), | 611 '/fake/test/app.apk'), |
| 612 'test.package'), | 612 'test.package'), |
| 613 (self.call.device._GetApplicationPathsInternal('test.package'), | 613 (self.call.device._GetApplicationPathsInternal('test.package'), |
| 614 ['/fake/data/app/test.package.apk']), | 614 ['/fake/data/app/test.package.apk']), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 ['base.apk', 'split2.apk']), | 677 ['base.apk', 'split2.apk']), |
| 678 (['split2.apk'], None)), | 678 (['split2.apk'], None)), |
| 679 (self.call.adb.InstallMultiple( | 679 (self.call.adb.InstallMultiple( |
| 680 ['split2.apk'], partial='test.package', reinstall=True))): | 680 ['split2.apk'], partial='test.package', reinstall=True))): |
| 681 self.device.InstallSplitApk('base.apk', | 681 self.device.InstallSplitApk('base.apk', |
| 682 ['split1.apk', 'split2.apk', 'split3.apk'], | 682 ['split1.apk', 'split2.apk', 'split3.apk'], |
| 683 reinstall=True, permissions=[], retries=0) | 683 reinstall=True, permissions=[], retries=0) |
| 684 | 684 |
| 685 | 685 |
| 686 class DeviceUtilsUninstallTest(DeviceUtilsTest): | 686 class DeviceUtilsUninstallTest(DeviceUtilsTest): |
| 687 | |
| 688 def testUninstall_callsThrough(self): | 687 def testUninstall_callsThrough(self): |
| 689 with self.assertCalls( | 688 with self.assertCalls( |
| 689 (self.call.device._GetApplicationPathsInternal('test.package'), |
| 690 ['/path.apk']), |
| 690 self.call.adb.Uninstall('test.package', True)): | 691 self.call.adb.Uninstall('test.package', True)): |
| 691 self.device.Uninstall('test.package', True) | 692 self.device.Uninstall('test.package', True) |
| 692 | 693 |
| 694 def testUninstall_noop(self): |
| 695 with self.assertCalls( |
| 696 (self.call.device._GetApplicationPathsInternal('test.package'), [])): |
| 697 self.device.Uninstall('test.package', True) |
| 698 |
| 693 | 699 |
| 694 class DeviceUtilsSuTest(DeviceUtilsTest): | 700 class DeviceUtilsSuTest(DeviceUtilsTest): |
| 695 def testSu_preM(self): | 701 def testSu_preM(self): |
| 696 with self.patch_call( | 702 with self.patch_call( |
| 697 self.call.device.build_version_sdk, | 703 self.call.device.build_version_sdk, |
| 698 return_value=version_codes.LOLLIPOP_MR1): | 704 return_value=version_codes.LOLLIPOP_MR1): |
| 699 self.assertEquals('su -c foo', self.device._Su('foo')) | 705 self.assertEquals('su -c foo', self.device._Su('foo')) |
| 700 | 706 |
| 701 def testSu_mAndAbove(self): | 707 def testSu_mAndAbove(self): |
| 702 with self.patch_call( | 708 with self.patch_call( |
| (...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2092 def testGrantPermissions_BlackList(self): | 2098 def testGrantPermissions_BlackList(self): |
| 2093 with self.patch_call( | 2099 with self.patch_call( |
| 2094 self.call.device.build_version_sdk, return_value=23): | 2100 self.call.device.build_version_sdk, return_value=23): |
| 2095 self.device.GrantPermissions( | 2101 self.device.GrantPermissions( |
| 2096 'package', ['android.permission.ACCESS_MOCK_LOCATION']) | 2102 'package', ['android.permission.ACCESS_MOCK_LOCATION']) |
| 2097 | 2103 |
| 2098 | 2104 |
| 2099 if __name__ == '__main__': | 2105 if __name__ == '__main__': |
| 2100 logging.getLogger().setLevel(logging.DEBUG) | 2106 logging.getLogger().setLevel(logging.DEBUG) |
| 2101 unittest.main(verbosity=2) | 2107 unittest.main(verbosity=2) |
| OLD | NEW |