https://bugs.webkit.org/show_bug.cgi?id=144038
[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 # We assume that this handle can only be used when the platform is OSX.
9 from AppKit import NSRunningApplication
10 from browser_driver import BrowserDriver
11
12
13 _log = logging.getLogger(__name__)
14
15
16 class OSXSafariDriver(BrowserDriver):
17
18     def prepareEnv(self):
19         self.closeBrowsers()
20         self.safariPreferences = ["-HomePage", "about:blank", "-WarnAboutFraudulentWebsites", "0", "-ExtensionsEnabled", "0", "-ShowStatusBar", "0", "-NewWindowBehavior", "1", "-NewTabBehavior", "1"]
21
22     def launchUrl(self, url, browserBuildPath=None):
23         args = [os.path.join(browserBuildPath, 'Safari.app/Contents/MacOS/Safari')]
24         args.extend(self.safariPreferences)
25         _log.info('Launching safari: %s with url: %s' % (args[0], url))
26         subprocess.Popen(args, env={'DYLD_FRAMEWORK_PATH': browserBuildPath, 'DYLD_LIBRARY_PATH': browserBuildPath}, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
27         # Stop for initialization of the safari process, otherwise, open
28         # command may use the system safari.
29         time.sleep(3)
30         subprocess.Popen(['open', url])
31
32     def closeBrowsers(self):
33         _log.info('Closing all existing safari processes')
34         safariInstances = NSRunningApplication.runningApplicationsWithBundleIdentifier_('com.apple.Safari')
35         for safariInstance in safariInstances:
36             safariInstance.terminate()