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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 self.call.adb.Reboot(), | 450 self.call.adb.Reboot(), |
451 (self.call.device.IsOnline(), True), | 451 (self.call.device.IsOnline(), True), |
452 (self.call.device.IsOnline(), False)): | 452 (self.call.device.IsOnline(), False)): |
453 self.device.Reboot(block=False) | 453 self.device.Reboot(block=False) |
454 | 454 |
455 def testReboot_blocking(self): | 455 def testReboot_blocking(self): |
456 with self.assertCalls( | 456 with self.assertCalls( |
457 self.call.adb.Reboot(), | 457 self.call.adb.Reboot(), |
458 (self.call.device.IsOnline(), True), | 458 (self.call.device.IsOnline(), True), |
459 (self.call.device.IsOnline(), False), | 459 (self.call.device.IsOnline(), False), |
460 self.call.device.WaitUntilFullyBooted()): | 460 self.call.device.WaitUntilFullyBooted(wifi=False)): |
461 self.device.Reboot(block=True) | 461 self.device.Reboot(block=True) |
462 | 462 |
| 463 def testReboot_blockUntilWifi(self): |
| 464 with self.assertCalls( |
| 465 self.call.adb.Reboot(), |
| 466 (self.call.device.IsOnline(), True), |
| 467 (self.call.device.IsOnline(), False), |
| 468 self.call.device.WaitUntilFullyBooted(wifi=True)): |
| 469 self.device.Reboot(block=True, wifi=True) |
| 470 |
463 | 471 |
464 class DeviceUtilsInstallTest(DeviceUtilsNewImplTest): | 472 class DeviceUtilsInstallTest(DeviceUtilsNewImplTest): |
465 | 473 |
466 def testInstall_noPriorInstall(self): | 474 def testInstall_noPriorInstall(self): |
467 with self.assertCalls( | 475 with self.assertCalls( |
468 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), | 476 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), |
469 'this.is.a.test.package'), | 477 'this.is.a.test.package'), |
470 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), | 478 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), |
471 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): | 479 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): |
472 self.device.Install('/fake/test/app.apk', retries=0) | 480 self.device.Install('/fake/test/app.apk', retries=0) |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 def testStat_doesNotExist(self): | 1231 def testStat_doesNotExist(self): |
1224 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), | 1232 result = [('.', adb_wrapper.DeviceStat(16889, 4096, 1417436123)), |
1225 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), | 1233 ('..', adb_wrapper.DeviceStat(16873, 4096, 12382237)), |
1226 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] | 1234 ('testfile.txt', adb_wrapper.DeviceStat(33206, 3, 1417436122))] |
1227 with self.assertCalls( | 1235 with self.assertCalls( |
1228 (self.call.adb.Ls('/data/local/tmp'), result)): | 1236 (self.call.adb.Ls('/data/local/tmp'), result)): |
1229 with self.assertRaises(device_errors.CommandFailedError): | 1237 with self.assertRaises(device_errors.CommandFailedError): |
1230 self.device.Stat('/data/local/tmp/does.not.exist.txt') | 1238 self.device.Stat('/data/local/tmp/does.not.exist.txt') |
1231 | 1239 |
1232 | 1240 |
1233 class DeviceUtilsSetJavaAssertsTest(DeviceUtilsOldImplTest): | 1241 class DeviceUtilsSetJavaAssertsTest(DeviceUtilsNewImplTest): |
1234 | |
1235 @staticmethod | |
1236 def mockNamedTemporary(name='/tmp/file/property.file', | |
1237 read_contents=''): | |
1238 mock_file = mock.MagicMock(spec=file) | |
1239 mock_file.name = name | |
1240 mock_file.__enter__.return_value = mock_file | |
1241 mock_file.read.return_value = read_contents | |
1242 return mock_file | |
1243 | 1242 |
1244 def testSetJavaAsserts_enable(self): | 1243 def testSetJavaAsserts_enable(self): |
1245 mock_file = self.mockNamedTemporary() | 1244 with self.assertCalls( |
1246 with mock.patch('tempfile.NamedTemporaryFile', | 1245 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), |
1247 return_value=mock_file), ( | 1246 'some.example.prop=with an example value\n' |
1248 mock.patch('__builtin__.open', return_value=mock_file)): | 1247 'some.other.prop=value_ok\n'), |
1249 with self.assertCallsSequence( | 1248 self.call.device.WriteFile( |
1250 [('adb -s 0123456789abcdef shell ls %s' % | 1249 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
1251 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 1250 'some.example.prop=with an example value\n' |
1252 '%s\r\n' % constants.DEVICE_LOCAL_PROPERTIES_PATH), | 1251 'some.other.prop=value_ok\n' |
1253 ('adb -s 0123456789abcdef pull %s %s' % | 1252 'dalvik.vm.enableassertions=all\n'), |
1254 (constants.DEVICE_LOCAL_PROPERTIES_PATH, mock_file.name), | 1253 (self.call.device.GetProp('dalvik.vm.enableassertions'), ''), |
1255 '100 B/s (100 bytes in 1.000s)\r\n'), | 1254 self.call.device.SetProp('dalvik.vm.enableassertions', 'all')): |
1256 ('adb -s 0123456789abcdef push %s %s' % | 1255 self.assertTrue(self.device.SetJavaAsserts(True)) |
1257 (mock_file.name, constants.DEVICE_LOCAL_PROPERTIES_PATH), | |
1258 '100 B/s (100 bytes in 1.000s)\r\n'), | |
1259 ('adb -s 0123456789abcdef shell ' | |
1260 'getprop dalvik.vm.enableassertions', | |
1261 '\r\n'), | |
1262 ('adb -s 0123456789abcdef shell ' | |
1263 'setprop dalvik.vm.enableassertions "all"', | |
1264 '')]): | |
1265 self.assertTrue(self.device.SetJavaAsserts(True)) | |
1266 | 1256 |
1267 def testSetJavaAsserts_disable(self): | 1257 def testSetJavaAsserts_disable(self): |
1268 mock_file = self.mockNamedTemporary( | 1258 with self.assertCalls( |
1269 read_contents='dalvik.vm.enableassertions=all\n') | 1259 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), |
1270 with mock.patch('tempfile.NamedTemporaryFile', | 1260 'some.example.prop=with an example value\n' |
1271 return_value=mock_file), ( | 1261 'dalvik.vm.enableassertions=all\n' |
1272 mock.patch('__builtin__.open', return_value=mock_file)): | 1262 'some.other.prop=value_ok\n'), |
1273 with self.assertCallsSequence( | 1263 self.call.device.WriteFile( |
1274 [('adb -s 0123456789abcdef shell ls %s' % | 1264 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
1275 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 1265 'some.example.prop=with an example value\n' |
1276 '%s\r\n' % constants.DEVICE_LOCAL_PROPERTIES_PATH), | 1266 'some.other.prop=value_ok\n'), |
1277 ('adb -s 0123456789abcdef pull %s %s' % | 1267 (self.call.device.GetProp('dalvik.vm.enableassertions'), 'all'), |
1278 (constants.DEVICE_LOCAL_PROPERTIES_PATH, mock_file.name), | 1268 self.call.device.SetProp('dalvik.vm.enableassertions', '')): |
1279 '100 B/s (100 bytes in 1.000s)\r\n'), | 1269 self.assertTrue(self.device.SetJavaAsserts(False)) |
1280 ('adb -s 0123456789abcdef push %s %s' % | |
1281 (mock_file.name, constants.DEVICE_LOCAL_PROPERTIES_PATH), | |
1282 '100 B/s (100 bytes in 1.000s)\r\n'), | |
1283 ('adb -s 0123456789abcdef shell ' | |
1284 'getprop dalvik.vm.enableassertions', | |
1285 'all\r\n'), | |
1286 ('adb -s 0123456789abcdef shell ' | |
1287 'setprop dalvik.vm.enableassertions ""', | |
1288 '')]): | |
1289 self.assertTrue(self.device.SetJavaAsserts(False)) | |
1290 | 1270 |
1291 def testSetJavaAsserts_alreadyEnabled(self): | 1271 def testSetJavaAsserts_alreadyEnabled(self): |
1292 mock_file = self.mockNamedTemporary( | 1272 with self.assertCalls( |
1293 read_contents='dalvik.vm.enableassertions=all\n') | 1273 (self.call.device.ReadFile(constants.DEVICE_LOCAL_PROPERTIES_PATH), |
1294 with mock.patch('tempfile.NamedTemporaryFile', | 1274 'some.example.prop=with an example value\n' |
1295 return_value=mock_file), ( | 1275 'dalvik.vm.enableassertions=all\n' |
1296 mock.patch('__builtin__.open', return_value=mock_file)): | 1276 'some.other.prop=value_ok\n'), |
1297 with self.assertCallsSequence( | 1277 (self.call.device.GetProp('dalvik.vm.enableassertions'), 'all')): |
1298 [('adb -s 0123456789abcdef shell ls %s' % | 1278 self.assertFalse(self.device.SetJavaAsserts(True)) |
1299 constants.DEVICE_LOCAL_PROPERTIES_PATH, | |
1300 '%s\r\n' % constants.DEVICE_LOCAL_PROPERTIES_PATH), | |
1301 ('adb -s 0123456789abcdef pull %s %s' % | |
1302 (constants.DEVICE_LOCAL_PROPERTIES_PATH, mock_file.name), | |
1303 '100 B/s (100 bytes in 1.000s)\r\n'), | |
1304 ('adb -s 0123456789abcdef shell ' | |
1305 'getprop dalvik.vm.enableassertions', | |
1306 'all\r\n')]): | |
1307 self.assertFalse(self.device.SetJavaAsserts(True)) | |
1308 | 1279 |
1309 | 1280 |
1310 class DeviceUtilsGetPropTest(DeviceUtilsNewImplTest): | 1281 class DeviceUtilsGetPropTest(DeviceUtilsNewImplTest): |
1311 | 1282 |
1312 def testGetProp_exists(self): | 1283 def testGetProp_exists(self): |
1313 with self.assertCall( | 1284 with self.assertCall( |
1314 self.call.adb.Shell('getprop test.property'), 'property_value\n'): | 1285 self.call.adb.Shell('getprop test.property'), 'property_value\n'): |
1315 self.assertEqual('property_value', | 1286 self.assertEqual('property_value', |
1316 self.device.GetProp('test.property')) | 1287 self.device.GetProp('test.property')) |
1317 | 1288 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 self.assertTrue( | 1455 self.assertTrue( |
1485 isinstance(device, device_utils.DeviceUtils) | 1456 isinstance(device, device_utils.DeviceUtils) |
1486 and serial == str(device), | 1457 and serial == str(device), |
1487 'Expected a DeviceUtils object with serial %s' % serial) | 1458 'Expected a DeviceUtils object with serial %s' % serial) |
1488 | 1459 |
1489 | 1460 |
1490 if __name__ == '__main__': | 1461 if __name__ == '__main__': |
1491 logging.getLogger().setLevel(logging.DEBUG) | 1462 logging.getLogger().setLevel(logging.DEBUG) |
1492 unittest.main(verbosity=2) | 1463 unittest.main(verbosity=2) |
1493 | 1464 |
OLD | NEW |