Move cursor to (10, 0) instead of (0, 0) and polish the mouse move code
[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 AppKit import NSRunningApplication
7 from AppKit import NSScreen
8 from Quartz import CGWarpMouseCursorPosition
9 from browser_driver import BrowserDriver
10
11
12 _log = logging.getLogger(__name__)
13
14
15 class OSXBrowserDriver(BrowserDriver):
16     bundleIdentifier = None
17
18     def prepareEnv(self):
19         self.closeBrowsers()
20         CGWarpMouseCursorPosition((10, 0))
21
22     def closeBrowsers(self):
23         self.terminateProcesses(self.bundleIdentifier)
24
25     @classmethod
26     def launchProcess(cls, buildDir, appName, url, args):
27         if not buildDir:
28             buildDir = '/Applications/'
29         appPath = os.path.join(buildDir, appName)
30
31         _log.info('Launching "%s" with url "%s"' % (appPath, url))
32
33         # FIXME: May need to be modified for a local build such as setting up DYLD libraries
34         args = ['open', '-a', appPath] + args
35         cls.launchProcessWithCaffinate(args)
36
37     @classmethod
38     def terminateProcesses(cls, bundleIdentifier):
39         _log.info('Closing all terminating all processes with the bundle identifier %s' % bundleIdentifier)
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         return NSScreen.mainScreen().frame().size