Stop python icon bouncing in the dock while running browser benchmarks.
[WebKit.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 from webkitpy.benchmark_runner.utils import write_defaults
8
9
10 _log = logging.getLogger(__name__)
11
12
13 class OSXBrowserDriver(BrowserDriver):
14     process_name = None
15     platform = 'osx'
16
17     def prepare_env(self, device_id):
18         self.close_browsers()
19         from Quartz import CGWarpMouseCursorPosition
20         CGWarpMouseCursorPosition((10, 0))
21         self.updated_dock_animation_defaults = write_defaults('com.apple.dock', 'launchanim', False)
22         if self.updated_dock_animation_defaults:
23             self._terminate_processes('Dock')
24
25     def restore_env(self):
26         if self.updated_dock_animation_defaults:
27             write_defaults('com.apple.dock', 'launchanim', True)
28             self._terminate_processes('Dock')
29
30     def close_browsers(self):
31         self._terminate_processes(self.process_name)
32
33     @classmethod
34     def _launch_process(cls, build_dir, app_name, url, args):
35         if not build_dir:
36             build_dir = '/Applications/'
37         app_path = os.path.join(build_dir, app_name)
38
39         _log.info('Launching "%s" with url "%s"' % (app_path, url))
40
41         # FIXME: May need to be modified for a local build such as setting up DYLD libraries
42         args = ['open', '-a', app_path] + args
43         cls._launch_process_with_caffinate(args)
44
45     @classmethod
46     def _terminate_processes(cls, process_name):
47         _log.info('Closing all processes with name %s' % process_name)
48         subprocess.call(['/usr/bin/killall', process_name])
49
50     @classmethod
51     def _launch_process_with_caffinate(cls, args, env=None):
52         process = subprocess.Popen(args, env=env)
53         subprocess.Popen(["/usr/bin/caffeinate", "-disw", str(process.pid)])
54         return process
55
56     @classmethod
57     def _screen_size(cls):
58         from AppKit import NSScreen
59         return NSScreen.mainScreen().frame().size