| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 | 288 |
| 289 def testHasRoot_true(self): | 289 def testHasRoot_true(self): |
| 290 with self.assertCall(self.call.adb.Shell('ls /root'), 'foo\n'): | 290 with self.assertCall(self.call.adb.Shell('ls /root'), 'foo\n'): |
| 291 self.assertTrue(self.device.HasRoot()) | 291 self.assertTrue(self.device.HasRoot()) |
| 292 | 292 |
| 293 def testHasRoot_false(self): | 293 def testHasRoot_false(self): |
| 294 with self.assertCall(self.call.adb.Shell('ls /root'), self.ShellError()): | 294 with self.assertCall(self.call.adb.Shell('ls /root'), self.ShellError()): |
| 295 self.assertFalse(self.device.HasRoot()) | 295 self.assertFalse(self.device.HasRoot()) |
| 296 | 296 |
| 297 | 297 |
| 298 class DeviceUtilsEnableRootTest(DeviceUtilsOldImplTest): | 298 class DeviceUtilsEnableRootTest(DeviceUtilsNewImplTest): |
| 299 | 299 |
| 300 def testEnableRoot_succeeds(self): | 300 def testEnableRoot_succeeds(self): |
| 301 with self.assertCallsSequence([ | 301 with self.assertCalls( |
| 302 ('adb -s 0123456789abcdef shell getprop ro.build.type', | 302 (self.call.device.IsUserBuild(), False), |
| 303 'userdebug\r\n'), | 303 self.call.adb.Root(), |
| 304 ('adb -s 0123456789abcdef root', 'restarting adbd as root\r\n'), | 304 self.call.adb.WaitForDevice()): |
| 305 ('adb -s 0123456789abcdef wait-for-device', ''), | |
| 306 ('adb -s 0123456789abcdef wait-for-device', '')]): | |
| 307 self.device.EnableRoot() | 305 self.device.EnableRoot() |
| 308 | 306 |
| 309 def testEnableRoot_userBuild(self): | 307 def testEnableRoot_userBuild(self): |
| 310 with self.assertCallsSequence([ | 308 with self.assertCalls( |
| 311 ('adb -s 0123456789abcdef shell getprop ro.build.type', 'user\r\n')]): | 309 (self.call.device.IsUserBuild(), True)): |
| 312 with self.assertRaises(device_errors.CommandFailedError): | 310 with self.assertRaises(device_errors.CommandFailedError): |
| 313 self.device.EnableRoot() | 311 self.device.EnableRoot() |
| 314 | 312 |
| 315 def testEnableRoot_rootFails(self): | 313 def testEnableRoot_rootFails(self): |
| 316 with self.assertCallsSequence([ | 314 with self.assertCalls( |
| 317 ('adb -s 0123456789abcdef shell getprop ro.build.type', | 315 (self.call.device.IsUserBuild(), False), |
| 318 'userdebug\r\n'), | 316 (self.call.adb.Root(), self.CommandError())): |
| 319 ('adb -s 0123456789abcdef root', 'no\r\n'), | |
| 320 ('adb -s 0123456789abcdef wait-for-device', '')]): | |
| 321 with self.assertRaises(device_errors.CommandFailedError): | 317 with self.assertRaises(device_errors.CommandFailedError): |
| 322 self.device.EnableRoot() | 318 self.device.EnableRoot() |
| 323 | 319 |
| 324 | 320 |
| 325 class DeviceUtilsIsUserBuildTest(DeviceUtilsNewImplTest): | 321 class DeviceUtilsIsUserBuildTest(DeviceUtilsNewImplTest): |
| 326 | 322 |
| 327 def testIsUserBuild_yes(self): | 323 def testIsUserBuild_yes(self): |
| 328 with self.assertCall( | 324 with self.assertCall( |
| 329 self.call.device.GetProp('ro.build.type', cache=True), 'user'): | 325 self.call.device.GetProp('ro.build.type', cache=True), 'user'): |
| 330 self.assertTrue(self.device.IsUserBuild()) | 326 self.assertTrue(self.device.IsUserBuild()) |
| (...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 self.device = device_utils.DeviceUtils(None) | 1539 self.device = device_utils.DeviceUtils(None) |
| 1544 with self.assertCalls('adb get-serialno', 'unknown'), ( | 1540 with self.assertCalls('adb get-serialno', 'unknown'), ( |
| 1545 self.assertRaises(device_errors.NoDevicesError)): | 1541 self.assertRaises(device_errors.NoDevicesError)): |
| 1546 str(self.device) | 1542 str(self.device) |
| 1547 | 1543 |
| 1548 | 1544 |
| 1549 if __name__ == '__main__': | 1545 if __name__ == '__main__': |
| 1550 logging.getLogger().setLevel(logging.DEBUG) | 1546 logging.getLogger().setLevel(logging.DEBUG) |
| 1551 unittest.main(verbosity=2) | 1547 unittest.main(verbosity=2) |
| 1552 | 1548 |
| OLD | NEW |