Index: tools/perf/profile_creators/extensions_profile_creator.py |
diff --git a/tools/perf/profile_creators/extensions_profile_creator.py b/tools/perf/profile_creators/extensions_profile_creator.py |
index f0b8e4719ce961debf4fd493768c2e22a7ccab97..8d51f453e0628b6d3e831fc13bd13f6cd6a802ef 100644 |
--- a/tools/perf/profile_creators/extensions_profile_creator.py |
+++ b/tools/perf/profile_creators/extensions_profile_creator.py |
@@ -54,7 +54,7 @@ class _ExtensionPageTest(page_test.PageTest): |
# Sleep for a bit to allow safe browsing and other data to load + |
# extensions to install. |
if not self._extensions_installed: |
- sleep_seconds = 5 * 60 |
+ sleep_seconds = 15 |
logging.info("Sleeping for %d seconds." % sleep_seconds) |
time.sleep(sleep_seconds) |
self._extensions_installed = True |
@@ -78,14 +78,16 @@ class _ExtensionPageTest(page_test.PageTest): |
installed_extensions) |
-def _ExternalExtensionsPath(): |
+def _ExternalExtensionsPath(profile_path): |
"""Returns the OS-dependent path at which to install the extension deployment |
- files""" |
+ files. |
+ |
+ |profile_path| is the path of the profile that will be used to launch the |
+ browser. |
+ """ |
if platform.system() == 'Darwin': |
- return os.path.join('/Library', 'Application Support', 'Google', 'Chrome', |
- 'External Extensions') |
- elif platform.system() == 'Linux': |
- return os.path.join('/opt', 'google', 'chrome', 'extensions' ) |
+ return str(profile_path) + '/External Extensions' |
+ |
else: |
raise NotImplementedError('Extension install on %s is not yet supported' % |
platform.system()) |
@@ -101,9 +103,15 @@ def _DownloadExtension(extension_id, output_dir): |
Returns: |
Extension file downloaded.""" |
extension_download_path = os.path.join(output_dir, "%s.crx" % extension_id) |
+ |
+ # Ideally, the Chrome version would be dynamically extracted from the binary. |
+ # Instead, we use a Chrome version whose release date is expected to be |
+ # about a hundred years in the future. |
+ chrome_version = '1000.0.0.0' |
extension_url = ( |
"https://clients2.google.com/service/update2/crx?response=redirect" |
- "&x=id%%3D%s%%26lang%%3Den-US%%26uc" % extension_id) |
+ "&prodversion=%s&x=id%%3D%s%%26lang%%3Den-US%%26uc" |
+ % (chrome_version, extension_id)) |
response = urllib2.urlopen(extension_url) |
assert(response.getcode() == 200) |
@@ -145,14 +153,14 @@ class ExtensionsProfileCreator(profile_creator.ProfileCreator): |
Subclasses are meant to be run interactively. |
""" |
def __init__(self, extensions_to_install=None, theme_to_install=None): |
- self._CheckTestEnvironment() |
super(ExtensionsProfileCreator, self).__init__() |
# List of extensions to install. |
- self._extensions_to_install = list(extensions_to_install or []) |
- |
- # Theme to install (if any). |
- self._theme_to_install = theme_to_install |
+ self._extensions_to_install = [] |
+ if extensions_to_install: |
+ self._extensions_to_install.extend(extensions_to_install) |
+ if theme_to_install: |
+ self._extensions_to_install.append(theme_to_install) |
# Directory to download extension files into. |
self._extension_download_dir = None |
@@ -160,23 +168,14 @@ class ExtensionsProfileCreator(profile_creator.ProfileCreator): |
# List of files to delete after run. |
self._files_to_cleanup = [] |
- def _CheckTestEnvironment(self): |
- # Running this script on a corporate network or other managed environment |
- # could potentially alter the profile contents. |
- hostname = socket.gethostname() |
- if hostname.endswith('corp.google.com'): |
- raise Exception("It appears you are connected to a corporate network " |
- "(hostname=%s). This script needs to be run off the corp " |
- "network." % hostname) |
- |
- prompt = ("\n!!!This script must be run on a fresh OS installation, " |
- "disconnected from any corporate network. Are you sure you want to " |
- "continue? (y/N) ") |
- if (raw_input(prompt).lower() != 'y'): |
- sys.exit(-1) |
- |
def Run(self, options): |
- self._PrepareExtensionInstallFiles() |
+ # Installing extensions requires that the profile directory exist before |
+ # the browser is launched. |
+ if not options.browser_options.profile_dir: |
+ options.browser_options.profile_dir = tempfile.mkdtemp() |
+ options.browser_options.disable_default_apps = False |
+ |
+ self._PrepareExtensionInstallFiles(options.browser_options.profile_dir) |
expectations = test_expectations.TestExpectations() |
results = results_options.CreateResults( |
@@ -204,24 +203,23 @@ class ExtensionsProfileCreator(profile_creator.ProfileCreator): |
'\n'.join(map(str, results.pages_that_failed))) |
raise Exception('ExtensionsProfileCreator failed.') |
- def _PrepareExtensionInstallFiles(self): |
+ def _PrepareExtensionInstallFiles(self, profile_path): |
"""Download extension archives and create extension install files.""" |
extensions_to_install = self._extensions_to_install |
- if self._theme_to_install: |
- extensions_to_install.append(self._theme_to_install) |
if not extensions_to_install: |
raise ValueError("No extensions or themes to install:", |
extensions_to_install) |
# Create external extensions path if it doesn't exist already. |
- external_extensions_dir = _ExternalExtensionsPath() |
+ external_extensions_dir = _ExternalExtensionsPath(profile_path) |
if not os.path.isdir(external_extensions_dir): |
os.makedirs(external_extensions_dir) |
self._extension_download_dir = tempfile.mkdtemp() |
num_extensions = len(extensions_to_install) |
- for i, extension_id in extensions_to_install: |
+ for i in range(num_extensions): |
+ extension_id = extensions_to_install[i] |
logging.info("Downloading %s - %d/%d" % ( |
extension_id, (i + 1), num_extensions)) |
extension_path = _DownloadExtension(extension_id, |