REGRESSION(r219850): run-benchmark script broken on Linux
[WebKit-https.git] / Tools / Scripts / webkitpy / benchmark_runner / browser_driver / osx_chrome_driver.py
1 #!/usr/bin/env python
2
3 import logging
4 import os
5
6 from osx_browser_driver import OSXBrowserDriver
7
8
9 _log = logging.getLogger(__name__)
10
11 class OSXChromeDriver(OSXBrowserDriver):
12     process_name = 'Google Chrome'
13     browser_name = 'chrome'
14     app_name = 'Google Chrome.app'
15
16     def launch_url(self, url, options, browser_build_path):
17         args_with_url = self._insert_url(create_args(), 2, url)
18         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
19
20     def launch_driver(self, url, options, browser_build_path):
21         chrome_options = create_chrome_options()
22         if browser_build_path:
23             app_path = os.path.join(browser_build_path, self.app_name)
24             binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
25             chrome_options.binary_location = binary_path
26         driver_executable = self.webdriver_binary_path
27         from webkitpy.thirdparty.autoinstalled.selenium import webdriver
28         driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
29         self._launch_webdriver(url=url, driver=driver)
30         return driver
31
32
33 class OSXChromeCanaryDriver(OSXBrowserDriver):
34     process_name = 'Google Chrome Canary'
35     browser_name = 'chrome-canary'
36     app_name = 'Google Chrome Canary.app'
37
38     def launch_url(self, url, options, browser_build_path):
39         args_with_url = self._insert_url(create_args(), 2, url)
40         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
41
42     def launch_driver(self, url, options, browser_build_path):
43         chrome_options = create_chrome_options()
44         if not browser_build_path:
45             browser_build_path = '/Applications/'
46         app_path = os.path.join(browser_build_path, self.app_name)
47         binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
48         chrome_options.binary_location = binary_path
49         driver_executable = self.webdriver_binary_path
50         from webkitpy.thirdparty.autoinstalled.selenium import webdriver
51         driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
52         self._launch_webdriver(url=url, driver=driver)
53         return driver
54
55
56 def create_args():
57     args = ['--args', '--homepage', create_window_size_arg()]
58     return args
59
60 def create_chrome_options():
61     from webkitpy.thirdparty.autoinstalled.selenium.webdriver.chrome.options import Options
62     chrome_options = Options()
63     chrome_options.add_argument("--disable-web-security")
64     chrome_options.add_argument("--user-data-dir")
65     chrome_options.add_argument("--disable-extensions")
66     chrome_options.add_argument(create_window_size_arg())
67     return chrome_options
68
69
70 def create_window_size_arg():
71     window_size_arg = '--window-size={width},{height}'.format(width=int(OSXBrowserDriver._screen_size().width), height=int(OSXBrowserDriver._screen_size().height))
72     return window_size_arg