run-benchmark should support Chrome Canary and Firefox Nightly
[WebKit-https.git] / Tools / Scripts / webkitpy / benchmark_runner / browser_driver / osx_safari_driver.py
1 #!/usr/bin/env python
2
3 import logging
4 import os
5 import subprocess
6 import time
7
8 from osx_browser_driver import OSXBrowserDriver
9 from webkitpy.benchmark_runner.utils import forceRemove
10
11
12 _log = logging.getLogger(__name__)
13
14
15 class OSXSafariDriver(OSXBrowserDriver):
16
17     def prepareEnv(self):
18         self.safariProcess = None
19         self.closeBrowsers()
20         forceRemove(os.path.join(os.path.expanduser('~'), 'Library/Saved Application State/com.apple.Safari.savedState'))
21         forceRemove(os.path.join(os.path.expanduser('~'), 'Library/Safari/LastSession.plist'))
22         self.safariPreferences = ["-HomePage", "about:blank", "-WarnAboutFraudulentWebsites", "0", "-ExtensionsEnabled", "0", "-ShowStatusBar", "0", "-NewWindowBehavior", "1", "-NewTabBehavior", "1"]
23
24     def launchUrl(self, url, browserBuildPath):
25         args = ['/Applications/Safari.app/Contents/MacOS/SafariForWebKitDevelopment']
26         env = {}
27         if browserBuildPath:
28             safariAppInBuildPath = os.path.join(browserBuildPath, 'Safari.app/Contents/MacOS/Safari')
29             if os.path.exists(safariAppInBuildPath):
30                 args = [safariAppInBuildPath]
31                 env = {'DYLD_FRAMEWORK_PATH': browserBuildPath, 'DYLD_LIBRARY_PATH': browserBuildPath}
32             else:
33                 _log.info('Could not find Safari.app at %s, using the system SafariForWebKitDevelopment in /Applications instead' % safariAppInBuildPath)
34
35         args.extend(self.safariPreferences)
36         _log.info('Launching safari: %s with url: %s' % (args[0], url))
37         self.safariProcess = subprocess.Popen(args, env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
38         # Stop for initialization of the safari process, otherwise, open
39         # command may use the system safari.
40         time.sleep(3)
41         subprocess.Popen(['open', url])
42
43     def closeBrowsers(self):
44         self.terminateProcesses('com.apple.Safari')
45         if self.safariProcess:
46             _log.info('Safari process console output:\nstdout: %s\nstderr: %s' % self.safariProcess.communicate())
47             if self.safariProcess.returncode:
48                 _log.error('Safari Crashed!')