OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 """Finds desktop browsers that can be controlled by telemetry.""" | |
5 | |
6 import os | |
7 import sys | |
8 | |
9 from telemetry.core import browser | |
10 from telemetry.core import possible_browser | |
11 from telemetry.core import util | |
12 from telemetry.core.platform import linux_platform_backend | |
13 from telemetry.core.platform import mac_platform_backend | |
14 from telemetry.core.platform import win_platform_backend | |
15 from telemetry.core.webdriver import webdriver_browser_backend | |
16 | |
17 | |
18 # Add webdriver selenium client to PYTHONPATH. | |
19 sys.path.insert(0, os.path.join(util.GetChromiumSrcDir(), | |
20 'third_party', 'webdriver', 'pylib')) | |
21 from selenium import webdriver # pylint: disable=F0401 | |
nduca
2013/07/30 06:49:45
What if this import fails for some reason? Can we
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Let's do it later. crbug.com/266177 was filed.
| |
22 | |
23 ALL_BROWSER_TYPES = ','.join([ | |
24 'internetexplorer', | |
25 'internetexplorer_x64']) | |
nduca
2013/07/30 06:49:45
i think we have a naming convention for multi word
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Changed to "internet-explorer-x64". Used x64 becau
| |
26 | |
27 | |
28 class PossibleWebDriverBrowser(possible_browser.PossibleBrowser): | |
29 """A browser that can be controlled through webdriver API.""" | |
30 | |
31 def __init__(self, browser_type, options): | |
32 super(PossibleWebDriverBrowser, self).__init__(browser_type, options) | |
33 | |
34 def CreatePlatformBackend(self): | |
35 if sys.platform.startswith('linux'): | |
nduca
2013/07/30 06:49:45
would a telemetry.core.platform.util.CreatePlatfor
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Done.
| |
36 return linux_platform_backend.LinuxPlatformBackend() | |
37 elif sys.platform == 'darwin': | |
38 return mac_platform_backend.MacPlatformBackend() | |
39 elif sys.platform == 'win32': | |
40 return win_platform_backend.WinPlatformBackend() | |
41 else: | |
42 raise NotImplementedError() | |
43 | |
44 def CreateWebDriverBackend(self): | |
45 raise NotImplementedError() | |
46 | |
47 def Create(self): | |
48 backend = self.CreateWebDriverBackend() | |
49 b = browser.Browser(backend, self.CreatePlatformBackend()) | |
50 backend.SetBrowser(b) | |
51 return b | |
52 | |
53 def SupportsOptions(self, options): | |
54 return True | |
nduca
2013/07/30 06:49:45
really? probably a TODO here no?
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Done.
| |
55 | |
56 @property | |
57 def last_modification_time(self): | |
58 return -1 | |
59 | |
60 def SelectDefaultBrowser(self, possible_browsers): # pylint: disable=W0613 | |
61 return None | |
62 | |
63 | |
64 class PossibleDesktopIE(PossibleWebDriverBrowser): | |
65 def __init__(self, browser_type, options, architecture): | |
66 super(PossibleDesktopIE, self).__init__(browser_type, options) | |
67 self._architecture = architecture | |
68 | |
69 def CreateWebDriverBackend(self): | |
70 # TODO Currently require that IEDriverServer.exe is in PATH. | |
nduca
2013/07/30 06:49:45
# TODO(username): Is our convention.
Also, phrase
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Thanks for detailed explanation.
crbug.com/266170
| |
71 driver = webdriver.Ie() | |
72 return webdriver_browser_backend.WebDriverBrowserBackend( | |
73 driver, False, self.options) | |
74 | |
75 | |
76 def FindAllAvailableBrowsers(options): | |
77 """Finds all the desktop browsers available on this machine.""" | |
78 browsers = [] | |
79 | |
80 # Look for the IE browser in the standard location. | |
81 if sys.platform.startswith('win'): | |
82 ie_path = os.path.join('Internet Explorer', 'iexplore.exe') | |
83 win_search_paths = { | |
84 '32' : { 'path' : os.getenv('PROGRAMFILES(X86)'), | |
85 'type' : 'internetexplorer'}, | |
86 '64' : { 'path' : os.getenv('PROGRAMFILES'), | |
87 'type' : 'internetexplorer_x64'}} | |
88 for architecture, ie_info in win_search_paths.iteritems(): | |
89 if not ie_info['path']: | |
90 continue | |
91 if os.path.exists(os.path.join(ie_info['path'], ie_path)): | |
92 browsers.append( | |
93 PossibleDesktopIE(ie_info['type'], options, architecture)) | |
94 | |
95 return browsers | |
OLD | NEW |