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 | |
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 if record: | |
126 logging.error('WPR cannot record without a specified archive.') | |
mattcary
2016/02/19 15:40:17
Do you want to assert rather than just logging an
gabadie
2016/02/22 10:05:00
Done.
| |
127 if network_condition_name: | |
128 logging.error('WPR cannot emulate network condition without a specified' + | |
129 'archive.') | |
122 yield [] | 130 yield [] |
123 return | 131 return |
124 | 132 |
125 wpr_server_args = ['--use_closest_match'] | 133 wpr_server_args = ['--use_closest_match'] |
126 if record: | 134 if record: |
127 wpr_server_args.append('--record') | 135 wpr_server_args.append('--record') |
128 if os.path.exists(wpr_archive_path): | 136 if os.path.exists(wpr_archive_path): |
129 os.remove(wpr_archive_path) | 137 os.remove(wpr_archive_path) |
130 else: | 138 else: |
131 assert os.path.exists(wpr_archive_path) | 139 assert os.path.exists(wpr_archive_path) |
140 if network_condition_name: | |
141 condition = chrome_setup.NETWORK_CONDITIONS[network_condition_name] | |
142 if record: | |
143 logging.warning('WPR network condition is ignored when recording.') | |
144 else: | |
145 wpr_server_args.extend([ | |
146 '--down', chrome_setup.BandwidthToString(condition['download']), | |
147 '--up', chrome_setup.BandwidthToString(condition['upload']), | |
148 '--delay_ms', str(condition['latency']), | |
149 '--shaping_type', 'proxy']) | |
132 | 150 |
133 if disable_script_injection: | 151 if disable_script_injection: |
134 # Remove default WPR injected scripts like deterministic.js which | 152 # Remove default WPR injected scripts like deterministic.js which |
135 # overrides Math.random. | 153 # overrides Math.random. |
136 wpr_server_args.extend(['--inject_scripts', '']) | 154 wpr_server_args.extend(['--inject_scripts', '']) |
137 | 155 |
138 # Deploy certification authority to the device. | 156 # Deploy certification authority to the device. |
139 temp_certificate_dir = tempfile.mkdtemp() | 157 temp_certificate_dir = tempfile.mkdtemp() |
140 wpr_ca_cert_path = os.path.join(temp_certificate_dir, 'testca.pem') | 158 wpr_ca_cert_path = os.path.join(temp_certificate_dir, 'testca.pem') |
141 certutils.write_dummy_ca_cert(*certutils.generate_dummy_ca_cert(), | 159 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] | 235 '--remote-debugging-port=%d' % OPTIONS.devtools_port] |
218 if OPTIONS.no_sandbox: | 236 if OPTIONS.no_sandbox: |
219 new_flags.append('--no-sandbox') | 237 new_flags.append('--no-sandbox') |
220 if additional_flags != None: | 238 if additional_flags != None: |
221 new_flags.extend(additional_flags) | 239 new_flags.extend(additional_flags) |
222 | 240 |
223 if device: | 241 if device: |
224 return _DevToolsConnectionOnDevice(device, new_flags) | 242 return _DevToolsConnectionOnDevice(device, new_flags) |
225 else: | 243 else: |
226 return chrome_setup.DevToolsConnectionForLocalBinary(new_flags) | 244 return chrome_setup.DevToolsConnectionForLocalBinary(new_flags) |
OLD | NEW |