| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 | 5 import logging |
| 6 import pipes | 6 import pipes |
| 7 import sys | 7 import sys |
| 8 import time | 8 import time |
| 9 | 9 |
| 10 from telemetry.core import exceptions | 10 from telemetry.core import exceptions |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 supports_tab_control=backend_settings.supports_tab_control, | 146 supports_tab_control=backend_settings.supports_tab_control, |
| 147 supports_extensions=False, browser_options=browser_options, | 147 supports_extensions=False, browser_options=browser_options, |
| 148 output_profile_path=output_profile_path, | 148 output_profile_path=output_profile_path, |
| 149 extensions_to_load=extensions_to_load) | 149 extensions_to_load=extensions_to_load) |
| 150 if len(extensions_to_load) > 0: | 150 if len(extensions_to_load) > 0: |
| 151 raise browser_backend.ExtensionsNotSupportedException( | 151 raise browser_backend.ExtensionsNotSupportedException( |
| 152 'Android browser does not support extensions.') | 152 'Android browser does not support extensions.') |
| 153 | 153 |
| 154 # Initialize fields so that an explosion during init doesn't break in Close. | 154 # Initialize fields so that an explosion during init doesn't break in Close. |
| 155 self._backend_settings = backend_settings | 155 self._backend_settings = backend_settings |
| 156 self._saved_cmdline = '' | 156 self._saved_cmdline = None |
| 157 self._target_arch = target_arch | 157 self._target_arch = target_arch |
| 158 self._saved_sslflag = '' | 158 self._saved_sslflag = '' |
| 159 | 159 |
| 160 # TODO(tonyg): This is flaky because it doesn't reserve the port that it | 160 # TODO(tonyg): This is flaky because it doesn't reserve the port that it |
| 161 # allocates. Need to fix this. | 161 # allocates. Need to fix this. |
| 162 self._port = adb_commands.AllocateTestServerPort() | 162 self._port = adb_commands.AllocateTestServerPort() |
| 163 | 163 |
| 164 # TODO(wuhu): Move to network controller backend. | 164 # TODO(wuhu): Move to network controller backend. |
| 165 self._platform_backend.InstallTestCa() | 165 self._platform_backend.InstallTestCa() |
| 166 | 166 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if values[0] in '"\'' and values[-1] == values[0]: | 212 if values[0] in '"\'' and values[-1] == values[0]: |
| 213 return arg | 213 return arg |
| 214 return '%s=%s' % (key, pipes.quote(values)) | 214 return '%s=%s' % (key, pipes.quote(values)) |
| 215 args = [self._backend_settings.pseudo_exec_name] | 215 args = [self._backend_settings.pseudo_exec_name] |
| 216 args.extend(self.GetBrowserStartupArgs()) | 216 args.extend(self.GetBrowserStartupArgs()) |
| 217 content = ' '.join(QuoteIfNeeded(arg) for arg in args) | 217 content = ' '.join(QuoteIfNeeded(arg) for arg in args) |
| 218 cmdline_file = self._backend_settings.GetCommandLineFile( | 218 cmdline_file = self._backend_settings.GetCommandLineFile( |
| 219 self._adb.IsUserBuild()) | 219 self._adb.IsUserBuild()) |
| 220 | 220 |
| 221 try: | 221 try: |
| 222 # Save the current command line to restore later, except if it appears to | 222 # Save the current command line to restore later |
| 223 # be a Telemetry created one. This is to prevent a common bug where | 223 self._saved_cmdline = self._adb.device().ReadFile( |
| 224 # --host-resolver-rules borks people's browsers if something goes wrong | 224 cmdline_file, as_root=True) |
| 225 # with Telemetry. | 225 # ... except if it appears to be a Telemetry created one. This is to |
| 226 self._saved_cmdline = ''.join(self._adb.device().ReadFile(cmdline_file)) | 226 # prevent common bug where --host-resolver-rules borks people's browsers |
| 227 # if something goes wrong with Telemetry. |
| 227 if '--host-resolver-rules' in self._saved_cmdline: | 228 if '--host-resolver-rules' in self._saved_cmdline: |
| 228 self._saved_cmdline = '' | 229 self._saved_cmdline = None |
| 230 except device_errors.CommandFailedError: # file may not exist |
| 231 self._saved_cmdline = None |
| 232 |
| 233 try: |
| 229 self._adb.device().WriteFile(cmdline_file, content, as_root=True) | 234 self._adb.device().WriteFile(cmdline_file, content, as_root=True) |
| 230 except device_errors.CommandFailedError: | 235 except device_errors.CommandFailedError as exc: |
| 231 logging.critical('Cannot set Chrome command line. ' | 236 logging.critical('Cannot set Chrome command line: %s', str(exc)) |
| 232 'Fix this by flashing to a userdebug build.') | 237 logging.critical('May be fixed by flashing to a userdebug build.') |
| 233 sys.exit(1) | 238 sys.exit(1) |
| 234 | 239 |
| 235 def _RestoreCommandLine(self): | 240 def _RestoreCommandLine(self): |
| 236 cmdline_file = self._backend_settings.GetCommandLineFile( | 241 cmdline_file = self._backend_settings.GetCommandLineFile( |
| 237 self._adb.IsUserBuild()) | 242 self._adb.IsUserBuild()) |
| 238 self._adb.device().WriteFile(cmdline_file, self._saved_cmdline, | 243 if self._saved_cmdline is not None: |
| 239 as_root=True) | 244 self._adb.device().WriteFile(cmdline_file, self._saved_cmdline, |
| 245 as_root=True) |
| 246 else: |
| 247 self._adb.device().RunShellCommand(['rm', cmdline_file], |
| 248 as_root=True) |
| 240 | 249 |
| 241 def Start(self): | 250 def Start(self): |
| 242 self._SetUpCommandLine() | 251 self._SetUpCommandLine() |
| 243 | 252 |
| 244 self._adb.device().RunShellCommand('logcat -c') | 253 self._adb.device().RunShellCommand('logcat -c') |
| 245 if self.browser_options.startup_url: | 254 if self.browser_options.startup_url: |
| 246 url = self.browser_options.startup_url | 255 url = self.browser_options.startup_url |
| 247 elif self.browser_options.profile_dir: | 256 elif self.browser_options.profile_dir: |
| 248 url = None | 257 url = None |
| 249 else: | 258 else: |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 350 |
| 342 def GetStandardOutput(self): | 351 def GetStandardOutput(self): |
| 343 return self._platform_backend.GetStandardOutput() | 352 return self._platform_backend.GetStandardOutput() |
| 344 | 353 |
| 345 def GetStackTrace(self): | 354 def GetStackTrace(self): |
| 346 return self._platform_backend.GetStackTrace(self._target_arch) | 355 return self._platform_backend.GetStackTrace(self._target_arch) |
| 347 | 356 |
| 348 @property | 357 @property |
| 349 def should_ignore_certificate_errors(self): | 358 def should_ignore_certificate_errors(self): |
| 350 return not self._platform_backend.is_test_ca_installed | 359 return not self._platform_backend.is_test_ca_installed |
| OLD | NEW |