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

Side by Side Diff: build/android/devil/android/device_utils_test.py

Issue 1398613002: DeviceUtils.ForceStop: no-op if the app isn't running (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 2 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/devil/android/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=protected-access 10 # pylint: disable=protected-access
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 self.device.Install(DeviceUtilsInstallTest.mock_apk, 620 self.device.Install(DeviceUtilsInstallTest.mock_apk,
621 reinstall=True, retries=0, permissions=[]) 621 reinstall=True, retries=0, permissions=[])
622 622
623 def testInstall_identicalPriorInstall_reinstall(self): 623 def testInstall_identicalPriorInstall_reinstall(self):
624 with self.assertCalls( 624 with self.assertCalls(
625 (self.call.device._GetApplicationPathsInternal('test.package'), 625 (self.call.device._GetApplicationPathsInternal('test.package'),
626 ['/fake/data/app/test.package.apk']), 626 ['/fake/data/app/test.package.apk']),
627 (self.call.device._ComputeStaleApks('test.package', 627 (self.call.device._ComputeStaleApks('test.package',
628 ['/fake/test/app.apk']), 628 ['/fake/test/app.apk']),
629 ([], None)), 629 ([], None)),
630 (self.call.device.RunShellCommand(['am', 'force-stop', 'test.package'], 630 (self.call.device.ForceStop('test.package'))):
631 check_return=True))):
632 self.device.Install(DeviceUtilsInstallTest.mock_apk, 631 self.device.Install(DeviceUtilsInstallTest.mock_apk,
633 reinstall=True, retries=0, permissions=[]) 632 reinstall=True, retries=0, permissions=[])
634 633
635 def testInstall_fails(self): 634 def testInstall_fails(self):
636 with self.assertCalls( 635 with self.assertCalls(
637 (self.call.device._GetApplicationPathsInternal('test.package'), []), 636 (self.call.device._GetApplicationPathsInternal('test.package'), []),
638 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), 637 (self.call.adb.Install('/fake/test/app.apk', reinstall=False),
639 self.CommandError('Failure\r\n'))): 638 self.CommandError('Failure\r\n'))):
640 with self.assertRaises(device_errors.CommandFailedError): 639 with self.assertRaises(device_errors.CommandFailedError):
641 self.device.Install(DeviceUtilsInstallTest.mock_apk, retries=0) 640 self.device.Install(DeviceUtilsInstallTest.mock_apk, retries=0)
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 (self.call.device.RunShellCommand( 1312 (self.call.device.RunShellCommand(
1314 ['dumpsys', 'window', 'windows'], check_return=True, 1313 ['dumpsys', 'window', 'windows'], check_return=True,
1315 large_output=True), 1314 large_output=True),
1316 ['mCurrentFocus Launcher'])): 1315 ['mCurrentFocus Launcher'])):
1317 self.device.GoHome() 1316 self.device.GoHome()
1318 1317
1319 class DeviceUtilsForceStopTest(DeviceUtilsTest): 1318 class DeviceUtilsForceStopTest(DeviceUtilsTest):
1320 1319
1321 def testForceStop(self): 1320 def testForceStop(self):
1322 with self.assertCall( 1321 with self.assertCall(
1323 self.call.adb.Shell('am force-stop test.package'), 1322 self.call.adb.Shell('p=test.package;if [[ "$(ps)" = *$p* ]]; then '
1323 'am force-stop $p; fi'),
1324 ''): 1324 ''):
1325 self.device.ForceStop('test.package') 1325 self.device.ForceStop('test.package')
1326 1326
1327 1327
1328 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): 1328 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest):
1329 1329
1330 def testClearApplicationState_setPermissions(self): 1330 def testClearApplicationState_setPermissions(self):
1331 with self.assertCalls( 1331 with self.assertCalls(
1332 (self.call.device.GetProp('ro.build.version.sdk', cache=True), '17'), 1332 (self.call.device.GetProp('ro.build.version.sdk', cache=True), '17'),
1333 (self.call.device._GetApplicationPathsInternal('this.package.exists'), 1333 (self.call.device._GetApplicationPathsInternal('this.package.exists'),
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 def testGrantPermissions_BlackList(self): 2130 def testGrantPermissions_BlackList(self):
2131 with self.patch_call( 2131 with self.patch_call(
2132 self.call.device.build_version_sdk, return_value=23): 2132 self.call.device.build_version_sdk, return_value=23):
2133 self.device.GrantPermissions( 2133 self.device.GrantPermissions(
2134 'package', ['android.permission.ACCESS_MOCK_LOCATION']) 2134 'package', ['android.permission.ACCESS_MOCK_LOCATION'])
2135 2135
2136 2136
2137 if __name__ == '__main__': 2137 if __name__ == '__main__':
2138 logging.getLogger().setLevel(logging.DEBUG) 2138 logging.getLogger().setLevel(logging.DEBUG)
2139 unittest.main(verbosity=2) 2139 unittest.main(verbosity=2)
OLDNEW
« no previous file with comments | « build/android/devil/android/device_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698