Add support for fast-cq mode to webkit-patch land-safely command
[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 webkitpy.benchmark_runner.browser_driver.osx_browser_driver import OSXBrowserDriver
7
8
9 _log = logging.getLogger(__name__)
10
11
12 class OSXChromeDriver(OSXBrowserDriver):
13     process_name = 'Google Chrome'
14     browser_name = 'chrome'
15     app_name = 'Google Chrome.app'
16     bundle_id = 'com.google.Chrome'
17
18     def launch_url(self, url, options, browser_build_path, browser_path):
19         # FIXME: handle self._browser_path.
20         args_with_url = self._insert_url(create_args(), 2, url)
21         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
22
23     def launch_driver(self, url, options, browser_build_path):
24         from selenium import webdriver
25         chrome_options = create_chrome_options()
26         if browser_build_path:
27             app_path = os.path.join(browser_build_path, self.app_name)
28             binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
29             chrome_options.binary_location = binary_path
30         driver_executable = self.webdriver_binary_path
31         driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
32         self._launch_webdriver(url=url, driver=driver)
33         return driver
34
35
36 class OSXChromeCanaryDriver(OSXBrowserDriver):
37     process_name = 'Google Chrome Canary'
38     browser_name = 'chrome-canary'
39     app_name = 'Google Chrome Canary.app'
40     bundle_id = 'com.google.Chrome.canary'
41
42     def launch_url(self, url, options, browser_build_path, browser_path):
43         # FIXME: handle self._browser_path.
44         args_with_url = self._insert_url(create_args(), 2, url)
45         self._launch_process(build_dir=browser_build_path, app_name=self.app_name, url=url, args=args_with_url)
46
47     def launch_driver(self, url, options, browser_build_path):
48         from selenium import webdriver
49         chrome_options = create_chrome_options()
50         if not browser_build_path:
51             browser_build_path = '/Applications/'
52         app_path = os.path.join(browser_build_path, self.app_name)
53         binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
54         chrome_options.binary_location = binary_path
55         driver_executable = self.webdriver_binary_path
56         driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
57         self._launch_webdriver(url=url, driver=driver)
58         return driver
59
60
61 def create_args():
62     args = ['--args', '--homepage', create_window_size_arg()]
63     return args
64
65
66 def create_chrome_options():
67     from selenium.webdriver.chrome.options import Options
68     chrome_options = Options()
69     chrome_options.add_argument("--disable-web-security")
70     chrome_options.add_argument("--user-data-dir")
71     chrome_options.add_argument("--disable-extensions")
72     chrome_options.add_argument(create_window_size_arg())
73     return chrome_options
74
75
76 def create_window_size_arg():
77     window_size_arg = '--window-size={width},{height}'.format(width=int(OSXBrowserDriver._screen_size().width), height=int(OSXBrowserDriver._screen_size().height))
78     return window_size_arg