9 from osx_browser_driver import OSXBrowserDriver
10 from webkitpy.benchmark_runner.utils import forceRemove
13 _log = logging.getLogger(__name__)
16 class OSXSafariDriver(OSXBrowserDriver):
17 bundleIdentifier = 'com.apple.Safari'
20 super(OSXSafariDriver, self).closeBrowsers()
21 self.safariProcess = None
22 forceRemove(os.path.join(os.path.expanduser('~'), 'Library/Saved Application State/com.apple.Safari.savedState'))
23 forceRemove(os.path.join(os.path.expanduser('~'), 'Library/Safari/LastSession.plist'))
25 self.safariPreferences = ["-HomePage", "about:blank", "-WarnAboutFraudulentWebsites", "0", "-ExtensionsEnabled", "0", "-ShowStatusBar", "0", "-NewWindowBehavior", "1", "-NewTabBehavior", "1"]
27 def launchUrl(self, url, browserBuildPath):
28 args = ['/Applications/Safari.app/Contents/MacOS/Safari']
31 safariAppInBuildPath = os.path.join(browserBuildPath, 'Safari.app/Contents/MacOS/Safari')
32 if os.path.exists(safariAppInBuildPath):
33 args = [safariAppInBuildPath]
34 env = {'DYLD_FRAMEWORK_PATH': browserBuildPath, 'DYLD_LIBRARY_PATH': browserBuildPath, '__XPC_DYLD_LIBRARY_PATH': browserBuildPath}
36 _log.info('Could not find Safari.app at %s, using the system Safari instead' % safariAppInBuildPath)
38 args.extend(self.safariPreferences)
39 _log.info('Launching safari: %s with url: %s' % (args[0], url))
40 self.safariProcess = OSXSafariDriver.launchProcessWithCaffinate(args, env)
42 # Stop for initialization of the safari process, otherwise, open
43 # command may use the system safari.
45 subprocess.Popen(['open', url])
47 def closeBrowsers(self):
48 super(OSXSafariDriver, self).closeBrowsers()
49 if self.safariProcess and self.safariProcess.returncode:
50 sys.exit('Browser crashed with exitcode %d' % self._process.returncode)
53 def maximizeWindow(cls):
55 subprocess.check_call(['/usr/bin/defaults', 'write', 'com.apple.Safari', 'NSWindow Frame BrowserWindowFrame', ' '.join(['0', '0', str(cls.screenSize().width), str(cls.screenSize().height)] * 2)])
56 except Exception as error:
57 _log.error('Reset safari window size failed - Error: {}'.format(error))