Commit 300f7a40 authored by erikchen's avatar erikchen Committed by Commit bot

Fix telemetry extension profile generator for OSX.

This CL includes several functionality fixes to the extension profile creator,
as well as several functionality improvements.
  - The URL to download extensions by identifier has changed, but the profile
  creator had not been updated.
  - Several of the extensions in many_extensions_profile_generator no longer
  exist, or no longer work.
  - There was a python error in _PrepareExtensionInstallFiles.
  - The old code waited 5 minutes for extensions to install. (And then waited
  for all tabs to load). The new code just waits 15 seconds, on the premise
  that it is better to fail fast than fail slow.
  - The old code required a clean installation of the OS, not connected to the
  corp network. The new code can be run from anywhere.

Caveat:
  - This CL removes the ability to generate an extension profile on Linux. This
  is not a functional change, since the previous code was already broken.

BUG=444230

Review URL: https://codereview.chromium.org/847583002

Cr-Commit-Position: refs/heads/master@{#311584}
parent 47ce03d7
......@@ -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,
......
......@@ -7,7 +7,7 @@ from profile_creators import extensions_profile_creator
class ManyExtensionsProfileCreator(
extensions_profile_creator.ExtensionsProfileCreator):
"""Install 25 popular extensions."""
"""Install many popular extensions."""
def __init__(self):
extensions_to_install = [
......@@ -19,23 +19,15 @@ class ManyExtensionsProfileCreator(
"elioihkkcdgakfbahdoddophfngopipi",
"fheoggkfdfchfphceeifdbepaooicaho",
"nkcpopggjcjkiicpenikeogioednjeac",
"gomekmidlodglbbmalcneegieacbdmki",
"ifohbjbgfchkkfhphahclmkpgejiplfo",
"jpmbfleldcgkldadpdinhjjopdfpjfjp",
"kbmfpngjjgdllneeigpgjifpgocmfgmb",
"pdnfnkhpgegpcingjbfihlkjeighnddk",
"aapbdbdomjkkjkaonfhkkikfgjllcleb",
"dhkplhfnhceodhffomolpfigojocbpcb",
"fjbbjfdilbioabojmcplalojlmdngbjl",
"gkojfkhlekighikafcpjkiklfbnlmeio",
"cpngackimfmofbokmjmljamhdncknpmg",
"hdokiejnpimakedhajhdlcegeplioahd",
"ninpnjfmichdlipckmfacdjbpbkkbcfa",
"mihcahmgecmbnbcchbopgniflfhgnkff",
"mgijmajocgfcbeboacabfgobmjgjcoja",
"ohjkicjidmohhfcjjlahfppkdblibkkb",
"bfbmjmiodbnnpllbbbfblcplfjjepjdn",
"opnbmdkdflhjiclaoiiifmheknpccalb"]
"ohjkicjidmohhfcjjlahfppkdblibkkb"]
super(ManyExtensionsProfileCreator, self).__init__(
extensions_to_install=extensions_to_install)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment