| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import shutil | 10 import shutil |
| 11 import stat | 11 import stat |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 import tempfile | 14 import tempfile |
| 15 import time | 15 import time |
| 16 import urllib2 | 16 import urllib2 |
| 17 import zipfile | 17 import zipfile |
| 18 | 18 |
| 19 from hooks import install | 19 from hooks import install |
| 20 | 20 |
| 21 # URL on omahaproxy.appspot.com which lists cloud storage buckets. | 21 # URL on omahaproxy.appspot.com which lists cloud storage buckets. |
| 22 OMAHA_URL = 'https://omahaproxy.appspot.com/all?os=%s&channel=stable' | 22 OMAHA_URL = 'https://omahaproxy.appspot.com/all?os=%s&channel=%s' |
| 23 | 23 |
| 24 # URL in cloud storage to download Chrome zip from. | 24 # URL in cloud storage to download Chrome zip from. |
| 25 CLOUDSTORAGE_URL = ('https://commondatastorage.googleapis.com/chrome-unsigned' | 25 CLOUDSTORAGE_URL = ('https://commondatastorage.googleapis.com/chrome-unsigned' |
| 26 '/desktop-W15K3Y/%s/%s/chrome-%s.zip') | 26 '/desktop-W15K3Y/%s/%s/chrome-%s.zip') |
| 27 | 27 |
| 28 # Default port to run on if not auto-assigning from OS | 28 # Default port to run on if not auto-assigning from OS |
| 29 DEFAULT_PORT = '8111' | 29 DEFAULT_PORT = '8111' |
| 30 | 30 |
| 31 # Mapping of sys.platform -> platform-specific names and paths. | 31 # Mapping of sys.platform -> platform-specific names and paths. |
| 32 PLATFORM_MAPPING = { | 32 PLATFORM_MAPPING = { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return path | 92 return path |
| 93 | 93 |
| 94 # Check if depot_tools is in the path | 94 # Check if depot_tools is in the path |
| 95 for path in os.environ['PATH'].split(os.pathsep): | 95 for path in os.environ['PATH'].split(os.pathsep): |
| 96 if IsDepotToolsPath(path): | 96 if IsDepotToolsPath(path): |
| 97 return path.rstrip(os.sep) | 97 return path.rstrip(os.sep) |
| 98 | 98 |
| 99 return None | 99 return None |
| 100 | 100 |
| 101 | 101 |
| 102 def DownloadSignedWinChromeStable(url, version): | 102 def DownloadSignedWinChrome(url, version): |
| 103 """On Windows, use signed Chrome since it may be more stable.""" | 103 """On Windows, use signed Chrome since it may be more stable.""" |
| 104 url = url.replace('%VERSION%', version) | 104 url = url.replace('%VERSION%', version) |
| 105 tmpdir = tempfile.mkdtemp() | 105 tmpdir = tempfile.mkdtemp() |
| 106 installer_path = os.path.join(tmpdir, url[url.rindex('/') + 1:]) | 106 installer_path = os.path.join(tmpdir, url[url.rindex('/') + 1:]) |
| 107 with open(installer_path, 'wb') as local_file: | 107 with open(installer_path, 'wb') as local_file: |
| 108 local_file.write(urllib2.urlopen(url).read()) | 108 local_file.write(urllib2.urlopen(url).read()) |
| 109 depot_tools_path = FindDepotTools() | 109 depot_tools_path = FindDepotTools() |
| 110 path_7z = os.path.join(depot_tools_path, 'win_toolchain', '7z', '7z.exe') | 110 path_7z = os.path.join(depot_tools_path, 'win_toolchain', '7z', '7z.exe') |
| 111 command_7z = [path_7z, 'x', '-o' + tmpdir, installer_path] | 111 command_7z = [path_7z, 'x', '-o' + tmpdir, installer_path] |
| 112 process_7z = subprocess.Popen( | 112 process_7z = subprocess.Popen( |
| 113 command_7z, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 113 command_7z, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 114 out_7z, err_7z = process_7z.communicate() | 114 out_7z, err_7z = process_7z.communicate() |
| 115 del out_7z, err_7z | 115 del out_7z, err_7z |
| 116 command_7z = [path_7z, 'x', '-o' + tmpdir, os.path.join(tmpdir, 'chrome.7z')] | 116 command_7z = [path_7z, 'x', '-o' + tmpdir, os.path.join(tmpdir, 'chrome.7z')] |
| 117 process_7z = subprocess.Popen( | 117 process_7z = subprocess.Popen( |
| 118 command_7z, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 118 command_7z, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 119 out_7z, err_7z = process_7z.communicate() | 119 out_7z, err_7z = process_7z.communicate() |
| 120 return tmpdir, version | 120 return tmpdir, version |
| 121 | 121 |
| 122 | 122 |
| 123 def DownloadChromeStable(): | 123 def DownloadChrome(channel): |
| 124 platform_data = PLATFORM_MAPPING[sys.platform] | 124 platform_data = PLATFORM_MAPPING[sys.platform] |
| 125 omaha_platform = platform_data['omaha'] | 125 omaha_platform = platform_data['omaha'] |
| 126 omaha_url = OMAHA_URL % omaha_platform | 126 omaha_url = OMAHA_URL % (omaha_platform, channel) |
| 127 response = urllib2.urlopen(omaha_url) | 127 response = urllib2.urlopen(omaha_url) |
| 128 version = response.readlines()[1].split(',')[2] | 128 version = response.readlines()[1].split(',')[2] |
| 129 if 'installer_url' in platform_data: | 129 if 'installer_url' in platform_data: |
| 130 return DownloadSignedWinChromeStable( | 130 return DownloadSignedWinChrome( |
| 131 platform_data['installer_url'], version) | 131 platform_data['installer_url'], version) |
| 132 cs_url = CLOUDSTORAGE_URL % ( | 132 cs_url = CLOUDSTORAGE_URL % ( |
| 133 version, | 133 version, |
| 134 platform_data['cs_dir'], | 134 platform_data['cs_dir'], |
| 135 platform_data['cs_filename']) | 135 platform_data['cs_filename']) |
| 136 tmpdir = tempfile.mkdtemp() | 136 tmpdir = tempfile.mkdtemp() |
| 137 zip_path = os.path.join(tmpdir, 'chrome.zip') | 137 zip_path = os.path.join(tmpdir, 'chrome.zip') |
| 138 with open(zip_path, 'wb') as local_file: | 138 with open(zip_path, 'wb') as local_file: |
| 139 local_file.write(urllib2.urlopen(cs_url).read()) | 139 local_file.write(urllib2.urlopen(cs_url).read()) |
| 140 zf = zipfile.ZipFile(zip_path) | 140 zf = zipfile.ZipFile(zip_path) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 parser = argparse.ArgumentParser( | 178 parser = argparse.ArgumentParser( |
| 179 description='Run dev_server tests for a project.') | 179 description='Run dev_server tests for a project.') |
| 180 parser.add_argument('--chrome_path', type=str, | 180 parser.add_argument('--chrome_path', type=str, |
| 181 help='Path to Chrome browser binary.') | 181 help='Path to Chrome browser binary.') |
| 182 parser.add_argument('--no-use-local-chrome', | 182 parser.add_argument('--no-use-local-chrome', |
| 183 dest='use_local_chrome', action='store_false') | 183 dest='use_local_chrome', action='store_false') |
| 184 parser.add_argument( | 184 parser.add_argument( |
| 185 '--no-install-hooks', dest='install_hooks', action='store_false') | 185 '--no-install-hooks', dest='install_hooks', action='store_false') |
| 186 parser.add_argument('--tests', type=str, | 186 parser.add_argument('--tests', type=str, |
| 187 help='Set of tests to run (tracing or perf_insights)') | 187 help='Set of tests to run (tracing or perf_insights)') |
| 188 parser.add_argument('--channel', type=str, default='stable', |
| 189 help='Chrome channel to run (stable or canary)') |
| 188 parser.set_defaults(install_hooks=True) | 190 parser.set_defaults(install_hooks=True) |
| 189 parser.set_defaults(use_local_chrome=True) | 191 parser.set_defaults(use_local_chrome=True) |
| 190 args = parser.parse_args(argv[1:]) | 192 args = parser.parse_args(argv[1:]) |
| 191 | 193 |
| 192 if args.install_hooks: | 194 if args.install_hooks: |
| 193 install.InstallHooks() | 195 install.InstallHooks() |
| 194 | 196 |
| 195 platform_data = PLATFORM_MAPPING[sys.platform] | 197 platform_data = PLATFORM_MAPPING[sys.platform] |
| 196 user_data_dir = tempfile.mkdtemp() | 198 user_data_dir = tempfile.mkdtemp() |
| 197 tmpdir = None | 199 tmpdir = None |
| (...skipping 11 matching lines...) Expand all Loading... |
| 209 server_process = subprocess.Popen( | 211 server_process = subprocess.Popen( |
| 210 server_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 212 server_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 211 bufsize=1) | 213 bufsize=1) |
| 212 time.sleep(1) | 214 time.sleep(1) |
| 213 if sys.platform != 'win32': | 215 if sys.platform != 'win32': |
| 214 output = server_process.stderr.readline() | 216 output = server_process.stderr.readline() |
| 215 port = re.search( | 217 port = re.search( |
| 216 'Now running on http://127.0.0.1:([\d]+)', output).group(1) | 218 'Now running on http://127.0.0.1:([\d]+)', output).group(1) |
| 217 | 219 |
| 218 xvfb_process = None | 220 xvfb_process = None |
| 221 chrome_info = None |
| 219 if args.use_local_chrome: | 222 if args.use_local_chrome: |
| 220 chrome_path = GetLocalChromePath(args.chrome_path) | 223 chrome_path = GetLocalChromePath(args.chrome_path) |
| 221 if not chrome_path: | 224 if not chrome_path: |
| 222 logging.error('Could not find path to chrome.') | 225 logging.error('Could not find path to chrome.') |
| 223 sys.exit(1) | 226 sys.exit(1) |
| 227 chrome_info = 'with command `%s`' % chrome_path |
| 224 else: | 228 else: |
| 225 tmpdir, version = DownloadChromeStable() | 229 channel = args.channel |
| 230 if sys.platform == 'linux2' and channel == 'canary': |
| 231 channel = 'dev' |
| 232 assert channel in ['stable', 'beta', 'dev', 'canary'] |
| 233 tmpdir, version = DownloadChrome(channel) |
| 226 if platform_data.get('use_xfvb'): | 234 if platform_data.get('use_xfvb'): |
| 227 xvfb_process = StartXvfb() | 235 xvfb_process = StartXvfb() |
| 228 chrome_path = os.path.join( | 236 chrome_path = os.path.join( |
| 229 tmpdir, platform_data['chromepath']) | 237 tmpdir, platform_data['chromepath']) |
| 230 os.chmod(chrome_path, os.stat(chrome_path).st_mode | stat.S_IEXEC) | 238 os.chmod(chrome_path, os.stat(chrome_path).st_mode | stat.S_IEXEC) |
| 231 if platform_data.get('additional_paths'): | 239 if platform_data.get('additional_paths'): |
| 232 for path in platform_data.get('additional_paths'): | 240 for path in platform_data.get('additional_paths'): |
| 233 path = path.replace('%VERSION%', version) | 241 path = path.replace('%VERSION%', version) |
| 234 path = os.path.join(tmpdir, path) | 242 path = os.path.join(tmpdir, path) |
| 235 os.chmod(path, os.stat(path).st_mode | stat.S_IEXEC) | 243 os.chmod(path, os.stat(path).st_mode | stat.S_IEXEC) |
| 244 chrome_info = version |
| 236 chrome_command = [ | 245 chrome_command = [ |
| 237 chrome_path, | 246 chrome_path, |
| 238 '--user-data-dir=%s' % user_data_dir, | 247 '--user-data-dir=%s' % user_data_dir, |
| 239 '--no-sandbox', | 248 '--no-sandbox', |
| 240 '--no-experiments', | 249 '--no-experiments', |
| 241 '--no-first-run', | 250 '--no-first-run', |
| 242 '--noerrdialogs', | 251 '--noerrdialogs', |
| 243 ('http://localhost:%s/%s/tests.html?' % (port, args.tests)) + | 252 ('http://localhost:%s/%s/tests.html?' % (port, args.tests)) + |
| 244 'headless=true&testTypeToRun=all', | 253 'headless=true&testTypeToRun=all', |
| 245 ] | 254 ] |
| 246 print "Starting Chrome..." | 255 print "Starting Chrome %s..." % chrome_info |
| 247 chrome_process = subprocess.Popen( | 256 chrome_process = subprocess.Popen( |
| 248 chrome_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 257 chrome_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 249 print "Waiting for tests to finish..." | 258 print "Waiting for tests to finish..." |
| 250 server_out, server_err = server_process.communicate() | 259 server_out, server_err = server_process.communicate() |
| 251 print "Killing Chrome..." | 260 print "Killing Chrome..." |
| 252 if sys.platform == 'win32': | 261 if sys.platform == 'win32': |
| 253 # Use taskkill on Windows to make sure Chrome and all subprocesses are | 262 # Use taskkill on Windows to make sure Chrome and all subprocesses are |
| 254 # killed. | 263 # killed. |
| 255 subprocess.call(['taskkill', '/F', '/T', '/PID', str(chrome_process.pid)]) | 264 subprocess.call(['taskkill', '/F', '/T', '/PID', str(chrome_process.pid)]) |
| 256 else: | 265 else: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 272 try: | 281 try: |
| 273 shutil.rmtree(tmpdir) | 282 shutil.rmtree(tmpdir) |
| 274 shutil.rmtree(user_data_dir) | 283 shutil.rmtree(user_data_dir) |
| 275 except OSError as e: | 284 except OSError as e: |
| 276 logging.error('Error cleaning up temp dirs %s and %s: %s' % ( | 285 logging.error('Error cleaning up temp dirs %s and %s: %s' % ( |
| 277 tmpdir, user_data_dir, e)) | 286 tmpdir, user_data_dir, e)) |
| 278 if xvfb_process: | 287 if xvfb_process: |
| 279 xvfb_process.kill() | 288 xvfb_process.kill() |
| 280 | 289 |
| 281 sys.exit(server_process.returncode) | 290 sys.exit(server_process.returncode) |
| OLD | NEW |