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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 | 98 |
99 | 99 |
100 def _SetUpDevice(device, package_info): | 100 def _SetUpDevice(device, package_info): |
101 """Enables root and closes Chrome on a device.""" | 101 """Enables root and closes Chrome on a device.""" |
102 device.EnableRoot() | 102 device.EnableRoot() |
103 device.KillAll(package_info.package, quiet=True) | 103 device.KillAll(package_info.package, quiet=True) |
104 | 104 |
105 | 105 |
106 @contextlib.contextmanager | 106 @contextlib.contextmanager |
107 def WprHost(device, wpr_archive_path, record=False, | 107 def WprHost(device, wpr_archive_path, record=False, |
108 network_condition_name=None, | |
108 disable_script_injection=False): | 109 disable_script_injection=False): |
109 """Launches web page replay host. | 110 """Launches web page replay host. |
110 | 111 |
111 Args: | 112 Args: |
112 device: Android device. | 113 device: Android device. |
113 wpr_archive_path: host sided WPR archive's path. | 114 wpr_archive_path: host sided WPR archive's path. |
115 network_condition_name: Network condition name available in | |
Benoit L
2016/02/22 14:11:25
tiny nit: the ordering of arguments should match t
| |
116 chrome_setup.NETWORK_CONDITIONS. | |
114 record: Enables or disables WPR archive recording. | 117 record: Enables or disables WPR archive recording. |
115 | 118 |
116 Returns: | 119 Returns: |
117 Additional flags list that may be used for chromium to load web page through | 120 Additional flags list that may be used for chromium to load web page through |
118 the running web page replay host. | 121 the running web page replay host. |
119 """ | 122 """ |
120 assert device | 123 assert device |
121 if wpr_archive_path == None: | 124 if wpr_archive_path == None: |
125 assert not record, 'WPR cannot record without a specified archive.' | |
126 assert not network_condition_name, ('WPR cannot emulate network condition' + | |
127 ' without a specified archive.') | |
122 yield [] | 128 yield [] |
123 return | 129 return |
124 | 130 |
125 wpr_server_args = ['--use_closest_match'] | 131 wpr_server_args = ['--use_closest_match'] |
126 if record: | 132 if record: |
127 wpr_server_args.append('--record') | 133 wpr_server_args.append('--record') |
128 if os.path.exists(wpr_archive_path): | 134 if os.path.exists(wpr_archive_path): |
129 os.remove(wpr_archive_path) | 135 os.remove(wpr_archive_path) |
130 else: | 136 else: |
131 assert os.path.exists(wpr_archive_path) | 137 assert os.path.exists(wpr_archive_path) |
138 if network_condition_name: | |
139 condition = chrome_setup.NETWORK_CONDITIONS[network_condition_name] | |
140 if record: | |
141 logging.warning('WPR network condition is ignored when recording.') | |
142 else: | |
143 wpr_server_args.extend([ | |
144 '--down', chrome_setup.BandwidthToString(condition['download']), | |
145 '--up', chrome_setup.BandwidthToString(condition['upload']), | |
146 '--delay_ms', str(condition['latency']), | |
147 '--shaping_type', 'proxy']) | |
132 | 148 |
133 if disable_script_injection: | 149 if disable_script_injection: |
134 # Remove default WPR injected scripts like deterministic.js which | 150 # Remove default WPR injected scripts like deterministic.js which |
135 # overrides Math.random. | 151 # overrides Math.random. |
136 wpr_server_args.extend(['--inject_scripts', '']) | 152 wpr_server_args.extend(['--inject_scripts', '']) |
137 | 153 |
138 # Deploy certification authority to the device. | 154 # Deploy certification authority to the device. |
139 temp_certificate_dir = tempfile.mkdtemp() | 155 temp_certificate_dir = tempfile.mkdtemp() |
140 wpr_ca_cert_path = os.path.join(temp_certificate_dir, 'testca.pem') | 156 wpr_ca_cert_path = os.path.join(temp_certificate_dir, 'testca.pem') |
141 certutils.write_dummy_ca_cert(*certutils.generate_dummy_ca_cert(), | 157 certutils.write_dummy_ca_cert(*certutils.generate_dummy_ca_cert(), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 '--remote-debugging-port=%d' % OPTIONS.devtools_port] | 233 '--remote-debugging-port=%d' % OPTIONS.devtools_port] |
218 if OPTIONS.no_sandbox: | 234 if OPTIONS.no_sandbox: |
219 new_flags.append('--no-sandbox') | 235 new_flags.append('--no-sandbox') |
220 if additional_flags != None: | 236 if additional_flags != None: |
221 new_flags.extend(additional_flags) | 237 new_flags.extend(additional_flags) |
222 | 238 |
223 if device: | 239 if device: |
224 return _DevToolsConnectionOnDevice(device, new_flags) | 240 return _DevToolsConnectionOnDevice(device, new_flags) |
225 else: | 241 else: |
226 return chrome_setup.DevToolsConnectionForLocalBinary(new_flags) | 242 return chrome_setup.DevToolsConnectionForLocalBinary(new_flags) |
OLD | NEW |