OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """PyAuto: Python Interface to Chromium's Automation Proxy. | 7 """PyAuto: Python Interface to Chromium's Automation Proxy. |
8 | 8 |
9 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 9 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
10 For complete documentation on the functionality available, | 10 For complete documentation on the functionality available, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 self.UseNamedChannelID(named_channel_id) | 164 self.UseNamedChannelID(named_channel_id) |
165 self.SetUp() # Fire browser | 165 self.SetUp() # Fire browser |
166 | 166 |
167 # TODO(dtu): Remove this after crosbug.com/4558 is fixed. | 167 # TODO(dtu): Remove this after crosbug.com/4558 is fixed. |
168 if self.IsChromeOS(): | 168 if self.IsChromeOS(): |
169 self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode']) | 169 self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode']) |
170 | 170 |
171 def tearDown(self): | 171 def tearDown(self): |
172 self.TearDown() # Destroy browser | 172 self.TearDown() # Destroy browser |
173 | 173 |
174 @staticmethod | 174 def CloseChromeOnChromeOS(self): |
175 def CloseChromeOnChromeOS(): | |
176 """Gracefully exit chrome on ChromeOS.""" | 175 """Gracefully exit chrome on ChromeOS.""" |
176 | |
177 def _GetListOfChromePids(): | |
178 """Retrieves the list of currently-running Chrome process IDs. | |
179 | |
180 Returns: | |
181 A list of strings, where each string represents a currently-running | |
182 'chrome' process ID. | |
183 """ | |
184 proc = subprocess.Popen(['ps', '-C', 'chrome'], stdout=subprocess.PIPE) | |
Nirnimesh
2011/06/08 18:32:22
'prep chrome' will be easier to parse
dennis_jeffrey
2011/06/08 21:50:31
Awesome! Thanks!
| |
185 output, _ = proc.communicate() | |
Nirnimesh
2011/06/08 18:32:22
output = proc.communicate()[0]
dennis_jeffrey
2011/06/08 21:50:31
This line has since been removed.
| |
186 pids = [] | |
187 for line in output.split('\n'): | |
188 line = line.strip() | |
189 if line.find('chrome') >= 0: | |
190 pids.append(line[:line.find(' ')]) | |
191 return pids | |
192 | |
193 orig_pids = _GetListOfChromePids() | |
177 subprocess.call(['pkill', 'chrome']) | 194 subprocess.call(['pkill', 'chrome']) |
178 | 195 |
196 def _DoesOldChromeProcessStillExist(): | |
Nirnimesh
2011/06/08 18:32:22
take orig_pids as arg
dennis_jeffrey
2011/06/08 21:50:31
Done.
| |
197 """Determines whether an originally-running 'chrome' process exists. | |
198 | |
199 Returns: | |
200 True, if an originally-running 'chrome' process still exists, or | |
201 False otherwise. | |
202 """ | |
203 new_pids = _GetListOfChromePids() | |
204 for new_pid in new_pids: | |
Nirnimesh
2011/06/08 18:32:22
merge with previous line
dennis_jeffrey
2011/06/08 21:50:31
Done.
| |
205 if new_pid in orig_pids: | |
206 return True | |
207 return False | |
208 | |
209 self.WaitUntil(lambda: not _DoesOldChromeProcessStillExist()) | |
Nirnimesh
2011/06/08 18:32:22
pass orig_pids as arg
Nirnimesh
2011/06/08 18:32:22
Why the negation? Just invert the function --
lamb
dennis_jeffrey
2011/06/08 21:50:31
Done.
dennis_jeffrey
2011/06/08 21:50:31
Done.
| |
210 | |
179 def EnableChromeTestingOnChromeOS(self): | 211 def EnableChromeTestingOnChromeOS(self): |
180 """Enables the named automation interface on chromeos. | 212 """Enables the named automation interface on chromeos. |
181 | 213 |
182 Restarts chrome so that you get a fresh instance. | 214 Restarts chrome so that you get a fresh instance. |
183 Also sets some testing-friendly flags for chrome. | 215 Also sets some testing-friendly flags for chrome. |
184 | 216 |
185 Expects suid python to be present in the same dir as pyautolib.py | 217 Expects suid python to be present in the same dir as pyautolib.py |
186 """ | 218 """ |
187 def _IsRootSuid(path): | 219 def _IsRootSuid(path): |
188 return os.path.isfile(path) and (os.stat(path).st_mode & stat.S_ISUID) | 220 return os.path.isfile(path) and (os.stat(path).st_mode & stat.S_ISUID) |
(...skipping 3435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3624 if self._options.verbose: | 3656 if self._options.verbose: |
3625 verbosity = 2 | 3657 verbosity = 2 |
3626 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) | 3658 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) |
3627 del loaded_tests # Need to destroy test cases before the suite | 3659 del loaded_tests # Need to destroy test cases before the suite |
3628 del pyauto_suite | 3660 del pyauto_suite |
3629 sys.exit(not result.wasSuccessful()) | 3661 sys.exit(not result.wasSuccessful()) |
3630 | 3662 |
3631 | 3663 |
3632 if __name__ == '__main__': | 3664 if __name__ == '__main__': |
3633 Main() | 3665 Main() |
OLD | NEW |