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 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1531 'Starting: Intent { act=android.intent.action.MAIN }\r\n'''), | 1531 'Starting: Intent { act=android.intent.action.MAIN }\r\n'''), |
1532 (self.call.device.RunShellCommand( | 1532 (self.call.device.RunShellCommand( |
1533 ['dumpsys', 'window', 'windows'], check_return=True, | 1533 ['dumpsys', 'window', 'windows'], check_return=True, |
1534 large_output=True), | 1534 large_output=True), |
1535 ['mCurrentFocus Launcher'])): | 1535 ['mCurrentFocus Launcher'])): |
1536 self.device.GoHome() | 1536 self.device.GoHome() |
1537 | 1537 |
1538 | 1538 |
1539 class DeviceUtilsForceStopTest(DeviceUtilsTest): | 1539 class DeviceUtilsForceStopTest(DeviceUtilsTest): |
1540 | 1540 |
| 1541 def testForceStop_sdkGreaterThanNougatMR1(self): |
| 1542 with self.patch_call(self.call.device.build_version_sdk, |
| 1543 return_value=(version_codes.NOUGAT_MR1 + 1)): |
| 1544 with self.patch_call(self.call.device.build_id, return_value='ZZZ99Z'): |
| 1545 with self.assertCall( |
| 1546 self.call.adb.Shell('p=test.package;if [[ "$(ps -e)" = *$p* ]]; ' |
| 1547 'then am force-stop $p; fi'), |
| 1548 ''): |
| 1549 self.device.ForceStop('test.package') |
| 1550 |
1541 def testForceStop(self): | 1551 def testForceStop(self): |
1542 with self.assertCall( | 1552 with self.patch_call(self.call.device.build_version_sdk, |
1543 self.call.adb.Shell('p=test.package;if [[ "$(ps)" = *$p* ]]; then ' | 1553 return_value=(version_codes.LOLLIPOP)): |
1544 'am force-stop $p; fi'), | 1554 with self.assertCall( |
1545 ''): | 1555 self.call.adb.Shell('p=test.package;if [[ "$(ps)" = *$p* ]]; then ' |
1546 self.device.ForceStop('test.package') | 1556 'am force-stop $p; fi'), |
| 1557 ''): |
| 1558 self.device.ForceStop('test.package') |
1547 | 1559 |
1548 | 1560 |
1549 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): | 1561 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): |
1550 | 1562 |
1551 def testClearApplicationState_setPermissions(self): | 1563 def testClearApplicationState_setPermissions(self): |
1552 with self.assertCalls( | 1564 with self.assertCalls( |
1553 (self.call.device.GetProp('ro.build.version.sdk', cache=True), '17'), | 1565 (self.call.device.GetProp('ro.build.version.sdk', cache=True), '17'), |
1554 (self.call.device._GetApplicationPathsInternal('this.package.exists'), | 1566 (self.call.device._GetApplicationPathsInternal('this.package.exists'), |
1555 ['/data/app/this.package.exists.apk']), | 1567 ['/data/app/this.package.exists.apk']), |
1556 (self.call.device.RunShellCommand( | 1568 (self.call.device.RunShellCommand( |
(...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2891 with self.assertCalls( | 2903 with self.assertCalls( |
2892 self.EnsureCacheInitialized()): | 2904 self.EnsureCacheInitialized()): |
2893 data = json.loads(self.device.DumpCacheData()) | 2905 data = json.loads(self.device.DumpCacheData()) |
2894 data['token'] = 'TOKEN' | 2906 data['token'] = 'TOKEN' |
2895 self.assertTrue(self.device.LoadCacheData(json.dumps(data))) | 2907 self.assertTrue(self.device.LoadCacheData(json.dumps(data))) |
2896 | 2908 |
2897 | 2909 |
2898 if __name__ == '__main__': | 2910 if __name__ == '__main__': |
2899 logging.getLogger().setLevel(logging.DEBUG) | 2911 logging.getLogger().setLevel(logging.DEBUG) |
2900 unittest.main(verbosity=2) | 2912 unittest.main(verbosity=2) |
OLD | NEW |