OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 'channel on first attempt. Something went very ' | 201 'channel on first attempt. Something went very ' |
202 'wrong. Chrome probably did not launch.') | 202 'wrong. Chrome probably did not launch.') |
203 | 203 |
204 # Forcibly trigger all plugins to get registered. crbug.com/94123 | 204 # Forcibly trigger all plugins to get registered. crbug.com/94123 |
205 # Sometimes flash files loaded too quickly after firing browser | 205 # Sometimes flash files loaded too quickly after firing browser |
206 # ends up getting downloaded, which seems to indicate that the plugin | 206 # ends up getting downloaded, which seems to indicate that the plugin |
207 # hasn't been registered yet. | 207 # hasn't been registered yet. |
208 if not self.IsChromeOS(): | 208 if not self.IsChromeOS(): |
209 self.GetPluginsInfo() | 209 self.GetPluginsInfo() |
210 | 210 |
211 # TODO(dtu): Remove this after crosbug.com/4558 is fixed. | |
212 if self.IsChromeOS(): | |
213 self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode']) | |
214 | |
215 if (self.IsChromeOS() and not self.GetLoginInfo()['is_logged_in'] and | 211 if (self.IsChromeOS() and not self.GetLoginInfo()['is_logged_in'] and |
216 self.ShouldOOBESkipToLogin()): | 212 self.ShouldOOBESkipToLogin()): |
217 if self.GetOOBEScreenInfo()['screen_name'] != 'login': | 213 if self.GetOOBEScreenInfo()['screen_name'] != 'login': |
218 self.SkipToLogin() | 214 self.SkipToLogin() |
219 if self.ShouldAutoLogin(): | 215 if self.ShouldAutoLogin(): |
220 # Login with default creds. | 216 # Login with default creds. |
221 sys.path.append('/usr/local') # to import autotest libs | 217 sys.path.append('/usr/local') # to import autotest libs |
222 from autotest.cros import constants | 218 from autotest.cros import constants |
223 creds = constants.CREDENTIALS['$default'] | 219 creds = constants.CREDENTIALS['$default'] |
224 self.Login(creds[0], creds[1]) | 220 self.Login(creds[0], creds[1]) |
(...skipping 4264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4489 panel = {} | 4485 panel = {} |
4490 panels.append(panel) | 4486 panels.append(panel) |
4491 tab = browser['tabs'][0] | 4487 tab = browser['tabs'][0] |
4492 panel['incognito'] = browser['incognito'] | 4488 panel['incognito'] = browser['incognito'] |
4493 panel['renderer_pid'] = tab['renderer_pid'] | 4489 panel['renderer_pid'] = tab['renderer_pid'] |
4494 panel['title'] = self.GetActiveTabTitle(browser['index']) | 4490 panel['title'] = self.GetActiveTabTitle(browser['index']) |
4495 panel['url'] = tab['url'] | 4491 panel['url'] = tab['url'] |
4496 | 4492 |
4497 return panels | 4493 return panels |
4498 | 4494 |
4499 def GetNetworkInfo(self): | |
4500 """Get details about ethernet, wifi, and cellular networks on chromeos. | |
4501 | |
4502 Returns: | |
4503 A dictionary. | |
4504 Sample: | |
4505 { u'cellular_available': True, | |
4506 u'cellular_enabled': False, | |
4507 u'connected_ethernet': u'/service/ethernet_abcd', | |
4508 u'connected_wifi': u'/service/wifi_abcd_1234_managed_none', | |
4509 u'ethernet_available': True, | |
4510 u'ethernet_enabled': True, | |
4511 u'ethernet_networks': | |
4512 { u'/service/ethernet_abcd': | |
4513 { u'device_path': u'/device/abcdeth', | |
4514 u'name': u'', | |
4515 u'service_path': | |
4516 u'/profile/default/ethernet_abcd', | |
4517 u'status': u'Connected'} | |
4518 u'network_type': pyautolib.TYPE_ETHERNET }, | |
4519 u'remembered_wifi': | |
4520 { u'/service/wifi_abcd_1234_managed_none': | |
4521 { u'device_path': u'', | |
4522 u'encrypted': False, | |
4523 u'encryption': u'', | |
4524 u'name': u'WifiNetworkName1', | |
4525 u'status': u'Unknown', | |
4526 u'strength': 0}, | |
4527 u'network_type': pyautolib.TYPE_WIFI | |
4528 }, | |
4529 u'wifi_available': True, | |
4530 u'wifi_enabled': True, | |
4531 u'wifi_networks': | |
4532 { u'/service/wifi_abcd_1234_managed_none': | |
4533 { u'device_path': u'/device/abcdwifi', | |
4534 u'encrypted': False, | |
4535 u'encryption': u'', | |
4536 u'name': u'WifiNetworkName1', | |
4537 u'status': u'Connected', | |
4538 u'strength': 76}, | |
4539 u'/service/wifi_abcd_1234_managed_802_1x': | |
4540 { u'encrypted': True, | |
4541 u'encryption': u'8021X', | |
4542 u'name': u'WifiNetworkName2', | |
4543 u'status': u'Idle', | |
4544 u'strength': 79} | |
4545 u'network_type': pyautolib.TYPE_WIFI }} | |
4546 | |
4547 | |
4548 Raises: | |
4549 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
4550 """ | |
4551 cmd_dict = { 'command': 'GetNetworkInfo' } | |
4552 network_info = self._GetResultFromJSONRequest(cmd_dict, windex=None) | |
4553 | |
4554 # Remembered networks do not have /service/ prepended to the service path | |
4555 # even though wifi_networks does. We want this prepended to allow for | |
4556 # consistency and easy string comparison with wifi_networks. | |
4557 remembered_wifi = {} | |
4558 network_info['remembered_wifi'] = dict([('/service/' + k, v) for k, v in | |
4559 network_info['remembered_wifi'].iteritems()]) | |
4560 | |
4561 return network_info | |
4562 | |
4563 def NetworkScan(self): | |
4564 """Causes ChromeOS to scan for available wifi networks. | |
4565 | |
4566 Blocks until scanning is complete. | |
4567 | |
4568 Returns: | |
4569 The new list of networks obtained from GetNetworkInfo(). | |
4570 | |
4571 Raises: | |
4572 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
4573 """ | |
4574 cmd_dict = { 'command': 'NetworkScan' } | |
4575 self._GetResultFromJSONRequest(cmd_dict, windex=None) | |
4576 return self.GetNetworkInfo() | |
4577 | |
4578 def ToggleNetworkDevice(self, device, enable): | |
4579 """Enable or disable a network device on ChromeOS. | |
4580 | |
4581 Valid device names are ethernet, wifi, cellular. | |
4582 | |
4583 Raises: | |
4584 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
4585 """ | |
4586 cmd_dict = { | |
4587 'command': 'ToggleNetworkDevice', | |
4588 'device': device, | |
4589 'enable': enable, | |
4590 } | |
4591 return self._GetResultFromJSONRequest(cmd_dict, windex=None) | |
4592 | |
4593 def ForgetAllRememberedNetworks(self): | |
4594 """Forgets all networks that the device has marked as remembered.""" | |
4595 for service in self.GetNetworkInfo()['remembered_wifi']: | |
4596 self.ForgetWifiNetwork(service) | |
4597 | |
4598 def ForgetWifiNetwork(self, service_path): | |
4599 """Forget a remembered network by its service path. | |
4600 | |
4601 This function is equivalent to clicking the 'Forget Network' button in the | |
4602 chrome://settings/internet page. This function does not indicate whether | |
4603 or not forget succeeded or failed. It is up to the caller to call | |
4604 GetNetworkInfo to check the updated remembered_wifi list to verify the | |
4605 service has been removed. | |
4606 | |
4607 Args: | |
4608 service_path: Flimflam path that defines the remembered network. | |
4609 | |
4610 Raises: | |
4611 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
4612 """ | |
4613 # Usually the service_path is prepended with '/service/', such as when the | |
4614 # service path is retrieved from GetNetworkInfo. ForgetWifiNetwork works | |
4615 # only for service paths where this has already been stripped. | |
4616 service_path = service_path.split('/service/')[-1] | |
4617 cmd_dict = { | |
4618 'command': 'ForgetWifiNetwork', | |
4619 'service_path': service_path, | |
4620 } | |
4621 self._GetResultFromJSONRequest(cmd_dict, windex=None, timeout=50000) | |
4622 | |
4623 def ConnectToHiddenWifiNetwork(self, ssid, security, password='', | |
4624 shared=True, save_credentials=False): | |
4625 """Connect to a wifi network by its service path. | |
4626 | |
4627 Blocks until connection succeeds or fails. | |
4628 | |
4629 Args: | |
4630 ssid: The SSID of the network to connect to. | |
4631 security: The network's security type. One of: 'SECURITY_NONE', | |
4632 'SECURITY_WEP', 'SECURITY_WPA', 'SECURITY_RSN', 'SECURITY_8021X' | |
4633 password: Passphrase for connecting to the wifi network. | |
4634 shared: Boolean value specifying whether the network should be shared. | |
4635 save_credentials: Boolean value specifying whether 802.1x credentials are | |
4636 saved. | |
4637 | |
4638 Returns: | |
4639 An error string if an error occured. | |
4640 None otherwise. | |
4641 | |
4642 Raises: | |
4643 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
4644 """ | |
4645 assert security in ('SECURITY_NONE', 'SECURITY_WEP', 'SECURITY_WPA', | |
4646 'SECURITY_RSN', 'SECURITY_8021X') | |
4647 cmd_dict = { | |
4648 'command': 'ConnectToHiddenWifiNetwork', | |
4649 'ssid': ssid, | |
4650 'security': security, | |
4651 'password': password, | |
4652 'shared': shared, | |
4653 'save_credentials': save_credentials, | |
4654 } | |
4655 result = self._GetResultFromJSONRequest( | |
4656 cmd_dict, windex=None, timeout=50000) | |
4657 return result.get('error_string') | |
4658 | |
4659 def EnableSpokenFeedback(self, enabled): | 4495 def EnableSpokenFeedback(self, enabled): |
4660 """Enables or disables spoken feedback accessibility mode. | 4496 """Enables or disables spoken feedback accessibility mode. |
4661 | 4497 |
4662 Args: | 4498 Args: |
4663 enabled: Boolean value indicating the desired state of spoken feedback. | 4499 enabled: Boolean value indicating the desired state of spoken feedback. |
4664 | 4500 |
4665 Raises: | 4501 Raises: |
4666 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 4502 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
4667 """ | 4503 """ |
4668 cmd_dict = { | 4504 cmd_dict = { |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5581 successful = result.wasSuccessful() | 5417 successful = result.wasSuccessful() |
5582 if not successful: | 5418 if not successful: |
5583 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5419 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
5584 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5420 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
5585 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5421 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
5586 sys.exit(not successful) | 5422 sys.exit(not successful) |
5587 | 5423 |
5588 | 5424 |
5589 if __name__ == '__main__': | 5425 if __name__ == '__main__': |
5590 Main() | 5426 Main() |
OLD | NEW |