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

Side by Side Diff: Tools/Scripts/webkitpy/layout_tests/port/android_unittest.py

Issue 546133003: Reformat webkitpy.layout_tests w/ format-webkitpy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (C) 2012 Google Inc. All rights reserved. 1 # Copyright (C) 2012 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 # Type of tombstone test which the mocked Android Debug Bridge should execute. 45 # Type of tombstone test which the mocked Android Debug Bridge should execute.
46 VALID_TOMBSTONE_TEST_TYPE = 0 46 VALID_TOMBSTONE_TEST_TYPE = 0
47 NO_FILES_TOMBSTONE_TEST_TYPE = 1 47 NO_FILES_TOMBSTONE_TEST_TYPE = 1
48 NO_PERMISSION_TOMBSTONE_TEST_TYPE = 2 48 NO_PERMISSION_TOMBSTONE_TEST_TYPE = 2
49 INVALID_ENTRY_TOMBSTONE_TEST_TYPE = 3 49 INVALID_ENTRY_TOMBSTONE_TEST_TYPE = 3
50 INVALID_ENTRIES_TOMBSTONE_TEST_TYPE = 4 50 INVALID_ENTRIES_TOMBSTONE_TEST_TYPE = 4
51 51
52 # Any "adb" commands will be interpret by this class instead of executing actual 52 # Any "adb" commands will be interpret by this class instead of executing actual
53 # commansd on the file system, which we don't want to do. 53 # commansd on the file system, which we don't want to do.
54
55
54 class MockAndroidDebugBridge: 56 class MockAndroidDebugBridge:
57
55 def __init__(self, device_count): 58 def __init__(self, device_count):
56 self._device_count = device_count 59 self._device_count = device_count
57 self._last_command = None 60 self._last_command = None
58 self._tombstone_output = None 61 self._tombstone_output = None
59 62
60 # Local public methods. 63 # Local public methods.
61 64
62 def run_command(self, args): 65 def run_command(self, args):
63 self._last_command = ' '.join(args) 66 self._last_command = ' '.join(args)
64 if args[0].startswith('path'): 67 if args[0].startswith('path'):
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 def _get_device_output(self): 108 def _get_device_output(self):
106 serials = ['123456789ABCDEF0', '123456789ABCDEF1', '123456789ABCDEF2', 109 serials = ['123456789ABCDEF0', '123456789ABCDEF1', '123456789ABCDEF2',
107 '123456789ABCDEF3', '123456789ABCDEF4', '123456789ABCDEF5'] 110 '123456789ABCDEF3', '123456789ABCDEF4', '123456789ABCDEF5']
108 output = 'List of devices attached\n' 111 output = 'List of devices attached\n'
109 for serial in serials[:self._device_count]: 112 for serial in serials[:self._device_count]:
110 output += '%s\tdevice\n' % serial 113 output += '%s\tdevice\n' % serial
111 return output 114 return output
112 115
113 116
114 class AndroidCommandsTest(unittest.TestCase): 117 class AndroidCommandsTest(unittest.TestCase):
118
115 def setUp(self): 119 def setUp(self):
116 android.AndroidCommands._adb_command_path = None 120 android.AndroidCommands._adb_command_path = None
117 android.AndroidCommands._adb_command_path_options = ['adb'] 121 android.AndroidCommands._adb_command_path_options = ['adb']
118 122
119 def make_executive(self, device_count): 123 def make_executive(self, device_count):
120 self._mock_executive = MockAndroidDebugBridge(device_count) 124 self._mock_executive = MockAndroidDebugBridge(device_count)
121 return MockExecutive2(run_command_fn=self._mock_executive.run_command) 125 return MockExecutive2(run_command_fn=self._mock_executive.run_command)
122 126
123 def make_android_commands(self, device_count, serial): 127 def make_android_commands(self, device_count, serial):
124 return android.AndroidCommands(self.make_executive(device_count), serial , debug_logging=False) 128 return android.AndroidCommands(self.make_executive(device_count), serial , debug_logging=False)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 def test_requires_http_server(self): 195 def test_requires_http_server(self):
192 self.assertTrue(self.make_port(device_count=1).requires_http_server()) 196 self.assertTrue(self.make_port(device_count=1).requires_http_server())
193 197
194 # Tests the default timeouts for Android, which are different than the rest of Chromium. 198 # Tests the default timeouts for Android, which are different than the rest of Chromium.
195 def test_default_timeout_ms(self): 199 def test_default_timeout_ms(self):
196 self.assertEqual(self.make_port(options=optparse.Values({'configuration' : 'Release'})).default_timeout_ms(), 10000) 200 self.assertEqual(self.make_port(options=optparse.Values({'configuration' : 'Release'})).default_timeout_ms(), 10000)
197 self.assertEqual(self.make_port(options=optparse.Values({'configuration' : 'Debug'})).default_timeout_ms(), 10000) 201 self.assertEqual(self.make_port(options=optparse.Values({'configuration' : 'Debug'})).default_timeout_ms(), 10000)
198 202
199 203
200 class ChromiumAndroidDriverTest(unittest.TestCase): 204 class ChromiumAndroidDriverTest(unittest.TestCase):
205
201 def setUp(self): 206 def setUp(self):
202 self._mock_adb = MockAndroidDebugBridge(1) 207 self._mock_adb = MockAndroidDebugBridge(1)
203 self._mock_executive = MockExecutive2(run_command_fn=self._mock_adb.run_ command) 208 self._mock_executive = MockExecutive2(run_command_fn=self._mock_adb.run_ command)
204 209
205 android_commands = android.AndroidCommands(self._mock_executive, '123456 789ABCDEF0', debug_logging=False) 210 android_commands = android.AndroidCommands(self._mock_executive, '123456 789ABCDEF0', debug_logging=False)
206 self._port = android.AndroidPort(MockSystemHost(executive=self._mock_exe cutive), 'android') 211 self._port = android.AndroidPort(MockSystemHost(executive=self._mock_exe cutive), 'android')
207 self._driver = android.ChromiumAndroidDriver(self._port, worker_number=0 , 212 self._driver = android.ChromiumAndroidDriver(self._port, worker_number=0 ,
208 pixel_tests=True, driver_details=android.ContentShellDriverDetails() , android_devices=self._port._devices) 213 pixel_tests=True, driver_de tails=android.ContentShellDriverDetails(), android_devices=self._port._devices)
209 214
210 # The cmd_line() method in the Android port is used for starting a shell, no t the test runner. 215 # The cmd_line() method in the Android port is used for starting a shell, no t the test runner.
211 def test_cmd_line(self): 216 def test_cmd_line(self):
212 self.assertEquals(['adb', '-s', '123456789ABCDEF0', 'shell'], self._driv er.cmd_line(False, [])) 217 self.assertEquals(['adb', '-s', '123456789ABCDEF0', 'shell'], self._driv er.cmd_line(False, []))
213 218
214 # Test that the Chromium Android port can interpret Android's shell output. 219 # Test that the Chromium Android port can interpret Android's shell output.
215 def test_read_prompt(self): 220 def test_read_prompt(self):
216 self._driver._server_process = driver_unittest.MockServerProcess(lines=[ 'root@android:/ # ']) 221 self._driver._server_process = driver_unittest.MockServerProcess(lines=[ 'root@android:/ # '])
217 self.assertIsNone(self._driver._read_prompt(time.time() + 1)) 222 self.assertIsNone(self._driver._read_prompt(time.time() + 1))
218 self._driver._server_process = driver_unittest.MockServerProcess(lines=[ '$ ']) 223 self._driver._server_process = driver_unittest.MockServerProcess(lines=[ '$ '])
219 self.assertIsNone(self._driver._read_prompt(time.time() + 1)) 224 self.assertIsNone(self._driver._read_prompt(time.time() + 1))
220 225
221 226
222 class ChromiumAndroidDriverTwoDriversTest(unittest.TestCase): 227 class ChromiumAndroidDriverTwoDriversTest(unittest.TestCase):
223 # Test two drivers getting the right serial numbers, and that we disregard p er-test arguments. 228 # Test two drivers getting the right serial numbers, and that we disregard p er-test arguments.
229
224 def test_two_drivers(self): 230 def test_two_drivers(self):
225 mock_adb = MockAndroidDebugBridge(2) 231 mock_adb = MockAndroidDebugBridge(2)
226 mock_executive = MockExecutive2(run_command_fn=mock_adb.run_command) 232 mock_executive = MockExecutive2(run_command_fn=mock_adb.run_command)
227 233
228 port = android.AndroidPort(MockSystemHost(executive=mock_executive), 'an droid') 234 port = android.AndroidPort(MockSystemHost(executive=mock_executive), 'an droid')
229 driver0 = android.ChromiumAndroidDriver(port, worker_number=0, pixel_tes ts=True, 235 driver0 = android.ChromiumAndroidDriver(port, worker_number=0, pixel_tes ts=True,
230 driver_details=android.ContentShellDriverDetails(), android_devices= port._devices) 236 driver_details=android.ContentSh ellDriverDetails(), android_devices=port._devices)
231 driver1 = android.ChromiumAndroidDriver(port, worker_number=1, pixel_tes ts=True, 237 driver1 = android.ChromiumAndroidDriver(port, worker_number=1, pixel_tes ts=True,
232 driver_details=android.ContentShellDriverDetails(), android_devices= port._devices) 238 driver_details=android.ContentSh ellDriverDetails(), android_devices=port._devices)
233 239
234 self.assertEqual(['adb', '-s', '123456789ABCDEF0', 'shell'], driver0.cmd _line(True, [])) 240 self.assertEqual(['adb', '-s', '123456789ABCDEF0', 'shell'], driver0.cmd _line(True, []))
235 self.assertEqual(['adb', '-s', '123456789ABCDEF1', 'shell'], driver1.cmd _line(True, ['anything'])) 241 self.assertEqual(['adb', '-s', '123456789ABCDEF1', 'shell'], driver1.cmd _line(True, ['anything']))
236 242
237 243
238 class ChromiumAndroidTwoPortsTest(unittest.TestCase): 244 class ChromiumAndroidTwoPortsTest(unittest.TestCase):
239 # Test that the driver's command line indeed goes through to the driver. 245 # Test that the driver's command line indeed goes through to the driver.
246
240 def test_options_with_two_ports(self): 247 def test_options_with_two_ports(self):
241 mock_adb = MockAndroidDebugBridge(2) 248 mock_adb = MockAndroidDebugBridge(2)
242 mock_executive = MockExecutive2(run_command_fn=mock_adb.run_command) 249 mock_executive = MockExecutive2(run_command_fn=mock_adb.run_command)
243 250
244 port0 = android.AndroidPort(MockSystemHost(executive=mock_executive), 251 port0 = android.AndroidPort(MockSystemHost(executive=mock_executive),
245 'android', options=MockOptions(additional_drt_flag=['--foo=bar'])) 252 'android', options=MockOptions(additional_dr t_flag=['--foo=bar']))
246 port1 = android.AndroidPort(MockSystemHost(executive=mock_executive), 253 port1 = android.AndroidPort(MockSystemHost(executive=mock_executive),
247 'android', options=MockOptions(driver_name='content_shell')) 254 'android', options=MockOptions(driver_name=' content_shell'))
248 255
249 self.assertEqual(1, port0.driver_cmd_line().count('--foo=bar')) 256 self.assertEqual(1, port0.driver_cmd_line().count('--foo=bar'))
250 self.assertEqual(0, port1.driver_cmd_line().count('--create-stdin-fifo') ) 257 self.assertEqual(0, port1.driver_cmd_line().count('--create-stdin-fifo') )
251 258
252 259
253 class ChromiumAndroidDriverTombstoneTest(unittest.TestCase): 260 class ChromiumAndroidDriverTombstoneTest(unittest.TestCase):
254 EXPECTED_STACKTRACE = '-rw------- 1000 1000 3604 2013-11-19 16:16 tombstone_ 10\ntombstone content' 261 EXPECTED_STACKTRACE = '-rw------- 1000 1000 3604 2013-11-19 16:16 tombstone_ 10\ntombstone content'
255 262
256 def setUp(self): 263 def setUp(self):
257 self._mock_adb = MockAndroidDebugBridge(1) 264 self._mock_adb = MockAndroidDebugBridge(1)
258 self._mock_executive = MockExecutive2(run_command_fn=self._mock_adb.run_ command) 265 self._mock_executive = MockExecutive2(run_command_fn=self._mock_adb.run_ command)
259 266
260 self._port = android.AndroidPort(MockSystemHost(executive=self._mock_exe cutive), 'android') 267 self._port = android.AndroidPort(MockSystemHost(executive=self._mock_exe cutive), 'android')
261 self._driver = android.ChromiumAndroidDriver(self._port, worker_number=0 , 268 self._driver = android.ChromiumAndroidDriver(self._port, worker_number=0 ,
262 pixel_tests=True, driver_details=android.ContentShellDriverDetails() , android_devices=self._port._devices) 269 pixel_tests=True, driver_de tails=android.ContentShellDriverDetails(), android_devices=self._port._devices)
263 270
264 self._errors = [] 271 self._errors = []
265 self._driver._log_error = lambda msg: self._errors.append(msg) 272 self._driver._log_error = lambda msg: self._errors.append(msg)
266 273
267 self._warnings = [] 274 self._warnings = []
268 self._driver._log_warning = lambda msg: self._warnings.append(msg) 275 self._driver._log_warning = lambda msg: self._warnings.append(msg)
269 276
270 # Tests that we return an empty string and log an error when no tombstones c ould be found. 277 # Tests that we return an empty string and log an error when no tombstones c ould be found.
271 def test_no_tombstones_found(self): 278 def test_no_tombstones_found(self):
272 self._mock_adb.set_tombstone_output('/data/tombstones/tombstone_*: No su ch file or directory') 279 self._mock_adb.set_tombstone_output('/data/tombstones/tombstone_*: No su ch file or directory')
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 # Tests that valid tombstone listings will return the contents of the most r ecent file. 318 # Tests that valid tombstone listings will return the contents of the most r ecent file.
312 def test_read_valid_tombstone_file(self): 319 def test_read_valid_tombstone_file(self):
313 self._mock_adb.set_tombstone_output('-rw------- 1000 1000 3604 2013-11-1 9 16:15 tombstone_00\n' + 320 self._mock_adb.set_tombstone_output('-rw------- 1000 1000 3604 2013-11-1 9 16:15 tombstone_00\n' +
314 '-rw------- 1000 1000 3604 2013-11-1 9 16:16 tombstone_10\n' + 321 '-rw------- 1000 1000 3604 2013-11-1 9 16:16 tombstone_10\n' +
315 '-rw------- 1000 1000 3604 2013-11-1 9 16:15 tombstone_02') 322 '-rw------- 1000 1000 3604 2013-11-1 9 16:15 tombstone_02')
316 stacktrace = self._driver._get_last_stacktrace() 323 stacktrace = self._driver._get_last_stacktrace()
317 324
318 self.assertEqual(0, len(self._warnings)) 325 self.assertEqual(0, len(self._warnings))
319 self.assertEqual(0, len(self._errors)) 326 self.assertEqual(0, len(self._errors))
320 self.assertEqual(ChromiumAndroidDriverTombstoneTest.EXPECTED_STACKTRACE, stacktrace) 327 self.assertEqual(ChromiumAndroidDriverTombstoneTest.EXPECTED_STACKTRACE, stacktrace)
OLDNEW
« no previous file with comments | « Tools/Scripts/webkitpy/layout_tests/port/android.py ('k') | Tools/Scripts/webkitpy/layout_tests/port/base.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698