OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """PyAuto: Python Interface to Chromium's Automation Proxy. | 6 """PyAuto: Python Interface to Chromium's Automation Proxy. |
7 | 7 |
8 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 8 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
9 For complete documentation on the functionality available, | 9 For complete documentation on the functionality available, |
10 run pydoc on this file. | 10 run pydoc on this file. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 if flag.startswith('--'): | 161 if flag.startswith('--'): |
162 flag = flag[2:] | 162 flag = flag[2:] |
163 split_pos = flag.find('=') | 163 split_pos = flag.find('=') |
164 if split_pos >= 0: | 164 if split_pos >= 0: |
165 flag_name = flag[:split_pos] | 165 flag_name = flag[:split_pos] |
166 flag_val = flag[split_pos + 1:] | 166 flag_val = flag[split_pos + 1:] |
167 self.AppendBrowserLaunchSwitch(flag_name, flag_val) | 167 self.AppendBrowserLaunchSwitch(flag_name, flag_val) |
168 else: | 168 else: |
169 self.AppendBrowserLaunchSwitch(flag) | 169 self.AppendBrowserLaunchSwitch(flag) |
170 | 170 |
171 def setUp(self): | 171 def __SetUp(self): |
172 """Override this method to launch browser differently. | |
173 | |
174 Can be used to prevent launching the browser window by default in case a | |
175 test wants to do some additional setup before firing browser. | |
176 | |
177 When using the named interface, it connects to an existing browser | |
178 instance. | |
179 """ | |
180 named_channel_id = None | 172 named_channel_id = None |
181 if _OPTIONS: | 173 if _OPTIONS: |
182 named_channel_id = _OPTIONS.channel_id | 174 named_channel_id = _OPTIONS.channel_id |
183 if self.IsChromeOS(): # Enable testing interface on ChromeOS. | 175 if self.IsChromeOS(): # Enable testing interface on ChromeOS. |
184 if self.get_clear_profile(): | 176 if self.get_clear_profile(): |
185 self.CleanupBrowserProfileOnChromeOS() | 177 self.CleanupBrowserProfileOnChromeOS() |
186 self.EnableCrashReportingOnChromeOS() | 178 self.EnableCrashReportingOnChromeOS() |
187 if not named_channel_id: | 179 if not named_channel_id: |
188 named_channel_id = self.EnableChromeTestingOnChromeOS() | 180 named_channel_id = self.EnableChromeTestingOnChromeOS() |
189 else: | 181 else: |
(...skipping 15 matching lines...) Expand all Loading... |
205 # TODO(dtu): Remove this after crosbug.com/4558 is fixed. | 197 # TODO(dtu): Remove this after crosbug.com/4558 is fixed. |
206 if self.IsChromeOS(): | 198 if self.IsChromeOS(): |
207 self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode']) | 199 self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode']) |
208 | 200 |
209 # If we are connected to any RemoteHosts, create PyAuto | 201 # If we are connected to any RemoteHosts, create PyAuto |
210 # instances on the remote sides and set them up too. | 202 # instances on the remote sides and set them up too. |
211 for remote in self.remotes: | 203 for remote in self.remotes: |
212 remote.CreateTarget(self) | 204 remote.CreateTarget(self) |
213 remote.setUp() | 205 remote.setUp() |
214 | 206 |
| 207 def setUp(self): |
| 208 """Override this method to launch browser differently. |
| 209 |
| 210 Can be used to prevent launching the browser window by default in case a |
| 211 test wants to do some additional setup before firing browser. |
| 212 |
| 213 When using the named interface, it connects to an existing browser |
| 214 instance. |
| 215 """ |
| 216 self.__SetUp() |
| 217 |
215 def tearDown(self): | 218 def tearDown(self): |
216 for remote in self.remotes: | 219 for remote in self.remotes: |
217 remote.tearDown() | 220 remote.tearDown() |
218 | 221 |
219 self.TearDown() # Destroy browser | 222 self.TearDown() # Destroy browser |
220 | 223 |
221 # Method required by the Python standard library unittest.TestCase. | 224 # Method required by the Python standard library unittest.TestCase. |
222 def runTest(self): | 225 def runTest(self): |
223 pass | 226 pass |
224 | 227 |
(...skipping 3445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3670 | 3673 |
3671 May return before logout is complete and | 3674 May return before logout is complete and |
3672 gives no indication of success or failure. | 3675 gives no indication of success or failure. |
3673 Should be logged in to work. | 3676 Should be logged in to work. |
3674 """ | 3677 """ |
3675 assert self.GetLoginInfo()['is_logged_in'], \ | 3678 assert self.GetLoginInfo()['is_logged_in'], \ |
3676 'Trying to log out when already logged out.' | 3679 'Trying to log out when already logged out.' |
3677 assert self.WaitForSessionManagerRestart( | 3680 assert self.WaitForSessionManagerRestart( |
3678 lambda: self.ApplyAccelerator(IDC_EXIT)), \ | 3681 lambda: self.ApplyAccelerator(IDC_EXIT)), \ |
3679 'Session manager did not restart after logout.' | 3682 'Session manager did not restart after logout.' |
3680 | 3683 self.__SetUp() |
3681 self.setUp() | |
3682 | 3684 |
3683 def LockScreen(self): | 3685 def LockScreen(self): |
3684 """Locks the screen on chromeos. | 3686 """Locks the screen on chromeos. |
3685 | 3687 |
3686 Waits until screen is locked. | 3688 Waits until screen is locked. |
3687 Should be logged in and screen should not be locked to work. | 3689 Should be logged in and screen should not be locked to work. |
3688 | 3690 |
3689 Raises: | 3691 Raises: |
3690 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 3692 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
3691 """ | 3693 """ |
(...skipping 27 matching lines...) Expand all Loading... |
3719 Effectively the same as clicking the "Sign out" link on the screen locker. | 3721 Effectively the same as clicking the "Sign out" link on the screen locker. |
3720 Screen should be locked for this to work. | 3722 Screen should be locked for this to work. |
3721 | 3723 |
3722 Raises: | 3724 Raises: |
3723 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 3725 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
3724 """ | 3726 """ |
3725 cmd_dict = { 'command': 'SignoutInScreenLocker' } | 3727 cmd_dict = { 'command': 'SignoutInScreenLocker' } |
3726 assert self.WaitForSessionManagerRestart( | 3728 assert self.WaitForSessionManagerRestart( |
3727 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \ | 3729 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \ |
3728 'Session manager did not restart after logout.' | 3730 'Session manager did not restart after logout.' |
3729 self.setUp() | 3731 self.__SetUp() |
3730 | 3732 |
3731 def GetBatteryInfo(self): | 3733 def GetBatteryInfo(self): |
3732 """Get details about battery state. | 3734 """Get details about battery state. |
3733 | 3735 |
3734 Returns: | 3736 Returns: |
3735 A dictionary with the following keys: | 3737 A dictionary with the following keys: |
3736 | 3738 |
3737 'battery_is_present': bool | 3739 'battery_is_present': bool |
3738 'line_power_on': bool | 3740 'line_power_on': bool |
3739 if 'battery_is_present': | 3741 if 'battery_is_present': |
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5047 successful = result.wasSuccessful() | 5049 successful = result.wasSuccessful() |
5048 if not successful: | 5050 if not successful: |
5049 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5051 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
5050 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5052 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
5051 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5053 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
5052 sys.exit(not successful) | 5054 sys.exit(not successful) |
5053 | 5055 |
5054 | 5056 |
5055 if __name__ == '__main__': | 5057 if __name__ == '__main__': |
5056 Main() | 5058 Main() |
OLD | NEW |