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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 device.adb.ForwardRemove(local) | 108 device.adb.ForwardRemove(local) |
109 | 109 |
110 | 110 |
111 def _SetUpDevice(device, package_info): | 111 def _SetUpDevice(device, package_info): |
112 """Enables root and closes Chrome on a device.""" | 112 """Enables root and closes Chrome on a device.""" |
113 device.EnableRoot() | 113 device.EnableRoot() |
114 device.KillAll(package_info.package, quiet=True) | 114 device.KillAll(package_info.package, quiet=True) |
115 | 115 |
116 | 116 |
117 @contextlib.contextmanager | 117 @contextlib.contextmanager |
118 def WprHost(device, wpr_archive_path, record=False): | 118 def WprHost(device, wpr_archive_path, record=False, |
| 119 disable_script_injection=False): |
119 """Launches web page replay host. | 120 """Launches web page replay host. |
120 | 121 |
121 Args: | 122 Args: |
122 device: Android device. | 123 device: Android device. |
123 wpr_archive_path: host sided WPR archive's path. | 124 wpr_archive_path: host sided WPR archive's path. |
124 record: Enables or disables WPR archive recording. | 125 record: Enables or disables WPR archive recording. |
125 | 126 |
126 Returns: | 127 Returns: |
127 Additional flags list that may be used for chromium to load web page through | 128 Additional flags list that may be used for chromium to load web page through |
128 the running web page replay host. | 129 the running web page replay host. |
129 """ | 130 """ |
130 assert device | 131 assert device |
131 if wpr_archive_path == None: | 132 if wpr_archive_path == None: |
132 yield [] | 133 yield [] |
133 return | 134 return |
134 | 135 |
135 wpr_server_args = ['--use_closest_match'] | 136 wpr_server_args = ['--use_closest_match'] |
136 if record: | 137 if record: |
137 wpr_server_args.append('--record') | 138 wpr_server_args.append('--record') |
138 if os.path.exists(wpr_archive_path): | 139 if os.path.exists(wpr_archive_path): |
139 os.remove(wpr_archive_path) | 140 os.remove(wpr_archive_path) |
140 else: | 141 else: |
141 assert os.path.exists(wpr_archive_path) | 142 assert os.path.exists(wpr_archive_path) |
142 | 143 |
| 144 if disable_script_injection: |
| 145 # Remove default WPR injected scripts like deterministic.js which |
| 146 # overrides Math.random. |
| 147 wpr_server_args.extend(['--inject_scripts', '']) |
| 148 |
143 # Deploy certification authority to the device. | 149 # Deploy certification authority to the device. |
144 temp_certificate_dir = tempfile.mkdtemp() | 150 temp_certificate_dir = tempfile.mkdtemp() |
145 wpr_ca_cert_path = os.path.join(temp_certificate_dir, 'testca.pem') | 151 wpr_ca_cert_path = os.path.join(temp_certificate_dir, 'testca.pem') |
146 certutils.write_dummy_ca_cert(*certutils.generate_dummy_ca_cert(), | 152 certutils.write_dummy_ca_cert(*certutils.generate_dummy_ca_cert(), |
147 cert_path=wpr_ca_cert_path) | 153 cert_path=wpr_ca_cert_path) |
148 | 154 |
149 device_cert_util = adb_install_cert.AndroidCertInstaller( | 155 device_cert_util = adb_install_cert.AndroidCertInstaller( |
150 device.adb.GetDeviceSerial(), None, wpr_ca_cert_path) | 156 device.adb.GetDeviceSerial(), None, wpr_ca_cert_path) |
151 device_cert_util.install_cert(overwrite_cert=True) | 157 device_cert_util.install_cert(overwrite_cert=True) |
152 wpr_server_args.extend(['--should_generate_certs', | 158 wpr_server_args.extend(['--should_generate_certs', |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 package: the key for chrome package info. | 259 package: the key for chrome package info. |
254 fn: the function to execute that launches chrome and performs the | 260 fn: the function to execute that launches chrome and performs the |
255 appropriate instrumentation. The function will receive a | 261 appropriate instrumentation. The function will receive a |
256 DevToolsConnection as its sole parameter. | 262 DevToolsConnection as its sole parameter. |
257 | 263 |
258 Returns: | 264 Returns: |
259 As fn() returns. | 265 As fn() returns. |
260 """ | 266 """ |
261 with DeviceConnection(device, package) as connection: | 267 with DeviceConnection(device, package) as connection: |
262 return fn(connection) | 268 return fn(connection) |
OLD | NEW |