OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 import contextlib | 5 import contextlib |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import shutil | 8 import shutil |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
(...skipping 11 matching lines...) Expand all Loading... |
22 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) | 22 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) |
23 from pylib import constants | 23 from pylib import constants |
24 from pylib import flag_changer | 24 from pylib import flag_changer |
25 | 25 |
26 sys.path.append(os.path.join(_SRC_DIR, 'tools', 'perf')) | 26 sys.path.append(os.path.join(_SRC_DIR, 'tools', 'perf')) |
27 from chrome_telemetry_build import chromium_config | 27 from chrome_telemetry_build import chromium_config |
28 | 28 |
29 sys.path.append(chromium_config.GetTelemetryDir()) | 29 sys.path.append(chromium_config.GetTelemetryDir()) |
30 from telemetry.internal.util import webpagereplay | 30 from telemetry.internal.util import webpagereplay |
31 | 31 |
| 32 sys.path.append(os.path.join(_SRC_DIR, 'third_party', 'webpagereplay')) |
| 33 import adb_install_cert |
| 34 import certutils |
| 35 |
32 import devtools_monitor | 36 import devtools_monitor |
33 | 37 |
34 DEVTOOLS_PORT = 9222 | 38 DEVTOOLS_PORT = 9222 |
35 DEVTOOLS_HOSTNAME = 'localhost' | 39 DEVTOOLS_HOSTNAME = 'localhost' |
36 DEFAULT_CHROME_PACKAGE = 'chrome' | 40 DEFAULT_CHROME_PACKAGE = 'chrome' |
37 | 41 |
38 | 42 |
39 @contextlib.contextmanager | 43 @contextlib.contextmanager |
40 def TemporaryDirectory(): | 44 def TemporaryDirectory(): |
41 """Returns a freshly-created directory that gets automatically deleted after | 45 """Returns a freshly-created directory that gets automatically deleted after |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 yield [] | 132 yield [] |
129 return | 133 return |
130 | 134 |
131 wpr_server_args = ['--use_closest_match'] | 135 wpr_server_args = ['--use_closest_match'] |
132 if record: | 136 if record: |
133 wpr_server_args.append('--record') | 137 wpr_server_args.append('--record') |
134 if os.path.exists(wpr_archive_path): | 138 if os.path.exists(wpr_archive_path): |
135 os.remove(wpr_archive_path) | 139 os.remove(wpr_archive_path) |
136 else: | 140 else: |
137 assert os.path.exists(wpr_archive_path) | 141 assert os.path.exists(wpr_archive_path) |
| 142 |
| 143 # Deploy certification authority to the device. |
| 144 temp_certificate_dir = tempfile.mkdtemp() |
| 145 wpr_ca_cert_path = os.path.join(temp_certificate_dir, 'testca.pem') |
| 146 certutils.write_dummy_ca_cert(*certutils.generate_dummy_ca_cert(), |
| 147 cert_path=wpr_ca_cert_path) |
| 148 |
| 149 device_cert_util = adb_install_cert.AndroidCertInstaller( |
| 150 device.adb.GetDeviceSerial(), None, wpr_ca_cert_path) |
| 151 device_cert_util.install_cert(overwrite_cert=True) |
| 152 wpr_server_args.extend(['--should_generate_certs', |
| 153 '--https_root_ca_cert_path=' + wpr_ca_cert_path]) |
| 154 |
| 155 # Set up WPR server and device forwarder. |
138 wpr_server = webpagereplay.ReplayServer(wpr_archive_path, | 156 wpr_server = webpagereplay.ReplayServer(wpr_archive_path, |
139 '127.0.0.1', 0, 0, None, wpr_server_args) | 157 '127.0.0.1', 0, 0, None, wpr_server_args) |
140 ports = wpr_server.StartServer()[:-1] | 158 ports = wpr_server.StartServer()[:-1] |
141 host_http_port = ports[0] | 159 host_http_port = ports[0] |
142 host_https_port = ports[1] | 160 host_https_port = ports[1] |
143 | 161 |
144 forwarder.Forwarder.Map([(0, host_http_port), (0, host_https_port)], device) | 162 forwarder.Forwarder.Map([(0, host_http_port), (0, host_https_port)], device) |
145 device_http_port = forwarder.Forwarder.DevicePortForHostPort(host_http_port) | 163 device_http_port = forwarder.Forwarder.DevicePortForHostPort(host_http_port) |
146 device_https_port = forwarder.Forwarder.DevicePortForHostPort(host_https_port) | 164 device_https_port = forwarder.Forwarder.DevicePortForHostPort(host_https_port) |
147 | 165 |
148 try: | 166 try: |
149 yield [ | 167 yield [ |
150 '--host-resolver-rules="MAP * 127.0.0.1,EXCLUDE localhost"', | 168 '--host-resolver-rules="MAP * 127.0.0.1,EXCLUDE localhost"', |
151 '--testing-fixed-http-port={}'.format(device_http_port), | 169 '--testing-fixed-http-port={}'.format(device_http_port), |
152 '--testing-fixed-https-port={}'.format(device_https_port)] | 170 '--testing-fixed-https-port={}'.format(device_https_port)] |
153 finally: | 171 finally: |
154 forwarder.Forwarder.UnmapDevicePort(device_http_port, device) | 172 forwarder.Forwarder.UnmapDevicePort(device_http_port, device) |
155 forwarder.Forwarder.UnmapDevicePort(device_https_port, device) | 173 forwarder.Forwarder.UnmapDevicePort(device_https_port, device) |
156 wpr_server.StopServer() | 174 wpr_server.StopServer() |
157 | 175 |
| 176 # Remove certification authority from the device. |
| 177 device_cert_util.remove_cert() |
| 178 shutil.rmtree(temp_certificate_dir) |
| 179 |
158 @contextlib.contextmanager | 180 @contextlib.contextmanager |
159 def DeviceConnection(device, | 181 def DeviceConnection(device, |
160 package=DEFAULT_CHROME_PACKAGE, | 182 package=DEFAULT_CHROME_PACKAGE, |
161 hostname=DEVTOOLS_HOSTNAME, | 183 hostname=DEVTOOLS_HOSTNAME, |
162 port=DEVTOOLS_PORT, | 184 port=DEVTOOLS_PORT, |
163 host_exe='out/Release/chrome', | 185 host_exe='out/Release/chrome', |
164 host_profile_dir=None, | 186 host_profile_dir=None, |
165 additional_flags=None): | 187 additional_flags=None): |
166 """Context for starting recording on a device. | 188 """Context for starting recording on a device. |
167 | 189 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 package: the key for chrome package info. | 253 package: the key for chrome package info. |
232 fn: the function to execute that launches chrome and performs the | 254 fn: the function to execute that launches chrome and performs the |
233 appropriate instrumentation. The function will receive a | 255 appropriate instrumentation. The function will receive a |
234 DevToolsConnection as its sole parameter. | 256 DevToolsConnection as its sole parameter. |
235 | 257 |
236 Returns: | 258 Returns: |
237 As fn() returns. | 259 As fn() returns. |
238 """ | 260 """ |
239 with DeviceConnection(device, package) as connection: | 261 with DeviceConnection(device, package) as connection: |
240 return fn(connection) | 262 return fn(connection) |
OLD | NEW |