48e15054c85f546035448c45ef3dc6dc4d0f4a53
[WebKit-https.git] / Tools / Scripts / webkitpy / benchmark_runner / browser_driver / osx_browser_driver.py
1
2 import logging
3 import os
4 import subprocess
5
6 from browser_driver import BrowserDriver
7
8
9 _log = logging.getLogger(__name__)
10
11
12 class OSXBrowserDriver(BrowserDriver):
13     process_name = None
14     platform = 'osx'
15
16     def prepare_env(self, device_id):
17         self.close_browsers()
18         from Quartz import CGWarpMouseCursorPosition
19         CGWarpMouseCursorPosition((10, 0))
20
21     def restore_env(self):
22         pass
23
24     def close_browsers(self):
25         self._terminate_processes(self.process_name)
26
27     @classmethod
28     def _launch_process(cls, build_dir, app_name, url, args):
29         if not build_dir:
30             build_dir = '/Applications/'
31         app_path = os.path.join(build_dir, app_name)
32
33         _log.info('Launching "%s" with url "%s"' % (app_path, url))
34
35         # FIXME: May need to be modified for a local build such as setting up DYLD libraries
36         args = ['open', '-a', app_path] + args
37         cls._launch_process_with_caffinate(args)
38
39     @classmethod
40     def _terminate_processes(cls, process_name):
41         _log.info('Closing all processes with name %s' % process_name)
42         subprocess.call(['/usr/bin/killall', process_name])
43
44     @classmethod
45     def _launch_process_with_caffinate(cls, args, env=None):
46         process = subprocess.Popen(args, env=env)
47         subprocess.Popen(["/usr/bin/caffeinate", "-disw", str(process.pid)])
48         return process
49
50     @classmethod
51     def _screen_size(cls):
52         from AppKit import NSScreen
53         return NSScreen.mainScreen().frame().size