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

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

Issue 377373004: [Android] Split DeviceUtils tests and run them in presubmit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
« build/android/PRESUBMIT.py ('K') | « build/android/PRESUBMIT.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python
1 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # 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
3 # found in the LICENSE file. 4 # found in the LICENSE file.
4 5
5 """ 6 """
6 Unit tests for the contents of device_utils.py (mostly DeviceUtils). 7 Unit tests for the contents of device_utils.py (mostly DeviceUtils).
7 """ 8 """
8 9
9 # pylint: disable=C0321 10 # pylint: disable=C0321
10 # pylint: disable=W0212 11 # pylint: disable=W0212
11 # pylint: disable=W0613 12 # pylint: disable=W0613
12 13
13 import collections 14 import collections
14 import datetime 15 import datetime
15 import logging 16 import logging
16 import os 17 import os
17 import re 18 import re
18 import signal 19 import signal
19 import sys 20 import sys
20 import unittest 21 import unittest
21 22
22 from pylib import android_commands 23 from pylib import android_commands
23 from pylib import constants 24 from pylib import constants
24 from pylib.device import adb_wrapper 25 from pylib.device import adb_wrapper
25 from pylib.device import device_errors 26 from pylib.device import device_errors
26 from pylib.device import device_utils 27 from pylib.device import device_utils
27 from pylib.device import intent 28 from pylib.device import intent
28 29
30 # RunCommand from third_party/android_testrunner/run_command.py is mocked
31 # below, so its path needs to be in sys.path.
29 sys.path.append(os.path.join( 32 sys.path.append(os.path.join(
30 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) 33 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner'))
31 import run_command as atr_run_command
32 34
33 sys.path.append(os.path.join( 35 sys.path.append(os.path.join(
34 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) 36 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
35 import mock # pylint: disable=F0401 37 import mock # pylint: disable=F0401
36 38
37 39
38 class DeviceUtilsTest(unittest.TestCase): 40 class DeviceUtilsTest(unittest.TestCase):
39 41
40 def testInitWithStr(self): 42 def testInitWithStr(self):
41 serial_as_str = str('0123456789abcdef') 43 serial_as_str = str('0123456789abcdef')
(...skipping 15 matching lines...) Expand all
57 serial = '0fedcba987654321' 59 serial = '0fedcba987654321'
58 a = android_commands.AndroidCommands(device=serial) 60 a = android_commands.AndroidCommands(device=serial)
59 d = device_utils.DeviceUtils(a) 61 d = device_utils.DeviceUtils(a)
60 self.assertEqual(serial, d.old_interface.GetDevice()) 62 self.assertEqual(serial, d.old_interface.GetDevice())
61 63
62 def testInitWithNone(self): 64 def testInitWithNone(self):
63 d = device_utils.DeviceUtils(None) 65 d = device_utils.DeviceUtils(None)
64 self.assertIsNone(d.old_interface.GetDevice()) 66 self.assertIsNone(d.old_interface.GetDevice())
65 67
66 68
67 # TODO(jbudorick) Split this into separate classes by DeviceUtils function. 69 class _PatchedFunction(object):
70 def __init__(self, patched=None, mocked=None):
71 self.patched = patched
72 self.mocked = mocked
73
74
68 class DeviceUtilsOldImplTest(unittest.TestCase): 75 class DeviceUtilsOldImplTest(unittest.TestCase):
69 76
70 class AndroidCommandsCalls(object): 77 class AndroidCommandsCalls(object):
71 78
72 def __init__(self, test_case, cmd_ret, comp): 79 def __init__(self, test_case, cmd_ret, comp):
73 self._cmds = cmd_ret 80 self._cmds = cmd_ret
74 self._comp = comp 81 self._comp = comp
82 self._run_command = _PatchedFunction()
75 self._test_case = test_case 83 self._test_case = test_case
76 self._total_received = 0 84 self._total_received = 0
77 85
78 def __enter__(self): 86 def __enter__(self):
79 atr_run_command.RunCommand = mock.Mock() 87 self._run_command.patched = mock.patch(
80 atr_run_command.RunCommand.side_effect = lambda c, **kw: self._ret(c) 88 'run_command.RunCommand',
89 side_effect=lambda c, **kw: self._ret(c))
90 self._run_command.mocked = self._run_command.patched.__enter__()
81 91
82 def _ret(self, actual_cmd): 92 def _ret(self, actual_cmd):
83 if sys.exc_info()[0] is None: 93 if sys.exc_info()[0] is None:
84 on_failure_fmt = ('\n' 94 on_failure_fmt = ('\n'
85 ' received command: %s\n' 95 ' received command: %s\n'
86 ' expected command: %s') 96 ' expected command: %s')
87 self._test_case.assertGreater( 97 self._test_case.assertGreater(
88 len(self._cmds), self._total_received, 98 len(self._cmds), self._total_received,
89 msg=on_failure_fmt % (actual_cmd, None)) 99 msg=on_failure_fmt % (actual_cmd, None))
90 expected_cmd, ret = self._cmds[self._total_received] 100 expected_cmd, ret = self._cmds[self._total_received]
91 self._total_received += 1 101 self._total_received += 1
92 self._test_case.assertTrue( 102 self._test_case.assertTrue(
93 self._comp(expected_cmd, actual_cmd), 103 self._comp(expected_cmd, actual_cmd),
94 msg=on_failure_fmt % (actual_cmd, expected_cmd)) 104 msg=on_failure_fmt % (actual_cmd, expected_cmd))
95 return ret 105 return ret
96 return '' 106 return ''
97 107
98 def __exit__(self, exc_type, _exc_val, exc_trace): 108 def __exit__(self, exc_type, exc_val, exc_tb):
109 self._run_command.patched.__exit__(exc_type, exc_val, exc_tb)
99 if exc_type is None: 110 if exc_type is None:
100 on_failure = "adb commands don't match.\nExpected:%s\nActual:%s" % ( 111 on_failure = "adb commands don't match.\nExpected:%s\nActual:%s" % (
101 ''.join('\n %s' % c for c, _ in self._cmds), 112 ''.join('\n %s' % c for c, _ in self._cmds),
102 ''.join('\n %s' % a[0] 113 ''.join('\n %s' % a[0]
103 for _, a, kw in atr_run_command.RunCommand.mock_calls)) 114 for _, a, kw in self._run_command.mocked.mock_calls))
104 self._test_case.assertEqual( 115 self._test_case.assertEqual(
105 len(self._cmds), len(atr_run_command.RunCommand.mock_calls), 116 len(self._cmds), len(self._run_command.mocked.mock_calls),
106 msg=on_failure) 117 msg=on_failure)
107 for (expected_cmd, _r), (_n, actual_args, actual_kwargs) in zip( 118 for (expected_cmd, _r), (_n, actual_args, actual_kwargs) in zip(
108 self._cmds, atr_run_command.RunCommand.mock_calls): 119 self._cmds, self._run_command.mocked.mock_calls):
109 self._test_case.assertEqual(1, len(actual_args), msg=on_failure) 120 self._test_case.assertEqual(1, len(actual_args), msg=on_failure)
110 self._test_case.assertTrue(self._comp(expected_cmd, actual_args[0]), 121 self._test_case.assertTrue(self._comp(expected_cmd, actual_args[0]),
111 msg=on_failure) 122 msg=on_failure)
112 self._test_case.assertTrue('timeout_time' in actual_kwargs, 123 self._test_case.assertTrue('timeout_time' in actual_kwargs,
113 msg=on_failure) 124 msg=on_failure)
114 self._test_case.assertTrue('retry_count' in actual_kwargs, 125 self._test_case.assertTrue('retry_count' in actual_kwargs,
115 msg=on_failure) 126 msg=on_failure)
116 127
117 def assertNoAdbCalls(self): 128 def assertNoAdbCalls(self):
118 return type(self).AndroidCommandsCalls(self, [], str.__eq__) 129 return type(self).AndroidCommandsCalls(self, [], str.__eq__)
119 130
120 def assertOldImplCalls(self, cmd, ret, comp=str.__eq__): 131 def assertCalls(self, cmd, ret, comp=str.__eq__):
121 return type(self).AndroidCommandsCalls(self, [(cmd, ret)], comp) 132 return type(self).AndroidCommandsCalls(self, [(cmd, ret)], comp)
122 133
123 def assertOldImplCallsSequence(self, cmd_ret, comp=str.__eq__): 134 def assertCallsSequence(self, cmd_ret, comp=str.__eq__):
124 return type(self).AndroidCommandsCalls(self, cmd_ret, comp) 135 return type(self).AndroidCommandsCalls(self, cmd_ret, comp)
125 136
126 def setUp(self): 137 def setUp(self):
127 self.device = device_utils.DeviceUtils( 138 self.device = device_utils.DeviceUtils(
128 '0123456789abcdef', default_timeout=1, default_retries=0) 139 '0123456789abcdef', default_timeout=1, default_retries=0)
129 140
141
142 class DeviceUtilsIsOnlineTest(DeviceUtilsOldImplTest):
143
130 def testIsOnline_true(self): 144 def testIsOnline_true(self):
131 with self.assertOldImplCalls('adb -s 0123456789abcdef get-state', 145 with self.assertCalls('adb -s 0123456789abcdef get-state',
132 'device\r\n'): 146 'device\r\n'):
133 self.assertTrue(self.device.IsOnline()) 147 self.assertTrue(self.device.IsOnline())
134 148
135 def testIsOnline_false(self): 149 def testIsOnline_false(self):
136 with self.assertOldImplCalls('adb -s 0123456789abcdef get-state', '\r\n'): 150 with self.assertCalls('adb -s 0123456789abcdef get-state', '\r\n'):
137 self.assertFalse(self.device.IsOnline()) 151 self.assertFalse(self.device.IsOnline())
138 152
153
154 class DeviceUtilsHasRootTest(DeviceUtilsOldImplTest):
155
139 def testHasRoot_true(self): 156 def testHasRoot_true(self):
140 with self.assertOldImplCalls("adb -s 0123456789abcdef shell 'ls /root'", 157 with self.assertCalls("adb -s 0123456789abcdef shell 'ls /root'",
141 'foo\r\n'): 158 'foo\r\n'):
142 self.assertTrue(self.device.HasRoot()) 159 self.assertTrue(self.device.HasRoot())
143 160
144 def testHasRoot_false(self): 161 def testHasRoot_false(self):
145 with self.assertOldImplCalls("adb -s 0123456789abcdef shell 'ls /root'", 162 with self.assertCalls("adb -s 0123456789abcdef shell 'ls /root'",
146 'Permission denied\r\n'): 163 'Permission denied\r\n'):
147 self.assertFalse(self.device.HasRoot()) 164 self.assertFalse(self.device.HasRoot())
148 165
166
167 class DeviceUtilsEnableRootTest(DeviceUtilsOldImplTest):
168
149 def testEnableRoot_succeeds(self): 169 def testEnableRoot_succeeds(self):
150 with self.assertOldImplCallsSequence([ 170 with self.assertCallsSequence([
151 ('adb -s 0123456789abcdef shell getprop ro.build.type', 171 ('adb -s 0123456789abcdef shell getprop ro.build.type',
152 'userdebug\r\n'), 172 'userdebug\r\n'),
153 ('adb -s 0123456789abcdef root', 'restarting adbd as root\r\n'), 173 ('adb -s 0123456789abcdef root', 'restarting adbd as root\r\n'),
154 ('adb -s 0123456789abcdef wait-for-device', ''), 174 ('adb -s 0123456789abcdef wait-for-device', ''),
155 ('adb -s 0123456789abcdef wait-for-device', '')]): 175 ('adb -s 0123456789abcdef wait-for-device', '')]):
156 self.device.EnableRoot() 176 self.device.EnableRoot()
157 177
158 def testEnableRoot_userBuild(self): 178 def testEnableRoot_userBuild(self):
159 with self.assertOldImplCallsSequence([ 179 with self.assertCallsSequence([
160 ('adb -s 0123456789abcdef shell getprop ro.build.type', 'user\r\n')]): 180 ('adb -s 0123456789abcdef shell getprop ro.build.type', 'user\r\n')]):
161 with self.assertRaises(device_errors.CommandFailedError): 181 with self.assertRaises(device_errors.CommandFailedError):
162 self.device.EnableRoot() 182 self.device.EnableRoot()
163 183
164 def testEnableRoot_rootFails(self): 184 def testEnableRoot_rootFails(self):
165 with self.assertOldImplCallsSequence([ 185 with self.assertCallsSequence([
166 ('adb -s 0123456789abcdef shell getprop ro.build.type', 186 ('adb -s 0123456789abcdef shell getprop ro.build.type',
167 'userdebug\r\n'), 187 'userdebug\r\n'),
168 ('adb -s 0123456789abcdef root', 'no\r\n'), 188 ('adb -s 0123456789abcdef root', 'no\r\n'),
169 ('adb -s 0123456789abcdef wait-for-device', '')]): 189 ('adb -s 0123456789abcdef wait-for-device', '')]):
170 with self.assertRaises(device_errors.CommandFailedError): 190 with self.assertRaises(device_errors.CommandFailedError):
171 self.device.EnableRoot() 191 self.device.EnableRoot()
172 192
193
194 class DeviceUtilsGetExternalStoragePathTest(DeviceUtilsOldImplTest):
195
173 def testGetExternalStoragePath_succeeds(self): 196 def testGetExternalStoragePath_succeeds(self):
174 fakeStoragePath = '/fake/storage/path' 197 fakeStoragePath = '/fake/storage/path'
175 with self.assertOldImplCalls( 198 with self.assertCalls(
176 "adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", 199 "adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'",
177 '%s\r\n' % fakeStoragePath): 200 '%s\r\n' % fakeStoragePath):
178 self.assertEquals(fakeStoragePath, 201 self.assertEquals(fakeStoragePath,
179 self.device.GetExternalStoragePath()) 202 self.device.GetExternalStoragePath())
180 203
181 def testGetExternalStoragePath_fails(self): 204 def testGetExternalStoragePath_fails(self):
182 with self.assertOldImplCalls( 205 with self.assertCalls(
183 "adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", '\r\n'): 206 "adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", '\r\n'):
184 with self.assertRaises(device_errors.CommandFailedError): 207 with self.assertRaises(device_errors.CommandFailedError):
185 self.device.GetExternalStoragePath() 208 self.device.GetExternalStoragePath()
186 209
210
211 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsOldImplTest):
212
187 def testWaitUntilFullyBooted_succeedsNoWifi(self): 213 def testWaitUntilFullyBooted_succeedsNoWifi(self):
188 with self.assertOldImplCallsSequence([ 214 with self.assertCallsSequence([
189 # AndroidCommands.WaitForSystemBootCompleted 215 # AndroidCommands.WaitForSystemBootCompleted
190 ('adb -s 0123456789abcdef wait-for-device', ''), 216 ('adb -s 0123456789abcdef wait-for-device', ''),
191 ('adb -s 0123456789abcdef shell getprop sys.boot_completed', '1\r\n'), 217 ('adb -s 0123456789abcdef shell getprop sys.boot_completed', '1\r\n'),
192 # AndroidCommands.WaitForDevicePm 218 # AndroidCommands.WaitForDevicePm
193 ('adb -s 0123456789abcdef wait-for-device', ''), 219 ('adb -s 0123456789abcdef wait-for-device', ''),
194 ('adb -s 0123456789abcdef shell pm path android', 220 ('adb -s 0123456789abcdef shell pm path android',
195 'package:this.is.a.test.package'), 221 'package:this.is.a.test.package'),
196 # AndroidCommands.WaitForSdCardReady 222 # AndroidCommands.WaitForSdCardReady
197 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", 223 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'",
198 '/fake/storage/path'), 224 '/fake/storage/path'),
199 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'", 225 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'",
200 'nothing\r\n') 226 'nothing\r\n')
201 ]): 227 ]):
202 self.device.WaitUntilFullyBooted(wifi=False) 228 self.device.WaitUntilFullyBooted(wifi=False)
203 229
204 def testWaitUntilFullyBooted_succeedsWithWifi(self): 230 def testWaitUntilFullyBooted_succeedsWithWifi(self):
205 with self.assertOldImplCallsSequence([ 231 with self.assertCallsSequence([
206 # AndroidCommands.WaitForSystemBootCompleted 232 # AndroidCommands.WaitForSystemBootCompleted
207 ('adb -s 0123456789abcdef wait-for-device', ''), 233 ('adb -s 0123456789abcdef wait-for-device', ''),
208 ('adb -s 0123456789abcdef shell getprop sys.boot_completed', '1\r\n'), 234 ('adb -s 0123456789abcdef shell getprop sys.boot_completed', '1\r\n'),
209 # AndroidCommands.WaitForDevicePm 235 # AndroidCommands.WaitForDevicePm
210 ('adb -s 0123456789abcdef wait-for-device', ''), 236 ('adb -s 0123456789abcdef wait-for-device', ''),
211 ('adb -s 0123456789abcdef shell pm path android', 237 ('adb -s 0123456789abcdef shell pm path android',
212 'package:this.is.a.test.package'), 238 'package:this.is.a.test.package'),
213 # AndroidCommands.WaitForSdCardReady 239 # AndroidCommands.WaitForSdCardReady
214 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", 240 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'",
215 '/fake/storage/path'), 241 '/fake/storage/path'),
216 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'", 242 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'",
217 'nothing\r\n'), 243 'nothing\r\n'),
218 # wait for wifi 244 # wait for wifi
219 ("adb -s 0123456789abcdef shell 'dumpsys wifi'", 'Wi-Fi is enabled')]): 245 ("adb -s 0123456789abcdef shell 'dumpsys wifi'", 'Wi-Fi is enabled')]):
220 self.device.WaitUntilFullyBooted(wifi=True) 246 self.device.WaitUntilFullyBooted(wifi=True)
221 247
222 def testWaitUntilFullyBooted_bootFails(self): 248 def testWaitUntilFullyBooted_bootFails(self):
223 with mock.patch('time.sleep'): 249 with mock.patch('time.sleep'):
224 with self.assertOldImplCallsSequence([ 250 with self.assertCallsSequence([
225 # AndroidCommands.WaitForSystemBootCompleted 251 # AndroidCommands.WaitForSystemBootCompleted
226 ('adb -s 0123456789abcdef wait-for-device', ''), 252 ('adb -s 0123456789abcdef wait-for-device', ''),
227 ('adb -s 0123456789abcdef shell getprop sys.boot_completed', 253 ('adb -s 0123456789abcdef shell getprop sys.boot_completed',
228 '0\r\n')]): 254 '0\r\n')]):
229 with self.assertRaises(device_errors.CommandTimeoutError): 255 with self.assertRaises(device_errors.CommandTimeoutError):
230 self.device.WaitUntilFullyBooted(wifi=False) 256 self.device.WaitUntilFullyBooted(wifi=False)
231 257
232 def testWaitUntilFullyBooted_devicePmFails(self): 258 def testWaitUntilFullyBooted_devicePmFails(self):
233 with mock.patch('time.sleep'): 259 with mock.patch('time.sleep'):
234 with self.assertOldImplCallsSequence([ 260 with self.assertCallsSequence([
235 # AndroidCommands.WaitForSystemBootCompleted 261 # AndroidCommands.WaitForSystemBootCompleted
236 ('adb -s 0123456789abcdef wait-for-device', ''), 262 ('adb -s 0123456789abcdef wait-for-device', ''),
237 ('adb -s 0123456789abcdef shell getprop sys.boot_completed', 263 ('adb -s 0123456789abcdef shell getprop sys.boot_completed',
238 '1\r\n')] 264 '1\r\n')]
239 # AndroidCommands.WaitForDevicePm 265 # AndroidCommands.WaitForDevicePm
240 + 3 * ([('adb -s 0123456789abcdef wait-for-device', '')] 266 + 3 * ([('adb -s 0123456789abcdef wait-for-device', '')]
241 + 24 * [('adb -s 0123456789abcdef shell pm path android', '\r\n')] 267 + 24 * [('adb -s 0123456789abcdef shell pm path android', '\r\n')]
242 + [("adb -s 0123456789abcdef shell 'stop'", '\r\n'), 268 + [("adb -s 0123456789abcdef shell 'stop'", '\r\n'),
243 ("adb -s 0123456789abcdef shell 'start'", '\r\n')])): 269 ("adb -s 0123456789abcdef shell 'start'", '\r\n')])):
244 with self.assertRaises(device_errors.CommandTimeoutError): 270 with self.assertRaises(device_errors.CommandTimeoutError):
245 self.device.WaitUntilFullyBooted(wifi=False) 271 self.device.WaitUntilFullyBooted(wifi=False)
246 272
247 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self): 273 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self):
248 with mock.patch('time.sleep'): 274 with mock.patch('time.sleep'):
249 with self.assertOldImplCallsSequence([ 275 with self.assertCallsSequence([
250 # AndroidCommands.WaitForSystemBootCompleted 276 # AndroidCommands.WaitForSystemBootCompleted
251 ('adb -s 0123456789abcdef wait-for-device', ''), 277 ('adb -s 0123456789abcdef wait-for-device', ''),
252 ('adb -s 0123456789abcdef shell getprop sys.boot_completed', 278 ('adb -s 0123456789abcdef shell getprop sys.boot_completed',
253 '1\r\n'), 279 '1\r\n'),
254 # AndroidCommands.WaitForDevicePm 280 # AndroidCommands.WaitForDevicePm
255 ('adb -s 0123456789abcdef wait-for-device', ''), 281 ('adb -s 0123456789abcdef wait-for-device', ''),
256 ('adb -s 0123456789abcdef shell pm path android', 282 ('adb -s 0123456789abcdef shell pm path android',
257 'package:this.is.a.test.package'), 283 'package:this.is.a.test.package'),
258 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", '\r\n')]): 284 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", '\r\n')]):
259 with self.assertRaises(device_errors.CommandFailedError): 285 with self.assertRaises(device_errors.CommandFailedError):
260 self.device.WaitUntilFullyBooted(wifi=False) 286 self.device.WaitUntilFullyBooted(wifi=False)
261 287
262 def testWaitUntilFullyBooted_sdCardReadyFails_emptyPath(self): 288 def testWaitUntilFullyBooted_sdCardReadyFails_emptyPath(self):
263 with mock.patch('time.sleep'): 289 with mock.patch('time.sleep'):
264 with self.assertOldImplCallsSequence([ 290 with self.assertCallsSequence([
265 # AndroidCommands.WaitForSystemBootCompleted 291 # AndroidCommands.WaitForSystemBootCompleted
266 ('adb -s 0123456789abcdef wait-for-device', ''), 292 ('adb -s 0123456789abcdef wait-for-device', ''),
267 ('adb -s 0123456789abcdef shell getprop sys.boot_completed', 293 ('adb -s 0123456789abcdef shell getprop sys.boot_completed',
268 '1\r\n'), 294 '1\r\n'),
269 # AndroidCommands.WaitForDevicePm 295 # AndroidCommands.WaitForDevicePm
270 ('adb -s 0123456789abcdef wait-for-device', ''), 296 ('adb -s 0123456789abcdef wait-for-device', ''),
271 ('adb -s 0123456789abcdef shell pm path android', 297 ('adb -s 0123456789abcdef shell pm path android',
272 'package:this.is.a.test.package'), 298 'package:this.is.a.test.package'),
273 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", 299 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'",
274 '/fake/storage/path\r\n'), 300 '/fake/storage/path\r\n'),
275 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'", '')]): 301 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'", '')]):
276 with self.assertRaises(device_errors.CommandTimeoutError): 302 with self.assertRaises(device_errors.CommandTimeoutError):
277 self.device.WaitUntilFullyBooted(wifi=False) 303 self.device.WaitUntilFullyBooted(wifi=False)
278 304
305
306 class DeviceUtilsRebootTest(DeviceUtilsOldImplTest):
307
279 def testReboot_nonBlocking(self): 308 def testReboot_nonBlocking(self):
280 with mock.patch('time.sleep'): 309 with mock.patch('time.sleep'):
281 with self.assertOldImplCallsSequence([ 310 with self.assertCallsSequence([
282 ('adb -s 0123456789abcdef reboot', ''), 311 ('adb -s 0123456789abcdef reboot', ''),
283 ('adb -s 0123456789abcdef get-state', 'unknown\r\n'), 312 ('adb -s 0123456789abcdef get-state', 'unknown\r\n'),
284 ('adb -s 0123456789abcdef wait-for-device', ''), 313 ('adb -s 0123456789abcdef wait-for-device', ''),
285 ('adb -s 0123456789abcdef shell pm path android', 314 ('adb -s 0123456789abcdef shell pm path android',
286 'package:this.is.a.test.package'), 315 'package:this.is.a.test.package'),
287 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", 316 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'",
288 '/fake/storage/path\r\n'), 317 '/fake/storage/path\r\n'),
289 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'", 318 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'",
290 'nothing\r\n')]): 319 'nothing\r\n')]):
291 self.device.Reboot(block=False) 320 self.device.Reboot(block=False)
292 321
293 def testReboot_blocking(self): 322 def testReboot_blocking(self):
294 with mock.patch('time.sleep'): 323 with mock.patch('time.sleep'):
295 with self.assertOldImplCallsSequence([ 324 with self.assertCallsSequence([
296 ('adb -s 0123456789abcdef reboot', ''), 325 ('adb -s 0123456789abcdef reboot', ''),
297 ('adb -s 0123456789abcdef get-state', 'unknown\r\n'), 326 ('adb -s 0123456789abcdef get-state', 'unknown\r\n'),
298 ('adb -s 0123456789abcdef wait-for-device', ''), 327 ('adb -s 0123456789abcdef wait-for-device', ''),
299 ('adb -s 0123456789abcdef shell pm path android', 328 ('adb -s 0123456789abcdef shell pm path android',
300 'package:this.is.a.test.package'), 329 'package:this.is.a.test.package'),
301 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'", 330 ("adb -s 0123456789abcdef shell 'echo $EXTERNAL_STORAGE'",
302 '/fake/storage/path\r\n'), 331 '/fake/storage/path\r\n'),
303 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'", 332 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'",
304 'nothing\r\n'), 333 'nothing\r\n'),
305 ('adb -s 0123456789abcdef wait-for-device', ''), 334 ('adb -s 0123456789abcdef wait-for-device', ''),
306 ('adb -s 0123456789abcdef shell getprop sys.boot_completed', 335 ('adb -s 0123456789abcdef shell getprop sys.boot_completed',
307 '1\r\n'), 336 '1\r\n'),
308 ('adb -s 0123456789abcdef wait-for-device', ''), 337 ('adb -s 0123456789abcdef wait-for-device', ''),
309 ('adb -s 0123456789abcdef shell pm path android', 338 ('adb -s 0123456789abcdef shell pm path android',
310 'package:this.is.a.test.package'), 339 'package:this.is.a.test.package'),
311 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'", 340 ("adb -s 0123456789abcdef shell 'ls /fake/storage/path'",
312 'nothing\r\n')]): 341 'nothing\r\n')]):
313 self.device.Reboot(block=True) 342 self.device.Reboot(block=True)
314 343
344
345 class DeviceUtilsInstallTest(DeviceUtilsOldImplTest):
346
315 def testInstall_noPriorInstall(self): 347 def testInstall_noPriorInstall(self):
316 with mock.patch('os.path.isfile', return_value=True), ( 348 with mock.patch('os.path.isfile', return_value=True), (
317 mock.patch('pylib.utils.apk_helper.GetPackageName', 349 mock.patch('pylib.utils.apk_helper.GetPackageName',
318 return_value='this.is.a.test.package')): 350 return_value='this.is.a.test.package')):
319 with self.assertOldImplCallsSequence([ 351 with self.assertCallsSequence([
320 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'", 352 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'",
321 ''), 353 ''),
322 ("adb -s 0123456789abcdef install /fake/test/app.apk", 354 ("adb -s 0123456789abcdef install /fake/test/app.apk",
323 'Success\r\n')]): 355 'Success\r\n')]):
324 self.device.Install('/fake/test/app.apk', retries=0) 356 self.device.Install('/fake/test/app.apk', retries=0)
325 357
326 def testInstall_differentPriorInstall(self): 358 def testInstall_differentPriorInstall(self):
327 def mockGetFilesChanged(host_path, device_path, ignore_filenames): 359 def mockGetFilesChanged(host_path, device_path, ignore_filenames):
328 return [(host_path, device_path)] 360 return [(host_path, device_path)]
329 361
330 # Pylint raises a false positive "operator not preceded by a space" 362 # Pylint raises a false positive "operator not preceded by a space"
331 # warning below. 363 # warning below.
332 # pylint: disable=C0322 364 # pylint: disable=C0322
333 with mock.patch('os.path.isfile', return_value=True), ( 365 with mock.patch('os.path.isfile', return_value=True), (
334 mock.patch('os.path.exists', return_value=True)), ( 366 mock.patch('os.path.exists', return_value=True)), (
335 mock.patch('pylib.utils.apk_helper.GetPackageName', 367 mock.patch('pylib.utils.apk_helper.GetPackageName',
336 return_value='this.is.a.test.package')), ( 368 return_value='this.is.a.test.package')), (
337 mock.patch('pylib.constants.GetOutDirectory', 369 mock.patch('pylib.constants.GetOutDirectory',
338 return_value='/fake/test/out')), ( 370 return_value='/fake/test/out')), (
339 mock.patch('pylib.android_commands.AndroidCommands.GetFilesChanged', 371 mock.patch('pylib.android_commands.AndroidCommands.GetFilesChanged',
340 side_effect=mockGetFilesChanged)): 372 side_effect=mockGetFilesChanged)):
341 # pylint: enable=C0322 373 # pylint: enable=C0322
342 with self.assertOldImplCallsSequence([ 374 with self.assertCallsSequence([
343 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'", 375 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'",
344 'package:/fake/data/app/this.is.a.test.package.apk\r\n'), 376 'package:/fake/data/app/this.is.a.test.package.apk\r\n'),
345 # GetFilesChanged is mocked, so its adb calls are omitted. 377 # GetFilesChanged is mocked, so its adb calls are omitted.
346 ('adb -s 0123456789abcdef uninstall this.is.a.test.package', 378 ('adb -s 0123456789abcdef uninstall this.is.a.test.package',
347 'Success\r\n'), 379 'Success\r\n'),
348 ('adb -s 0123456789abcdef install /fake/test/app.apk', 380 ('adb -s 0123456789abcdef install /fake/test/app.apk',
349 'Success\r\n')]): 381 'Success\r\n')]):
350 self.device.Install('/fake/test/app.apk', retries=0) 382 self.device.Install('/fake/test/app.apk', retries=0)
351 383
352 def testInstall_differentPriorInstall_reinstall(self): 384 def testInstall_differentPriorInstall_reinstall(self):
353 def mockGetFilesChanged(host_path, device_path, ignore_filenames): 385 def mockGetFilesChanged(host_path, device_path, ignore_filenames):
354 return [(host_path, device_path)] 386 return [(host_path, device_path)]
355 387
356 # Pylint raises a false positive "operator not preceded by a space" 388 # Pylint raises a false positive "operator not preceded by a space"
357 # warning below. 389 # warning below.
358 # pylint: disable=C0322 390 # pylint: disable=C0322
359 with mock.patch('os.path.isfile', return_value=True), ( 391 with mock.patch('os.path.isfile', return_value=True), (
360 mock.patch('pylib.utils.apk_helper.GetPackageName', 392 mock.patch('pylib.utils.apk_helper.GetPackageName',
361 return_value='this.is.a.test.package')), ( 393 return_value='this.is.a.test.package')), (
362 mock.patch('pylib.constants.GetOutDirectory', 394 mock.patch('pylib.constants.GetOutDirectory',
363 return_value='/fake/test/out')), ( 395 return_value='/fake/test/out')), (
364 mock.patch('pylib.android_commands.AndroidCommands.GetFilesChanged', 396 mock.patch('pylib.android_commands.AndroidCommands.GetFilesChanged',
365 side_effect=mockGetFilesChanged)): 397 side_effect=mockGetFilesChanged)):
366 # pylint: enable=C0322 398 # pylint: enable=C0322
367 with self.assertOldImplCallsSequence([ 399 with self.assertCallsSequence([
368 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'", 400 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'",
369 'package:/fake/data/app/this.is.a.test.package.apk\r\n'), 401 'package:/fake/data/app/this.is.a.test.package.apk\r\n'),
370 # GetFilesChanged is mocked, so its adb calls are omitted. 402 # GetFilesChanged is mocked, so its adb calls are omitted.
371 ('adb -s 0123456789abcdef install -r /fake/test/app.apk', 403 ('adb -s 0123456789abcdef install -r /fake/test/app.apk',
372 'Success\r\n')]): 404 'Success\r\n')]):
373 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0) 405 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0)
374 406
375 def testInstall_identicalPriorInstall(self): 407 def testInstall_identicalPriorInstall(self):
376 def mockGetFilesChanged(host_path, device_path, ignore_filenames): 408 def mockGetFilesChanged(host_path, device_path, ignore_filenames):
377 return [] 409 return []
378 410
379 with mock.patch('pylib.utils.apk_helper.GetPackageName', 411 with mock.patch('pylib.utils.apk_helper.GetPackageName',
380 return_value='this.is.a.test.package'), ( 412 return_value='this.is.a.test.package'), (
381 mock.patch('pylib.android_commands.AndroidCommands.GetFilesChanged', 413 mock.patch('pylib.android_commands.AndroidCommands.GetFilesChanged',
382 side_effect=mockGetFilesChanged)): 414 side_effect=mockGetFilesChanged)):
383 with self.assertOldImplCallsSequence([ 415 with self.assertCallsSequence([
384 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'", 416 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'",
385 'package:/fake/data/app/this.is.a.test.package.apk\r\n') 417 'package:/fake/data/app/this.is.a.test.package.apk\r\n')
386 # GetFilesChanged is mocked, so its adb calls are omitted. 418 # GetFilesChanged is mocked, so its adb calls are omitted.
387 ]): 419 ]):
388 self.device.Install('/fake/test/app.apk', retries=0) 420 self.device.Install('/fake/test/app.apk', retries=0)
389 421
390 def testInstall_fails(self): 422 def testInstall_fails(self):
391 with mock.patch('os.path.isfile', return_value=True), ( 423 with mock.patch('os.path.isfile', return_value=True), (
392 mock.patch('pylib.utils.apk_helper.GetPackageName', 424 mock.patch('pylib.utils.apk_helper.GetPackageName',
393 return_value='this.is.a.test.package')): 425 return_value='this.is.a.test.package')):
394 with self.assertOldImplCallsSequence([ 426 with self.assertCallsSequence([
395 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'", 427 ("adb -s 0123456789abcdef shell 'pm path this.is.a.test.package'",
396 ''), 428 ''),
397 ("adb -s 0123456789abcdef install /fake/test/app.apk", 429 ("adb -s 0123456789abcdef install /fake/test/app.apk",
398 'Failure\r\n')]): 430 'Failure\r\n')]):
399 with self.assertRaises(device_errors.CommandFailedError): 431 with self.assertRaises(device_errors.CommandFailedError):
400 self.device.Install('/fake/test/app.apk', retries=0) 432 self.device.Install('/fake/test/app.apk', retries=0)
401 433
434
435 class DeviceUtilsRunShellCommandTest(DeviceUtilsOldImplTest):
436
402 def testRunShellCommand_commandAsList(self): 437 def testRunShellCommand_commandAsList(self):
403 with self.assertOldImplCalls( 438 with self.assertCalls(
404 "adb -s 0123456789abcdef shell 'pm list packages'", 439 "adb -s 0123456789abcdef shell 'pm list packages'",
405 'pacakge:android\r\n'): 440 'pacakge:android\r\n'):
406 self.device.RunShellCommand(['pm', 'list', 'packages']) 441 self.device.RunShellCommand(['pm', 'list', 'packages'])
407 442
408 def testRunShellCommand_commandAsString(self): 443 def testRunShellCommand_commandAsString(self):
409 with self.assertOldImplCalls( 444 with self.assertCalls(
410 "adb -s 0123456789abcdef shell 'dumpsys wifi'", 445 "adb -s 0123456789abcdef shell 'dumpsys wifi'",
411 'Wi-Fi is enabled\r\n'): 446 'Wi-Fi is enabled\r\n'):
412 self.device.RunShellCommand('dumpsys wifi') 447 self.device.RunShellCommand('dumpsys wifi')
413 448
414 def testRunShellCommand_withSu(self): 449 def testRunShellCommand_withSu(self):
415 with self.assertOldImplCallsSequence([ 450 with self.assertCallsSequence([
416 ("adb -s 0123456789abcdef shell 'ls /root'", 'Permission denied\r\n'), 451 ("adb -s 0123456789abcdef shell 'ls /root'", 'Permission denied\r\n'),
417 ("adb -s 0123456789abcdef shell 'su -c setprop service.adb.root 0'", 452 ("adb -s 0123456789abcdef shell 'su -c setprop service.adb.root 0'",
418 '')]): 453 '')]):
419 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True) 454 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True)
420 455
421 def testRunShellCommand_withRoot(self): 456 def testRunShellCommand_withRoot(self):
422 with self.assertOldImplCallsSequence([ 457 with self.assertCallsSequence([
423 ("adb -s 0123456789abcdef shell 'ls /root'", 'hello\r\nworld\r\n'), 458 ("adb -s 0123456789abcdef shell 'ls /root'", 'hello\r\nworld\r\n'),
424 ("adb -s 0123456789abcdef shell 'setprop service.adb.root 0'", '')]): 459 ("adb -s 0123456789abcdef shell 'setprop service.adb.root 0'", '')]):
425 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True) 460 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True)
426 461
427 def testRunShellCommand_checkReturn_success(self): 462 def testRunShellCommand_checkReturn_success(self):
428 with self.assertOldImplCalls( 463 with self.assertCalls(
429 "adb -s 0123456789abcdef shell 'echo $ANDROID_DATA; echo %$?'", 464 "adb -s 0123456789abcdef shell 'echo $ANDROID_DATA; echo %$?'",
430 '/data\r\n%0\r\n'): 465 '/data\r\n%0\r\n'):
431 self.device.RunShellCommand('echo $ANDROID_DATA', check_return=True) 466 self.device.RunShellCommand('echo $ANDROID_DATA', check_return=True)
432 467
433 def testRunShellCommand_checkReturn_failure(self): 468 def testRunShellCommand_checkReturn_failure(self):
434 with self.assertOldImplCalls( 469 with self.assertCalls(
435 "adb -s 0123456789abcdef shell 'echo $ANDROID_DATA; echo %$?'", 470 "adb -s 0123456789abcdef shell 'echo $ANDROID_DATA; echo %$?'",
436 '\r\n%1\r\n'): 471 '\r\n%1\r\n'):
437 with self.assertRaises(device_errors.CommandFailedError): 472 with self.assertRaises(device_errors.CommandFailedError):
438 self.device.RunShellCommand('echo $ANDROID_DATA', check_return=True) 473 self.device.RunShellCommand('echo $ANDROID_DATA', check_return=True)
439 474
475
476 class DeviceUtilsKillAllTest(DeviceUtilsOldImplTest):
477
440 def testKillAll_noMatchingProcesses(self): 478 def testKillAll_noMatchingProcesses(self):
441 with self.assertOldImplCalls( 479 with self.assertCalls(
442 "adb -s 0123456789abcdef shell 'ps'", 480 "adb -s 0123456789abcdef shell 'ps'",
443 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'): 481 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'):
444 with self.assertRaises(device_errors.CommandFailedError): 482 with self.assertRaises(device_errors.CommandFailedError):
445 self.device.KillAll('test_process') 483 self.device.KillAll('test_process')
446 484
447 def testKillAll_nonblocking(self): 485 def testKillAll_nonblocking(self):
448 with self.assertOldImplCallsSequence([ 486 with self.assertCallsSequence([
449 ("adb -s 0123456789abcdef shell 'ps'", 487 ("adb -s 0123456789abcdef shell 'ps'",
450 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 488 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
451 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 489 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
452 'this.is.a.test.process\r\n'), 490 'this.is.a.test.process\r\n'),
453 ("adb -s 0123456789abcdef shell 'ps'", 491 ("adb -s 0123456789abcdef shell 'ps'",
454 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 492 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
455 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 493 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
456 'this.is.a.test.process\r\n'), 494 'this.is.a.test.process\r\n'),
457 ("adb -s 0123456789abcdef shell 'kill -9 1234'", '')]): 495 ("adb -s 0123456789abcdef shell 'kill -9 1234'", '')]):
458 self.device.KillAll('this.is.a.test.process', blocking=False) 496 self.device.KillAll('this.is.a.test.process', blocking=False)
459 497
460 def testKillAll_blocking(self): 498 def testKillAll_blocking(self):
461 with mock.patch('time.sleep'): 499 with mock.patch('time.sleep'):
462 with self.assertOldImplCallsSequence([ 500 with self.assertCallsSequence([
463 ("adb -s 0123456789abcdef shell 'ps'", 501 ("adb -s 0123456789abcdef shell 'ps'",
464 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 502 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
465 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 503 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
466 'this.is.a.test.process\r\n'), 504 'this.is.a.test.process\r\n'),
467 ("adb -s 0123456789abcdef shell 'ps'", 505 ("adb -s 0123456789abcdef shell 'ps'",
468 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 506 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
469 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 507 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
470 'this.is.a.test.process\r\n'), 508 'this.is.a.test.process\r\n'),
471 ("adb -s 0123456789abcdef shell 'kill -9 1234'", ''), 509 ("adb -s 0123456789abcdef shell 'kill -9 1234'", ''),
472 ("adb -s 0123456789abcdef shell 'ps'", 510 ("adb -s 0123456789abcdef shell 'ps'",
473 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 511 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
474 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 512 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
475 'this.is.a.test.process\r\n'), 513 'this.is.a.test.process\r\n'),
476 ("adb -s 0123456789abcdef shell 'ps'", 514 ("adb -s 0123456789abcdef shell 'ps'",
477 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n')]): 515 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n')]):
478 self.device.KillAll('this.is.a.test.process', blocking=True) 516 self.device.KillAll('this.is.a.test.process', blocking=True)
479 517
480 def testKillAll_root(self): 518 def testKillAll_root(self):
481 with self.assertOldImplCallsSequence([ 519 with self.assertCallsSequence([
482 ("adb -s 0123456789abcdef shell 'ps'", 520 ("adb -s 0123456789abcdef shell 'ps'",
483 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 521 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
484 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 522 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
485 'this.is.a.test.process\r\n'), 523 'this.is.a.test.process\r\n'),
486 ("adb -s 0123456789abcdef shell 'ps'", 524 ("adb -s 0123456789abcdef shell 'ps'",
487 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 525 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
488 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 526 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
489 'this.is.a.test.process\r\n'), 527 'this.is.a.test.process\r\n'),
490 ("adb -s 0123456789abcdef shell 'su -c kill -9 1234'", '')]): 528 ("adb -s 0123456789abcdef shell 'su -c kill -9 1234'", '')]):
491 self.device.KillAll('this.is.a.test.process', as_root=True) 529 self.device.KillAll('this.is.a.test.process', as_root=True)
492 530
493 def testKillAll_sigterm(self): 531 def testKillAll_sigterm(self):
494 with self.assertOldImplCallsSequence([ 532 with self.assertCallsSequence([
495 ("adb -s 0123456789abcdef shell 'ps'", 533 ("adb -s 0123456789abcdef shell 'ps'",
496 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 534 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
497 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 535 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
498 'this.is.a.test.process\r\n'), 536 'this.is.a.test.process\r\n'),
499 ("adb -s 0123456789abcdef shell 'ps'", 537 ("adb -s 0123456789abcdef shell 'ps'",
500 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' 538 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'
501 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' 539 'u0_a1 1234 174 123456 54321 ffffffff 456789ab '
502 'this.is.a.test.process\r\n'), 540 'this.is.a.test.process\r\n'),
503 ("adb -s 0123456789abcdef shell 'kill -15 1234'", '')]): 541 ("adb -s 0123456789abcdef shell 'kill -15 1234'", '')]):
504 self.device.KillAll('this.is.a.test.process', signum=signal.SIGTERM) 542 self.device.KillAll('this.is.a.test.process', signum=signal.SIGTERM)
505 543
544
545 class DeviceUtilsStartActivityTest(DeviceUtilsOldImplTest):
546
506 def testStartActivity_actionOnly(self): 547 def testStartActivity_actionOnly(self):
507 test_intent = intent.Intent(action='android.intent.action.VIEW') 548 test_intent = intent.Intent(action='android.intent.action.VIEW')
508 with self.assertOldImplCalls( 549 with self.assertCalls(
509 "adb -s 0123456789abcdef shell 'am start " 550 "adb -s 0123456789abcdef shell 'am start "
510 "-a android.intent.action.VIEW'", 551 "-a android.intent.action.VIEW'",
511 'Starting: Intent { act=android.intent.action.VIEW }'): 552 'Starting: Intent { act=android.intent.action.VIEW }'):
512 self.device.StartActivity(test_intent) 553 self.device.StartActivity(test_intent)
513 554
514 def testStartActivity_success(self): 555 def testStartActivity_success(self):
515 test_intent = intent.Intent(action='android.intent.action.VIEW', 556 test_intent = intent.Intent(action='android.intent.action.VIEW',
516 package='this.is.a.test.package', 557 package='this.is.a.test.package',
517 activity='.Main') 558 activity='.Main')
518 with self.assertOldImplCalls( 559 with self.assertCalls(
519 "adb -s 0123456789abcdef shell 'am start " 560 "adb -s 0123456789abcdef shell 'am start "
520 "-a android.intent.action.VIEW " 561 "-a android.intent.action.VIEW "
521 "-n this.is.a.test.package/.Main'", 562 "-n this.is.a.test.package/.Main'",
522 'Starting: Intent { act=android.intent.action.VIEW }'): 563 'Starting: Intent { act=android.intent.action.VIEW }'):
523 self.device.StartActivity(test_intent) 564 self.device.StartActivity(test_intent)
524 565
525 def testStartActivity_failure(self): 566 def testStartActivity_failure(self):
526 test_intent = intent.Intent(action='android.intent.action.VIEW', 567 test_intent = intent.Intent(action='android.intent.action.VIEW',
527 package='this.is.a.test.package', 568 package='this.is.a.test.package',
528 activity='.Main') 569 activity='.Main')
529 with self.assertOldImplCalls( 570 with self.assertCalls(
530 "adb -s 0123456789abcdef shell 'am start " 571 "adb -s 0123456789abcdef shell 'am start "
531 "-a android.intent.action.VIEW " 572 "-a android.intent.action.VIEW "
532 "-n this.is.a.test.package/.Main'", 573 "-n this.is.a.test.package/.Main'",
533 'Error: Failed to start test activity'): 574 'Error: Failed to start test activity'):
534 with self.assertRaises(device_errors.CommandFailedError): 575 with self.assertRaises(device_errors.CommandFailedError):
535 self.device.StartActivity(test_intent) 576 self.device.StartActivity(test_intent)
536 577
537 def testStartActivity_blocking(self): 578 def testStartActivity_blocking(self):
538 test_intent = intent.Intent(action='android.intent.action.VIEW', 579 test_intent = intent.Intent(action='android.intent.action.VIEW',
539 package='this.is.a.test.package', 580 package='this.is.a.test.package',
540 activity='.Main') 581 activity='.Main')
541 with self.assertOldImplCalls( 582 with self.assertCalls(
542 "adb -s 0123456789abcdef shell 'am start " 583 "adb -s 0123456789abcdef shell 'am start "
543 "-a android.intent.action.VIEW " 584 "-a android.intent.action.VIEW "
544 "-W " 585 "-W "
545 "-n this.is.a.test.package/.Main'", 586 "-n this.is.a.test.package/.Main'",
546 'Starting: Intent { act=android.intent.action.VIEW }'): 587 'Starting: Intent { act=android.intent.action.VIEW }'):
547 self.device.StartActivity(test_intent, blocking=True) 588 self.device.StartActivity(test_intent, blocking=True)
548 589
549 def testStartActivity_withCategory(self): 590 def testStartActivity_withCategory(self):
550 test_intent = intent.Intent(action='android.intent.action.VIEW', 591 test_intent = intent.Intent(action='android.intent.action.VIEW',
551 package='this.is.a.test.package', 592 package='this.is.a.test.package',
552 activity='.Main', 593 activity='.Main',
553 category='android.intent.category.HOME') 594 category='android.intent.category.HOME')
554 with self.assertOldImplCalls( 595 with self.assertCalls(
555 "adb -s 0123456789abcdef shell 'am start " 596 "adb -s 0123456789abcdef shell 'am start "
556 "-a android.intent.action.VIEW " 597 "-a android.intent.action.VIEW "
557 "-c android.intent.category.HOME " 598 "-c android.intent.category.HOME "
558 "-n this.is.a.test.package/.Main'", 599 "-n this.is.a.test.package/.Main'",
559 'Starting: Intent { act=android.intent.action.VIEW }'): 600 'Starting: Intent { act=android.intent.action.VIEW }'):
560 self.device.StartActivity(test_intent) 601 self.device.StartActivity(test_intent)
561 602
562 def testStartActivity_withMultipleCategories(self): 603 def testStartActivity_withMultipleCategories(self):
563 # The new implementation will start the activity with all provided 604 # The new implementation will start the activity with all provided
564 # categories. The old one only uses the first category. 605 # categories. The old one only uses the first category.
565 test_intent = intent.Intent(action='android.intent.action.VIEW', 606 test_intent = intent.Intent(action='android.intent.action.VIEW',
566 package='this.is.a.test.package', 607 package='this.is.a.test.package',
567 activity='.Main', 608 activity='.Main',
568 category=['android.intent.category.HOME', 609 category=['android.intent.category.HOME',
569 'android.intent.category.BROWSABLE']) 610 'android.intent.category.BROWSABLE'])
570 with self.assertOldImplCalls( 611 with self.assertCalls(
571 "adb -s 0123456789abcdef shell 'am start " 612 "adb -s 0123456789abcdef shell 'am start "
572 "-a android.intent.action.VIEW " 613 "-a android.intent.action.VIEW "
573 "-c android.intent.category.HOME " 614 "-c android.intent.category.HOME "
574 "-n this.is.a.test.package/.Main'", 615 "-n this.is.a.test.package/.Main'",
575 'Starting: Intent { act=android.intent.action.VIEW }'): 616 'Starting: Intent { act=android.intent.action.VIEW }'):
576 self.device.StartActivity(test_intent) 617 self.device.StartActivity(test_intent)
577 618
578 def testStartActivity_withData(self): 619 def testStartActivity_withData(self):
579 test_intent = intent.Intent(action='android.intent.action.VIEW', 620 test_intent = intent.Intent(action='android.intent.action.VIEW',
580 package='this.is.a.test.package', 621 package='this.is.a.test.package',
581 activity='.Main', 622 activity='.Main',
582 data='http://www.google.com/') 623 data='http://www.google.com/')
583 with self.assertOldImplCalls( 624 with self.assertCalls(
584 "adb -s 0123456789abcdef shell 'am start " 625 "adb -s 0123456789abcdef shell 'am start "
585 "-a android.intent.action.VIEW " 626 "-a android.intent.action.VIEW "
586 "-n this.is.a.test.package/.Main " 627 "-n this.is.a.test.package/.Main "
587 "-d \"http://www.google.com/\"'", 628 "-d \"http://www.google.com/\"'",
588 'Starting: Intent { act=android.intent.action.VIEW }'): 629 'Starting: Intent { act=android.intent.action.VIEW }'):
589 self.device.StartActivity(test_intent) 630 self.device.StartActivity(test_intent)
590 631
591 def testStartActivity_withStringExtra(self): 632 def testStartActivity_withStringExtra(self):
592 test_intent = intent.Intent(action='android.intent.action.VIEW', 633 test_intent = intent.Intent(action='android.intent.action.VIEW',
593 package='this.is.a.test.package', 634 package='this.is.a.test.package',
594 activity='.Main', 635 activity='.Main',
595 extras={'foo': 'test'}) 636 extras={'foo': 'test'})
596 with self.assertOldImplCalls( 637 with self.assertCalls(
597 "adb -s 0123456789abcdef shell 'am start " 638 "adb -s 0123456789abcdef shell 'am start "
598 "-a android.intent.action.VIEW " 639 "-a android.intent.action.VIEW "
599 "-n this.is.a.test.package/.Main " 640 "-n this.is.a.test.package/.Main "
600 "--es foo test'", 641 "--es foo test'",
601 'Starting: Intent { act=android.intent.action.VIEW }'): 642 'Starting: Intent { act=android.intent.action.VIEW }'):
602 self.device.StartActivity(test_intent) 643 self.device.StartActivity(test_intent)
603 644
604 def testStartActivity_withBoolExtra(self): 645 def testStartActivity_withBoolExtra(self):
605 test_intent = intent.Intent(action='android.intent.action.VIEW', 646 test_intent = intent.Intent(action='android.intent.action.VIEW',
606 package='this.is.a.test.package', 647 package='this.is.a.test.package',
607 activity='.Main', 648 activity='.Main',
608 extras={'foo': True}) 649 extras={'foo': True})
609 with self.assertOldImplCalls( 650 with self.assertCalls(
610 "adb -s 0123456789abcdef shell 'am start " 651 "adb -s 0123456789abcdef shell 'am start "
611 "-a android.intent.action.VIEW " 652 "-a android.intent.action.VIEW "
612 "-n this.is.a.test.package/.Main " 653 "-n this.is.a.test.package/.Main "
613 "--ez foo True'", 654 "--ez foo True'",
614 'Starting: Intent { act=android.intent.action.VIEW }'): 655 'Starting: Intent { act=android.intent.action.VIEW }'):
615 self.device.StartActivity(test_intent) 656 self.device.StartActivity(test_intent)
616 657
617 def testStartActivity_withIntExtra(self): 658 def testStartActivity_withIntExtra(self):
618 test_intent = intent.Intent(action='android.intent.action.VIEW', 659 test_intent = intent.Intent(action='android.intent.action.VIEW',
619 package='this.is.a.test.package', 660 package='this.is.a.test.package',
620 activity='.Main', 661 activity='.Main',
621 extras={'foo': 123}) 662 extras={'foo': 123})
622 with self.assertOldImplCalls( 663 with self.assertCalls(
623 "adb -s 0123456789abcdef shell 'am start " 664 "adb -s 0123456789abcdef shell 'am start "
624 "-a android.intent.action.VIEW " 665 "-a android.intent.action.VIEW "
625 "-n this.is.a.test.package/.Main " 666 "-n this.is.a.test.package/.Main "
626 "--ei foo 123'", 667 "--ei foo 123'",
627 'Starting: Intent { act=android.intent.action.VIEW }'): 668 'Starting: Intent { act=android.intent.action.VIEW }'):
628 self.device.StartActivity(test_intent) 669 self.device.StartActivity(test_intent)
629 670
630 def testStartActivity_withTraceFile(self): 671 def testStartActivity_withTraceFile(self):
631 test_intent = intent.Intent(action='android.intent.action.VIEW', 672 test_intent = intent.Intent(action='android.intent.action.VIEW',
632 package='this.is.a.test.package', 673 package='this.is.a.test.package',
633 activity='.Main') 674 activity='.Main')
634 with self.assertOldImplCalls( 675 with self.assertCalls(
635 "adb -s 0123456789abcdef shell 'am start " 676 "adb -s 0123456789abcdef shell 'am start "
636 "-a android.intent.action.VIEW " 677 "-a android.intent.action.VIEW "
637 "-n this.is.a.test.package/.Main " 678 "-n this.is.a.test.package/.Main "
638 "--start-profiler test_trace_file.out'", 679 "--start-profiler test_trace_file.out'",
639 'Starting: Intent { act=android.intent.action.VIEW }'): 680 'Starting: Intent { act=android.intent.action.VIEW }'):
640 self.device.StartActivity(test_intent, 681 self.device.StartActivity(test_intent,
641 trace_file_name='test_trace_file.out') 682 trace_file_name='test_trace_file.out')
642 683
643 def testStartActivity_withForceStop(self): 684 def testStartActivity_withForceStop(self):
644 test_intent = intent.Intent(action='android.intent.action.VIEW', 685 test_intent = intent.Intent(action='android.intent.action.VIEW',
645 package='this.is.a.test.package', 686 package='this.is.a.test.package',
646 activity='.Main') 687 activity='.Main')
647 with self.assertOldImplCalls( 688 with self.assertCalls(
648 "adb -s 0123456789abcdef shell 'am start " 689 "adb -s 0123456789abcdef shell 'am start "
649 "-a android.intent.action.VIEW " 690 "-a android.intent.action.VIEW "
650 "-S " 691 "-S "
651 "-n this.is.a.test.package/.Main'", 692 "-n this.is.a.test.package/.Main'",
652 'Starting: Intent { act=android.intent.action.VIEW }'): 693 'Starting: Intent { act=android.intent.action.VIEW }'):
653 self.device.StartActivity(test_intent, force_stop=True) 694 self.device.StartActivity(test_intent, force_stop=True)
654 695
655 def testStartActivity_withFlags(self): 696 def testStartActivity_withFlags(self):
656 test_intent = intent.Intent(action='android.intent.action.VIEW', 697 test_intent = intent.Intent(action='android.intent.action.VIEW',
657 package='this.is.a.test.package', 698 package='this.is.a.test.package',
658 activity='.Main', 699 activity='.Main',
659 flags='0x10000000') 700 flags='0x10000000')
660 with self.assertOldImplCalls( 701 with self.assertCalls(
661 "adb -s 0123456789abcdef shell 'am start " 702 "adb -s 0123456789abcdef shell 'am start "
662 "-a android.intent.action.VIEW " 703 "-a android.intent.action.VIEW "
663 "-n this.is.a.test.package/.Main " 704 "-n this.is.a.test.package/.Main "
664 "-f 0x10000000'", 705 "-f 0x10000000'",
665 'Starting: Intent { act=android.intent.action.VIEW }'): 706 'Starting: Intent { act=android.intent.action.VIEW }'):
666 self.device.StartActivity(test_intent) 707 self.device.StartActivity(test_intent)
667 708
709
710 class DeviceUtilsBroadcastIntentTest(DeviceUtilsOldImplTest):
711
668 def testBroadcastIntent_noExtras(self): 712 def testBroadcastIntent_noExtras(self):
669 test_intent = intent.Intent(action='test.package.with.an.INTENT') 713 test_intent = intent.Intent(action='test.package.with.an.INTENT')
670 with self.assertOldImplCalls( 714 with self.assertCalls(
671 "adb -s 0123456789abcdef shell 'am broadcast " 715 "adb -s 0123456789abcdef shell 'am broadcast "
672 "-a test.package.with.an.INTENT '", 716 "-a test.package.with.an.INTENT '",
673 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): 717 'Broadcasting: Intent { act=test.package.with.an.INTENT } '):
674 self.device.BroadcastIntent(test_intent) 718 self.device.BroadcastIntent(test_intent)
675 719
676 def testBroadcastIntent_withExtra(self): 720 def testBroadcastIntent_withExtra(self):
677 test_intent = intent.Intent(action='test.package.with.an.INTENT', 721 test_intent = intent.Intent(action='test.package.with.an.INTENT',
678 extras={'foo': 'bar'}) 722 extras={'foo': 'bar'})
679 with self.assertOldImplCalls( 723 with self.assertCalls(
680 "adb -s 0123456789abcdef shell 'am broadcast " 724 "adb -s 0123456789abcdef shell 'am broadcast "
681 "-a test.package.with.an.INTENT " 725 "-a test.package.with.an.INTENT "
682 "-e foo \"bar\"'", 726 "-e foo \"bar\"'",
683 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): 727 'Broadcasting: Intent { act=test.package.with.an.INTENT } '):
684 self.device.BroadcastIntent(test_intent) 728 self.device.BroadcastIntent(test_intent)
685 729
686 def testBroadcastIntent_withExtra_noValue(self): 730 def testBroadcastIntent_withExtra_noValue(self):
687 test_intent = intent.Intent(action='test.package.with.an.INTENT', 731 test_intent = intent.Intent(action='test.package.with.an.INTENT',
688 extras={'foo': None}) 732 extras={'foo': None})
689 with self.assertOldImplCalls( 733 with self.assertCalls(
690 "adb -s 0123456789abcdef shell 'am broadcast " 734 "adb -s 0123456789abcdef shell 'am broadcast "
691 "-a test.package.with.an.INTENT " 735 "-a test.package.with.an.INTENT "
692 "-e foo'", 736 "-e foo'",
693 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): 737 'Broadcasting: Intent { act=test.package.with.an.INTENT } '):
694 self.device.BroadcastIntent(test_intent) 738 self.device.BroadcastIntent(test_intent)
695 739
740
741 class DeviceUtilsGoHomeTest(DeviceUtilsOldImplTest):
742
696 def testGoHome(self): 743 def testGoHome(self):
697 with self.assertOldImplCalls( 744 with self.assertCalls(
698 "adb -s 0123456789abcdef shell 'am start " 745 "adb -s 0123456789abcdef shell 'am start "
699 "-W " 746 "-W "
700 "-a android.intent.action.MAIN " 747 "-a android.intent.action.MAIN "
701 "-c android.intent.category.HOME'", 748 "-c android.intent.category.HOME'",
702 'Starting: Intent { act=android.intent.action.MAIN }\r\n'): 749 'Starting: Intent { act=android.intent.action.MAIN }\r\n'):
703 self.device.GoHome() 750 self.device.GoHome()
704 751
752
753 class DeviceUtilsForceStopTest(DeviceUtilsOldImplTest):
754
705 def testForceStop(self): 755 def testForceStop(self):
706 with self.assertOldImplCalls( 756 with self.assertCalls(
707 "adb -s 0123456789abcdef shell 'am force-stop this.is.a.test.package'", 757 "adb -s 0123456789abcdef shell 'am force-stop this.is.a.test.package'",
708 ''): 758 ''):
709 self.device.ForceStop('this.is.a.test.package') 759 self.device.ForceStop('this.is.a.test.package')
710 760
761
762 class DeviceUtilsClearApplicationStateTest(DeviceUtilsOldImplTest):
763
711 def testClearApplicationState_packageExists(self): 764 def testClearApplicationState_packageExists(self):
712 with self.assertOldImplCalls( 765 with self.assertCalls(
713 "adb -s 0123456789abcdef shell 'pm path this.package.does.not.exist'", 766 "adb -s 0123456789abcdef shell 'pm path this.package.does.not.exist'",
714 ''): 767 ''):
715 self.device.ClearApplicationState('this.package.does.not.exist') 768 self.device.ClearApplicationState('this.package.does.not.exist')
716 769
717 def testClearApplicationState_packageDoesntExist(self): 770 def testClearApplicationState_packageDoesntExist(self):
718 with self.assertOldImplCallsSequence([ 771 with self.assertCallsSequence([
719 ("adb -s 0123456789abcdef shell 'pm path this.package.exists'", 772 ("adb -s 0123456789abcdef shell 'pm path this.package.exists'",
720 'package:/data/app/this.package.exists.apk'), 773 'package:/data/app/this.package.exists.apk'),
721 ("adb -s 0123456789abcdef shell 'pm clear this.package.exists'", 774 ("adb -s 0123456789abcdef shell 'pm clear this.package.exists'",
722 'Success\r\n')]): 775 'Success\r\n')]):
723 self.device.ClearApplicationState('this.package.exists') 776 self.device.ClearApplicationState('this.package.exists')
724 777
778
779 class DeviceUtilsSendKeyEventTest(DeviceUtilsOldImplTest):
780
725 def testSendKeyEvent(self): 781 def testSendKeyEvent(self):
726 with self.assertOldImplCalls( 782 with self.assertCalls(
727 "adb -s 0123456789abcdef shell 'input keyevent 66'", 783 "adb -s 0123456789abcdef shell 'input keyevent 66'",
728 ''): 784 ''):
729 self.device.SendKeyEvent(66) 785 self.device.SendKeyEvent(66)
730 786
787
788 class DeviceUtilsPushChangedFilesTest(DeviceUtilsOldImplTest):
789
790 class MockFileSystem(object):
791
792 @staticmethod
793 def osStatResult(
794 st_mode=None, st_ino=None, st_dev=None, st_nlink=None, st_uid=None,
795 st_gid=None, st_size=None, st_atime=None, st_mtime=None, st_ctime=None):
796 MockOSStatResult = collections.namedtuple('MockOSStatResult', [
797 'st_mode', 'st_ino', 'st_dev', 'st_nlink', 'st_uid', 'st_gid',
798 'st_size', 'st_atime', 'st_mtime', 'st_ctime'])
799 return MockOSStatResult(st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid,
800 st_size, st_atime, st_mtime, st_ctime)
801
802 def _get(self, mocked, path, default_val):
803 return (self.mock_file_info[path][mocked]
804 if path in self.mock_file_info
805 else default_val)
806
807 def _patched(self, target, default_val=None):
808 r = lambda f: self._get(target, f, default_val)
809 return _PatchedFunction(patched=mock.patch(target, side_effect=r))
810
811 def __init__(self):
812 self.mock_file_info = {}
813 self._os_path_exists = self._patched('os.path.exists', default_val=False)
814 self._os_path_getsize = self._patched('os.path.getsize', default_val=0)
815 self._os_path_isdir = self._patched('os.path.isdir', default_val=False)
816 self._os_stat = self._patched('os.stat', default_val=self.osStatResult())
817 self._os_walk = self._patched('os.walk', default_val=[])
818
819 def addMockFile(self, path, size, **kw):
820 self._addMockThing(path, size, False, **kw)
821
822 def addMockDirectory(self, path, size, **kw):
823 self._addMockThing(path, size, True, **kw)
824
825 def _addMockThing(self, path, size, is_dir, stat=None, walk=None):
826 if stat is None:
827 stat = self.osStatResult()
828 if walk is None:
829 walk = []
830 self.mock_file_info[path] = {
831 'os.path.exists': True,
832 'os.path.isdir': is_dir,
833 'os.path.getsize': size,
834 'os.stat': stat,
835 'os.walk': walk,
836 }
837
838 def __enter__(self):
839 self._os_path_exists.mocked = self._os_path_exists.patched.__enter__()
840 self._os_path_getsize.mocked = self._os_path_getsize.patched.__enter__()
841 self._os_path_isdir.mocked = self._os_path_isdir.patched.__enter__()
842 self._os_stat.mocked = self._os_stat.patched.__enter__()
843 self._os_walk.mocked = self._os_walk.patched.__enter__()
844
845 def __exit__(self, exc_type, exc_val, exc_tb):
846 self._os_walk.patched.__exit__()
847 self._os_stat.patched.__exit__()
848 self._os_path_isdir.patched.__exit__(exc_type, exc_val, exc_tb)
849 self._os_path_getsize.patched.__exit__(exc_type, exc_val, exc_tb)
850 self._os_path_exists.patched.__exit__(exc_type, exc_val, exc_tb)
851
852
731 def testPushChangedFiles_noHostPath(self): 853 def testPushChangedFiles_noHostPath(self):
732 with mock.patch('os.path.exists', return_value=False): 854 with mock.patch('os.path.exists', return_value=False):
733 with self.assertRaises(device_errors.CommandFailedError): 855 with self.assertRaises(device_errors.CommandFailedError):
734 self.device.PushChangedFiles('/test/host/path', '/test/device/path') 856 self.device.PushChangedFiles('/test/host/path', '/test/device/path')
735 857
736 def testPushChangedFiles_file_noChange(self): 858 def testPushChangedFiles_file_noChange(self):
737 self.device.old_interface._push_if_needed_cache = {} 859 self.device.old_interface._push_if_needed_cache = {}
738 860
739 host_file_path = '/test/host/path' 861 host_file_path = '/test/host/path'
740 device_file_path = '/test/device/path' 862 device_file_path = '/test/device/path'
741 863
742 mock_file_info = { 864 mock_fs = self.MockFileSystem()
743 '/test/host/path': { 865 mock_fs.addMockFile(host_file_path, 100)
744 'os.path.exists': True,
745 'os.path.isdir': False,
746 'os.path.getsize': 100,
747 },
748 }
749
750 os_path_exists = mock.Mock()
751 os_path_exists.side_effect = lambda f: mock_file_info[f]['os.path.exists']
752
753 os_path_isdir = mock.Mock()
754 os_path_isdir.side_effect = lambda f: mock_file_info[f]['os.path.isdir']
755
756 os_path_getsize = mock.Mock()
757 os_path_getsize.side_effect = lambda f: mock_file_info[f]['os.path.getsize']
758 866
759 self.device.old_interface.GetFilesChanged = mock.Mock(return_value=[]) 867 self.device.old_interface.GetFilesChanged = mock.Mock(return_value=[])
760 868
761 with mock.patch('os.path.exists', new=os_path_exists), ( 869 with mock_fs:
762 mock.patch('os.path.isdir', new=os_path_isdir)), (
763 mock.patch('os.path.getsize', new=os_path_getsize)):
764 # GetFilesChanged is mocked, so its adb calls are omitted. 870 # GetFilesChanged is mocked, so its adb calls are omitted.
765 with self.assertNoAdbCalls(): 871 with self.assertNoAdbCalls():
766 self.device.PushChangedFiles(host_file_path, device_file_path) 872 self.device.PushChangedFiles(host_file_path, device_file_path)
767 873
768 @staticmethod
769 def createMockOSStatResult(
770 st_mode=None, st_ino=None, st_dev=None, st_nlink=None, st_uid=None,
771 st_gid=None, st_size=None, st_atime=None, st_mtime=None, st_ctime=None):
772 MockOSStatResult = collections.namedtuple('MockOSStatResult', [
773 'st_mode', 'st_ino', 'st_dev', 'st_nlink', 'st_uid', 'st_gid',
774 'st_size', 'st_atime', 'st_mtime', 'st_ctime'])
775 return MockOSStatResult(st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid,
776 st_size, st_atime, st_mtime, st_ctime)
777
778 def testPushChangedFiles_file_changed(self): 874 def testPushChangedFiles_file_changed(self):
779 self.device.old_interface._push_if_needed_cache = {} 875 self.device.old_interface._push_if_needed_cache = {}
780 876
781 host_file_path = '/test/host/path' 877 host_file_path = '/test/host/path'
782 device_file_path = '/test/device/path' 878 device_file_path = '/test/device/path'
783 879
784 mock_file_info = { 880 mock_fs = self.MockFileSystem()
785 '/test/host/path': { 881 mock_fs.addMockFile(
786 'os.path.exists': True, 882 host_file_path, 100,
787 'os.path.isdir': False, 883 stat=self.MockFileSystem.osStatResult(st_mtime=1000000000))
788 'os.path.getsize': 100,
789 'os.stat': self.createMockOSStatResult(st_mtime=1000000000)
790 },
791 }
792
793 os_path_exists = mock.Mock()
794 os_path_exists.side_effect = lambda f: mock_file_info[f]['os.path.exists']
795
796 os_path_isdir = mock.Mock()
797 os_path_isdir.side_effect = lambda f: mock_file_info[f]['os.path.isdir']
798
799 os_path_getsize = mock.Mock()
800 os_path_getsize.side_effect = lambda f: mock_file_info[f]['os.path.getsize']
801
802 os_stat = mock.Mock()
803 os_stat.side_effect = lambda f: mock_file_info[f]['os.stat']
804 884
805 self.device.old_interface.GetFilesChanged = mock.Mock( 885 self.device.old_interface.GetFilesChanged = mock.Mock(
806 return_value=[('/test/host/path', '/test/device/path')]) 886 return_value=[('/test/host/path', '/test/device/path')])
807 887
808 with mock.patch('os.path.exists', new=os_path_exists), ( 888 with mock_fs:
809 mock.patch('os.path.isdir', new=os_path_isdir)), ( 889 with self.assertCalls('adb -s 0123456789abcdef push '
810 mock.patch('os.path.getsize', new=os_path_getsize)), (
811 mock.patch('os.stat', new=os_stat)):
812 with self.assertOldImplCalls('adb -s 0123456789abcdef push '
813 '/test/host/path /test/device/path', '100 B/s (100 B in 1.000s)\r\n'): 890 '/test/host/path /test/device/path', '100 B/s (100 B in 1.000s)\r\n'):
814 self.device.PushChangedFiles(host_file_path, device_file_path) 891 self.device.PushChangedFiles(host_file_path, device_file_path)
815 892
816 def testPushChangedFiles_directory_nothingChanged(self): 893 def testPushChangedFiles_directory_nothingChanged(self):
817 self.device.old_interface._push_if_needed_cache = {} 894 self.device.old_interface._push_if_needed_cache = {}
818 895
819 host_file_path = '/test/host/path' 896 host_file_path = '/test/host/path'
820 device_file_path = '/test/device/path' 897 device_file_path = '/test/device/path'
821 898
822 mock_file_info = { 899 mock_fs = self.MockFileSystem()
823 '/test/host/path': { 900 mock_fs.addMockDirectory(
824 'os.path.exists': True, 901 host_file_path, 256,
825 'os.path.isdir': True, 902 stat=self.MockFileSystem.osStatResult(st_mtime=1000000000))
826 'os.path.getsize': 256, 903 mock_fs.addMockFile(
827 'os.stat': self.createMockOSStatResult(st_mtime=1000000000) 904 host_file_path + '/file1', 251,
828 }, 905 stat=self.MockFileSystem.osStatResult(st_mtime=1000000001))
829 '/test/host/path/file1': { 906 mock_fs.addMockFile(
830 'os.path.exists': True, 907 host_file_path + '/file2', 252,
831 'os.path.isdir': False, 908 stat=self.MockFileSystem.osStatResult(st_mtime=1000000002))
832 'os.path.getsize': 251,
833 'os.stat': self.createMockOSStatResult(st_mtime=1000000001)
834 },
835 '/test/host/path/file2': {
836 'os.path.exists': True,
837 'os.path.isdir': False,
838 'os.path.getsize': 252,
839 'os.stat': self.createMockOSStatResult(st_mtime=1000000002)
840 },
841 }
842
843 os_path_exists = mock.Mock()
844 os_path_exists.side_effect = lambda f: mock_file_info[f]['os.path.exists']
845
846 os_path_isdir = mock.Mock()
847 os_path_isdir.side_effect = lambda f: mock_file_info[f]['os.path.isdir']
848
849 os_path_getsize = mock.Mock()
850 os_path_getsize.side_effect = lambda f: mock_file_info[f]['os.path.getsize']
851
852 os_stat = mock.Mock()
853 os_stat.side_effect = lambda f: mock_file_info[f]['os.stat']
854 909
855 self.device.old_interface.GetFilesChanged = mock.Mock(return_value=[]) 910 self.device.old_interface.GetFilesChanged = mock.Mock(return_value=[])
856 911
857 with mock.patch('os.path.exists', new=os_path_exists), ( 912 with mock_fs:
858 mock.patch('os.path.isdir', new=os_path_isdir)), ( 913 with self.assertCallsSequence([
859 mock.patch('os.path.getsize', new=os_path_getsize)), (
860 mock.patch('os.stat', new=os_stat)):
861 with self.assertOldImplCallsSequence([
862 ("adb -s 0123456789abcdef shell 'mkdir -p \"/test/device/path\"'", 914 ("adb -s 0123456789abcdef shell 'mkdir -p \"/test/device/path\"'",
863 '')]): 915 '')]):
864 self.device.PushChangedFiles(host_file_path, device_file_path) 916 self.device.PushChangedFiles(host_file_path, device_file_path)
865 917
866 def testPushChangedFiles_directory_somethingChanged(self): 918 def testPushChangedFiles_directory_somethingChanged(self):
867 self.device.old_interface._push_if_needed_cache = {} 919 self.device.old_interface._push_if_needed_cache = {}
868 920
869 host_file_path = '/test/host/path' 921 host_file_path = '/test/host/path'
870 device_file_path = '/test/device/path' 922 device_file_path = '/test/device/path'
871 923
872 mock_file_info = { 924 mock_fs = self.MockFileSystem()
873 '/test/host/path': { 925 mock_fs.addMockDirectory(
874 'os.path.exists': True, 926 host_file_path, 256,
875 'os.path.isdir': True, 927 stat=self.MockFileSystem.osStatResult(st_mtime=1000000000),
876 'os.path.getsize': 256, 928 walk=[('/test/host/path', [], ['file1', 'file2'])])
877 'os.stat': self.createMockOSStatResult(st_mtime=1000000000), 929 mock_fs.addMockFile(
878 'os.walk': [('/test/host/path', [], ['file1', 'file2'])] 930 host_file_path + '/file1', 256,
879 }, 931 stat=self.MockFileSystem.osStatResult(st_mtime=1000000001))
880 '/test/host/path/file1': { 932 mock_fs.addMockFile(
881 'os.path.exists': True, 933 host_file_path + '/file2', 256,
882 'os.path.isdir': False, 934 stat=self.MockFileSystem.osStatResult(st_mtime=1000000002))
883 'os.path.getsize': 256,
884 'os.stat': self.createMockOSStatResult(st_mtime=1000000001)
885 },
886 '/test/host/path/file2': {
887 'os.path.exists': True,
888 'os.path.isdir': False,
889 'os.path.getsize': 256,
890 'os.stat': self.createMockOSStatResult(st_mtime=1000000002)
891 },
892 }
893
894 os_path_exists = mock.Mock()
895 os_path_exists.side_effect = lambda f: mock_file_info[f]['os.path.exists']
896
897 os_path_isdir = mock.Mock()
898 os_path_isdir.side_effect = lambda f: mock_file_info[f]['os.path.isdir']
899
900 os_path_getsize = mock.Mock()
901 os_path_getsize.side_effect = lambda f: mock_file_info[f]['os.path.getsize']
902
903 os_stat = mock.Mock()
904 os_stat.side_effect = lambda f: mock_file_info[f]['os.stat']
905
906 os_walk = mock.Mock()
907 os_walk.side_effect = lambda f: mock_file_info[f]['os.walk']
908 935
909 self.device.old_interface.GetFilesChanged = mock.Mock( 936 self.device.old_interface.GetFilesChanged = mock.Mock(
910 return_value=[('/test/host/path/file1', '/test/device/path/file1')]) 937 return_value=[('/test/host/path/file1', '/test/device/path/file1')])
911 938
912 with mock.patch('os.path.exists', new=os_path_exists), ( 939 with mock_fs:
913 mock.patch('os.path.isdir', new=os_path_isdir)), ( 940 with self.assertCallsSequence([
914 mock.patch('os.path.getsize', new=os_path_getsize)), (
915 mock.patch('os.stat', new=os_stat)), (
916 mock.patch('os.walk', new=os_walk)):
917 with self.assertOldImplCallsSequence([
918 ("adb -s 0123456789abcdef shell 'mkdir -p \"/test/device/path\"'", 941 ("adb -s 0123456789abcdef shell 'mkdir -p \"/test/device/path\"'",
919 ''), 942 ''),
920 ('adb -s 0123456789abcdef push ' 943 ('adb -s 0123456789abcdef push '
921 '/test/host/path/file1 /test/device/path/file1', 944 '/test/host/path/file1 /test/device/path/file1',
922 '256 B/s (256 B in 1.000s)\r\n')]): 945 '256 B/s (256 B in 1.000s)\r\n')]):
923 self.device.PushChangedFiles(host_file_path, device_file_path) 946 self.device.PushChangedFiles(host_file_path, device_file_path)
924 947
925 def testPushChangedFiles_directory_everythingChanged(self): 948 def testPushChangedFiles_directory_everythingChanged(self):
926 self.device.old_interface._push_if_needed_cache = {} 949 self.device.old_interface._push_if_needed_cache = {}
927 950
928 host_file_path = '/test/host/path' 951 host_file_path = '/test/host/path'
929 device_file_path = '/test/device/path' 952 device_file_path = '/test/device/path'
930 953
931 mock_file_info = { 954 mock_fs = self.MockFileSystem()
932 '/test/host/path': { 955 mock_fs.addMockDirectory(
933 'os.path.exists': True, 956 host_file_path, 256,
934 'os.path.isdir': True, 957 stat=self.MockFileSystem.osStatResult(st_mtime=1000000000))
935 'os.path.getsize': 256, 958 mock_fs.addMockFile(
936 'os.stat': self.createMockOSStatResult(st_mtime=1000000000) 959 host_file_path + '/file1', 256,
937 }, 960 stat=self.MockFileSystem.osStatResult(st_mtime=1000000001))
938 '/test/host/path/file1': { 961 mock_fs.addMockFile(
939 'os.path.exists': True, 962 host_file_path + '/file2', 256,
940 'os.path.isdir': False, 963 stat=self.MockFileSystem.osStatResult(st_mtime=1000000002))
941 'os.path.getsize': 256,
942 'os.stat': self.createMockOSStatResult(st_mtime=1000000001)
943 },
944 '/test/host/path/file2': {
945 'os.path.exists': True,
946 'os.path.isdir': False,
947 'os.path.getsize': 256,
948 'os.stat': self.createMockOSStatResult(st_mtime=1000000002)
949 },
950 }
951
952 os_path_exists = mock.Mock()
953 os_path_exists.side_effect = lambda f: mock_file_info[f]['os.path.exists']
954
955 os_path_isdir = mock.Mock()
956 os_path_isdir.side_effect = lambda f: mock_file_info[f]['os.path.isdir']
957
958 os_path_getsize = mock.Mock()
959 os_path_getsize.side_effect = lambda f: mock_file_info[f]['os.path.getsize']
960
961 os_stat = mock.Mock()
962 os_stat.side_effect = lambda f: mock_file_info[f]['os.stat']
963 964
964 self.device.old_interface.GetFilesChanged = mock.Mock( 965 self.device.old_interface.GetFilesChanged = mock.Mock(
965 return_value=[('/test/host/path/file1', '/test/device/path/file1'), 966 return_value=[('/test/host/path/file1', '/test/device/path/file1'),
966 ('/test/host/path/file2', '/test/device/path/file2')]) 967 ('/test/host/path/file2', '/test/device/path/file2')])
967 968
968 with mock.patch('os.path.exists', new=os_path_exists), ( 969 with mock_fs:
969 mock.patch('os.path.isdir', new=os_path_isdir)), ( 970 with self.assertCallsSequence([
970 mock.patch('os.path.getsize', new=os_path_getsize)), (
971 mock.patch('os.stat', new=os_stat)):
972 with self.assertOldImplCallsSequence([
973 ("adb -s 0123456789abcdef shell 'mkdir -p \"/test/device/path\"'", 971 ("adb -s 0123456789abcdef shell 'mkdir -p \"/test/device/path\"'",
974 ''), 972 ''),
975 ('adb -s 0123456789abcdef push /test/host/path /test/device/path', 973 ('adb -s 0123456789abcdef push /test/host/path /test/device/path',
976 '768 B/s (768 B in 1.000s)\r\n')]): 974 '768 B/s (768 B in 1.000s)\r\n')]):
977 self.device.PushChangedFiles(host_file_path, device_file_path) 975 self.device.PushChangedFiles(host_file_path, device_file_path)
978 976
977
978 class DeviceUtilsFileExistsTest(DeviceUtilsOldImplTest):
979
979 def testFileExists_usingTest_fileExists(self): 980 def testFileExists_usingTest_fileExists(self):
980 with self.assertOldImplCalls( 981 with self.assertCalls(
981 "adb -s 0123456789abcdef shell " 982 "adb -s 0123456789abcdef shell "
982 "'test -e \"/data/app/test.file.exists\"; echo $?'", 983 "'test -e \"/data/app/test.file.exists\"; echo $?'",
983 '0\r\n'): 984 '0\r\n'):
984 self.assertTrue(self.device.FileExists('/data/app/test.file.exists')) 985 self.assertTrue(self.device.FileExists('/data/app/test.file.exists'))
985 986
986 def testFileExists_usingTest_fileDoesntExist(self): 987 def testFileExists_usingTest_fileDoesntExist(self):
987 with self.assertOldImplCalls( 988 with self.assertCalls(
988 "adb -s 0123456789abcdef shell " 989 "adb -s 0123456789abcdef shell "
989 "'test -e \"/data/app/test.file.does.not.exist\"; echo $?'", 990 "'test -e \"/data/app/test.file.does.not.exist\"; echo $?'",
990 '1\r\n'): 991 '1\r\n'):
991 self.assertFalse(self.device.FileExists( 992 self.assertFalse(self.device.FileExists(
992 '/data/app/test.file.does.not.exist')) 993 '/data/app/test.file.does.not.exist'))
993 994
994 def testFileExists_usingLs_fileExists(self): 995 def testFileExists_usingLs_fileExists(self):
995 with self.assertOldImplCallsSequence([ 996 with self.assertCallsSequence([
996 ("adb -s 0123456789abcdef shell " 997 ("adb -s 0123456789abcdef shell "
997 "'test -e \"/data/app/test.file.exists\"; echo $?'", 998 "'test -e \"/data/app/test.file.exists\"; echo $?'",
998 'test: not found\r\n'), 999 'test: not found\r\n'),
999 ("adb -s 0123456789abcdef shell " 1000 ("adb -s 0123456789abcdef shell "
1000 "'ls \"/data/app/test.file.exists\" >/dev/null 2>&1; echo $?'", 1001 "'ls \"/data/app/test.file.exists\" >/dev/null 2>&1; echo $?'",
1001 '0\r\n')]): 1002 '0\r\n')]):
1002 self.assertTrue(self.device.FileExists('/data/app/test.file.exists')) 1003 self.assertTrue(self.device.FileExists('/data/app/test.file.exists'))
1003 1004
1004 def testFileExists_usingLs_fileDoesntExist(self): 1005 def testFileExists_usingLs_fileDoesntExist(self):
1005 with self.assertOldImplCallsSequence([ 1006 with self.assertCallsSequence([
1006 ("adb -s 0123456789abcdef shell " 1007 ("adb -s 0123456789abcdef shell "
1007 "'test -e \"/data/app/test.file.does.not.exist\"; echo $?'", 1008 "'test -e \"/data/app/test.file.does.not.exist\"; echo $?'",
1008 'test: not found\r\n'), 1009 'test: not found\r\n'),
1009 ("adb -s 0123456789abcdef shell " 1010 ("adb -s 0123456789abcdef shell "
1010 "'ls \"/data/app/test.file.does.not.exist\" " 1011 "'ls \"/data/app/test.file.does.not.exist\" "
1011 ">/dev/null 2>&1; echo $?'", 1012 ">/dev/null 2>&1; echo $?'",
1012 '1\r\n')]): 1013 '1\r\n')]):
1013 self.assertFalse(self.device.FileExists( 1014 self.assertFalse(self.device.FileExists(
1014 '/data/app/test.file.does.not.exist')) 1015 '/data/app/test.file.does.not.exist'))
1015 1016
1017
1018 class DeviceUtilsPullFileTest(DeviceUtilsOldImplTest):
1019
1016 def testPullFile_existsOnDevice(self): 1020 def testPullFile_existsOnDevice(self):
1017 with mock.patch('os.path.exists', return_value=True): 1021 with mock.patch('os.path.exists', return_value=True):
1018 with self.assertOldImplCallsSequence([ 1022 with self.assertCallsSequence([
1019 ('adb -s 0123456789abcdef shell ' 1023 ('adb -s 0123456789abcdef shell '
1020 'ls /data/app/test.file.exists', 1024 'ls /data/app/test.file.exists',
1021 '/data/app/test.file.exists'), 1025 '/data/app/test.file.exists'),
1022 ('adb -s 0123456789abcdef pull ' 1026 ('adb -s 0123456789abcdef pull '
1023 '/data/app/test.file.exists /test/file/host/path', 1027 '/data/app/test.file.exists /test/file/host/path',
1024 '100 B/s (100 bytes in 1.000s)\r\n')]): 1028 '100 B/s (100 bytes in 1.000s)\r\n')]):
1025 self.device.PullFile('/data/app/test.file.exists', 1029 self.device.PullFile('/data/app/test.file.exists',
1026 '/test/file/host/path') 1030 '/test/file/host/path')
1027 1031
1028 def testPullFile_doesntExistOnDevice(self): 1032 def testPullFile_doesntExistOnDevice(self):
1029 with mock.patch('os.path.exists', return_value=True): 1033 with mock.patch('os.path.exists', return_value=True):
1030 with self.assertOldImplCalls( 1034 with self.assertCalls(
1031 'adb -s 0123456789abcdef shell ' 1035 'adb -s 0123456789abcdef shell '
1032 'ls /data/app/test.file.does.not.exist', 1036 'ls /data/app/test.file.does.not.exist',
1033 '/data/app/test.file.does.not.exist: No such file or directory\r\n'): 1037 '/data/app/test.file.does.not.exist: No such file or directory\r\n'):
1034 with self.assertRaises(device_errors.CommandFailedError): 1038 with self.assertRaises(device_errors.CommandFailedError):
1035 self.device.PullFile('/data/app/test.file.does.not.exist', 1039 self.device.PullFile('/data/app/test.file.does.not.exist',
1036 '/test/file/host/path') 1040 '/test/file/host/path')
1037 1041
1042
1043 class DeviceUtilsReadFileTest(DeviceUtilsOldImplTest):
1044
1038 def testReadFile_exists(self): 1045 def testReadFile_exists(self):
1039 with self.assertOldImplCallsSequence([ 1046 with self.assertCallsSequence([
1040 ("adb -s 0123456789abcdef shell " 1047 ("adb -s 0123456789abcdef shell "
1041 "'cat \"/read/this/test/file\" 2>/dev/null'", 1048 "'cat \"/read/this/test/file\" 2>/dev/null'",
1042 'this is a test file')]): 1049 'this is a test file')]):
1043 self.assertEqual(['this is a test file'], 1050 self.assertEqual(['this is a test file'],
1044 self.device.ReadFile('/read/this/test/file')) 1051 self.device.ReadFile('/read/this/test/file'))
1045 1052
1046 def testReadFile_doesNotExist(self): 1053 def testReadFile_doesNotExist(self):
1047 with self.assertOldImplCalls( 1054 with self.assertCalls(
1048 "adb -s 0123456789abcdef shell " 1055 "adb -s 0123456789abcdef shell "
1049 "'cat \"/this/file/does.not.exist\" 2>/dev/null'", 1056 "'cat \"/this/file/does.not.exist\" 2>/dev/null'",
1050 ''): 1057 ''):
1051 self.device.ReadFile('/this/file/does.not.exist') 1058 self.device.ReadFile('/this/file/does.not.exist')
1052 1059
1053 def testReadFile_asRoot_withRoot(self): 1060 def testReadFile_asRoot_withRoot(self):
1054 self.device.old_interface._privileged_command_runner = ( 1061 self.device.old_interface._privileged_command_runner = (
1055 self.device.old_interface.RunShellCommand) 1062 self.device.old_interface.RunShellCommand)
1056 self.device.old_interface._protected_file_access_method_initialized = True 1063 self.device.old_interface._protected_file_access_method_initialized = True
1057 with self.assertOldImplCallsSequence([ 1064 with self.assertCallsSequence([
1058 ("adb -s 0123456789abcdef shell " 1065 ("adb -s 0123456789abcdef shell "
1059 "'cat \"/this/file/must.be.read.by.root\" 2> /dev/null'", 1066 "'cat \"/this/file/must.be.read.by.root\" 2> /dev/null'",
1060 'this is a test file\nread by root')]): 1067 'this is a test file\nread by root')]):
1061 self.assertEqual( 1068 self.assertEqual(
1062 ['this is a test file', 'read by root'], 1069 ['this is a test file', 'read by root'],
1063 self.device.ReadFile('/this/file/must.be.read.by.root', 1070 self.device.ReadFile('/this/file/must.be.read.by.root',
1064 as_root=True)) 1071 as_root=True))
1065 1072
1066 def testReadFile_asRoot_withSu(self): 1073 def testReadFile_asRoot_withSu(self):
1067 self.device.old_interface._privileged_command_runner = ( 1074 self.device.old_interface._privileged_command_runner = (
1068 self.device.old_interface.RunShellCommandWithSU) 1075 self.device.old_interface.RunShellCommandWithSU)
1069 self.device.old_interface._protected_file_access_method_initialized = True 1076 self.device.old_interface._protected_file_access_method_initialized = True
1070 with self.assertOldImplCallsSequence([ 1077 with self.assertCallsSequence([
1071 ("adb -s 0123456789abcdef shell " 1078 ("adb -s 0123456789abcdef shell "
1072 "'su -c cat \"/this/file/can.be.read.with.su\" 2> /dev/null'", 1079 "'su -c cat \"/this/file/can.be.read.with.su\" 2> /dev/null'",
1073 'this is a test file\nread with su')]): 1080 'this is a test file\nread with su')]):
1074 self.assertEqual( 1081 self.assertEqual(
1075 ['this is a test file', 'read with su'], 1082 ['this is a test file', 'read with su'],
1076 self.device.ReadFile('/this/file/can.be.read.with.su', 1083 self.device.ReadFile('/this/file/can.be.read.with.su',
1077 as_root=True)) 1084 as_root=True))
1078 1085
1079 def testReadFile_asRoot_rejected(self): 1086 def testReadFile_asRoot_rejected(self):
1080 self.device.old_interface._privileged_command_runner = None 1087 self.device.old_interface._privileged_command_runner = None
1081 self.device.old_interface._protected_file_access_method_initialized = True 1088 self.device.old_interface._protected_file_access_method_initialized = True
1082 with self.assertRaises(device_errors.CommandFailedError): 1089 with self.assertRaises(device_errors.CommandFailedError):
1083 self.device.ReadFile('/this/file/cannot.be.read.by.user', 1090 self.device.ReadFile('/this/file/cannot.be.read.by.user',
1084 as_root=True) 1091 as_root=True)
1085 1092
1093
1094 class DeviceUtilsWriteFileTest(DeviceUtilsOldImplTest):
1095
1086 def testWriteFile_basic(self): 1096 def testWriteFile_basic(self):
1087 mock_file = mock.MagicMock(spec=file) 1097 mock_file = mock.MagicMock(spec=file)
1088 mock_file.name = '/tmp/file/to.be.pushed' 1098 mock_file.name = '/tmp/file/to.be.pushed'
1089 mock_file.__enter__.return_value = mock_file 1099 mock_file.__enter__.return_value = mock_file
1090 with mock.patch('tempfile.NamedTemporaryFile', 1100 with mock.patch('tempfile.NamedTemporaryFile',
1091 return_value=mock_file): 1101 return_value=mock_file):
1092 with self.assertOldImplCalls( 1102 with self.assertCalls(
1093 'adb -s 0123456789abcdef push ' 1103 'adb -s 0123456789abcdef push '
1094 '/tmp/file/to.be.pushed /test/file/written.to.device', 1104 '/tmp/file/to.be.pushed /test/file/written.to.device',
1095 '100 B/s (100 bytes in 1.000s)\r\n'): 1105 '100 B/s (100 bytes in 1.000s)\r\n'):
1096 self.device.WriteFile('/test/file/written.to.device', 1106 self.device.WriteFile('/test/file/written.to.device',
1097 'new test file contents') 1107 'new test file contents')
1098 mock_file.write.assert_called_once_with('new test file contents') 1108 mock_file.write.assert_called_once_with('new test file contents')
1099 1109
1100 def testWriteFile_asRoot_withRoot(self): 1110 def testWriteFile_asRoot_withRoot(self):
1101 self.device.old_interface._external_storage = '/fake/storage/path' 1111 self.device.old_interface._external_storage = '/fake/storage/path'
1102 self.device.old_interface._privileged_command_runner = ( 1112 self.device.old_interface._privileged_command_runner = (
1103 self.device.old_interface.RunShellCommand) 1113 self.device.old_interface.RunShellCommand)
1104 self.device.old_interface._protected_file_access_method_initialized = True 1114 self.device.old_interface._protected_file_access_method_initialized = True
1105 1115
1106 mock_file = mock.MagicMock(spec=file) 1116 mock_file = mock.MagicMock(spec=file)
1107 mock_file.name = '/tmp/file/to.be.pushed' 1117 mock_file.name = '/tmp/file/to.be.pushed'
1108 mock_file.__enter__.return_value = mock_file 1118 mock_file.__enter__.return_value = mock_file
1109 with mock.patch('tempfile.NamedTemporaryFile', 1119 with mock.patch('tempfile.NamedTemporaryFile',
1110 return_value=mock_file): 1120 return_value=mock_file):
1111 with self.assertOldImplCallsSequence( 1121 with self.assertCallsSequence(
1112 cmd_ret=[ 1122 cmd_ret=[
1113 # Create temporary contents file 1123 # Create temporary contents file
1114 (r"adb -s 0123456789abcdef shell " 1124 (r"adb -s 0123456789abcdef shell "
1115 "'test -e \"/fake/storage/path/temp_file-\d+-\d+\"; " 1125 "'test -e \"/fake/storage/path/temp_file-\d+-\d+\"; "
1116 "echo \$\?'", 1126 "echo \$\?'",
1117 '1\r\n'), 1127 '1\r\n'),
1118 # Create temporary script file 1128 # Create temporary script file
1119 (r"adb -s 0123456789abcdef shell " 1129 (r"adb -s 0123456789abcdef shell "
1120 "'test -e \"/fake/storage/path/temp_file-\d+-\d+\.sh\"; " 1130 "'test -e \"/fake/storage/path/temp_file-\d+-\d+\.sh\"; "
1121 "echo \$\?'", 1131 "echo \$\?'",
(...skipping 22 matching lines...) Expand all
1144 self.device.old_interface._external_storage = '/fake/storage/path' 1154 self.device.old_interface._external_storage = '/fake/storage/path'
1145 self.device.old_interface._privileged_command_runner = ( 1155 self.device.old_interface._privileged_command_runner = (
1146 self.device.old_interface.RunShellCommandWithSU) 1156 self.device.old_interface.RunShellCommandWithSU)
1147 self.device.old_interface._protected_file_access_method_initialized = True 1157 self.device.old_interface._protected_file_access_method_initialized = True
1148 1158
1149 mock_file = mock.MagicMock(spec=file) 1159 mock_file = mock.MagicMock(spec=file)
1150 mock_file.name = '/tmp/file/to.be.pushed' 1160 mock_file.name = '/tmp/file/to.be.pushed'
1151 mock_file.__enter__.return_value = mock_file 1161 mock_file.__enter__.return_value = mock_file
1152 with mock.patch('tempfile.NamedTemporaryFile', 1162 with mock.patch('tempfile.NamedTemporaryFile',
1153 return_value=mock_file): 1163 return_value=mock_file):
1154 with self.assertOldImplCallsSequence( 1164 with self.assertCallsSequence(
1155 cmd_ret=[ 1165 cmd_ret=[
1156 # Create temporary contents file 1166 # Create temporary contents file
1157 (r"adb -s 0123456789abcdef shell " 1167 (r"adb -s 0123456789abcdef shell "
1158 "'test -e \"/fake/storage/path/temp_file-\d+-\d+\"; " 1168 "'test -e \"/fake/storage/path/temp_file-\d+-\d+\"; "
1159 "echo \$\?'", 1169 "echo \$\?'",
1160 '1\r\n'), 1170 '1\r\n'),
1161 # Create temporary script file 1171 # Create temporary script file
1162 (r"adb -s 0123456789abcdef shell " 1172 (r"adb -s 0123456789abcdef shell "
1163 "'test -e \"/fake/storage/path/temp_file-\d+-\d+\.sh\"; " 1173 "'test -e \"/fake/storage/path/temp_file-\d+-\d+\.sh\"; "
1164 "echo \$\?'", 1174 "echo \$\?'",
(...skipping 18 matching lines...) Expand all
1183 self.device.WriteFile('/test/file/written.to.device', 1193 self.device.WriteFile('/test/file/written.to.device',
1184 'new test file contents', as_root=True) 1194 'new test file contents', as_root=True)
1185 1195
1186 def testWriteFile_asRoot_rejected(self): 1196 def testWriteFile_asRoot_rejected(self):
1187 self.device.old_interface._privileged_command_runner = None 1197 self.device.old_interface._privileged_command_runner = None
1188 self.device.old_interface._protected_file_access_method_initialized = True 1198 self.device.old_interface._protected_file_access_method_initialized = True
1189 with self.assertRaises(device_errors.CommandFailedError): 1199 with self.assertRaises(device_errors.CommandFailedError):
1190 self.device.WriteFile('/test/file/no.permissions.to.write', 1200 self.device.WriteFile('/test/file/no.permissions.to.write',
1191 'new test file contents', as_root=True) 1201 'new test file contents', as_root=True)
1192 1202
1203
1204 class DeviceUtilsLsTest(DeviceUtilsOldImplTest):
1205
1193 def testLs_nothing(self): 1206 def testLs_nothing(self):
1194 with self.assertOldImplCallsSequence([ 1207 with self.assertCallsSequence([
1195 ("adb -s 0123456789abcdef shell 'ls -lR /this/file/does.not.exist'", 1208 ("adb -s 0123456789abcdef shell 'ls -lR /this/file/does.not.exist'",
1196 '/this/file/does.not.exist: No such file or directory\r\n'), 1209 '/this/file/does.not.exist: No such file or directory\r\n'),
1197 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]): 1210 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]):
1198 self.assertEqual({}, self.device.Ls('/this/file/does.not.exist')) 1211 self.assertEqual({}, self.device.Ls('/this/file/does.not.exist'))
1199 1212
1200 def testLs_file(self): 1213 def testLs_file(self):
1201 with self.assertOldImplCallsSequence([ 1214 with self.assertCallsSequence([
1202 ("adb -s 0123456789abcdef shell 'ls -lR /this/is/a/test.file'", 1215 ("adb -s 0123456789abcdef shell 'ls -lR /this/is/a/test.file'",
1203 '-rw-rw---- testuser testgroup 4096 1970-01-01 00:00 test.file\r\n'), 1216 '-rw-rw---- testuser testgroup 4096 1970-01-01 00:00 test.file\r\n'),
1204 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]): 1217 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]):
1205 self.assertEqual( 1218 self.assertEqual(
1206 {'test.file': (4096, datetime.datetime(1970, 1, 1))}, 1219 {'test.file': (4096, datetime.datetime(1970, 1, 1))},
1207 self.device.Ls('/this/is/a/test.file')) 1220 self.device.Ls('/this/is/a/test.file'))
1208 1221
1209 def testLs_directory(self): 1222 def testLs_directory(self):
1210 with self.assertOldImplCallsSequence([ 1223 with self.assertCallsSequence([
1211 ("adb -s 0123456789abcdef shell 'ls -lR /this/is/a/test.directory'", 1224 ("adb -s 0123456789abcdef shell 'ls -lR /this/is/a/test.directory'",
1212 '\r\n' 1225 '\r\n'
1213 '/this/is/a/test.directory:\r\n' 1226 '/this/is/a/test.directory:\r\n'
1214 '-rw-rw---- testuser testgroup 4096 1970-01-01 18:19 test.file\r\n'), 1227 '-rw-rw---- testuser testgroup 4096 1970-01-01 18:19 test.file\r\n'),
1215 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]): 1228 ("adb -s 0123456789abcdef shell 'date +%z'", '+0000')]):
1216 self.assertEqual( 1229 self.assertEqual(
1217 {'test.file': (4096, datetime.datetime(1970, 1, 1, 18, 19))}, 1230 {'test.file': (4096, datetime.datetime(1970, 1, 1, 18, 19))},
1218 self.device.Ls('/this/is/a/test.directory')) 1231 self.device.Ls('/this/is/a/test.directory'))
1219 1232
1220 def testLs_directories(self): 1233 def testLs_directories(self):
1221 with self.assertOldImplCallsSequence([ 1234 with self.assertCallsSequence([
1222 ("adb -s 0123456789abcdef shell 'ls -lR /this/is/a/test.directory'", 1235 ("adb -s 0123456789abcdef shell 'ls -lR /this/is/a/test.directory'",
1223 '\r\n' 1236 '\r\n'
1224 '/this/is/a/test.directory:\r\n' 1237 '/this/is/a/test.directory:\r\n'
1225 'drwxr-xr-x testuser testgroup 1970-01-01 00:00 test.subdirectory\r\n' 1238 'drwxr-xr-x testuser testgroup 1970-01-01 00:00 test.subdirectory\r\n'
1226 '\r\n' 1239 '\r\n'
1227 '/this/is/a/test.directory/test.subdirectory:\r\n' 1240 '/this/is/a/test.directory/test.subdirectory:\r\n'
1228 '-rw-rw---- testuser testgroup 4096 1970-01-01 00:00 test.file\r\n'), 1241 '-rw-rw---- testuser testgroup 4096 1970-01-01 00:00 test.file\r\n'),
1229 ("adb -s 0123456789abcdef shell 'date +%z'", '-0700')]): 1242 ("adb -s 0123456789abcdef shell 'date +%z'", '-0700')]):
1230 self.assertEqual( 1243 self.assertEqual(
1231 {'test.subdirectory/test.file': 1244 {'test.subdirectory/test.file':
1232 (4096, datetime.datetime(1970, 1, 1, 7, 0, 0))}, 1245 (4096, datetime.datetime(1970, 1, 1, 7, 0, 0))},
1233 self.device.Ls('/this/is/a/test.directory')) 1246 self.device.Ls('/this/is/a/test.directory'))
1234 1247
1248
1249 class DeviceUtilsSetJavaAssertsTest(DeviceUtilsOldImplTest):
1250
1235 @staticmethod 1251 @staticmethod
1236 def mockNamedTemporary(name='/tmp/file/property.file', 1252 def mockNamedTemporary(name='/tmp/file/property.file',
1237 read_contents=''): 1253 read_contents=''):
1238 mock_file = mock.MagicMock(spec=file) 1254 mock_file = mock.MagicMock(spec=file)
1239 mock_file.name = name 1255 mock_file.name = name
1240 mock_file.__enter__.return_value = mock_file 1256 mock_file.__enter__.return_value = mock_file
1241 mock_file.read.return_value = read_contents 1257 mock_file.read.return_value = read_contents
1242 return mock_file 1258 return mock_file
1243 1259
1244 def testSetJavaAsserts_enable(self): 1260 def testSetJavaAsserts_enable(self):
1245 mock_file = self.mockNamedTemporary() 1261 mock_file = self.mockNamedTemporary()
1246 with mock.patch('tempfile.NamedTemporaryFile', 1262 with mock.patch('tempfile.NamedTemporaryFile',
1247 return_value=mock_file), ( 1263 return_value=mock_file), (
1248 mock.patch('__builtin__.open', return_value=mock_file)): 1264 mock.patch('__builtin__.open', return_value=mock_file)):
1249 with self.assertOldImplCallsSequence( 1265 with self.assertCallsSequence(
1250 [('adb -s 0123456789abcdef shell ls %s' % 1266 [('adb -s 0123456789abcdef shell ls %s' %
1251 constants.DEVICE_LOCAL_PROPERTIES_PATH, 1267 constants.DEVICE_LOCAL_PROPERTIES_PATH,
1252 '%s\r\n' % constants.DEVICE_LOCAL_PROPERTIES_PATH), 1268 '%s\r\n' % constants.DEVICE_LOCAL_PROPERTIES_PATH),
1253 ('adb -s 0123456789abcdef pull %s %s' % 1269 ('adb -s 0123456789abcdef pull %s %s' %
1254 (constants.DEVICE_LOCAL_PROPERTIES_PATH, mock_file.name), 1270 (constants.DEVICE_LOCAL_PROPERTIES_PATH, mock_file.name),
1255 '100 B/s (100 bytes in 1.000s)\r\n'), 1271 '100 B/s (100 bytes in 1.000s)\r\n'),
1256 ('adb -s 0123456789abcdef push %s %s' % 1272 ('adb -s 0123456789abcdef push %s %s' %
1257 (mock_file.name, constants.DEVICE_LOCAL_PROPERTIES_PATH), 1273 (mock_file.name, constants.DEVICE_LOCAL_PROPERTIES_PATH),
1258 '100 B/s (100 bytes in 1.000s)\r\n'), 1274 '100 B/s (100 bytes in 1.000s)\r\n'),
1259 ('adb -s 0123456789abcdef shell ' 1275 ('adb -s 0123456789abcdef shell '
1260 'getprop dalvik.vm.enableassertions', 1276 'getprop dalvik.vm.enableassertions',
1261 '\r\n'), 1277 '\r\n'),
1262 ('adb -s 0123456789abcdef shell ' 1278 ('adb -s 0123456789abcdef shell '
1263 'setprop dalvik.vm.enableassertions "all"', 1279 'setprop dalvik.vm.enableassertions "all"',
1264 '')]): 1280 '')]):
1265 self.device.SetJavaAsserts(True) 1281 self.device.SetJavaAsserts(True)
1266 1282
1267 def testSetJavaAsserts_disable(self): 1283 def testSetJavaAsserts_disable(self):
1268 mock_file = self.mockNamedTemporary( 1284 mock_file = self.mockNamedTemporary(
1269 read_contents='dalvik.vm.enableassertions=all\n') 1285 read_contents='dalvik.vm.enableassertions=all\n')
1270 with mock.patch('tempfile.NamedTemporaryFile', 1286 with mock.patch('tempfile.NamedTemporaryFile',
1271 return_value=mock_file), ( 1287 return_value=mock_file), (
1272 mock.patch('__builtin__.open', return_value=mock_file)): 1288 mock.patch('__builtin__.open', return_value=mock_file)):
1273 with self.assertOldImplCallsSequence( 1289 with self.assertCallsSequence(
1274 [('adb -s 0123456789abcdef shell ls %s' % 1290 [('adb -s 0123456789abcdef shell ls %s' %
1275 constants.DEVICE_LOCAL_PROPERTIES_PATH, 1291 constants.DEVICE_LOCAL_PROPERTIES_PATH,
1276 '%s\r\n' % constants.DEVICE_LOCAL_PROPERTIES_PATH), 1292 '%s\r\n' % constants.DEVICE_LOCAL_PROPERTIES_PATH),
1277 ('adb -s 0123456789abcdef pull %s %s' % 1293 ('adb -s 0123456789abcdef pull %s %s' %
1278 (constants.DEVICE_LOCAL_PROPERTIES_PATH, mock_file.name), 1294 (constants.DEVICE_LOCAL_PROPERTIES_PATH, mock_file.name),
1279 '100 B/s (100 bytes in 1.000s)\r\n'), 1295 '100 B/s (100 bytes in 1.000s)\r\n'),
1280 ('adb -s 0123456789abcdef push %s %s' % 1296 ('adb -s 0123456789abcdef push %s %s' %
1281 (mock_file.name, constants.DEVICE_LOCAL_PROPERTIES_PATH), 1297 (mock_file.name, constants.DEVICE_LOCAL_PROPERTIES_PATH),
1282 '100 B/s (100 bytes in 1.000s)\r\n'), 1298 '100 B/s (100 bytes in 1.000s)\r\n'),
1283 ('adb -s 0123456789abcdef shell ' 1299 ('adb -s 0123456789abcdef shell '
1284 'getprop dalvik.vm.enableassertions', 1300 'getprop dalvik.vm.enableassertions',
1285 'all\r\n'), 1301 'all\r\n'),
1286 ('adb -s 0123456789abcdef shell ' 1302 ('adb -s 0123456789abcdef shell '
1287 'setprop dalvik.vm.enableassertions ""', 1303 'setprop dalvik.vm.enableassertions ""',
1288 '')]): 1304 '')]):
1289 self.device.SetJavaAsserts(False) 1305 self.device.SetJavaAsserts(False)
1290 1306
1291 def testSetJavaAsserts_alreadyEnabled(self): 1307 def testSetJavaAsserts_alreadyEnabled(self):
1292 mock_file = self.mockNamedTemporary( 1308 mock_file = self.mockNamedTemporary(
1293 read_contents='dalvik.vm.enableassertions=all\n') 1309 read_contents='dalvik.vm.enableassertions=all\n')
1294 with mock.patch('tempfile.NamedTemporaryFile', 1310 with mock.patch('tempfile.NamedTemporaryFile',
1295 return_value=mock_file), ( 1311 return_value=mock_file), (
1296 mock.patch('__builtin__.open', return_value=mock_file)): 1312 mock.patch('__builtin__.open', return_value=mock_file)):
1297 with self.assertOldImplCallsSequence( 1313 with self.assertCallsSequence(
1298 [('adb -s 0123456789abcdef shell ls %s' % 1314 [('adb -s 0123456789abcdef shell ls %s' %
1299 constants.DEVICE_LOCAL_PROPERTIES_PATH, 1315 constants.DEVICE_LOCAL_PROPERTIES_PATH,
1300 '%s\r\n' % constants.DEVICE_LOCAL_PROPERTIES_PATH), 1316 '%s\r\n' % constants.DEVICE_LOCAL_PROPERTIES_PATH),
1301 ('adb -s 0123456789abcdef pull %s %s' % 1317 ('adb -s 0123456789abcdef pull %s %s' %
1302 (constants.DEVICE_LOCAL_PROPERTIES_PATH, mock_file.name), 1318 (constants.DEVICE_LOCAL_PROPERTIES_PATH, mock_file.name),
1303 '100 B/s (100 bytes in 1.000s)\r\n'), 1319 '100 B/s (100 bytes in 1.000s)\r\n'),
1304 ('adb -s 0123456789abcdef shell ' 1320 ('adb -s 0123456789abcdef shell '
1305 'getprop dalvik.vm.enableassertions', 1321 'getprop dalvik.vm.enableassertions',
1306 'all\r\n')]): 1322 'all\r\n')]):
1307 self.assertFalse(self.device.SetJavaAsserts(True)) 1323 self.assertFalse(self.device.SetJavaAsserts(True))
1308 1324
1325
1326 class DeviceUtilsGetPropTest(DeviceUtilsOldImplTest):
1327
1309 def testGetProp_exists(self): 1328 def testGetProp_exists(self):
1310 with self.assertOldImplCalls( 1329 with self.assertCalls(
1311 'adb -s 0123456789abcdef shell getprop this.is.a.test.property', 1330 'adb -s 0123456789abcdef shell getprop this.is.a.test.property',
1312 'test_property_value\r\n'): 1331 'test_property_value\r\n'):
1313 self.assertEqual('test_property_value', 1332 self.assertEqual('test_property_value',
1314 self.device.GetProp('this.is.a.test.property')) 1333 self.device.GetProp('this.is.a.test.property'))
1315 1334
1316 def testGetProp_doesNotExist(self): 1335 def testGetProp_doesNotExist(self):
1317 with self.assertOldImplCalls( 1336 with self.assertCalls(
1318 'adb -s 0123456789abcdef shell ' 1337 'adb -s 0123456789abcdef shell '
1319 'getprop this.property.does.not.exist', ''): 1338 'getprop this.property.does.not.exist', ''):
1320 self.assertEqual('', self.device.GetProp('this.property.does.not.exist')) 1339 self.assertEqual('', self.device.GetProp('this.property.does.not.exist'))
1321 1340
1322 def testGetProp_cachedRoProp(self): 1341 def testGetProp_cachedRoProp(self):
1323 with self.assertOldImplCalls( 1342 with self.assertCalls(
1324 'adb -s 0123456789abcdef shell ' 1343 'adb -s 0123456789abcdef shell '
1325 'getprop ro.build.type', 'userdebug'): 1344 'getprop ro.build.type', 'userdebug'):
1326 self.assertEqual('userdebug', self.device.GetProp('ro.build.type')) 1345 self.assertEqual('userdebug', self.device.GetProp('ro.build.type'))
1327 self.assertEqual('userdebug', self.device.GetProp('ro.build.type')) 1346 self.assertEqual('userdebug', self.device.GetProp('ro.build.type'))
1328 1347
1348
1349 class DeviceUtilsSetPropTest(DeviceUtilsOldImplTest):
1350
1329 def testSetProp(self): 1351 def testSetProp(self):
1330 with self.assertOldImplCalls( 1352 with self.assertCalls(
1331 'adb -s 0123456789abcdef shell ' 1353 'adb -s 0123456789abcdef shell '
1332 'setprop this.is.a.test.property "test_property_value"', 1354 'setprop this.is.a.test.property "test_property_value"',
1333 ''): 1355 ''):
1334 self.device.SetProp('this.is.a.test.property', 'test_property_value') 1356 self.device.SetProp('this.is.a.test.property', 'test_property_value')
1335 1357
1336 1358
1337 if __name__ == '__main__': 1359 if __name__ == '__main__':
1338 logging.getLogger().setLevel(logging.DEBUG) 1360 logging.getLogger().setLevel(logging.DEBUG)
1339 unittest.main(verbosity=2) 1361 unittest.main(verbosity=2)
1340 1362
OLDNEW
« build/android/PRESUBMIT.py ('K') | « build/android/PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698