OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 logging | |
6 import os | 5 import os |
7 | 6 |
8 from telemetry.internal.util import wpr_server | 7 from telemetry.internal.util import wpr_server |
9 from telemetry.internal.util import webpagereplay_go_server | 8 from telemetry.internal.util import webpagereplay_go_server |
10 from telemetry.internal.util import ts_proxy_server | 9 from telemetry.internal.util import ts_proxy_server |
11 from telemetry.util import wpr_modes | 10 from telemetry.util import wpr_modes |
12 | 11 |
13 | 12 |
14 class ArchiveDoesNotExistError(Exception): | 13 class ArchiveDoesNotExistError(Exception): |
15 """Raised when the archive path does not exist for replay mode.""" | 14 """Raised when the archive path does not exist for replay mode.""" |
(...skipping 13 matching lines...) Expand all Loading... |
29 """ | 28 """ |
30 | 29 |
31 def __init__(self, platform_backend): | 30 def __init__(self, platform_backend): |
32 self._platform_backend = platform_backend | 31 self._platform_backend = platform_backend |
33 self._wpr_mode = None | 32 self._wpr_mode = None |
34 self._extra_wpr_args = None | 33 self._extra_wpr_args = None |
35 self._use_wpr_go = False | 34 self._use_wpr_go = False |
36 self._archive_path = None | 35 self._archive_path = None |
37 self._make_javascript_deterministic = None | 36 self._make_javascript_deterministic = None |
38 self._forwarder = None | 37 self._forwarder = None |
39 self._is_test_ca_installed = None | |
40 self._wpr_server = None | 38 self._wpr_server = None |
41 self._ts_proxy_server = None | 39 self._ts_proxy_server = None |
42 self._port_pair = None | 40 self._port_pair = None |
43 self._use_live_traffic = None | 41 self._use_live_traffic = None |
44 | 42 |
45 def InitializeIfNeeded(self, use_live_traffic): | 43 def InitializeIfNeeded(self, use_live_traffic): |
46 """ | 44 """ |
47 This may, e.g., install test certificates and perform any needed setup | 45 This may, e.g., install test certificates and perform any needed setup |
48 on the target platform. | 46 on the target platform. |
49 | 47 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 Args: | 88 Args: |
91 wpr_mode: a mode for web page replay; available modes are | 89 wpr_mode: a mode for web page replay; available modes are |
92 wpr_modes.WPR_OFF, wpr_modes.APPEND, wpr_modes.WPR_REPLAY, or | 90 wpr_modes.WPR_OFF, wpr_modes.APPEND, wpr_modes.WPR_REPLAY, or |
93 wpr_modes.WPR_RECORD. | 91 wpr_modes.WPR_RECORD. |
94 extra_wpr_args: an list of extra arguments for web page replay. | 92 extra_wpr_args: an list of extra arguments for web page replay. |
95 """ | 93 """ |
96 assert not self.is_open, 'Network controller is already open' | 94 assert not self.is_open, 'Network controller is already open' |
97 self._wpr_mode = wpr_mode | 95 self._wpr_mode = wpr_mode |
98 self._extra_wpr_args = extra_wpr_args | 96 self._extra_wpr_args = extra_wpr_args |
99 self._use_wpr_go = use_wpr_go | 97 self._use_wpr_go = use_wpr_go |
100 self._InstallTestCa() | |
101 | 98 |
102 def Close(self): | 99 def Close(self): |
103 """Undo changes in the target platform used for network control. | 100 """Undo changes in the target platform used for network control. |
104 | 101 |
105 Implicitly stops replay if currently active. | 102 Implicitly stops replay if currently active. |
106 """ | 103 """ |
107 self.StopReplay() | 104 self.StopReplay() |
108 self._StopForwarder() | 105 self._StopForwarder() |
109 self._StopTsProxyServer() | 106 self._StopTsProxyServer() |
110 self._RemoveTestCa() | |
111 self._make_javascript_deterministic = None | 107 self._make_javascript_deterministic = None |
112 self._archive_path = None | 108 self._archive_path = None |
113 self._extra_wpr_args = None | 109 self._extra_wpr_args = None |
114 self._use_wpr_go = False | 110 self._use_wpr_go = False |
115 self._wpr_mode = None | 111 self._wpr_mode = None |
116 | 112 |
117 def _InstallTestCa(self): | |
118 if not self._platform_backend.supports_test_ca or not self._use_wpr_go: | |
119 return | |
120 try: | |
121 self._platform_backend.InstallTestCa() | |
122 logging.info('Test certificate authority installed on target platform.') | |
123 except Exception: # pylint: disable=broad-except | |
124 logging.exception( | |
125 'Failed to install test certificate authority on target platform. ' | |
126 'Browsers may fall back to ignoring certificate errors.') | |
127 self._RemoveTestCa() | |
128 | |
129 @property | |
130 def is_test_ca_installed(self): | |
131 return self._is_test_ca_installed | |
132 | |
133 def _RemoveTestCa(self): | |
134 if not self._is_test_ca_installed: | |
135 return | |
136 try: | |
137 self._platform_backend.RemoveTestCa() | |
138 except Exception: # pylint: disable=broad-except | |
139 # Best effort cleanup - show the error and continue. | |
140 logging.exception( | |
141 'Error trying to remove certificate authority from target platform.') | |
142 finally: | |
143 self._is_test_ca_installed = False | |
144 | |
145 def StartReplay(self, archive_path, make_javascript_deterministic=False): | 113 def StartReplay(self, archive_path, make_javascript_deterministic=False): |
146 """Start web page replay from a given replay archive. | 114 """Start web page replay from a given replay archive. |
147 | 115 |
148 Starts as needed, and reuses if possible, the replay server on the host and | 116 Starts as needed, and reuses if possible, the replay server on the host and |
149 a forwarder from the host to the target platform. | 117 a forwarder from the host to the target platform. |
150 | 118 |
151 Implementation details | 119 Implementation details |
152 ---------------------- | 120 ---------------------- |
153 | 121 |
154 The local host is where Telemetry is run. The remote is host where | 122 The local host is where Telemetry is run. The remote is host where |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 self._ts_proxy_server.StartServer() | 225 self._ts_proxy_server.StartServer() |
258 return self._ts_proxy_server.port | 226 return self._ts_proxy_server.port |
259 | 227 |
260 @property | 228 @property |
261 def forwarder(self): | 229 def forwarder(self): |
262 return self._forwarder | 230 return self._forwarder |
263 | 231 |
264 @property | 232 @property |
265 def ts_proxy_server(self): | 233 def ts_proxy_server(self): |
266 return self._ts_proxy_server | 234 return self._ts_proxy_server |
OLD | NEW |