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 """Controller objects that control the context in which chrome runs. | 5 """Controller objects that control the context in which chrome runs. |
6 | 6 |
7 This is responsible for the setup necessary for launching chrome, and for | 7 This is responsible for the setup necessary for launching chrome, and for |
8 creating a DevToolsConnection. There are remote device and local | 8 creating a DevToolsConnection. There are remote device and local |
9 desktop-specific versions. | 9 desktop-specific versions. |
10 """ | 10 """ |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 | 75 |
76 class ChromeControllerError(Exception): | 76 class ChromeControllerError(Exception): |
77 """Chrome error with detailed log. | 77 """Chrome error with detailed log. |
78 | 78 |
79 Note: | 79 Note: |
80 Some of these errors might be known intermittent errors that can usually be | 80 Some of these errors might be known intermittent errors that can usually be |
81 retried by the caller after re-doing any specific setup again. | 81 retried by the caller after re-doing any specific setup again. |
82 """ | 82 """ |
83 _INTERMITTENT_WHITE_LIST = {websocket.WebSocketTimeoutException, | 83 _INTERMITTENT_WHITE_LIST = {websocket.WebSocketTimeoutException, |
84 devtools_monitor.DevToolsConnectionTargetCrashed} | 84 devtools_monitor.DevToolsConnectionTargetCrashed} |
85 _PASSTHROUGH_WHITE_LIST = (MemoryError, SyntaxError) | |
pasko
2016/06/01 12:47:17
wow, interesting, did you actually hit a memory er
gabadie
2016/06/01 12:54:43
It is not obvious in this CL but there is exceptio
pasko
2016/06/01 13:42:22
thanks, it is indeed not obvious
| |
85 | 86 |
86 def __init__(self, log): | 87 def __init__(self, log): |
87 """Constructor | 88 """Constructor |
88 | 89 |
89 Args: | 90 Args: |
90 log: String containing the log of the running Chrome instance that was | 91 log: String containing the log of the running Chrome instance that was |
91 running. It will be interleaved with any other running Android | 92 running. It will be interleaved with any other running Android |
92 package. | 93 package. |
93 """ | 94 """ |
94 self.error_type, self.error_value, self.error_traceback = sys.exc_info() | 95 self.error_type, self.error_value, self.error_traceback = sys.exc_info() |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 continue | 348 continue |
348 yield connection | 349 yield connection |
349 if self._slow_death: | 350 if self._slow_death: |
350 self._device.adb.Shell('am start com.google.android.launcher') | 351 self._device.adb.Shell('am start com.google.android.launcher') |
351 time.sleep(self.TIME_TO_IDLE_SECONDS) | 352 time.sleep(self.TIME_TO_IDLE_SECONDS) |
352 break | 353 break |
353 else: | 354 else: |
354 raise ChromeControllerInternalError( | 355 raise ChromeControllerInternalError( |
355 'Failed to connect to Chrome devtools after {} ' | 356 'Failed to connect to Chrome devtools after {} ' |
356 'attempts.'.format(self.DEVTOOLS_CONNECTION_ATTEMPTS)) | 357 'attempts.'.format(self.DEVTOOLS_CONNECTION_ATTEMPTS)) |
357 except: | 358 except ChromeControllerError._PASSTHROUGH_WHITE_LIST: |
359 raise | |
360 except Exception: | |
358 logcat = ''.join([l + '\n' for l in self._device.adb.Logcat(dump=True)]) | 361 logcat = ''.join([l + '\n' for l in self._device.adb.Logcat(dump=True)]) |
359 raise ChromeControllerError(log=logcat) | 362 raise ChromeControllerError(log=logcat) |
360 finally: | 363 finally: |
361 self._device.ForceStop(package_info.package) | 364 self._device.ForceStop(package_info.package) |
362 | 365 |
363 def ResetBrowserState(self): | 366 def ResetBrowserState(self): |
364 """Override for chrome state reseting.""" | 367 """Override for chrome state reseting.""" |
365 logging.info('Reset chrome\'s profile') | 368 logging.info('Reset chrome\'s profile') |
366 package_info = OPTIONS.ChromePackage() | 369 package_info = OPTIONS.ChromePackage() |
367 # We assume all the browser is in the Default user profile directory. | 370 # We assume all the browser is in the Default user profile directory. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 raise ChromeControllerInternalError( | 516 raise ChromeControllerInternalError( |
514 'Failed to connect to Chrome devtools after {} ' | 517 'Failed to connect to Chrome devtools after {} ' |
515 'attempts.'.format(self.DEVTOOLS_CONNECTION_ATTEMPTS)) | 518 'attempts.'.format(self.DEVTOOLS_CONNECTION_ATTEMPTS)) |
516 # Start and yield the devtool connection. | 519 # Start and yield the devtool connection. |
517 self._StartConnection(connection) | 520 self._StartConnection(connection) |
518 yield connection | 521 yield connection |
519 if self._slow_death: | 522 if self._slow_death: |
520 connection.Close() | 523 connection.Close() |
521 chrome_process.wait() | 524 chrome_process.wait() |
522 chrome_process = None | 525 chrome_process = None |
523 except: | 526 except ChromeControllerError._PASSTHROUGH_WHITE_LIST: |
527 raise | |
528 except Exception: | |
524 raise ChromeControllerError(log=open(tmp_log.name).read()) | 529 raise ChromeControllerError(log=open(tmp_log.name).read()) |
525 finally: | 530 finally: |
526 if OPTIONS.local_noisy: | 531 if OPTIONS.local_noisy: |
527 sys.stderr.write(open(tmp_log.name).read()) | 532 sys.stderr.write(open(tmp_log.name).read()) |
528 del tmp_log | 533 del tmp_log |
529 if chrome_process: | 534 if chrome_process: |
530 try: | 535 try: |
531 chrome_process.kill() | 536 chrome_process.kill() |
532 except OSError: | 537 except OSError: |
533 pass # Chrome is already dead. | 538 pass # Chrome is already dead. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 if (not os.path.isdir(self._profile_dir) or | 586 if (not os.path.isdir(self._profile_dir) or |
582 os.listdir(self._profile_dir) == []): | 587 os.listdir(self._profile_dir) == []): |
583 # Launch chrome so that it populates the profile directory. | 588 # Launch chrome so that it populates the profile directory. |
584 with self.Open(): | 589 with self.Open(): |
585 pass | 590 pass |
586 assert os.path.isdir(self._profile_dir) | 591 assert os.path.isdir(self._profile_dir) |
587 assert os.path.isdir(os.path.dirname(self._GetCacheDirectoryPath())) | 592 assert os.path.isdir(os.path.dirname(self._GetCacheDirectoryPath())) |
588 | 593 |
589 def _GetCacheDirectoryPath(self): | 594 def _GetCacheDirectoryPath(self): |
590 return os.path.join(self._profile_dir, 'Default', 'Cache') | 595 return os.path.join(self._profile_dir, 'Default', 'Cache') |
OLD | NEW |