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 self._wpr_server = webpagereplay.ReplayServer(self._wpr_archive, | 138 args = ['--user_closest_match'] |
139 '127.0.0.1', 0, 0, None, | 139 if self._is_test_ca_installed: |
140 ['--should_generate_certs', | 140 args.extend(['--should_generate_certs', |
141 '--https_root_ca_cert_path=' + self._wpr_ca_cert_path, | 141 '--https_root_ca_cert_path=' + self._wpr_ca_cert_path]) |
142 '--use_closest_match']) | 142 wpr_server = webpagereplay.ReplayServer(self._wpr_archive, |
143 ports = self._wpr_server.StartServer()[:-1] | 143 '127.0.0.1', 0, 0, None, args) |
| 144 ports = wpr_server.StartServer()[:-1] |
| 145 self._wpr_server = wpr_server |
144 self._host_http_port = ports[0] | 146 self._host_http_port = ports[0] |
145 self._host_https_port = ports[1] | 147 self._host_https_port = ports[1] |
146 | 148 |
147 def _StopWpr(self): | 149 def _StopWpr(self): |
148 """ Stop the WPR and forwarder. """ | 150 """ Stop the WPR and forwarder. """ |
149 print 'Stopping WPR on host...' | 151 print 'Stopping WPR on host...' |
150 if self._wpr_server: | 152 if self._wpr_server: |
151 self._wpr_server.StopServer() | 153 self._wpr_server.StopServer() |
| 154 self._wpr_server = None |
152 | 155 |
153 def _StartForwarder(self): | 156 def _StartForwarder(self): |
154 """Sets up forwarding of device ports to the host, and configures chrome | 157 """Sets up forwarding of device ports to the host, and configures chrome |
155 to use those ports. | 158 to use those ports. |
156 """ | 159 """ |
| 160 if not self._wpr_server: |
| 161 logging.warning('No host WPR server to forward to.') |
| 162 return |
157 print 'Starting device forwarder...' | 163 print 'Starting device forwarder...' |
158 forwarder.Forwarder.Map([(0, self._host_http_port), | 164 forwarder.Forwarder.Map([(0, self._host_http_port), |
159 (0, self._host_https_port)], | 165 (0, self._host_https_port)], |
160 self._device) | 166 self._device) |
161 device_http = forwarder.Forwarder.DevicePortForHostPort( | 167 device_http = forwarder.Forwarder.DevicePortForHostPort( |
162 self._host_http_port) | 168 self._host_http_port) |
163 device_https = forwarder.Forwarder.DevicePortForHostPort( | 169 device_https = forwarder.Forwarder.DevicePortForHostPort( |
164 self._host_https_port) | 170 self._host_https_port) |
165 self._flag_changer = flag_changer.FlagChanger( | 171 self._flag_changer = flag_changer.FlagChanger( |
166 self._device, self._cmdline_file) | 172 self._device, self._cmdline_file) |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 print 'Pulling cyglog data...' | 349 print 'Pulling cyglog data...' |
344 self._SetUpHostFolders() | 350 self._SetUpHostFolders() |
345 self._device.old_interface.Adb().Pull( | 351 self._device.old_interface.Adb().Pull( |
346 self._DEVICE_CYGLOG_DIR, self._host_cyglog_dir) | 352 self._DEVICE_CYGLOG_DIR, self._host_cyglog_dir) |
347 files = os.listdir(self._host_cyglog_dir) | 353 files = os.listdir(self._host_cyglog_dir) |
348 | 354 |
349 if len(files) == 0: | 355 if len(files) == 0: |
350 raise NoCyglogDataError('No cyglog data was collected') | 356 raise NoCyglogDataError('No cyglog data was collected') |
351 | 357 |
352 return [os.path.join(self._host_cyglog_dir, x) for x in files] | 358 return [os.path.join(self._host_cyglog_dir, x) for x in files] |
OLD | NEW |