| 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 21 matching lines...) Expand all Loading... |
| 32 # RunCommand from third_party/android_testrunner/run_command.py is mocked | 32 # RunCommand from third_party/android_testrunner/run_command.py is mocked |
| 33 # below, so its path needs to be in sys.path. | 33 # below, so its path needs to be in sys.path. |
| 34 sys.path.append(os.path.join( | 34 sys.path.append(os.path.join( |
| 35 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 35 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
| 36 | 36 |
| 37 sys.path.append(os.path.join( | 37 sys.path.append(os.path.join( |
| 38 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) | 38 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) |
| 39 import mock # pylint: disable=F0401 | 39 import mock # pylint: disable=F0401 |
| 40 | 40 |
| 41 | 41 |
| 42 class DeviceUtilsInitTest(unittest.TestCase): | 42 class DeviceUtilsTest(unittest.TestCase): |
| 43 | 43 |
| 44 def testInitWithStr(self): | 44 def testInitWithStr(self): |
| 45 serial_as_str = str('0123456789abcdef') | 45 serial_as_str = str('0123456789abcdef') |
| 46 d = device_utils.DeviceUtils('0123456789abcdef') | 46 d = device_utils.DeviceUtils('0123456789abcdef') |
| 47 self.assertEqual(serial_as_str, d.adb.GetDeviceSerial()) | 47 self.assertEqual(serial_as_str, d.adb.GetDeviceSerial()) |
| 48 | 48 |
| 49 def testInitWithUnicode(self): | 49 def testInitWithUnicode(self): |
| 50 serial_as_unicode = unicode('fedcba9876543210') | 50 serial_as_unicode = unicode('fedcba9876543210') |
| 51 d = device_utils.DeviceUtils(serial_as_unicode) | 51 d = device_utils.DeviceUtils(serial_as_unicode) |
| 52 self.assertEqual(serial_as_unicode, d.adb.GetDeviceSerial()) | 52 self.assertEqual(serial_as_unicode, d.adb.GetDeviceSerial()) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 def __exit__(self, exc_type, exc_val, exc_tb): | 114 def __exit__(self, exc_type, exc_val, exc_tb): |
| 115 pass | 115 pass |
| 116 | 116 |
| 117 | 117 |
| 118 class _PatchedFunction(object): | 118 class _PatchedFunction(object): |
| 119 def __init__(self, patched=None, mocked=None): | 119 def __init__(self, patched=None, mocked=None): |
| 120 self.patched = patched | 120 self.patched = patched |
| 121 self.mocked = mocked | 121 self.mocked = mocked |
| 122 | 122 |
| 123 | 123 |
| 124 class DeviceUtilsOldImplTest(unittest.TestCase): |
| 125 |
| 126 class AndroidCommandsCalls(object): |
| 127 |
| 128 def __init__(self, test_case, cmd_ret, comp): |
| 129 self._cmds = cmd_ret |
| 130 self._comp = comp |
| 131 self._run_command = _PatchedFunction() |
| 132 self._test_case = test_case |
| 133 self._total_received = 0 |
| 134 |
| 135 def __enter__(self): |
| 136 self._run_command.patched = mock.patch( |
| 137 'run_command.RunCommand', |
| 138 side_effect=lambda c, **kw: self._ret(c)) |
| 139 self._run_command.mocked = self._run_command.patched.__enter__() |
| 140 |
| 141 def _ret(self, actual_cmd): |
| 142 if sys.exc_info()[0] is None: |
| 143 on_failure_fmt = ('\n' |
| 144 ' received command: %s\n' |
| 145 ' expected command: %s') |
| 146 self._test_case.assertGreater( |
| 147 len(self._cmds), self._total_received, |
| 148 msg=on_failure_fmt % (actual_cmd, None)) |
| 149 expected_cmd, ret = self._cmds[self._total_received] |
| 150 self._total_received += 1 |
| 151 self._test_case.assertTrue( |
| 152 self._comp(expected_cmd, actual_cmd), |
| 153 msg=on_failure_fmt % (actual_cmd, expected_cmd)) |
| 154 return ret |
| 155 return '' |
| 156 |
| 157 def __exit__(self, exc_type, exc_val, exc_tb): |
| 158 self._run_command.patched.__exit__(exc_type, exc_val, exc_tb) |
| 159 if exc_type is None: |
| 160 on_failure = "adb commands don't match.\nExpected:%s\nActual:%s" % ( |
| 161 ''.join('\n %s' % c for c, _ in self._cmds), |
| 162 ''.join('\n %s' % a[0] |
| 163 for _, a, kw in self._run_command.mocked.mock_calls)) |
| 164 self._test_case.assertEqual( |
| 165 len(self._cmds), len(self._run_command.mocked.mock_calls), |
| 166 msg=on_failure) |
| 167 for (expected_cmd, _r), (_n, actual_args, actual_kwargs) in zip( |
| 168 self._cmds, self._run_command.mocked.mock_calls): |
| 169 self._test_case.assertEqual(1, len(actual_args), msg=on_failure) |
| 170 self._test_case.assertTrue(self._comp(expected_cmd, actual_args[0]), |
| 171 msg=on_failure) |
| 172 self._test_case.assertTrue('timeout_time' in actual_kwargs, |
| 173 msg=on_failure) |
| 174 self._test_case.assertTrue('retry_count' in actual_kwargs, |
| 175 msg=on_failure) |
| 176 |
| 177 def assertNoAdbCalls(self): |
| 178 return type(self).AndroidCommandsCalls(self, [], str.__eq__) |
| 179 |
| 180 def assertCalls(self, cmd, ret, comp=str.__eq__): |
| 181 return type(self).AndroidCommandsCalls(self, [(cmd, ret)], comp) |
| 182 |
| 183 def assertCallsSequence(self, cmd_ret, comp=str.__eq__): |
| 184 return type(self).AndroidCommandsCalls(self, cmd_ret, comp) |
| 185 |
| 186 def setUp(self): |
| 187 self._get_adb_path_patch = mock.patch('pylib.constants.GetAdbPath', |
| 188 mock.Mock(return_value='adb')) |
| 189 self._get_adb_path_patch.start() |
| 190 self.device = device_utils.DeviceUtils( |
| 191 '0123456789abcdef', default_timeout=1, default_retries=0) |
| 192 |
| 193 def tearDown(self): |
| 194 self._get_adb_path_patch.stop() |
| 195 |
| 196 |
| 124 def _AdbWrapperMock(test_serial): | 197 def _AdbWrapperMock(test_serial): |
| 125 adb = mock.Mock(spec=adb_wrapper.AdbWrapper) | 198 adb = mock.Mock(spec=adb_wrapper.AdbWrapper) |
| 126 adb.__str__ = mock.Mock(return_value=test_serial) | 199 adb.__str__ = mock.Mock(return_value=test_serial) |
| 127 adb.GetDeviceSerial.return_value = test_serial | 200 adb.GetDeviceSerial.return_value = test_serial |
| 128 return adb | 201 return adb |
| 129 | 202 |
| 130 | 203 |
| 131 class DeviceUtilsTest(mock_calls.TestCase): | 204 class DeviceUtilsNewImplTest(mock_calls.TestCase): |
| 132 | 205 |
| 133 def setUp(self): | 206 def setUp(self): |
| 134 self.adb = _AdbWrapperMock('0123456789abcdef') | 207 self.adb = _AdbWrapperMock('0123456789abcdef') |
| 135 self.device = device_utils.DeviceUtils( | 208 self.device = device_utils.DeviceUtils( |
| 136 self.adb, default_timeout=10, default_retries=0) | 209 self.adb, default_timeout=10, default_retries=0) |
| 137 self.watchMethodCalls(self.call.adb, ignore=['GetDeviceSerial']) | 210 self.watchMethodCalls(self.call.adb, ignore=['GetDeviceSerial']) |
| 138 | 211 |
| 139 def ShellError(self, output=None, status=1): | 212 def ShellError(self, output=None, status=1): |
| 140 def action(cmd, *args, **kwargs): | 213 def action(cmd, *args, **kwargs): |
| 141 raise device_errors.AdbShellCommandFailedError( | 214 raise device_errors.AdbShellCommandFailedError( |
| 142 cmd, output, status, str(self.device)) | 215 cmd, output, status, str(self.device)) |
| 143 if output is None: | 216 if output is None: |
| 144 output = 'Permission denied\n' | 217 output = 'Permission denied\n' |
| 145 return action | 218 return action |
| 146 | 219 |
| 147 def TimeoutError(self, msg=None): | 220 def TimeoutError(self, msg=None): |
| 148 if msg is None: | 221 if msg is None: |
| 149 msg = 'Operation timed out' | 222 msg = 'Operation timed out' |
| 150 return mock.Mock(side_effect=device_errors.CommandTimeoutError( | 223 return mock.Mock(side_effect=device_errors.CommandTimeoutError( |
| 151 msg, str(self.device))) | 224 msg, str(self.device))) |
| 152 | 225 |
| 153 def CommandError(self, msg=None): | 226 def CommandError(self, msg=None): |
| 154 if msg is None: | 227 if msg is None: |
| 155 msg = 'Command failed' | 228 msg = 'Command failed' |
| 156 return mock.Mock(side_effect=device_errors.CommandFailedError( | 229 return mock.Mock(side_effect=device_errors.CommandFailedError( |
| 157 msg, str(self.device))) | 230 msg, str(self.device))) |
| 158 | 231 |
| 159 | 232 |
| 160 class DeviceUtilsIsOnlineTest(DeviceUtilsTest): | 233 class DeviceUtilsIsOnlineTest(DeviceUtilsNewImplTest): |
| 161 | 234 |
| 162 def testIsOnline_true(self): | 235 def testIsOnline_true(self): |
| 163 with self.assertCall(self.call.adb.GetState(), 'device'): | 236 with self.assertCall(self.call.adb.GetState(), 'device'): |
| 164 self.assertTrue(self.device.IsOnline()) | 237 self.assertTrue(self.device.IsOnline()) |
| 165 | 238 |
| 166 def testIsOnline_false(self): | 239 def testIsOnline_false(self): |
| 167 with self.assertCall(self.call.adb.GetState(), 'offline'): | 240 with self.assertCall(self.call.adb.GetState(), 'offline'): |
| 168 self.assertFalse(self.device.IsOnline()) | 241 self.assertFalse(self.device.IsOnline()) |
| 169 | 242 |
| 170 def testIsOnline_error(self): | 243 def testIsOnline_error(self): |
| 171 with self.assertCall(self.call.adb.GetState(), self.CommandError()): | 244 with self.assertCall(self.call.adb.GetState(), self.CommandError()): |
| 172 self.assertFalse(self.device.IsOnline()) | 245 self.assertFalse(self.device.IsOnline()) |
| 173 | 246 |
| 174 | 247 |
| 175 class DeviceUtilsHasRootTest(DeviceUtilsTest): | 248 class DeviceUtilsHasRootTest(DeviceUtilsNewImplTest): |
| 176 | 249 |
| 177 def testHasRoot_true(self): | 250 def testHasRoot_true(self): |
| 178 with self.assertCall(self.call.adb.Shell('ls /root'), 'foo\n'): | 251 with self.assertCall(self.call.adb.Shell('ls /root'), 'foo\n'): |
| 179 self.assertTrue(self.device.HasRoot()) | 252 self.assertTrue(self.device.HasRoot()) |
| 180 | 253 |
| 181 def testHasRoot_false(self): | 254 def testHasRoot_false(self): |
| 182 with self.assertCall(self.call.adb.Shell('ls /root'), self.ShellError()): | 255 with self.assertCall(self.call.adb.Shell('ls /root'), self.ShellError()): |
| 183 self.assertFalse(self.device.HasRoot()) | 256 self.assertFalse(self.device.HasRoot()) |
| 184 | 257 |
| 185 | 258 |
| 186 class DeviceUtilsEnableRootTest(DeviceUtilsTest): | 259 class DeviceUtilsEnableRootTest(DeviceUtilsNewImplTest): |
| 187 | 260 |
| 188 def testEnableRoot_succeeds(self): | 261 def testEnableRoot_succeeds(self): |
| 189 with self.assertCalls( | 262 with self.assertCalls( |
| 190 (self.call.device.IsUserBuild(), False), | 263 (self.call.device.IsUserBuild(), False), |
| 191 self.call.adb.Root(), | 264 self.call.adb.Root(), |
| 192 self.call.adb.WaitForDevice()): | 265 self.call.adb.WaitForDevice()): |
| 193 self.device.EnableRoot() | 266 self.device.EnableRoot() |
| 194 | 267 |
| 195 def testEnableRoot_userBuild(self): | 268 def testEnableRoot_userBuild(self): |
| 196 with self.assertCalls( | 269 with self.assertCalls( |
| 197 (self.call.device.IsUserBuild(), True)): | 270 (self.call.device.IsUserBuild(), True)): |
| 198 with self.assertRaises(device_errors.CommandFailedError): | 271 with self.assertRaises(device_errors.CommandFailedError): |
| 199 self.device.EnableRoot() | 272 self.device.EnableRoot() |
| 200 | 273 |
| 201 def testEnableRoot_rootFails(self): | 274 def testEnableRoot_rootFails(self): |
| 202 with self.assertCalls( | 275 with self.assertCalls( |
| 203 (self.call.device.IsUserBuild(), False), | 276 (self.call.device.IsUserBuild(), False), |
| 204 (self.call.adb.Root(), self.CommandError())): | 277 (self.call.adb.Root(), self.CommandError())): |
| 205 with self.assertRaises(device_errors.CommandFailedError): | 278 with self.assertRaises(device_errors.CommandFailedError): |
| 206 self.device.EnableRoot() | 279 self.device.EnableRoot() |
| 207 | 280 |
| 208 | 281 |
| 209 class DeviceUtilsIsUserBuildTest(DeviceUtilsTest): | 282 class DeviceUtilsIsUserBuildTest(DeviceUtilsNewImplTest): |
| 210 | 283 |
| 211 def testIsUserBuild_yes(self): | 284 def testIsUserBuild_yes(self): |
| 212 with self.assertCall( | 285 with self.assertCall( |
| 213 self.call.device.GetProp('ro.build.type', cache=True), 'user'): | 286 self.call.device.GetProp('ro.build.type', cache=True), 'user'): |
| 214 self.assertTrue(self.device.IsUserBuild()) | 287 self.assertTrue(self.device.IsUserBuild()) |
| 215 | 288 |
| 216 def testIsUserBuild_no(self): | 289 def testIsUserBuild_no(self): |
| 217 with self.assertCall( | 290 with self.assertCall( |
| 218 self.call.device.GetProp('ro.build.type', cache=True), 'userdebug'): | 291 self.call.device.GetProp('ro.build.type', cache=True), 'userdebug'): |
| 219 self.assertFalse(self.device.IsUserBuild()) | 292 self.assertFalse(self.device.IsUserBuild()) |
| 220 | 293 |
| 221 | 294 |
| 222 class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsTest): | 295 class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsNewImplTest): |
| 223 | 296 |
| 224 def testGetExternalStoragePath_succeeds(self): | 297 def testGetExternalStoragePath_succeeds(self): |
| 225 with self.assertCall( | 298 with self.assertCall( |
| 226 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'): | 299 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'): |
| 227 self.assertEquals('/fake/storage/path', | 300 self.assertEquals('/fake/storage/path', |
| 228 self.device.GetExternalStoragePath()) | 301 self.device.GetExternalStoragePath()) |
| 229 | 302 |
| 230 def testGetExternalStoragePath_fails(self): | 303 def testGetExternalStoragePath_fails(self): |
| 231 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'): | 304 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'): |
| 232 with self.assertRaises(device_errors.CommandFailedError): | 305 with self.assertRaises(device_errors.CommandFailedError): |
| 233 self.device.GetExternalStoragePath() | 306 self.device.GetExternalStoragePath() |
| 234 | 307 |
| 235 | 308 |
| 236 class DeviceUtilsGetApplicationPathTest(DeviceUtilsTest): | 309 class DeviceUtilsGetApplicationPathTest(DeviceUtilsNewImplTest): |
| 237 | 310 |
| 238 def testGetApplicationPath_exists(self): | 311 def testGetApplicationPath_exists(self): |
| 239 with self.assertCalls( | 312 with self.assertCalls( |
| 240 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), | 313 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), |
| 241 (self.call.adb.Shell('pm path android'), | 314 (self.call.adb.Shell('pm path android'), |
| 242 'package:/path/to/android.apk\n')): | 315 'package:/path/to/android.apk\n')): |
| 243 self.assertEquals('/path/to/android.apk', | 316 self.assertEquals('/path/to/android.apk', |
| 244 self.device.GetApplicationPath('android')) | 317 self.device.GetApplicationPath('android')) |
| 245 | 318 |
| 246 def testGetApplicationPath_notExists(self): | 319 def testGetApplicationPath_notExists(self): |
| 247 with self.assertCalls( | 320 with self.assertCalls( |
| 248 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), | 321 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), |
| 249 (self.call.adb.Shell('pm path not.installed.app'), '')): | 322 (self.call.adb.Shell('pm path not.installed.app'), '')): |
| 250 self.assertEquals(None, | 323 self.assertEquals(None, |
| 251 self.device.GetApplicationPath('not.installed.app')) | 324 self.device.GetApplicationPath('not.installed.app')) |
| 252 | 325 |
| 253 def testGetApplicationPath_fails(self): | 326 def testGetApplicationPath_fails(self): |
| 254 with self.assertCalls( | 327 with self.assertCalls( |
| 255 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), | 328 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), |
| 256 (self.call.adb.Shell('pm path android'), | 329 (self.call.adb.Shell('pm path android'), |
| 257 self.CommandError('ERROR. Is package manager running?\n'))): | 330 self.CommandError('ERROR. Is package manager running?\n'))): |
| 258 with self.assertRaises(device_errors.CommandFailedError): | 331 with self.assertRaises(device_errors.CommandFailedError): |
| 259 self.device.GetApplicationPath('android') | 332 self.device.GetApplicationPath('android') |
| 260 | 333 |
| 261 | 334 |
| 262 @mock.patch('time.sleep', mock.Mock()) | 335 @mock.patch('time.sleep', mock.Mock()) |
| 263 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): | 336 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsNewImplTest): |
| 264 | 337 |
| 265 def testWaitUntilFullyBooted_succeedsNoWifi(self): | 338 def testWaitUntilFullyBooted_succeedsNoWifi(self): |
| 266 with self.assertCalls( | 339 with self.assertCalls( |
| 267 self.call.adb.WaitForDevice(), | 340 self.call.adb.WaitForDevice(), |
| 268 # sd_card_ready | 341 # sd_card_ready |
| 269 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), | 342 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), |
| 270 (self.call.adb.Shell('test -d /fake/storage/path'), ''), | 343 (self.call.adb.Shell('test -d /fake/storage/path'), ''), |
| 271 # pm_ready | 344 # pm_ready |
| 272 (self.call.device.GetApplicationPath('android'), | 345 (self.call.device.GetApplicationPath('android'), |
| 273 'package:/some/fake/path'), | 346 'package:/some/fake/path'), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), | 436 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), |
| 364 # wifi_enabled | 437 # wifi_enabled |
| 365 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), | 438 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), |
| 366 # wifi_enabled | 439 # wifi_enabled |
| 367 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): | 440 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): |
| 368 with self.assertRaises(device_errors.CommandTimeoutError): | 441 with self.assertRaises(device_errors.CommandTimeoutError): |
| 369 self.device.WaitUntilFullyBooted(wifi=True) | 442 self.device.WaitUntilFullyBooted(wifi=True) |
| 370 | 443 |
| 371 | 444 |
| 372 @mock.patch('time.sleep', mock.Mock()) | 445 @mock.patch('time.sleep', mock.Mock()) |
| 373 class DeviceUtilsRebootTest(DeviceUtilsTest): | 446 class DeviceUtilsRebootTest(DeviceUtilsNewImplTest): |
| 374 | 447 |
| 375 def testReboot_nonBlocking(self): | 448 def testReboot_nonBlocking(self): |
| 376 with self.assertCalls( | 449 with self.assertCalls( |
| 377 self.call.adb.Reboot(), | 450 self.call.adb.Reboot(), |
| 378 (self.call.device.IsOnline(), True), | 451 (self.call.device.IsOnline(), True), |
| 379 (self.call.device.IsOnline(), False)): | 452 (self.call.device.IsOnline(), False)): |
| 380 self.device.Reboot(block=False) | 453 self.device.Reboot(block=False) |
| 381 | 454 |
| 382 def testReboot_blocking(self): | 455 def testReboot_blocking(self): |
| 383 with self.assertCalls( | 456 with self.assertCalls( |
| 384 self.call.adb.Reboot(), | 457 self.call.adb.Reboot(), |
| 385 (self.call.device.IsOnline(), True), | 458 (self.call.device.IsOnline(), True), |
| 386 (self.call.device.IsOnline(), False), | 459 (self.call.device.IsOnline(), False), |
| 387 self.call.device.WaitUntilFullyBooted(wifi=False)): | 460 self.call.device.WaitUntilFullyBooted(wifi=False)): |
| 388 self.device.Reboot(block=True) | 461 self.device.Reboot(block=True) |
| 389 | 462 |
| 390 def testReboot_blockUntilWifi(self): | 463 def testReboot_blockUntilWifi(self): |
| 391 with self.assertCalls( | 464 with self.assertCalls( |
| 392 self.call.adb.Reboot(), | 465 self.call.adb.Reboot(), |
| 393 (self.call.device.IsOnline(), True), | 466 (self.call.device.IsOnline(), True), |
| 394 (self.call.device.IsOnline(), False), | 467 (self.call.device.IsOnline(), False), |
| 395 self.call.device.WaitUntilFullyBooted(wifi=True)): | 468 self.call.device.WaitUntilFullyBooted(wifi=True)): |
| 396 self.device.Reboot(block=True, wifi=True) | 469 self.device.Reboot(block=True, wifi=True) |
| 397 | 470 |
| 398 | 471 |
| 399 class DeviceUtilsInstallTest(DeviceUtilsTest): | 472 class DeviceUtilsInstallTest(DeviceUtilsNewImplTest): |
| 400 | 473 |
| 401 def testInstall_noPriorInstall(self): | 474 def testInstall_noPriorInstall(self): |
| 402 with self.assertCalls( | 475 with self.assertCalls( |
| 403 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), | 476 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), |
| 404 'this.is.a.test.package'), | 477 'this.is.a.test.package'), |
| 405 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), | 478 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), |
| 406 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): | 479 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): |
| 407 self.device.Install('/fake/test/app.apk', retries=0) | 480 self.device.Install('/fake/test/app.apk', retries=0) |
| 408 | 481 |
| 409 def testInstall_differentPriorInstall(self): | 482 def testInstall_differentPriorInstall(self): |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 with self.assertCalls( | 519 with self.assertCalls( |
| 447 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), | 520 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), |
| 448 'this.is.a.test.package'), | 521 'this.is.a.test.package'), |
| 449 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), | 522 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), |
| 450 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), | 523 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), |
| 451 self.CommandError('Failure\r\n'))): | 524 self.CommandError('Failure\r\n'))): |
| 452 with self.assertRaises(device_errors.CommandFailedError): | 525 with self.assertRaises(device_errors.CommandFailedError): |
| 453 self.device.Install('/fake/test/app.apk', retries=0) | 526 self.device.Install('/fake/test/app.apk', retries=0) |
| 454 | 527 |
| 455 | 528 |
| 456 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): | 529 class DeviceUtilsRunShellCommandTest(DeviceUtilsNewImplTest): |
| 457 | 530 |
| 458 def setUp(self): | 531 def setUp(self): |
| 459 super(DeviceUtilsRunShellCommandTest, self).setUp() | 532 super(DeviceUtilsRunShellCommandTest, self).setUp() |
| 460 self.device.NeedsSU = mock.Mock(return_value=False) | 533 self.device.NeedsSU = mock.Mock(return_value=False) |
| 461 | 534 |
| 462 def testRunShellCommand_commandAsList(self): | 535 def testRunShellCommand_commandAsList(self): |
| 463 with self.assertCall(self.call.adb.Shell('pm list packages'), ''): | 536 with self.assertCall(self.call.adb.Shell('pm list packages'), ''): |
| 464 self.device.RunShellCommand(['pm', 'list', 'packages']) | 537 self.device.RunShellCommand(['pm', 'list', 'packages']) |
| 465 | 538 |
| 466 def testRunShellCommand_commandAsListQuoted(self): | 539 def testRunShellCommand_commandAsListQuoted(self): |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 self.device.RunShellCommand(cmd, check_return=True) | 649 self.device.RunShellCommand(cmd, check_return=True) |
| 577 | 650 |
| 578 def testRunShellCommand_checkReturn_disabled(self): | 651 def testRunShellCommand_checkReturn_disabled(self): |
| 579 cmd = 'ls /root' | 652 cmd = 'ls /root' |
| 580 output = 'opendir failed, Permission denied\n' | 653 output = 'opendir failed, Permission denied\n' |
| 581 with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)): | 654 with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)): |
| 582 self.assertEquals([output.rstrip()], | 655 self.assertEquals([output.rstrip()], |
| 583 self.device.RunShellCommand(cmd, check_return=False)) | 656 self.device.RunShellCommand(cmd, check_return=False)) |
| 584 | 657 |
| 585 | 658 |
| 586 class DeviceUtilsGetDevicePieWrapper(DeviceUtilsTest): | 659 class DeviceUtilsGetDevicePieWrapper(DeviceUtilsNewImplTest): |
| 587 | 660 |
| 588 def testGetDevicePieWrapper_jb(self): | 661 def testGetDevicePieWrapper_jb(self): |
| 589 with self.assertCall( | 662 with self.assertCall( |
| 590 self.call.device.build_version_sdk(), | 663 self.call.device.build_version_sdk(), |
| 591 constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN): | 664 constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN): |
| 592 self.assertEqual('', self.device.GetDevicePieWrapper()) | 665 self.assertEqual('', self.device.GetDevicePieWrapper()) |
| 593 | 666 |
| 594 def testGetDevicePieWrapper_ics(self): | 667 def testGetDevicePieWrapper_ics(self): |
| 595 with self.assertCalls( | 668 with self.assertCalls( |
| 596 (self.call.device.build_version_sdk(), | 669 (self.call.device.build_version_sdk(), |
| 597 constants.ANDROID_SDK_VERSION_CODES.ICE_CREAM_SANDWICH), | 670 constants.ANDROID_SDK_VERSION_CODES.ICE_CREAM_SANDWICH), |
| 598 (mock.call.pylib.constants.GetOutDirectory(), '/foo/bar'), | 671 (mock.call.pylib.constants.GetOutDirectory(), '/foo/bar'), |
| 599 (mock.call.os.path.exists(mock.ANY), True), | 672 (mock.call.os.path.exists(mock.ANY), True), |
| 600 (self.call.adb.Push(mock.ANY, mock.ANY), '')): | 673 (self.call.adb.Push(mock.ANY, mock.ANY), '')): |
| 601 self.assertNotEqual('', self.device.GetDevicePieWrapper()) | 674 self.assertNotEqual('', self.device.GetDevicePieWrapper()) |
| 602 | 675 |
| 603 | 676 |
| 604 @mock.patch('time.sleep', mock.Mock()) | 677 @mock.patch('time.sleep', mock.Mock()) |
| 605 class DeviceUtilsKillAllTest(DeviceUtilsTest): | 678 class DeviceUtilsKillAllTest(DeviceUtilsNewImplTest): |
| 606 | 679 |
| 607 def testKillAll_noMatchingProcesses(self): | 680 def testKillAll_noMatchingProcesses(self): |
| 608 with self.assertCall(self.call.adb.Shell('ps'), | 681 with self.assertCall(self.call.adb.Shell('ps'), |
| 609 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'): | 682 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'): |
| 610 with self.assertRaises(device_errors.CommandFailedError): | 683 with self.assertRaises(device_errors.CommandFailedError): |
| 611 self.device.KillAll('test_process') | 684 self.device.KillAll('test_process') |
| 612 | 685 |
| 613 def testKillAll_nonblocking(self): | 686 def testKillAll_nonblocking(self): |
| 614 with self.assertCalls( | 687 with self.assertCalls( |
| 615 (self.call.adb.Shell('ps'), | 688 (self.call.adb.Shell('ps'), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 646 def testKillAll_sigterm(self): | 719 def testKillAll_sigterm(self): |
| 647 with self.assertCalls( | 720 with self.assertCalls( |
| 648 (self.call.adb.Shell('ps'), | 721 (self.call.adb.Shell('ps'), |
| 649 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' | 722 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' |
| 650 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'), | 723 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'), |
| 651 (self.call.adb.Shell('kill -15 1234'), '')): | 724 (self.call.adb.Shell('kill -15 1234'), '')): |
| 652 self.assertEquals(1, | 725 self.assertEquals(1, |
| 653 self.device.KillAll('some.process', signum=signal.SIGTERM)) | 726 self.device.KillAll('some.process', signum=signal.SIGTERM)) |
| 654 | 727 |
| 655 | 728 |
| 656 class DeviceUtilsStartActivityTest(DeviceUtilsTest): | 729 class DeviceUtilsStartActivityTest(DeviceUtilsNewImplTest): |
| 657 | 730 |
| 658 def testStartActivity_actionOnly(self): | 731 def testStartActivity_actionOnly(self): |
| 659 test_intent = intent.Intent(action='android.intent.action.VIEW') | 732 test_intent = intent.Intent(action='android.intent.action.VIEW') |
| 660 with self.assertCall( | 733 with self.assertCall( |
| 661 self.call.adb.Shell('am start ' | 734 self.call.adb.Shell('am start ' |
| 662 '-a android.intent.action.VIEW'), | 735 '-a android.intent.action.VIEW'), |
| 663 'Starting: Intent { act=android.intent.action.VIEW }'): | 736 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 664 self.device.StartActivity(test_intent) | 737 self.device.StartActivity(test_intent) |
| 665 | 738 |
| 666 def testStartActivity_success(self): | 739 def testStartActivity_success(self): |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 flags='0x10000000') | 883 flags='0x10000000') |
| 811 with self.assertCall( | 884 with self.assertCall( |
| 812 self.call.adb.Shell('am start ' | 885 self.call.adb.Shell('am start ' |
| 813 '-a android.intent.action.VIEW ' | 886 '-a android.intent.action.VIEW ' |
| 814 '-n this.is.a.test.package/.Main ' | 887 '-n this.is.a.test.package/.Main ' |
| 815 '-f 0x10000000'), | 888 '-f 0x10000000'), |
| 816 'Starting: Intent { act=android.intent.action.VIEW }'): | 889 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 817 self.device.StartActivity(test_intent) | 890 self.device.StartActivity(test_intent) |
| 818 | 891 |
| 819 | 892 |
| 820 class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest): | 893 class DeviceUtilsStartInstrumentationTest(DeviceUtilsNewImplTest): |
| 821 | 894 |
| 822 def testStartInstrumentation_nothing(self): | 895 def testStartInstrumentation_nothing(self): |
| 823 with self.assertCalls( | 896 with self.assertCalls( |
| 824 self.call.device.RunShellCommand( | 897 self.call.device.RunShellCommand( |
| 825 ['am', 'instrument', 'test.package/.TestInstrumentation'], | 898 ['am', 'instrument', 'test.package/.TestInstrumentation'], |
| 826 check_return=True)): | 899 check_return=True)): |
| 827 self.device.StartInstrumentation( | 900 self.device.StartInstrumentation( |
| 828 'test.package/.TestInstrumentation', | 901 'test.package/.TestInstrumentation', |
| 829 finish=False, raw=False, extras=None) | 902 finish=False, raw=False, extras=None) |
| 830 | 903 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 852 with self.assertCalls( | 925 with self.assertCalls( |
| 853 self.call.device.RunShellCommand( | 926 self.call.device.RunShellCommand( |
| 854 ['am', 'instrument', '-e', 'foo', 'Foo', '-e', 'bar', 'Bar', | 927 ['am', 'instrument', '-e', 'foo', 'Foo', '-e', 'bar', 'Bar', |
| 855 'test.package/.TestInstrumentation'], | 928 'test.package/.TestInstrumentation'], |
| 856 check_return=True)): | 929 check_return=True)): |
| 857 self.device.StartInstrumentation( | 930 self.device.StartInstrumentation( |
| 858 'test.package/.TestInstrumentation', | 931 'test.package/.TestInstrumentation', |
| 859 finish=False, raw=False, extras={'foo': 'Foo', 'bar': 'Bar'}) | 932 finish=False, raw=False, extras={'foo': 'Foo', 'bar': 'Bar'}) |
| 860 | 933 |
| 861 | 934 |
| 862 class DeviceUtilsBroadcastIntentTest(DeviceUtilsTest): | 935 class DeviceUtilsBroadcastIntentTest(DeviceUtilsNewImplTest): |
| 863 | 936 |
| 864 def testBroadcastIntent_noExtras(self): | 937 def testBroadcastIntent_noExtras(self): |
| 865 test_intent = intent.Intent(action='test.package.with.an.INTENT') | 938 test_intent = intent.Intent(action='test.package.with.an.INTENT') |
| 866 with self.assertCall( | 939 with self.assertCall( |
| 867 self.call.adb.Shell('am broadcast -a test.package.with.an.INTENT'), | 940 self.call.adb.Shell('am broadcast -a test.package.with.an.INTENT'), |
| 868 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): | 941 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): |
| 869 self.device.BroadcastIntent(test_intent) | 942 self.device.BroadcastIntent(test_intent) |
| 870 | 943 |
| 871 def testBroadcastIntent_withExtra(self): | 944 def testBroadcastIntent_withExtra(self): |
| 872 test_intent = intent.Intent(action='test.package.with.an.INTENT', | 945 test_intent = intent.Intent(action='test.package.with.an.INTENT', |
| 873 extras={'foo': 'bar value'}) | 946 extras={'foo': 'bar value'}) |
| 874 with self.assertCall( | 947 with self.assertCall( |
| 875 self.call.adb.Shell( | 948 self.call.adb.Shell( |
| 876 "am broadcast -a test.package.with.an.INTENT --es foo 'bar value'"), | 949 "am broadcast -a test.package.with.an.INTENT --es foo 'bar value'"), |
| 877 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): | 950 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): |
| 878 self.device.BroadcastIntent(test_intent) | 951 self.device.BroadcastIntent(test_intent) |
| 879 | 952 |
| 880 def testBroadcastIntent_withExtra_noValue(self): | 953 def testBroadcastIntent_withExtra_noValue(self): |
| 881 test_intent = intent.Intent(action='test.package.with.an.INTENT', | 954 test_intent = intent.Intent(action='test.package.with.an.INTENT', |
| 882 extras={'foo': None}) | 955 extras={'foo': None}) |
| 883 with self.assertCall( | 956 with self.assertCall( |
| 884 self.call.adb.Shell( | 957 self.call.adb.Shell( |
| 885 'am broadcast -a test.package.with.an.INTENT --esn foo'), | 958 'am broadcast -a test.package.with.an.INTENT --esn foo'), |
| 886 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): | 959 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): |
| 887 self.device.BroadcastIntent(test_intent) | 960 self.device.BroadcastIntent(test_intent) |
| 888 | 961 |
| 889 | 962 |
| 890 class DeviceUtilsGoHomeTest(DeviceUtilsTest): | 963 class DeviceUtilsGoHomeTest(DeviceUtilsNewImplTest): |
| 891 | 964 |
| 892 def testGoHome(self): | 965 def testGoHome(self): |
| 893 with self.assertCall( | 966 with self.assertCall( |
| 894 self.call.adb.Shell('am start -W -a android.intent.action.MAIN ' | 967 self.call.adb.Shell('am start -W -a android.intent.action.MAIN ' |
| 895 '-c android.intent.category.HOME'), | 968 '-c android.intent.category.HOME'), |
| 896 'Starting: Intent { act=android.intent.action.MAIN }\r\n'): | 969 'Starting: Intent { act=android.intent.action.MAIN }\r\n'): |
| 897 self.device.GoHome() | 970 self.device.GoHome() |
| 898 | 971 |
| 899 | 972 |
| 900 class DeviceUtilsForceStopTest(DeviceUtilsTest): | 973 class DeviceUtilsForceStopTest(DeviceUtilsNewImplTest): |
| 901 | 974 |
| 902 def testForceStop(self): | 975 def testForceStop(self): |
| 903 with self.assertCall( | 976 with self.assertCall( |
| 904 self.call.adb.Shell('am force-stop this.is.a.test.package'), | 977 self.call.adb.Shell('am force-stop this.is.a.test.package'), |
| 905 ''): | 978 ''): |
| 906 self.device.ForceStop('this.is.a.test.package') | 979 self.device.ForceStop('this.is.a.test.package') |
| 907 | 980 |
| 908 | 981 |
| 909 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): | 982 class DeviceUtilsClearApplicationStateTest(DeviceUtilsNewImplTest): |
| 910 | 983 |
| 911 def testClearApplicationState_packageDoesntExist(self): | 984 def testClearApplicationState_packageDoesntExist(self): |
| 912 with self.assertCalls( | 985 with self.assertCalls( |
| 913 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), | 986 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), |
| 914 (self.call.device.GetApplicationPath('this.package.does.not.exist'), | 987 (self.call.device.GetApplicationPath('this.package.does.not.exist'), |
| 915 None)): | 988 None)): |
| 916 self.device.ClearApplicationState('this.package.does.not.exist') | 989 self.device.ClearApplicationState('this.package.does.not.exist') |
| 917 | 990 |
| 918 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self): | 991 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self): |
| 919 with self.assertCalls( | 992 with self.assertCalls( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 932 self.device.ClearApplicationState('this.package.exists') | 1005 self.device.ClearApplicationState('this.package.exists') |
| 933 | 1006 |
| 934 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self): | 1007 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self): |
| 935 with self.assertCalls( | 1008 with self.assertCalls( |
| 936 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), | 1009 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), |
| 937 (self.call.adb.Shell('pm clear this.package.exists'), | 1010 (self.call.adb.Shell('pm clear this.package.exists'), |
| 938 'Success\r\n')): | 1011 'Success\r\n')): |
| 939 self.device.ClearApplicationState('this.package.exists') | 1012 self.device.ClearApplicationState('this.package.exists') |
| 940 | 1013 |
| 941 | 1014 |
| 942 class DeviceUtilsSendKeyEventTest(DeviceUtilsTest): | 1015 class DeviceUtilsSendKeyEventTest(DeviceUtilsNewImplTest): |
| 943 | 1016 |
| 944 def testSendKeyEvent(self): | 1017 def testSendKeyEvent(self): |
| 945 with self.assertCall(self.call.adb.Shell('input keyevent 66'), ''): | 1018 with self.assertCall(self.call.adb.Shell('input keyevent 66'), ''): |
| 946 self.device.SendKeyEvent(66) | 1019 self.device.SendKeyEvent(66) |
| 947 | 1020 |
| 948 | 1021 |
| 949 class DeviceUtilsPushChangedFilesIndividuallyTest(DeviceUtilsTest): | 1022 class DeviceUtilsPushChangedFilesIndividuallyTest(DeviceUtilsNewImplTest): |
| 950 | 1023 |
| 951 def testPushChangedFilesIndividually_empty(self): | 1024 def testPushChangedFilesIndividually_empty(self): |
| 952 test_files = [] | 1025 test_files = [] |
| 953 with self.assertCalls(): | 1026 with self.assertCalls(): |
| 954 self.device._PushChangedFilesIndividually(test_files) | 1027 self.device._PushChangedFilesIndividually(test_files) |
| 955 | 1028 |
| 956 def testPushChangedFilesIndividually_single(self): | 1029 def testPushChangedFilesIndividually_single(self): |
| 957 test_files = [('/test/host/path', '/test/device/path')] | 1030 test_files = [('/test/host/path', '/test/device/path')] |
| 958 with self.assertCalls(self.call.adb.Push(*test_files[0])): | 1031 with self.assertCalls(self.call.adb.Push(*test_files[0])): |
| 959 self.device._PushChangedFilesIndividually(test_files) | 1032 self.device._PushChangedFilesIndividually(test_files) |
| 960 | 1033 |
| 961 def testPushChangedFilesIndividually_multiple(self): | 1034 def testPushChangedFilesIndividually_multiple(self): |
| 962 test_files = [ | 1035 test_files = [ |
| 963 ('/test/host/path/file1', '/test/device/path/file1'), | 1036 ('/test/host/path/file1', '/test/device/path/file1'), |
| 964 ('/test/host/path/file2', '/test/device/path/file2')] | 1037 ('/test/host/path/file2', '/test/device/path/file2')] |
| 965 with self.assertCalls( | 1038 with self.assertCalls( |
| 966 self.call.adb.Push(*test_files[0]), | 1039 self.call.adb.Push(*test_files[0]), |
| 967 self.call.adb.Push(*test_files[1])): | 1040 self.call.adb.Push(*test_files[1])): |
| 968 self.device._PushChangedFilesIndividually(test_files) | 1041 self.device._PushChangedFilesIndividually(test_files) |
| 969 | 1042 |
| 970 | 1043 |
| 971 class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsTest): | 1044 class DeviceUtilsPushChangedFilesZippedTest(DeviceUtilsNewImplTest): |
| 972 | 1045 |
| 973 def testPushChangedFilesZipped_empty(self): | 1046 def testPushChangedFilesZipped_empty(self): |
| 974 test_files = [] | 1047 test_files = [] |
| 975 with self.assertCalls(): | 1048 with self.assertCalls(): |
| 976 self.device._PushChangedFilesZipped(test_files) | 1049 self.device._PushChangedFilesZipped(test_files) |
| 977 | 1050 |
| 978 def _testPushChangedFilesZipped_spec(self, test_files): | 1051 def _testPushChangedFilesZipped_spec(self, test_files): |
| 979 mock_zip_temp = mock.mock_open() | 1052 mock_zip_temp = mock.mock_open() |
| 980 mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip' | 1053 mock_zip_temp.return_value.name = '/test/temp/file/tmp.zip' |
| 981 with self.assertCalls( | 1054 with self.assertCalls( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1000 def testPushChangedFilesZipped_single(self): | 1073 def testPushChangedFilesZipped_single(self): |
| 1001 self._testPushChangedFilesZipped_spec( | 1074 self._testPushChangedFilesZipped_spec( |
| 1002 [('/test/host/path/file1', '/test/device/path/file1')]) | 1075 [('/test/host/path/file1', '/test/device/path/file1')]) |
| 1003 | 1076 |
| 1004 def testPushChangedFilesZipped_multiple(self): | 1077 def testPushChangedFilesZipped_multiple(self): |
| 1005 self._testPushChangedFilesZipped_spec( | 1078 self._testPushChangedFilesZipped_spec( |
| 1006 [('/test/host/path/file1', '/test/device/path/file1'), | 1079 [('/test/host/path/file1', '/test/device/path/file1'), |
| 1007 ('/test/host/path/file2', '/test/device/path/file2')]) | 1080 ('/test/host/path/file2', '/test/device/path/file2')]) |
| 1008 | 1081 |
| 1009 | 1082 |
| 1010 class DeviceUtilsFileExistsTest(DeviceUtilsTest): | 1083 class DeviceUtilsFileExistsTest(DeviceUtilsNewImplTest): |
| 1011 | 1084 |
| 1012 def testFileExists_usingTest_fileExists(self): | 1085 def testFileExists_usingTest_fileExists(self): |
| 1013 with self.assertCall( | 1086 with self.assertCall( |
| 1014 self.call.device.RunShellCommand( | 1087 self.call.device.RunShellCommand( |
| 1015 ['test', '-e', '/path/file.exists'], check_return=True), ''): | 1088 ['test', '-e', '/path/file.exists'], check_return=True), ''): |
| 1016 self.assertTrue(self.device.FileExists('/path/file.exists')) | 1089 self.assertTrue(self.device.FileExists('/path/file.exists')) |
| 1017 | 1090 |
| 1018 def testFileExists_usingTest_fileDoesntExist(self): | 1091 def testFileExists_usingTest_fileDoesntExist(self): |
| 1019 with self.assertCall( | 1092 with self.assertCall( |
| 1020 self.call.device.RunShellCommand( | 1093 self.call.device.RunShellCommand( |
| 1021 ['test', '-e', '/does/not/exist'], check_return=True), | 1094 ['test', '-e', '/does/not/exist'], check_return=True), |
| 1022 self.ShellError('', 1)): | 1095 self.ShellError('', 1)): |
| 1023 self.assertFalse(self.device.FileExists('/does/not/exist')) | 1096 self.assertFalse(self.device.FileExists('/does/not/exist')) |
| 1024 | 1097 |
| 1025 | 1098 |
| 1026 class DeviceUtilsPullFileTest(DeviceUtilsTest): | 1099 class DeviceUtilsPullFileTest(DeviceUtilsNewImplTest): |
| 1027 | 1100 |
| 1028 def testPullFile_existsOnDevice(self): | 1101 def testPullFile_existsOnDevice(self): |
| 1029 with mock.patch('os.path.exists', return_value=True): | 1102 with mock.patch('os.path.exists', return_value=True): |
| 1030 with self.assertCall( | 1103 with self.assertCall( |
| 1031 self.call.adb.Pull('/data/app/test.file.exists', | 1104 self.call.adb.Pull('/data/app/test.file.exists', |
| 1032 '/test/file/host/path')): | 1105 '/test/file/host/path')): |
| 1033 self.device.PullFile('/data/app/test.file.exists', | 1106 self.device.PullFile('/data/app/test.file.exists', |
| 1034 '/test/file/host/path') | 1107 '/test/file/host/path') |
| 1035 | 1108 |
| 1036 def testPullFile_doesntExistOnDevice(self): | 1109 def testPullFile_doesntExistOnDevice(self): |
| 1037 with mock.patch('os.path.exists', return_value=True): | 1110 with mock.patch('os.path.exists', return_value=True): |
| 1038 with self.assertCall( | 1111 with self.assertCall( |
| 1039 self.call.adb.Pull('/data/app/test.file.does.not.exist', | 1112 self.call.adb.Pull('/data/app/test.file.does.not.exist', |
| 1040 '/test/file/host/path'), | 1113 '/test/file/host/path'), |
| 1041 self.CommandError('remote object does not exist')): | 1114 self.CommandError('remote object does not exist')): |
| 1042 with self.assertRaises(device_errors.CommandFailedError): | 1115 with self.assertRaises(device_errors.CommandFailedError): |
| 1043 self.device.PullFile('/data/app/test.file.does.not.exist', | 1116 self.device.PullFile('/data/app/test.file.does.not.exist', |
| 1044 '/test/file/host/path') | 1117 '/test/file/host/path') |
| 1045 | 1118 |
| 1046 | 1119 |
| 1047 class DeviceUtilsReadFileTest(DeviceUtilsTest): | 1120 class DeviceUtilsReadFileTest(DeviceUtilsNewImplTest): |
| 1048 | 1121 |
| 1049 def testReadFile_exists(self): | 1122 def testReadFile_exists(self): |
| 1050 with self.assertCall( | 1123 with self.assertCall( |
| 1051 self.call.adb.Shell('cat /read/this/test/file'), | 1124 self.call.adb.Shell('cat /read/this/test/file'), |
| 1052 'this is a test file\r\n'): | 1125 'this is a test file\r\n'): |
| 1053 self.assertEqual('this is a test file\n', | 1126 self.assertEqual('this is a test file\n', |
| 1054 self.device.ReadFile('/read/this/test/file')) | 1127 self.device.ReadFile('/read/this/test/file')) |
| 1055 | 1128 |
| 1056 def testReadFile_doesNotExist(self): | 1129 def testReadFile_doesNotExist(self): |
| 1057 with self.assertCall( | 1130 with self.assertCall( |
| 1058 self.call.adb.Shell('cat /this/file/does.not.exist'), | 1131 self.call.adb.Shell('cat /this/file/does.not.exist'), |
| 1059 self.ShellError('/system/bin/sh: cat: /this/file/does.not.exist: ' | 1132 self.ShellError('/system/bin/sh: cat: /this/file/does.not.exist: ' |
| 1060 'No such file or directory')): | 1133 'No such file or directory')): |
| 1061 with self.assertRaises(device_errors.AdbCommandFailedError): | 1134 with self.assertRaises(device_errors.AdbCommandFailedError): |
| 1062 self.device.ReadFile('/this/file/does.not.exist') | 1135 self.device.ReadFile('/this/file/does.not.exist') |
| 1063 | 1136 |
| 1064 def testReadFile_withSU(self): | 1137 def testReadFile_withSU(self): |
| 1065 with self.assertCalls( | 1138 with self.assertCalls( |
| 1066 (self.call.device.NeedsSU(), True), | 1139 (self.call.device.NeedsSU(), True), |
| 1067 (self.call.adb.Shell("su -c sh -c 'cat /this/file/can.be.read.with.su'"), | 1140 (self.call.adb.Shell("su -c sh -c 'cat /this/file/can.be.read.with.su'"), |
| 1068 'this is a test file\nread with su')): | 1141 'this is a test file\nread with su')): |
| 1069 self.assertEqual( | 1142 self.assertEqual( |
| 1070 'this is a test file\nread with su\n', | 1143 'this is a test file\nread with su\n', |
| 1071 self.device.ReadFile('/this/file/can.be.read.with.su', | 1144 self.device.ReadFile('/this/file/can.be.read.with.su', |
| 1072 as_root=True)) | 1145 as_root=True)) |
| 1073 | 1146 |
| 1074 | 1147 |
| 1075 class DeviceUtilsWriteFileTest(DeviceUtilsTest): | 1148 class DeviceUtilsWriteFileTest(DeviceUtilsNewImplTest): |
| 1076 | 1149 |
| 1077 def testWriteFileWithPush_success(self): | 1150 def testWriteFileWithPush_success(self): |
| 1078 tmp_host = MockTempFile('/tmp/file/on.host') | 1151 tmp_host = MockTempFile('/tmp/file/on.host') |
| 1079 contents = 'some interesting contents' | 1152 contents = 'some interesting contents' |
| 1080 with self.assertCalls( | 1153 with self.assertCalls( |
| 1081 (mock.call.tempfile.NamedTemporaryFile(), tmp_host), | 1154 (mock.call.tempfile.NamedTemporaryFile(), tmp_host), |
| 1082 self.call.adb.Push('/tmp/file/on.host', '/path/to/device/file')): | 1155 self.call.adb.Push('/tmp/file/on.host', '/path/to/device/file')): |
| 1083 self.device._WriteFileWithPush('/path/to/device/file', contents) | 1156 self.device._WriteFileWithPush('/path/to/device/file', contents) |
| 1084 tmp_host.file.write.assert_called_once_with(contents) | 1157 tmp_host.file.write.assert_called_once_with(contents) |
| 1085 | 1158 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 self.device.WriteFile('/test/file/to write', 'the contents') | 1201 self.device.WriteFile('/test/file/to write', 'the contents') |
| 1129 | 1202 |
| 1130 def testWriteFile_withEchoAndSU(self): | 1203 def testWriteFile_withEchoAndSU(self): |
| 1131 with self.assertCalls( | 1204 with self.assertCalls( |
| 1132 (self.call.device.NeedsSU(), True), | 1205 (self.call.device.NeedsSU(), True), |
| 1133 (self.call.adb.Shell("su -c sh -c 'echo -n contents > /test/file'"), | 1206 (self.call.adb.Shell("su -c sh -c 'echo -n contents > /test/file'"), |
| 1134 '')): | 1207 '')): |
| 1135 self.device.WriteFile('/test/file', 'contents', as_root=True) | 1208 self.device.WriteFile('/test/file', 'contents', as_root=True) |
| 1136 | 1209 |
| 1137 | 1210 |
| 1138 class DeviceUtilsLsTest(DeviceUtilsTest): | 1211 class DeviceUtilsLsTest(DeviceUtilsNewImplTest): |
| 1139 | 1212 |
| 1140 def testLs_directory(self): | 1213 def testLs_directory(self): |
| 1141 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), | 1214 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), |
| 1142 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1215 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
| 1143 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] | 1216 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] |
| 1144 with self.assertCalls( | 1217 with self.assertCalls( |
| 1145 (self.call.adb.Ls('/data/local/tmp'), result)): | 1218 (self.call.adb.Ls('/data/local/tmp'), result)): |
| 1146 self.assertEquals(result, | 1219 self.assertEquals(result, |
| 1147 self.device.Ls('/data/local/tmp')) | 1220 self.device.Ls('/data/local/tmp')) |
| 1148 | 1221 |
| 1149 def testLs_nothing(self): | 1222 def testLs_nothing(self): |
| 1150 with self.assertCalls( | 1223 with self.assertCalls( |
| 1151 (self.call.adb.Ls('/data/local/tmp/testfile.txt'), [])): | 1224 (self.call.adb.Ls('/data/local/tmp/testfile.txt'), [])): |
| 1152 self.assertEquals([], | 1225 self.assertEquals([], |
| 1153 self.device.Ls('/data/local/tmp/testfile.txt')) | 1226 self.device.Ls('/data/local/tmp/testfile.txt')) |
| 1154 | 1227 |
| 1155 | 1228 |
| 1156 class DeviceUtilsStatTest(DeviceUtilsTest): | 1229 class DeviceUtilsStatTest(DeviceUtilsNewImplTest): |
| 1157 | 1230 |
| 1158 def testStat_file(self): | 1231 def testStat_file(self): |
| 1159 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), | 1232 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), |
| 1160 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1233 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
| 1161 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] | 1234 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] |
| 1162 with self.assertCalls( | 1235 with self.assertCalls( |
| 1163 (self.call.adb.Ls('/data/local/tmp'), result)): | 1236 (self.call.adb.Ls('/data/local/tmp'), result)): |
| 1164 self.assertEquals(adb_wrapper.DeviceStat(33206, 3, 1417436122), | 1237 self.assertEquals(adb_wrapper.DeviceStat(33206, 3, 1417436122), |
| 1165 self.device.Stat('/data/local/tmp/testfile.txt')) | 1238 self.device.Stat('/data/local/tmp/testfile.txt')) |
| 1166 | 1239 |
| 1167 def testStat_directory(self): | 1240 def testStat_directory(self): |
| 1168 result = [('.', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1241 result = [('.', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
| 1169 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1242 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
| 1170 ('tmp', adb_wrapper.DeviceStat(16889, 4096, 1417436123))] | 1243 ('tmp', adb_wrapper.DeviceStat(16889, 4096, 1417436123))] |
| 1171 with self.assertCalls( | 1244 with self.assertCalls( |
| 1172 (self.call.adb.Ls('/data/local'), result)): | 1245 (self.call.adb.Ls('/data/local'), result)): |
| 1173 self.assertEquals(adb_wrapper.DeviceStat(16889, 4096, 1417436123), | 1246 self.assertEquals(adb_wrapper.DeviceStat(16889, 4096, 1417436123), |
| 1174 self.device.Stat('/data/local/tmp')) | 1247 self.device.Stat('/data/local/tmp')) |
| 1175 | 1248 |
| 1176 def testStat_doesNotExist(self): | 1249 def testStat_doesNotExist(self): |
| 1177 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), | 1250 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), |
| 1178 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1251 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
| 1179 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] | 1252 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] |
| 1180 with self.assertCalls( | 1253 with self.assertCalls( |
| 1181 (self.call.adb.Ls('/data/local/tmp'), result)): | 1254 (self.call.adb.Ls('/data/local/tmp'), result)): |
| 1182 with self.assertRaises(device_errors.CommandFailedError): | 1255 with self.assertRaises(device_errors.CommandFailedError): |
| 1183 self.device.Stat('/data/local/tmp/does.not.exist.txt') | 1256 self.device.Stat('/data/local/tmp/does.not.exist.txt') |
| 1184 | 1257 |
| 1185 | 1258 |
| 1186 class DeviceUtilsSetJavaAssertsTest(DeviceUtilsTest): | 1259 class DeviceUtilsSetJavaAssertsTest(DeviceUtilsNewImplTest): |
| 1187 | 1260 |
| 1188 def testSetJavaAsserts_enable(self): | 1261 def testSetJavaAsserts_enable(self): |
| 1189 with self.assertCalls( | 1262 with self.assertCalls( |
| 1190 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), | 1263 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), |
| 1191 'some.example.prop=with an example value\n' | 1264 'some.example.prop=with an example value\n' |
| 1192 'some.other.prop=value_ok\n'), | 1265 'some.other.prop=value_ok\n'), |
| 1193 self.call.device.WriteFile( | 1266 self.call.device.WriteFile( |
| 1194 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 1267 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
| 1195 'some.example.prop=with an example value\n' | 1268 'some.example.prop=with an example value\n' |
| 1196 'some.other.prop=value_ok\n' | 1269 'some.other.prop=value_ok\n' |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1216 def testSetJavaAsserts_alreadyEnabled(self): | 1289 def testSetJavaAsserts_alreadyEnabled(self): |
| 1217 with self.assertCalls( | 1290 with self.assertCalls( |
| 1218 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), | 1291 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), |
| 1219 'some.example.prop=with an example value\n' | 1292 'some.example.prop=with an example value\n' |
| 1220 'dalvik.vm.enableassertions=all\n' | 1293 'dalvik.vm.enableassertions=all\n' |
| 1221 'some.other.prop=value_ok\n'), | 1294 'some.other.prop=value_ok\n'), |
| 1222 (self.call.device.GetProp('dalvik.vm.enableassertions'), 'all')): | 1295 (self.call.device.GetProp('dalvik.vm.enableassertions'), 'all')): |
| 1223 self.assertFalse(self.device.SetJavaAsserts(True)) | 1296 self.assertFalse(self.device.SetJavaAsserts(True)) |
| 1224 | 1297 |
| 1225 | 1298 |
| 1226 class DeviceUtilsGetPropTest(DeviceUtilsTest): | 1299 class DeviceUtilsGetPropTest(DeviceUtilsNewImplTest): |
| 1227 | 1300 |
| 1228 def testGetProp_exists(self): | 1301 def testGetProp_exists(self): |
| 1229 with self.assertCall( | 1302 with self.assertCall( |
| 1230 self.call.adb.Shell('getprop test.property'), 'property_value\n'): | 1303 self.call.adb.Shell('getprop test.property'), 'property_value\n'): |
| 1231 self.assertEqual('property_value', | 1304 self.assertEqual('property_value', |
| 1232 self.device.GetProp('test.property')) | 1305 self.device.GetProp('test.property')) |
| 1233 | 1306 |
| 1234 def testGetProp_doesNotExist(self): | 1307 def testGetProp_doesNotExist(self): |
| 1235 with self.assertCall( | 1308 with self.assertCall( |
| 1236 self.call.adb.Shell('getprop property.does.not.exist'), '\n'): | 1309 self.call.adb.Shell('getprop property.does.not.exist'), '\n'): |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1250 (self.call.adb.Shell('getprop ro.build.type'), self.ShellError()), | 1323 (self.call.adb.Shell('getprop ro.build.type'), self.ShellError()), |
| 1251 (self.call.adb.Shell('getprop ro.build.type'), 'userdebug\n')): | 1324 (self.call.adb.Shell('getprop ro.build.type'), 'userdebug\n')): |
| 1252 self.assertEqual('userdebug', | 1325 self.assertEqual('userdebug', |
| 1253 self.device.GetProp('ro.build.type', | 1326 self.device.GetProp('ro.build.type', |
| 1254 cache=True, retries=3)) | 1327 cache=True, retries=3)) |
| 1255 self.assertEqual('userdebug', | 1328 self.assertEqual('userdebug', |
| 1256 self.device.GetProp('ro.build.type', | 1329 self.device.GetProp('ro.build.type', |
| 1257 cache=True, retries=3)) | 1330 cache=True, retries=3)) |
| 1258 | 1331 |
| 1259 | 1332 |
| 1260 class DeviceUtilsSetPropTest(DeviceUtilsTest): | 1333 class DeviceUtilsSetPropTest(DeviceUtilsNewImplTest): |
| 1261 | 1334 |
| 1262 def testSetProp(self): | 1335 def testSetProp(self): |
| 1263 with self.assertCall( | 1336 with self.assertCall( |
| 1264 self.call.adb.Shell("setprop test.property 'test value'"), ''): | 1337 self.call.adb.Shell("setprop test.property 'test value'"), ''): |
| 1265 self.device.SetProp('test.property', 'test value') | 1338 self.device.SetProp('test.property', 'test value') |
| 1266 | 1339 |
| 1267 def testSetProp_check_succeeds(self): | 1340 def testSetProp_check_succeeds(self): |
| 1268 with self.assertCalls( | 1341 with self.assertCalls( |
| 1269 (self.call.adb.Shell('setprop test.property new_value'), ''), | 1342 (self.call.adb.Shell('setprop test.property new_value'), ''), |
| 1270 (self.call.adb.Shell('getprop test.property'), 'new_value')): | 1343 (self.call.adb.Shell('getprop test.property'), 'new_value')): |
| 1271 self.device.SetProp('test.property', 'new_value', check=True) | 1344 self.device.SetProp('test.property', 'new_value', check=True) |
| 1272 | 1345 |
| 1273 def testSetProp_check_fails(self): | 1346 def testSetProp_check_fails(self): |
| 1274 with self.assertCalls( | 1347 with self.assertCalls( |
| 1275 (self.call.adb.Shell('setprop test.property new_value'), ''), | 1348 (self.call.adb.Shell('setprop test.property new_value'), ''), |
| 1276 (self.call.adb.Shell('getprop test.property'), 'old_value')): | 1349 (self.call.adb.Shell('getprop test.property'), 'old_value')): |
| 1277 with self.assertRaises(device_errors.CommandFailedError): | 1350 with self.assertRaises(device_errors.CommandFailedError): |
| 1278 self.device.SetProp('test.property', 'new_value', check=True) | 1351 self.device.SetProp('test.property', 'new_value', check=True) |
| 1279 | 1352 |
| 1280 | 1353 |
| 1281 class DeviceUtilsGetPidsTest(DeviceUtilsTest): | 1354 class DeviceUtilsGetPidsTest(DeviceUtilsNewImplTest): |
| 1282 | 1355 |
| 1283 def testGetPids_noMatches(self): | 1356 def testGetPids_noMatches(self): |
| 1284 with self.assertCall(self.call.adb.Shell('ps'), | 1357 with self.assertCall(self.call.adb.Shell('ps'), |
| 1285 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' | 1358 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' |
| 1286 'user 1000 100 1024 1024 ffffffff 00000000 no.match\n'): | 1359 'user 1000 100 1024 1024 ffffffff 00000000 no.match\n'): |
| 1287 self.assertEqual({}, self.device.GetPids('does.not.match')) | 1360 self.assertEqual({}, self.device.GetPids('does.not.match')) |
| 1288 | 1361 |
| 1289 def testGetPids_oneMatch(self): | 1362 def testGetPids_oneMatch(self): |
| 1290 with self.assertCall(self.call.adb.Shell('ps'), | 1363 with self.assertCall(self.call.adb.Shell('ps'), |
| 1291 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' | 1364 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1307 def testGetPids_exactMatch(self): | 1380 def testGetPids_exactMatch(self): |
| 1308 with self.assertCall(self.call.adb.Shell('ps'), | 1381 with self.assertCall(self.call.adb.Shell('ps'), |
| 1309 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' | 1382 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' |
| 1310 'user 1000 100 1024 1024 ffffffff 00000000 not.exact.match\n' | 1383 'user 1000 100 1024 1024 ffffffff 00000000 not.exact.match\n' |
| 1311 'user 1234 100 1024 1024 ffffffff 00000000 exact.match\n'): | 1384 'user 1234 100 1024 1024 ffffffff 00000000 exact.match\n'): |
| 1312 self.assertEqual( | 1385 self.assertEqual( |
| 1313 {'not.exact.match': '1000', 'exact.match': '1234'}, | 1386 {'not.exact.match': '1000', 'exact.match': '1234'}, |
| 1314 self.device.GetPids('exact.match')) | 1387 self.device.GetPids('exact.match')) |
| 1315 | 1388 |
| 1316 | 1389 |
| 1317 class DeviceUtilsTakeScreenshotTest(DeviceUtilsTest): | 1390 class DeviceUtilsTakeScreenshotTest(DeviceUtilsNewImplTest): |
| 1318 | 1391 |
| 1319 def testTakeScreenshot_fileNameProvided(self): | 1392 def testTakeScreenshot_fileNameProvided(self): |
| 1320 with self.assertCalls( | 1393 with self.assertCalls( |
| 1321 (mock.call.pylib.utils.device_temp_file.DeviceTempFile( | 1394 (mock.call.pylib.utils.device_temp_file.DeviceTempFile( |
| 1322 self.adb, suffix='.png'), | 1395 self.adb, suffix='.png'), |
| 1323 MockTempFile('/tmp/path/temp-123.png')), | 1396 MockTempFile('/tmp/path/temp-123.png')), |
| 1324 (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'), | 1397 (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'), |
| 1325 ''), | 1398 ''), |
| 1326 self.call.device.PullFile('/tmp/path/temp-123.png', | 1399 self.call.device.PullFile('/tmp/path/temp-123.png', |
| 1327 '/test/host/screenshot.png')): | 1400 '/test/host/screenshot.png')): |
| 1328 self.device.TakeScreenshot('/test/host/screenshot.png') | 1401 self.device.TakeScreenshot('/test/host/screenshot.png') |
| 1329 | 1402 |
| 1330 | 1403 |
| 1331 class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsTest): | 1404 class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsOldImplTest): |
| 1332 | 1405 |
| 1333 def setUp(self): | 1406 def setUp(self): |
| 1334 super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp() | 1407 super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp() |
| 1408 self.device.old_interface._privileged_command_runner = ( |
| 1409 self.device.old_interface.RunShellCommand) |
| 1410 self.device.old_interface._protected_file_access_method_initialized = True |
| 1335 | 1411 |
| 1336 def testGetMemoryUsageForPid_validPid(self): | 1412 def testGetMemoryUsageForPid_validPid(self): |
| 1337 with self.assertCalls( | 1413 with self.assertCallsSequence([ |
| 1338 (self.call.device.RunShellCommand( | 1414 ("adb -s 0123456789abcdef shell 'showmap 1234'", |
| 1339 ['showmap', '1234'], as_root=True, check_return=True), | 1415 '100 101 102 103 104 105 106 107 TOTAL\r\n'), |
| 1340 ['100 101 102 103 104 105 106 107 TOTAL']), | 1416 ("adb -s 0123456789abcdef shell " |
| 1341 (self.call.device.ReadFile('/proc/1234/status', as_root=True), | 1417 "'cat \"/proc/1234/status\" 2> /dev/null'", |
| 1342 'VmHWM: 1024 kB\n')): | 1418 'VmHWM: 1024 kB') |
| 1419 ]): |
| 1343 self.assertEqual( | 1420 self.assertEqual( |
| 1344 { | 1421 { |
| 1345 'Size': 100, | 1422 'Size': 100, |
| 1346 'Rss': 101, | 1423 'Rss': 101, |
| 1347 'Pss': 102, | 1424 'Pss': 102, |
| 1348 'Shared_Clean': 103, | 1425 'Shared_Clean': 103, |
| 1349 'Shared_Dirty': 104, | 1426 'Shared_Dirty': 104, |
| 1350 'Private_Clean': 105, | 1427 'Private_Clean': 105, |
| 1351 'Private_Dirty': 106, | 1428 'Private_Dirty': 106, |
| 1352 'VmHWM': 1024 | 1429 'VmHWM': 1024 |
| 1353 }, | 1430 }, |
| 1354 self.device.GetMemoryUsageForPid(1234)) | 1431 self.device.GetMemoryUsageForPid(1234)) |
| 1355 | 1432 |
| 1356 def testGetMemoryUsageForPid_noSmaps(self): | 1433 def testGetMemoryUsageForPid_invalidPid(self): |
| 1357 with self.assertCalls( | 1434 with self.assertCalls( |
| 1358 (self.call.device.RunShellCommand( | 1435 "adb -s 0123456789abcdef shell 'showmap 4321'", |
| 1359 ['showmap', '4321'], as_root=True, check_return=True), | 1436 'cannot open /proc/4321/smaps: No such file or directory\r\n'): |
| 1360 ['cannot open /proc/4321/smaps: No such file or directory']), | 1437 self.assertEqual({}, self.device.GetMemoryUsageForPid(4321)) |
| 1361 (self.call.device.ReadFile('/proc/4321/status', as_root=True), | |
| 1362 'VmHWM: 1024 kb\n')): | |
| 1363 self.assertEquals({'VmHWM': 1024}, self.device.GetMemoryUsageForPid(4321)) | |
| 1364 | |
| 1365 def testGetMemoryUsageForPid_noStatus(self): | |
| 1366 with self.assertCalls( | |
| 1367 (self.call.device.RunShellCommand( | |
| 1368 ['showmap', '4321'], as_root=True, check_return=True), | |
| 1369 ['100 101 102 103 104 105 106 107 TOTAL']), | |
| 1370 (self.call.device.ReadFile('/proc/4321/status', as_root=True), | |
| 1371 self.CommandError())): | |
| 1372 self.assertEquals( | |
| 1373 { | |
| 1374 'Size': 100, | |
| 1375 'Rss': 101, | |
| 1376 'Pss': 102, | |
| 1377 'Shared_Clean': 103, | |
| 1378 'Shared_Dirty': 104, | |
| 1379 'Private_Clean': 105, | |
| 1380 'Private_Dirty': 106, | |
| 1381 }, | |
| 1382 self.device.GetMemoryUsageForPid(4321)) | |
| 1383 | 1438 |
| 1384 | 1439 |
| 1385 class DeviceUtilsStrTest(DeviceUtilsTest): | 1440 class DeviceUtilsStrTest(DeviceUtilsNewImplTest): |
| 1386 | 1441 |
| 1387 def testStr_returnsSerial(self): | 1442 def testStr_returnsSerial(self): |
| 1388 with self.assertCalls( | 1443 with self.assertCalls( |
| 1389 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): | 1444 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): |
| 1390 self.assertEqual('0123456789abcdef', str(self.device)) | 1445 self.assertEqual('0123456789abcdef', str(self.device)) |
| 1391 | 1446 |
| 1392 | 1447 |
| 1393 class DeviceUtilsParallelTest(mock_calls.TestCase): | 1448 class DeviceUtilsParallelTest(mock_calls.TestCase): |
| 1394 | 1449 |
| 1395 def testParallel_default(self): | 1450 def testParallel_default(self): |
| 1396 test_serials = ['0123456789abcdef', 'fedcba9876543210'] | 1451 test_serials = ['0123456789abcdef', 'fedcba9876543210'] |
| 1397 with self.assertCall( | 1452 with self.assertCall( |
| 1398 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), | 1453 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), |
| 1399 [_AdbWrapperMock(serial) for serial in test_serials]): | 1454 [_AdbWrapperMock(serial) for serial in test_serials]): |
| 1400 parallel_devices = device_utils.DeviceUtils.parallel() | 1455 parallel_devices = device_utils.DeviceUtils.parallel() |
| 1401 for serial, device in zip(test_serials, parallel_devices.pGet(None)): | 1456 for serial, device in zip(test_serials, parallel_devices.pGet(None)): |
| 1402 self.assertTrue( | 1457 self.assertTrue( |
| 1403 isinstance(device, device_utils.DeviceUtils) | 1458 isinstance(device, device_utils.DeviceUtils) |
| 1404 and serial == str(device), | 1459 and serial == str(device), |
| 1405 'Expected a DeviceUtils object with serial %s' % serial) | 1460 'Expected a DeviceUtils object with serial %s' % serial) |
| 1406 | 1461 |
| 1407 def testParallel_noDevices(self): | |
| 1408 with self.assertCall( | |
| 1409 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), []): | |
| 1410 with self.assertRaises(device_errors.NoDevicesError): | |
| 1411 device_utils.DeviceUtils.parallel() | |
| 1412 | |
| 1413 | 1462 |
| 1414 if __name__ == '__main__': | 1463 if __name__ == '__main__': |
| 1415 logging.getLogger().setLevel(logging.DEBUG) | 1464 logging.getLogger().setLevel(logging.DEBUG) |
| 1416 unittest.main(verbosity=2) | 1465 unittest.main(verbosity=2) |
| 1417 | 1466 |
| OLD | NEW |