Get rid of factory json files in benchmark_runner
[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     bundleIdentifier = None
14     platform = 'osx'
15
16     def prepareEnv(self, deviceID):
17         self.closeBrowsers()
18         from Quartz import CGWarpMouseCursorPosition
19         CGWarpMouseCursorPosition((10, 0))
20
21     def closeBrowsers(self):
22         self.terminateProcesses(self.bundleIdentifier)
23
24     @classmethod
25     def launchProcess(cls, buildDir, appName, url, args):
26         if not buildDir:
27             buildDir = '/Applications/'
28         appPath = os.path.join(buildDir, appName)
29
30         _log.info('Launching "%s" with url "%s"' % (appPath, url))
31
32         # FIXME: May need to be modified for a local build such as setting up DYLD libraries
33         args = ['open', '-a', appPath] + args
34         cls.launchProcessWithCaffinate(args)
35
36     @classmethod
37     def terminateProcesses(cls, bundleIdentifier):
38         _log.info('Closing all terminating all processes with the bundle identifier %s' % bundleIdentifier)
39         from AppKit import NSRunningApplication
40         processes = NSRunningApplication.runningApplicationsWithBundleIdentifier_(bundleIdentifier)
41         for process in processes:
42             process.terminate()
43
44     @classmethod
45     def launchProcessWithCaffinate(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 screenSize(cls):
52         from AppKit import NSScreen
53         return NSScreen.mainScreen().frame().size