OLD | NEW |
---|---|
1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2015 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 """Utility library for running a startup profile on an Android device. | 5 """Utility library for running a startup profile on an Android device. |
6 | 6 |
7 Sets up a device for cygprofile, disables sandboxing permissions, and sets up | 7 Sets up a device for cygprofile, disables sandboxing permissions, and sets up |
8 support for web page replay, device forwarding, and fake certificate authority | 8 support for web page replay, device forwarding, and fake certificate authority |
9 to make runs repeatable. | 9 to make runs repeatable. |
10 """ | 10 """ |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 self._is_test_ca_installed = False | 128 self._is_test_ca_installed = False |
129 | 129 |
130 shutil.rmtree(os.path.dirname(self._wpr_ca_cert_path), ignore_errors=True) | 130 shutil.rmtree(os.path.dirname(self._wpr_ca_cert_path), ignore_errors=True) |
131 self._wpr_ca_cert_path = None | 131 self._wpr_ca_cert_path = None |
132 self._device_cert_util = None | 132 self._device_cert_util = None |
133 | 133 |
134 def _BringUpWpr(self): | 134 def _BringUpWpr(self): |
135 """Start the WPR server on the host and the forwarder on the device.""" | 135 """Start the WPR server on the host and the forwarder on the device.""" |
136 print 'Starting WPR on host...' | 136 print 'Starting WPR on host...' |
137 _DownloadFromCloudStorage(self._WPR_BUCKET, self._wpr_archive_hash) | 137 _DownloadFromCloudStorage(self._WPR_BUCKET, self._wpr_archive_hash) |
138 args = ['--user_closest_match'] | |
139 if self._is_test_ca_installed: | |
140 args.extend(['--should_generate_certs', | |
141 '--https_root_ca_cert_path=' + self._wpr_ca_cert_path]) | |
138 self._wpr_server = webpagereplay.ReplayServer(self._wpr_archive, | 142 self._wpr_server = webpagereplay.ReplayServer(self._wpr_archive, |
139 '127.0.0.1', 0, 0, None, | 143 '127.0.0.1', 0, 0, None, args) |
140 ['--should_generate_certs', | |
141 '--https_root_ca_cert_path=' + self._wpr_ca_cert_path, | |
142 '--use_closest_match']) | |
143 ports = self._wpr_server.StartServer()[:-1] | 144 ports = self._wpr_server.StartServer()[:-1] |
144 self._host_http_port = ports[0] | 145 self._host_http_port = ports[0] |
145 self._host_https_port = ports[1] | 146 self._host_https_port = ports[1] |
146 | 147 |
147 def _StopWpr(self): | 148 def _StopWpr(self): |
148 """ Stop the WPR and forwarder. """ | 149 """ Stop the WPR and forwarder. """ |
149 print 'Stopping WPR on host...' | 150 print 'Stopping WPR on host...' |
150 if self._wpr_server: | 151 if self._wpr_server: |
151 self._wpr_server.StopServer() | 152 self._wpr_server.StopServer() |
153 self._wpr_server = None | |
152 | 154 |
153 def _StartForwarder(self): | 155 def _StartForwarder(self): |
154 """Sets up forwarding of device ports to the host, and configures chrome | 156 """Sets up forwarding of device ports to the host, and configures chrome |
155 to use those ports. | 157 to use those ports. |
156 """ | 158 """ |
159 if not self._host_http_port or not self._host_https_port: | |
pasko
2015/04/15 09:59:02
I think it's easier to reason about error cases if
azarchs
2015/04/15 10:54:11
Done.
| |
160 logging.warning('No host WPR server to forward to.') | |
161 return | |
157 print 'Starting device forwarder...' | 162 print 'Starting device forwarder...' |
158 forwarder.Forwarder.Map([(0, self._host_http_port), | 163 forwarder.Forwarder.Map([(0, self._host_http_port), |
159 (0, self._host_https_port)], | 164 (0, self._host_https_port)], |
160 self._device) | 165 self._device) |
161 device_http = forwarder.Forwarder.DevicePortForHostPort( | 166 device_http = forwarder.Forwarder.DevicePortForHostPort( |
162 self._host_http_port) | 167 self._host_http_port) |
163 device_https = forwarder.Forwarder.DevicePortForHostPort( | 168 device_https = forwarder.Forwarder.DevicePortForHostPort( |
164 self._host_https_port) | 169 self._host_https_port) |
165 self._flag_changer = flag_changer.FlagChanger( | 170 self._flag_changer = flag_changer.FlagChanger( |
166 self._device, self._cmdline_file) | 171 self._device, self._cmdline_file) |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 print 'Pulling cyglog data...' | 348 print 'Pulling cyglog data...' |
344 self._SetUpHostFolders() | 349 self._SetUpHostFolders() |
345 self._device.old_interface.Adb().Pull( | 350 self._device.old_interface.Adb().Pull( |
346 self._DEVICE_CYGLOG_DIR, self._host_cyglog_dir) | 351 self._DEVICE_CYGLOG_DIR, self._host_cyglog_dir) |
347 files = os.listdir(self._host_cyglog_dir) | 352 files = os.listdir(self._host_cyglog_dir) |
348 | 353 |
349 if len(files) == 0: | 354 if len(files) == 0: |
350 raise NoCyglogDataError('No cyglog data was collected') | 355 raise NoCyglogDataError('No cyglog data was collected') |
351 | 356 |
352 return [os.path.join(self._host_cyglog_dir, x) for x in files] | 357 return [os.path.join(self._host_cyglog_dir, x) for x in files] |
OLD | NEW |