What's new? | Help | Directory | Sign in
Google
             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import os
import subprocess
import signal
import time

# Windows imports.
if os.name == 'nt':
import win32api
import win32con
import wmi

class BaseBrowserLauncher:
"""Handle launching and killing of a specific test browser."""
# Time given to allow firefox to update test profile and close.

FIREFOX_QUITTING_SLEEP_TIME = 15 #seconds

def launch(self, url):
""" Launch browser to the given url and track the returned process.

Args:
url: Url to launch
"""
command = self.browser_command
command.append(url)
print 'launching: %s' % str(command)
self.process = subprocess.Popen(command)


class BaseWin32Launcher(BaseBrowserLauncher):
"""Abstract base class for Win32 launchers."""

def launch(self, url):
""" First perform some cleanup, then launch browser. """
self._DestroyOldSlaveProcesses()
BaseBrowserLauncher.launch(self, url)

def _killInstancesByName(self, process_name):
"""Kill all instances of given process name.

Args:
process_name: String name of process to kill.
"""
process_list = wmi.WMI().Win32_Process(Name=process_name)
for process in process_list:
pid = process.ProcessID
print 'killing process: %d' % pid
handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, pid)
win32api.TerminateProcess(handle, 0)
win32api.CloseHandle(handle)
# Don't return until processes are gone
while len(wmi.WMI().Win32_Process(Name=process_name)) > 0:
time.sleep(1)


def _DestroyOldSlaveProcesses(self):
"""Check for and kill any existing gears slave processes.

Gears internal tests create some slave processes while running.
Here we check to see if any did not shut down properly and
destroy any that remain.
"""
process_list = wmi.WMI().Win32_Process(Name='rundll32.exe')
for process in process_list:
pid = process.ProcessID
print 'RUNDLL32 PROCESS** %s' % process.CommandLine
if process.CommandLine.rfind('gears.dll') > 0:
print 'Killing deadlocked slave process: %d' % pid
handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, pid)
win32api.TerminateProcess(handle, 0)
win32api.CloseHandle(handle)


class BaseFirefoxWin32Launcher(BaseWin32Launcher):
"""Abstract base class for win32 firefox launchers."""

def __init__(self, profile, firefox_path, automated=True):
self.killAllInstances()
program_files = os.getenv('PROGRAMFILES')
self.browser_command = [os.path.join(program_files, firefox_path)]
if automated:
self.browser_command.extend(['-profile', profile])

def killAllInstances(self):
self._killInstancesByName('firefox.exe')
self._killInstancesByName('crashreporter.exe')


class Firefox2Win32Launcher(BaseFirefoxWin32Launcher):
"""Launcher for ff2 in Windows."""

FIREFOX_PATH = 'Mozilla Firefox\\firefox.exe'

def __init__(self, profile, automated=True):
BaseFirefoxWin32Launcher.__init__(self, profile, self.FIREFOX_PATH,
automated)

def type(self):
return 'Firefox2Win32'


class Firefox3Win32Launcher(BaseFirefoxWin32Launcher):
"""Launcher for ff3 on Windows."""

FIREFOX_PATH = 'Mozilla Firefox 3\\firefox.exe'

def __init__(self, profile, automated=True):
BaseFirefoxWin32Launcher.__init__(self, profile, self.FIREFOX_PATH,
automated)

def type(self):
return 'Firefox3Win32'


class IExploreWin32Launcher(BaseWin32Launcher):
"""Launcher for iexplorer browser on Win32 platforms."""

def __init__(self, automated=True):
self.killAllInstances()
program_files = os.getenv('PROGRAMFILES')
ie_path = os.path.join(program_files, 'internet explorer\\iexplore.exe')
self.browser_command = [ie_path]

def killAllInstances(self):
"""Kill all instances of iexplore.exe

Must kill ie by name and not pid for ie7 compatibility.
"""
self._killInstancesByName('iexplore.exe')
# Also kill ie's crash handler process
self._killInstancesByName('iedw.exe')

def type(self):
return 'IExploreWin32'


class ChromeWin32Launcher(BaseWin32Launcher):
"""Launcher class for win32 Google Chrome."""

CHROME_PATH = r'Google\Chrome\Application\chrome.exe'

def __init__(self):
self.killAllInstances()
home = os.getenv('USERPROFILE')
appdata_xp = os.path.join(home, 'Local Settings\\Application Data')
appdata_vista = os.path.join(home, 'AppData\\Local')
if os.path.exists(appdata_vista):
self.browser_command = [os.path.join(appdata_vista,
ChromeWin32Launcher.CHROME_PATH)]
elif os.path.exists(appdata_xp):
self.browser_command = [os.path.join(appdata_xp,
ChromeWin32Launcher.CHROME_PATH)]

def killAllInstances(self):
self._killInstancesByName('chrome.exe')

def type(self):
return 'ChromeWin32'


class IExploreWinCeLauncher(BaseBrowserLauncher):
"""Launcher for pocket ie on Windows Mobile."""

