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

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

Issue 18292002: Rename chromium-android port to android (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added a TODO to remove '--platform chromium' Created 7 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 | 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 18 matching lines...) Expand all
29 import optparse 29 import optparse
30 import StringIO 30 import StringIO
31 import time 31 import time
32 import unittest2 as unittest 32 import unittest2 as unittest
33 import sys 33 import sys
34 34
35 from webkitpy.common.system import executive_mock 35 from webkitpy.common.system import executive_mock
36 from webkitpy.common.system.executive_mock import MockExecutive2 36 from webkitpy.common.system.executive_mock import MockExecutive2
37 from webkitpy.common.system.systemhost_mock import MockSystemHost 37 from webkitpy.common.system.systemhost_mock import MockSystemHost
38 38
39 from webkitpy.layout_tests.port import chromium_android 39 from webkitpy.layout_tests.port import android
40 from webkitpy.layout_tests.port import chromium_port_testcase 40 from webkitpy.layout_tests.port import chromium_port_testcase
41 from webkitpy.layout_tests.port import driver 41 from webkitpy.layout_tests.port import driver
42 from webkitpy.layout_tests.port import driver_unittest 42 from webkitpy.layout_tests.port import driver_unittest
43 from webkitpy.tool.mocktool import MockOptions 43 from webkitpy.tool.mocktool import MockOptions
44 44
45 45
46 # Any "adb" commands will be interpret by this class instead of executing actual 46 # Any "adb" commands will be interpret by this class instead of executing actual
47 # commansd on the file system, which we don't want to do. 47 # commansd on the file system, which we don't want to do.
48 class MockAndroidDebugBridge: 48 class MockAndroidDebugBridge:
49 def __init__(self, device_count): 49 def __init__(self, device_count):
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 serials = ['123456789ABCDEF0', '123456789ABCDEF1', '123456789ABCDEF2', 83 serials = ['123456789ABCDEF0', '123456789ABCDEF1', '123456789ABCDEF2',
84 '123456789ABCDEF3', '123456789ABCDEF4', '123456789ABCDEF5'] 84 '123456789ABCDEF3', '123456789ABCDEF4', '123456789ABCDEF5']
85 output = 'List of devices attached\n' 85 output = 'List of devices attached\n'
86 for serial in serials[:self._device_count]: 86 for serial in serials[:self._device_count]:
87 output += '%s\tdevice\n' % serial 87 output += '%s\tdevice\n' % serial
88 return output 88 return output
89 89
90 90
91 class AndroidCommandsTest(unittest.TestCase): 91 class AndroidCommandsTest(unittest.TestCase):
92 def setUp(self): 92 def setUp(self):
93 chromium_android.AndroidCommands._adb_command_path = None 93 android.AndroidCommands._adb_command_path = None
94 chromium_android.AndroidCommands._adb_command_path_options = ['adb'] 94 android.AndroidCommands._adb_command_path_options = ['adb']
95 95
96 def make_executive(self, device_count): 96 def make_executive(self, device_count):
97 self._mock_executive = MockAndroidDebugBridge(device_count) 97 self._mock_executive = MockAndroidDebugBridge(device_count)
98 return MockExecutive2(run_command_fn=self._mock_executive.run_command) 98 return MockExecutive2(run_command_fn=self._mock_executive.run_command)
99 99
100 def make_android_commands(self, device_count, serial): 100 def make_android_commands(self, device_count, serial):
101 return chromium_android.AndroidCommands(self.make_executive(device_count ), serial) 101 return android.AndroidCommands(self.make_executive(device_count), serial )
102 102
103 # The "adb" binary with the latest version should be used. 103 # The "adb" binary with the latest version should be used.
104 def serial_test_adb_command_path(self): 104 def serial_test_adb_command_path(self):
105 executive = self.make_executive(0) 105 executive = self.make_executive(0)
106 106
107 chromium_android.AndroidCommands.set_adb_command_path_options(['path1', 'path2', 'path3']) 107 android.AndroidCommands.set_adb_command_path_options(['path1', 'path2', 'path3'])
108 self.assertEqual('path2', chromium_android.AndroidCommands.adb_command_p ath(executive)) 108 self.assertEqual('path2', android.AndroidCommands.adb_command_path(execu tive))
109 109
110 # The used adb command should include the device's serial number, and get_se rial() should reflect this. 110 # The used adb command should include the device's serial number, and get_se rial() should reflect this.
111 def test_adb_command_and_get_serial(self): 111 def test_adb_command_and_get_serial(self):
112 android_commands = self.make_android_commands(1, '123456789ABCDEF0') 112 android_commands = self.make_android_commands(1, '123456789ABCDEF0')
113 self.assertEquals(['adb', '-s', '123456789ABCDEF0'], android_commands.ad b_command()) 113 self.assertEquals(['adb', '-s', '123456789ABCDEF0'], android_commands.ad b_command())
114 self.assertEquals('123456789ABCDEF0', android_commands.get_serial()) 114 self.assertEquals('123456789ABCDEF0', android_commands.get_serial())
115 115
116 # Running an adb command should return the command's output. 116 # Running an adb command should return the command's output.
117 def test_run_command(self): 117 def test_run_command(self):
118 android_commands = self.make_android_commands(1, '123456789ABCDEF0') 118 android_commands = self.make_android_commands(1, '123456789ABCDEF0')
119 119
120 output = android_commands.run(['command']) 120 output = android_commands.run(['command'])
121 self.assertEquals('adb -s 123456789ABCDEF0 command', self._mock_executiv e.last_command()) 121 self.assertEquals('adb -s 123456789ABCDEF0 command', self._mock_executiv e.last_command())
122 self.assertEquals('mockoutput', output) 122 self.assertEquals('mockoutput', output)
123 123
124 # Test that the convenience methods create the expected commands. 124 # Test that the convenience methods create the expected commands.
125 def test_convenience_methods(self): 125 def test_convenience_methods(self):
126 android_commands = self.make_android_commands(1, '123456789ABCDEF0') 126 android_commands = self.make_android_commands(1, '123456789ABCDEF0')
127 127
128 android_commands.file_exists('/tombstones') 128 android_commands.file_exists('/tombstones')
129 self.assertEquals('adb -s 123456789ABCDEF0 shell ls /tombstones', self._ mock_executive.last_command()) 129 self.assertEquals('adb -s 123456789ABCDEF0 shell ls /tombstones', self._ mock_executive.last_command())
130 130
131 android_commands.push('foo', 'bar') 131 android_commands.push('foo', 'bar')
132 self.assertEquals('adb -s 123456789ABCDEF0 push foo bar', self._mock_exe cutive.last_command()) 132 self.assertEquals('adb -s 123456789ABCDEF0 push foo bar', self._mock_exe cutive.last_command())
133 133
134 android_commands.pull('bar', 'foo') 134 android_commands.pull('bar', 'foo')
135 self.assertEquals('adb -s 123456789ABCDEF0 pull bar foo', self._mock_exe cutive.last_command()) 135 self.assertEquals('adb -s 123456789ABCDEF0 pull bar foo', self._mock_exe cutive.last_command())
136 136
137 137
138 class ChromiumAndroidPortTest(chromium_port_testcase.ChromiumPortTestCase): 138 class AndroidPortTest(chromium_port_testcase.ChromiumPortTestCase):
139 port_name = 'chromium-android' 139 port_name = 'android'
140 port_maker = chromium_android.ChromiumAndroidPort 140 port_maker = android.AndroidPort
141 141
142 def make_port(self, **kwargs): 142 def make_port(self, **kwargs):
143 port = super(ChromiumAndroidPortTest, self).make_port(**kwargs) 143 port = super(AndroidPortTest, self).make_port(**kwargs)
144 port._mock_adb = MockAndroidDebugBridge(kwargs.get('device_count', 1)) 144 port._mock_adb = MockAndroidDebugBridge(kwargs.get('device_count', 1))
145 port._executive = MockExecutive2(run_command_fn=port._mock_adb.run_comma nd) 145 port._executive = MockExecutive2(run_command_fn=port._mock_adb.run_comma nd)
146 return port 146 return port
147 147
148 # Test that content_shell currently is the only supported driver. 148 # Test that content_shell currently is the only supported driver.
149 def test_non_content_shell_driver(self): 149 def test_non_content_shell_driver(self):
150 self.assertRaises(self.make_port, options=optparse.Values({'driver_name' : 'foobar'})) 150 self.assertRaises(self.make_port, options=optparse.Values({'driver_name' : 'foobar'}))
151 151
152 # Test that the number of child processes to create depends on the devices. 152 # Test that the number of child processes to create depends on the devices.
153 def test_default_child_processes(self): 153 def test_default_child_processes(self):
(...skipping 11 matching lines...) Expand all
165 def test_default_timeout_ms(self): 165 def test_default_timeout_ms(self):
166 self.assertEqual(self.make_port(options=optparse.Values({'configuration' : 'Release'})).default_timeout_ms(), 10000) 166 self.assertEqual(self.make_port(options=optparse.Values({'configuration' : 'Release'})).default_timeout_ms(), 10000)
167 self.assertEqual(self.make_port(options=optparse.Values({'configuration' : 'Debug'})).default_timeout_ms(), 10000) 167 self.assertEqual(self.make_port(options=optparse.Values({'configuration' : 'Debug'})).default_timeout_ms(), 10000)
168 168
169 169
170 class ChromiumAndroidDriverTest(unittest.TestCase): 170 class ChromiumAndroidDriverTest(unittest.TestCase):
171 def setUp(self): 171 def setUp(self):
172 self._mock_adb = MockAndroidDebugBridge(1) 172 self._mock_adb = MockAndroidDebugBridge(1)
173 self._mock_executive = MockExecutive2(run_command_fn=self._mock_adb.run_ command) 173 self._mock_executive = MockExecutive2(run_command_fn=self._mock_adb.run_ command)
174 174
175 android_commands = chromium_android.AndroidCommands(self._mock_executive , '123456789ABCDEF0') 175 android_commands = android.AndroidCommands(self._mock_executive, '123456 789ABCDEF0')
176 self._port = chromium_android.ChromiumAndroidPort(MockSystemHost(executi ve=self._mock_executive), 'chromium-android') 176 self._port = android.AndroidPort(MockSystemHost(executive=self._mock_exe cutive), 'android')
177 self._driver = chromium_android.ChromiumAndroidDriver(self._port, worker _number=0, 177 self._driver = android.ChromiumAndroidDriver(self._port, worker_number=0 ,
178 pixel_tests=True, driver_details=chromium_android.ContentShellDriver Details(), android_devices=self._port._devices) 178 pixel_tests=True, driver_details=android.ContentShellDriverDetails() , android_devices=self._port._devices)
179 179
180 # The cmd_line() method in the Android port is used for starting a shell, no t the test runner. 180 # The cmd_line() method in the Android port is used for starting a shell, no t the test runner.
181 def test_cmd_line(self): 181 def test_cmd_line(self):
182 self.assertEquals(['adb', '-s', '123456789ABCDEF0', 'shell'], self._driv er.cmd_line(False, [])) 182 self.assertEquals(['adb', '-s', '123456789ABCDEF0', 'shell'], self._driv er.cmd_line(False, []))
183 183
184 # Test that the Chromium Android port can interpret Android's shell output. 184 # Test that the Chromium Android port can interpret Android's shell output.
185 def test_read_prompt(self): 185 def test_read_prompt(self):
186 self._driver._server_process = driver_unittest.MockServerProcess(lines=[ 'root@android:/ # ']) 186 self._driver._server_process = driver_unittest.MockServerProcess(lines=[ 'root@android:/ # '])
187 self.assertIsNone(self._driver._read_prompt(time.time() + 1)) 187 self.assertIsNone(self._driver._read_prompt(time.time() + 1))
188 self._driver._server_process = driver_unittest.MockServerProcess(lines=[ '$ ']) 188 self._driver._server_process = driver_unittest.MockServerProcess(lines=[ '$ '])
189 self.assertIsNone(self._driver._read_prompt(time.time() + 1)) 189 self.assertIsNone(self._driver._read_prompt(time.time() + 1))
190 190
191 191
192 class ChromiumAndroidDriverTwoDriversTest(unittest.TestCase): 192 class ChromiumAndroidDriverTwoDriversTest(unittest.TestCase):
193 # Test two drivers getting the right serial numbers, and that we disregard p er-test arguments. 193 # Test two drivers getting the right serial numbers, and that we disregard p er-test arguments.
194 def test_two_drivers(self): 194 def test_two_drivers(self):
195 mock_adb = MockAndroidDebugBridge(2) 195 mock_adb = MockAndroidDebugBridge(2)
196 mock_executive = MockExecutive2(run_command_fn=mock_adb.run_command) 196 mock_executive = MockExecutive2(run_command_fn=mock_adb.run_command)
197 197
198 port = chromium_android.ChromiumAndroidPort(MockSystemHost(executive=moc k_executive), 'chromium-android') 198 port = android.AndroidPort(MockSystemHost(executive=mock_executive), 'an droid')
199 driver0 = chromium_android.ChromiumAndroidDriver(port, worker_number=0, pixel_tests=True, 199 driver0 = android.ChromiumAndroidDriver(port, worker_number=0, pixel_tes ts=True,
200 driver_details=chromium_android.ContentShellDriverDetails(), android _devices=port._devices) 200 driver_details=android.ContentShellDriverDetails(), android_devices= port._devices)
201 driver1 = chromium_android.ChromiumAndroidDriver(port, worker_number=1, pixel_tests=True, 201 driver1 = android.ChromiumAndroidDriver(port, worker_number=1, pixel_tes ts=True,
202 driver_details=chromium_android.ContentShellDriverDetails(), android _devices=port._devices) 202 driver_details=android.ContentShellDriverDetails(), android_devices= port._devices)
203 203
204 self.assertEqual(['adb', '-s', '123456789ABCDEF0', 'shell'], driver0.cmd _line(True, [])) 204 self.assertEqual(['adb', '-s', '123456789ABCDEF0', 'shell'], driver0.cmd _line(True, []))
205 self.assertEqual(['adb', '-s', '123456789ABCDEF1', 'shell'], driver1.cmd _line(True, ['anything'])) 205 self.assertEqual(['adb', '-s', '123456789ABCDEF1', 'shell'], driver1.cmd _line(True, ['anything']))
206 206
207 207
208 class ChromiumAndroidTwoPortsTest(unittest.TestCase): 208 class ChromiumAndroidTwoPortsTest(unittest.TestCase):
209 # Test that the driver's command line indeed goes through to the driver. 209 # Test that the driver's command line indeed goes through to the driver.
210 def test_options_with_two_ports(self): 210 def test_options_with_two_ports(self):
211 mock_adb = MockAndroidDebugBridge(2) 211 mock_adb = MockAndroidDebugBridge(2)
212 mock_executive = MockExecutive2(run_command_fn=mock_adb.run_command) 212 mock_executive = MockExecutive2(run_command_fn=mock_adb.run_command)
213 213
214 port0 = chromium_android.ChromiumAndroidPort(MockSystemHost(executive=mo ck_executive), 214 port0 = android.AndroidPort(MockSystemHost(executive=mock_executive),
215 'chromium-android', options=MockOptions(additional_drt_flag=['--foo= bar'])) 215 'android', options=MockOptions(additional_drt_flag=['--foo=bar']))
216 port1 = chromium_android.ChromiumAndroidPort(MockSystemHost(executive=mo ck_executive), 216 port1 = android.AndroidPort(MockSystemHost(executive=mock_executive),
217 'chromium-android', options=MockOptions(driver_name='content_shell') ) 217 'android', options=MockOptions(driver_name='content_shell'))
218 218
219 self.assertEqual(1, port0.driver_cmd_line().count('--foo=bar')) 219 self.assertEqual(1, port0.driver_cmd_line().count('--foo=bar'))
220 self.assertEqual(0, port1.driver_cmd_line().count('--create-stdin-fifo') ) 220 self.assertEqual(0, port1.driver_cmd_line().count('--create-stdin-fifo') )
OLDNEW
« no previous file with comments | « Tools/Scripts/webkitpy/layout_tests/port/android.py ('k') | Tools/Scripts/webkitpy/layout_tests/port/builders.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698