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 """ |
11 | 11 |
12 import contextlib | 12 import contextlib |
13 import copy | 13 import copy |
14 import datetime | 14 import datetime |
15 import errno | 15 import errno |
16 import logging | 16 import logging |
17 import os | 17 import os |
18 import platform | 18 import platform |
19 import shutil | 19 import shutil |
20 import socket | 20 import socket |
21 import subprocess | 21 import subprocess |
22 import sys | 22 import sys |
23 import tempfile | 23 import tempfile |
24 import time | 24 import time |
25 import traceback | 25 import traceback |
26 | 26 |
27 import psutil | 27 import psutil |
28 | 28 |
29 import chrome_cache | 29 import chrome_cache |
| 30 import chrome_setup |
30 import common_util | 31 import common_util |
31 import device_setup | 32 import device_setup |
32 import devtools_monitor | 33 import devtools_monitor |
33 import emulation | 34 import emulation |
34 from options import OPTIONS | 35 from options import OPTIONS |
35 | 36 |
36 _SRC_DIR = os.path.abspath(os.path.join( | 37 _SRC_DIR = os.path.abspath(os.path.join( |
37 os.path.dirname(__file__), '..', '..', '..')) | 38 os.path.dirname(__file__), '..', '..', '..')) |
38 _CATAPULT_DIR = os.path.join(_SRC_DIR, 'third_party', 'catapult') | 39 _CATAPULT_DIR = os.path.join(_SRC_DIR, 'third_party', 'catapult') |
39 | 40 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 class ChromeControllerBase(object): | 140 class ChromeControllerBase(object): |
140 """Base class for all controllers. | 141 """Base class for all controllers. |
141 | 142 |
142 Defines common operations but should not be created directly. | 143 Defines common operations but should not be created directly. |
143 """ | 144 """ |
144 METADATA_GATHERER = ChromeControllerMetadataGatherer() | 145 METADATA_GATHERER = ChromeControllerMetadataGatherer() |
145 DEVTOOLS_CONNECTION_ATTEMPTS = 10 | 146 DEVTOOLS_CONNECTION_ATTEMPTS = 10 |
146 DEVTOOLS_CONNECTION_ATTEMPT_INTERVAL_SECONDS = 1 | 147 DEVTOOLS_CONNECTION_ATTEMPT_INTERVAL_SECONDS = 1 |
147 | 148 |
148 def __init__(self): | 149 def __init__(self): |
149 self._chrome_args = [ | 150 self._chrome_args = chrome_setup.CHROME_ARGS + [ |
150 # Disable backgound network requests that may pollute WPR archive, | |
151 # pollute HTTP cache generation, and introduce noise in loading | |
152 # performance. | |
153 '--disable-background-networking', | |
154 '--disable-default-apps', | |
155 '--no-proxy-server', | |
156 # TODO(gabadie): Remove once crbug.com/354743 done. | |
157 '--safebrowsing-disable-auto-update', | |
158 | |
159 # Disables actions that chrome performs only on first run or each | |
160 # launches, which can interfere with page load performance, or even | |
161 # block its execution by waiting for user input. | |
162 '--disable-fre', | |
163 '--no-default-browser-check', | |
164 '--no-first-run', | |
165 | |
166 # Tests & dev-tools related stuff. | 151 # Tests & dev-tools related stuff. |
167 '--enable-test-events', | 152 '--enable-test-events', |
168 '--remote-debugging-port=%d' % OPTIONS.devtools_port, | 153 '--remote-debugging-port=%d' % OPTIONS.devtools_port, |
169 | 154 |
170 # Detailed log. | 155 # Detailed log. |
171 '--enable-logging=stderr', | 156 '--enable-logging=stderr', |
172 '--v=1', | 157 '--v=1', |
173 ] | 158 ] |
174 self._wpr_attributes = None | 159 self._wpr_attributes = None |
175 self._metadata = {} | 160 self._metadata = {} |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 except Exception: | 384 except Exception: |
400 logcat = ''.join([l + '\n' for l in self._device.adb.Logcat(dump=True)]) | 385 logcat = ''.join([l + '\n' for l in self._device.adb.Logcat(dump=True)]) |
401 raise ChromeControllerError(log=logcat) | 386 raise ChromeControllerError(log=logcat) |
402 finally: | 387 finally: |
403 self._device.ForceStop(package_info.package) | 388 self._device.ForceStop(package_info.package) |
404 self._DismissCrashDialogIfNeeded() | 389 self._DismissCrashDialogIfNeeded() |
405 | 390 |
406 def ResetBrowserState(self): | 391 def ResetBrowserState(self): |
407 """Override resetting Chrome local state.""" | 392 """Override resetting Chrome local state.""" |
408 logging.info('Resetting Chrome local state') | 393 logging.info('Resetting Chrome local state') |
409 package = OPTIONS.ChromePackage().package | 394 chrome_setup.ResetChromeLocalState(self._device, |
410 # Remove the Chrome Profile and the various disk caches. Other parts | 395 OPTIONS.ChromePackage().package) |
411 # theoretically should not affect loading performance. Also remove the tab | 396 |
412 # state to prevent it from growing infinitely. [:D] | |
413 for directory in ['app_chrome/Default', 'cache', 'app_chrome/ShaderCache', | |
414 'app_tabs']: | |
415 cmd = ['rm', '-rf', '/data/data/{}/{}'.format(package, directory)] | |
416 self._device.adb.Shell(subprocess.list2cmdline(cmd)) | |
417 | 397 |
418 def RebootDevice(self): | 398 def RebootDevice(self): |
419 """Reboot the remote device.""" | 399 """Reboot the remote device.""" |
420 assert self._wpr_attributes is None, 'WPR should be closed before rebooting' | 400 assert self._wpr_attributes is None, 'WPR should be closed before rebooting' |
421 logging.warning('Rebooting the device') | 401 logging.warning('Rebooting the device') |
422 device_setup.Reboot(self._device) | 402 device_setup.Reboot(self._device) |
423 self._InitDevice() | 403 self._InitDevice() |
424 | 404 |
425 def PushBrowserCache(self, cache_path): | 405 def PushBrowserCache(self, cache_path): |
426 """Override for chrome cache pushing.""" | 406 """Override for chrome cache pushing.""" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 if (not os.path.isdir(self._profile_dir) or | 624 if (not os.path.isdir(self._profile_dir) or |
645 os.listdir(self._profile_dir) == []): | 625 os.listdir(self._profile_dir) == []): |
646 # Launch chrome so that it populates the profile directory. | 626 # Launch chrome so that it populates the profile directory. |
647 with self.Open(): | 627 with self.Open(): |
648 pass | 628 pass |
649 assert os.path.isdir(self._profile_dir) | 629 assert os.path.isdir(self._profile_dir) |
650 assert os.path.isdir(os.path.dirname(self._GetCacheDirectoryPath())) | 630 assert os.path.isdir(os.path.dirname(self._GetCacheDirectoryPath())) |
651 | 631 |
652 def _GetCacheDirectoryPath(self): | 632 def _GetCacheDirectoryPath(self): |
653 return os.path.join(self._profile_dir, 'Default', 'Cache') | 633 return os.path.join(self._profile_dir, 'Default', 'Cache') |
OLD | NEW |