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

Side by Side Diff: build/android/pylib/device/device_utils_test.py

Issue 547623002: Simpler logic to setup/restore Chrome command line (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nit (lined up params) Created 6 years, 3 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
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=C0321 10 # pylint: disable=C0321
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 self.device.WriteFile('/test/file/written.to.device', 1200 self.device.WriteFile('/test/file/written.to.device',
1201 'new test file contents', as_root=True) 1201 'new test file contents', as_root=True)
1202 1202
1203 def testWriteFile_asRoot_rejected(self): 1203 def testWriteFile_asRoot_rejected(self):
1204 self.device.old_interface._privileged_command_runner = None 1204 self.device.old_interface._privileged_command_runner = None
1205 self.device.old_interface._protected_file_access_method_initialized = True 1205 self.device.old_interface._protected_file_access_method_initialized = True
1206 with self.assertRaises(device_errors.CommandFailedError): 1206 with self.assertRaises(device_errors.CommandFailedError):
1207 self.device.WriteFile('/test/file/no.permissions.to.write', 1207 self.device.WriteFile('/test/file/no.permissions.to.write',
1208 'new test file contents', as_root=True) 1208 'new test file contents', as_root=True)
1209 1209
1210 class DeviceUtilsWriteTextFileTest(DeviceUtilsOldImplTest):
1211
1212 def testWriteTextFileTest_basic(self):
1213 with self.assertCalls(
1214 "adb -s 0123456789abcdef shell 'echo some.string"
1215 " > /test/file/to.write; echo %$?'", '%0\r\n'):
1216 self.device.WriteTextFile('/test/file/to.write', 'some.string')
1217
1218 def testWriteTextFileTest_stringWithSpaces(self):
1219 with self.assertCalls(
1220 "adb -s 0123456789abcdef shell 'echo '\\''some other string'\\''"
1221 " > /test/file/to.write; echo %$?'", '%0\r\n'):
1222 self.device.WriteTextFile('/test/file/to.write', 'some other string')
1223
1224 def testWriteTextFileTest_asRoot_withSu(self):
1225 with self.assertCallsSequence([
1226 ("adb -s 0123456789abcdef shell 'ls /root'", 'Permission denied\r\n'),
1227 ("adb -s 0123456789abcdef shell 'su -c echo some.string"
1228 " > /test/file/to.write; echo %$?'", '%0\r\n')]):
1229 self.device.WriteTextFile('/test/file/to.write', 'some.string',
1230 as_root=True)
1231
1232 def testWriteTextFileTest_asRoot_withRoot(self):
1233 with self.assertCallsSequence([
1234 ("adb -s 0123456789abcdef shell 'ls /root'", 'hello\r\nworld\r\n'),
1235 ("adb -s 0123456789abcdef shell 'echo some.string"
1236 " > /test/file/to.write; echo %$?'", '%0\r\n')]):
1237 self.device.WriteTextFile('/test/file/to.write', 'some.string',
1238 as_root=True)
1239
1240 def testWriteTextFileTest_asRoot_rejected(self):
1241 with self.assertCallsSequence([
1242 ("adb -s 0123456789abcdef shell 'ls /root'", 'Permission denied\r\n'),
1243 ("adb -s 0123456789abcdef shell 'su -c echo some.string"
1244 " > /test/file/to.write; echo %$?'", '%1\r\n')]):
1245 with self.assertRaises(device_errors.CommandFailedError):
1246 self.device.WriteTextFile('/test/file/to.write', 'some.string',
1247 as_root=True)
1210 1248
1211 class DeviceUtilsLsTest(DeviceUtilsOldImplTest): 1249 class DeviceUtilsLsTest(DeviceUtilsOldImplTest):
1212 1250
1213 def testLs_nothing(self): 1251 def testLs_nothing(self):
1214 with self.assertCallsSequence([ 1252 with self.assertCallsSequence([
1215 ("adb -s 0123456789abcdef shell 'ls -lR /this/file/does.not.exist'", 1253 ("adb -s 0123456789abcdef shell 'ls -lR /this/file/does.not.exist'",
1216 '/this/file/does.not.exist: No such file or directory\r\n'), 1254 '/this/file/does.not.exist: No such file or directory\r\n'),
1217 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]): 1255 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]):
1218 self.assertEqual({}, self.device.Ls('/this/file/does.not.exist')) 1256 self.assertEqual({}, self.device.Ls('/this/file/does.not.exist'))
1219 1257
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 self.device = device_utils.DeviceUtils(None) 1531 self.device = device_utils.DeviceUtils(None)
1494 with self.assertCalls('adb get-serialno', 'unknown'), ( 1532 with self.assertCalls('adb get-serialno', 'unknown'), (
1495 self.assertRaises(device_errors.NoDevicesError)): 1533 self.assertRaises(device_errors.NoDevicesError)):
1496 str(self.device) 1534 str(self.device)
1497 1535
1498 1536
1499 if __name__ == '__main__': 1537 if __name__ == '__main__':
1500 logging.getLogger().setLevel(logging.DEBUG) 1538 logging.getLogger().setLevel(logging.DEBUG)
1501 unittest.main(verbosity=2) 1539 unittest.main(verbosity=2)
1502 1540
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | tools/telemetry/telemetry/core/backends/chrome/android_browser_backend.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698