def __init__(self, automated=True):
self.killAllInstances()

def type(self):
return 'IExploreWinCE'

def launch(self, url):
"""Do launch."""
# Requires rapistart.exe in path.
launch_cmd = ['rapistart.exe', '\windows\iexplore.exe', url]
subprocess.Popen(launch_cmd)

def killAllInstances(self):
""" Kill browser. """
# Requires pkill.exe in path.
print 'Killing pocket ie on device'
kill_cmd = ['pkill.exe', 'iexplore.exe']
subprocess.Popen(kill_cmd)


class BasePosixLauncher(BaseBrowserLauncher):
"""Abstract base class for posix platform launchers."""

def _killInstancesByName(self, process_name):
"""Kill all instances of process process_name.

Args:
process_name: string name of process to kill
"""
print 'Attempting to kill all processes named %s' % process_name
kill_cmd = ['killall', '-9', process_name]
p = subprocess.Popen(kill_cmd)
p.wait()


class SafariMacLauncher(BasePosixLauncher):
"""Launcher for Safari on OS X."""

def __init__(self, automated=True):
self.killAllInstances()
self.browser_command = ['open', '-a', 'Safari']

def killAllInstances(self):
"""Kill all instances of safari.

Must kill safari by name, as the pid can't be tracked on launch.
"""
self._killInstancesByName('Safari')

def type(self):
return 'SafariMac'


class BaseFirefoxMacLauncher(BasePosixLauncher):
"""Abstract base class for firefox launchers on OSX."""

def __init__(self, profile, automated, firefox_bin):
"""Set firefox vars."""
self.killAllInstances()
self.browser_command = [firefox_bin]
if automated:
self.browser_command.extend(['-P', profile])

def killAllInstances(self):
"""Kill all firefox and ff crash reporter instances."""
self._killInstancesByName('firefox-bin')
self._killInstancesByName('crashreporter')


class Firefox2MacLauncher(BaseFirefoxMacLauncher):
"""Firefox 2 implementation for FirefoxMacLauncher."""

FIREFOX_PATH = '/Applications/Firefox.app/Contents/MacOS/firefox-bin'

def __init__(self, profile, automated=True):
firefox_bin = Firefox2MacLauncher.FIREFOX_PATH
BaseFirefoxMacLauncher.__init__(self, profile, automated, firefox_bin)

def type(self):
return 'Firefox2Mac'


class Firefox3MacLauncher(BaseFirefoxMacLauncher):
"""Firefox 3 implementation for FirefoxMacLauncher."""

FIREFOX_PATH = '/Applications/Firefox3.app/Contents/MacOS/firefox-bin'

def __init__(self, profile, automated=True):
firefox_bin = Firefox3MacLauncher.FIREFOX_PATH
BaseFirefoxMacLauncher.__init__(self, profile, automated, firefox_bin)

def type(self):
return 'Firefox3Mac'


class BaseFirefoxLinuxLauncher(BasePosixLauncher):
"""Abstract base class for firefox launchers on linux."""

def __init__(self, profile, automated=True):
self.killAllInstances()
home = os.getenv('HOME')
if automated:
self.browser_command.extend(['-P', profile])

def killAllInstances(self):
self._killInstancesByName('firefox-bin')


class Firefox2LinuxLauncher(BaseFirefoxLinuxLauncher):
"""Launcher for firefox2 on linux, extends BaseFirefoxLinuxLauncher."""

def __init__(self, profile, automated=True):
self.browser_command = ['firefox2']
BaseFirefoxLinuxLauncher.__init__(self, profile, automated)

def type(self):
return 'Firefox2Linux'


class Firefox3LinuxLauncher(BaseFirefoxLinuxLauncher):
"""Launcher for firefox3 on linux, extends BaseFirefoxLinuxLauncher."""

def __init__(self, profile, automated=True):
self.browser_command = ['firefox3']
BaseFirefoxLinuxLauncher.__init__(self, profile, automated)

def type(self):
return 'Firefox3Linux'
Show details Hide details

Change log

r2804 by gears.daemon on Sep 04, 2008   Diff
[Author: ace]

Fixing Chrome path in vista runner take 2

TBR=playmobil
CC=gears-internal
DELTA=25  (0 added, 0 deleted, 25 changed)
OCL=8187995
SCL=8188012
Go to: 
Project members, sign in to write a code review

Older revisions

r2801 by gears.daemon on Sep 04, 2008   Diff
[Author: ace]

Fixing runner issue caused by having
both Chrome and not Chrome msi
installers in the
...
r2792 by gears.daemon on Sep 03, 2008   Diff
[Author: ace]

Folding google chrome test runner into
win32 test runner.

...
r2758 by gears.daemon on Aug 22, 2008   Diff
[Author: ace]

Adding clean-up to wince launcher
constructor.
Switching from SIGTERM to SIGKILL in
...
All revisions of this file

File info

Size: 8706 bytes, 291 lines

File properties

svn:executable
*