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(['pgrep', 'chrome'], stdout=subprocess.PIPE) |
| 185 proc.wait() |
| 186 return [x.strip() for x in proc.stdout.readlines()] |
| 187 |
| 188 orig_pids = _GetListOfChromePids() |
177 subprocess.call(['pkill', 'chrome']) | 189 subprocess.call(['pkill', 'chrome']) |
178 | 190 |
| 191 def _AreOrigPidsDead(orig_pids): |
| 192 """Determines whether all originally-running 'chrome' processes are dead. |
| 193 |
| 194 Args: |
| 195 orig_pids: A list of strings, where each string represents the PID for |
| 196 an originally-running 'chrome' process. |
| 197 |
| 198 Returns: |
| 199 True, if all originally-running 'chrome' processes have been killed, or |
| 200 False otherwise. |
| 201 """ |
| 202 for new_pid in _GetListOfChromePids(): |
| 203 if new_pid in orig_pids: |
| 204 return False |
| 205 return True |
| 206 |
| 207 self.WaitUntil(lambda: _AreOrigPidsDead(orig_pids)) |
| 208 |
179 def EnableChromeTestingOnChromeOS(self): | 209 def EnableChromeTestingOnChromeOS(self): |
180 """Enables the named automation interface on chromeos. | 210 """Enables the named automation interface on chromeos. |
181 | 211 |
182 Restarts chrome so that you get a fresh instance. | 212 Restarts chrome so that you get a fresh instance. |
183 Also sets some testing-friendly flags for chrome. | 213 Also sets some testing-friendly flags for chrome. |
184 | 214 |
185 Expects suid python to be present in the same dir as pyautolib.py | 215 Expects suid python to be present in the same dir as pyautolib.py |
186 """ | 216 """ |
187 def _IsRootSuid(path): | 217 def _IsRootSuid(path): |
188 return os.path.isfile(path) and (os.stat(path).st_mode & stat.S_ISUID) | 218 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: | 3654 if self._options.verbose: |
3625 verbosity = 2 | 3655 verbosity = 2 |
3626 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) | 3656 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) |
3627 del loaded_tests # Need to destroy test cases before the suite | 3657 del loaded_tests # Need to destroy test cases before the suite |
3628 del pyauto_suite | 3658 del pyauto_suite |
3629 sys.exit(not result.wasSuccessful()) | 3659 sys.exit(not result.wasSuccessful()) |
3630 | 3660 |
3631 | 3661 |
3632 if __name__ == '__main__': | 3662 if __name__ == '__main__': |
3633 Main() | 3663 Main() |
OLD | NEW |