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

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

Issue 294113003: [Android] Convert to DeviceUtils versions of WaitUntilFullyBooted and GetExternalStoragePath. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """ 5 """
6 Unit tests for the contents of device_utils.py (mostly DeviceUtils). 6 Unit tests for the contents of device_utils.py (mostly DeviceUtils).
7 """ 7 """
8 8
9 # pylint: disable=W0212 9 # pylint: disable=W0212
10 # pylint: disable=W0613 10 # pylint: disable=W0613
11 11
12 import random 12 import random
13 import time
13 import unittest 14 import unittest
14 15
15 from pylib import android_commands 16 from pylib import android_commands
16 from pylib import cmd_helper 17 from pylib import cmd_helper
17 from pylib.device import adb_wrapper 18 from pylib.device import adb_wrapper
18 from pylib.device import device_errors 19 from pylib.device import device_errors
19 from pylib.device import device_utils 20 from pylib.device import device_utils
20 21
21 22
22 class DeviceUtilsTest(unittest.TestCase): 23 class DeviceUtilsTest(unittest.TestCase):
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 d = device_utils.DeviceUtils(a) 64 d = device_utils.DeviceUtils(a)
64 self.assertEqual(serial, d.old_interface.GetDevice()) 65 self.assertEqual(serial, d.old_interface.GetDevice())
65 66
66 def testInitWithNone(self): 67 def testInitWithNone(self):
67 d = device_utils.DeviceUtils(None) 68 d = device_utils.DeviceUtils(None)
68 self.assertIsNone(d.old_interface.GetDevice()) 69 self.assertIsNone(d.old_interface.GetDevice())
69 70
70 @staticmethod 71 @staticmethod
71 def _getTestAdbWrapper(): 72 def _getTestAdbWrapper():
72 devices = adb_wrapper.AdbWrapper.GetDevices() 73 devices = adb_wrapper.AdbWrapper.GetDevices()
73 if devices: 74 start_time = time.time()
74 return random.choice(devices) 75 while time.time() - start_time < device_utils._DEFAULT_TIMEOUT:
75 return None 76 if devices:
77 return random.choice(devices)
78 time.sleep(1)
79 raise device_errors.DeviceUnreachableError(
80 'No devices available for testing...')
76 81
77 @staticmethod 82 @staticmethod
78 def _getUnusedSerial(): 83 def _getUnusedSerial():
79 used_devices = [str(d) for d in adb_wrapper.AdbWrapper.GetDevices()] 84 used_devices = [str(d) for d in adb_wrapper.AdbWrapper.GetDevices()]
80 while True: 85 while True:
81 serial = '' 86 serial = ''
82 for _ in xrange(0, 16): 87 for _ in xrange(0, 16):
83 serial += random.choice('0123456789abcdef') 88 serial += random.choice('0123456789abcdef')
84 if serial not in used_devices: 89 if serial not in used_devices:
85 return serial 90 return serial
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 self.assertTrue(d.HasRoot()) 141 self.assertTrue(d.HasRoot())
137 else: 142 else:
138 self.assertFalse(d.HasRoot()) 143 self.assertFalse(d.HasRoot())
139 with self.assertRaises(device_errors.CommandFailedError): 144 with self.assertRaises(device_errors.CommandFailedError):
140 d.EnableRoot() 145 d.EnableRoot()
141 else: 146 else:
142 self.assertTrue(d.HasRoot()) 147 self.assertTrue(d.HasRoot())
143 d.EnableRoot() 148 d.EnableRoot()
144 self.assertTrue(d.HasRoot()) 149 self.assertTrue(d.HasRoot())
145 150
151 def testGetExternalStorage(self):
152 a = self._getTestAdbWrapper()
153 d = device_utils.DeviceUtils(a)
154
155 actual_external_storage = a.Shell('echo $EXTERNAL_STORAGE').splitlines()[0]
156 if actual_external_storage and len(actual_external_storage) != 0:
157 self.assertEquals(actual_external_storage, d.GetExternalStoragePath())
158
159 def testWaitUntilFullyBooted(self):
160 a = self._getTestAdbWrapper()
161 d = device_utils.DeviceUtils(a)
162
163 a.Reboot()
164 while a.GetState() == 'device':
165 time.sleep(0.1)
166 d.WaitUntilFullyBooted(wifi=True)
167 self.assertEquals(
168 '1', a.Shell('getprop sys.boot_completed').splitlines()[0])
169 self.assertTrue(
170 a.Shell('pm path android').splitlines()[0].startswith('package:'))
171 self.assertTrue(a.Shell('ls $EXTERNAL_STORAGE'))
172 self.assertTrue(
173 'Wi-Fi is enabled' in a.Shell('dumpsys wifi').splitlines())
174
146 175
147 if __name__ == '__main__': 176 if __name__ == '__main__':
148 unittest.main(verbosity=2, buffer=True) 177 unittest.main(verbosity=2, buffer=True)
149 178
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/test_package_apk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698