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 2405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2416 """ | 2416 """ |
2417 cmd_dict = { 'command': 'SignoutInScreenLocker' } | 2417 cmd_dict = { 'command': 'SignoutInScreenLocker' } |
2418 self._GetResultFromJSONRequest(cmd_dict, windex=-1) | 2418 self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
2419 | 2419 |
2420 def GetBatteryInfo(self): | 2420 def GetBatteryInfo(self): |
2421 """Get details about battery state. | 2421 """Get details about battery state. |
2422 | 2422 |
2423 Returns: | 2423 Returns: |
2424 A dictionary with the following keys: | 2424 A dictionary with the following keys: |
2425 | 2425 |
2426 'battery_is_present' : bool | 2426 'battery_is_present': bool |
2427 'line_power_on' : bool | 2427 'line_power_on': bool |
2428 if 'battery_is_present': | 2428 if 'battery_is_present': |
2429 'battery_percentage' : float (0 ~ 100) | 2429 'battery_percentage': float (0 ~ 100) |
2430 'battery_fully_charged' : bool | 2430 'battery_fully_charged': bool |
2431 if 'line_power_on': | 2431 if 'line_power_on': |
2432 'battery_time_to_full' : int (seconds) | 2432 'battery_time_to_full': int (seconds) |
2433 else: | 2433 else: |
2434 'battery_time_to_empty' : int (seconds) | 2434 'battery_time_to_empty': int (seconds) |
2435 | 2435 |
2436 If it is still calculating the time left, 'battery_time_to_full' | 2436 If it is still calculating the time left, 'battery_time_to_full' |
2437 and 'battery_time_to_empty' will be absent. | 2437 and 'battery_time_to_empty' will be absent. |
2438 | 2438 |
2439 Use 'battery_fully_charged' instead of 'battery_percentage' | 2439 Use 'battery_fully_charged' instead of 'battery_percentage' |
2440 or 'battery_time_to_full' to determine whether the battery | 2440 or 'battery_time_to_full' to determine whether the battery |
2441 is fully charged, since the percentage is only approximate. | 2441 is fully charged, since the percentage is only approximate. |
2442 | 2442 |
2443 Sample: | 2443 Sample: |
2444 { u'battery_is_present': True, | 2444 { u'battery_is_present': True, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2499 """Causes ChromeOS to scan for available wifi networks. | 2499 """Causes ChromeOS to scan for available wifi networks. |
2500 | 2500 |
2501 Blocks until scanning is complete. | 2501 Blocks until scanning is complete. |
2502 | 2502 |
2503 Raises: | 2503 Raises: |
2504 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 2504 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
2505 """ | 2505 """ |
2506 cmd_dict = { 'command': 'NetworkScan' } | 2506 cmd_dict = { 'command': 'NetworkScan' } |
2507 self._GetResultFromJSONRequest(cmd_dict, windex=-1) | 2507 self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
2508 | 2508 |
| 2509 PROXY_TYPE_DIRECT = 1 |
| 2510 PROXY_TYPE_MANUAL = 2 |
| 2511 PROXY_TYPE_PAC = 3 |
| 2512 |
| 2513 def GetProxyTypeName(self, proxy_type): |
| 2514 values = { self.PROXY_TYPE_DIRECT: 'Direct Internet connection', |
| 2515 self.PROXY_TYPE_MANUAL: 'Manual proxy configuration', |
| 2516 self.PROXY_TYPE_PAC: 'Automatic proxy configuration' } |
| 2517 return values[proxy_type] |
| 2518 |
| 2519 def GetProxySettingsOnChromeOS(self): |
| 2520 """Get current proxy settings on Chrome OS. |
| 2521 |
| 2522 Returns: |
| 2523 A dictionary. See SetProxySettings() below |
| 2524 for the full list of possible dictionary keys. |
| 2525 |
| 2526 Samples: |
| 2527 { u'ignorelist': [], |
| 2528 u'single': False, |
| 2529 u'type': 1} |
| 2530 |
| 2531 { u'ignorelist': [u'www.example.com', u'www.example2.com'], |
| 2532 u'single': True, |
| 2533 u'singlehttp': u'24.27.78.152', |
| 2534 u'singlehttpport': 1728, |
| 2535 u'type': 2} |
| 2536 |
| 2537 { u'ignorelist': [], |
| 2538 u'pacurl': u'http://example.com/config.pac', |
| 2539 u'single': False, |
| 2540 u'type': 3} |
| 2541 |
| 2542 Raises: |
| 2543 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2544 """ |
| 2545 cmd_dict = { 'command': 'GetProxySettings' } |
| 2546 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
| 2547 |
| 2548 def SetProxySettingsOnChromeOS(self, key, value): |
| 2549 """Set a proxy setting on Chrome OS. |
| 2550 |
| 2551 Owner must be logged in for these to persist. |
| 2552 If user is not logged in or is logged in as non-owner or guest, |
| 2553 proxy settings do not persist across browser restarts or login/logout. |
| 2554 |
| 2555 Valid settings are: |
| 2556 'type': int - Type of proxy. Should be one of: |
| 2557 PROXY_TYPE_DIRECT, PROXY_TYPE_MANUAL, PROXY_TYPE_PAC. |
| 2558 'ignorelist': list - The list of hosts and domains to ignore. |
| 2559 |
| 2560 These settings set 'type' to PROXY_TYPE_MANUAL: |
| 2561 'single': boolean - Whether to use the same proxy for all protocols. |
| 2562 |
| 2563 These settings set 'single' to True: |
| 2564 'singlehttp': string - If single is true, the proxy address to use. |
| 2565 'singlehttpport': int - If single is true, the proxy port to use. |
| 2566 |
| 2567 These settings set 'single' to False: |
| 2568 'httpurl': string - HTTP proxy address. |
| 2569 'httpport': int - HTTP proxy port. |
| 2570 'httpsurl': string - Secure HTTP proxy address. |
| 2571 'httpsport': int - Secure HTTP proxy port. |
| 2572 'ftpurl': string - FTP proxy address. |
| 2573 'ftpport': int - FTP proxy port. |
| 2574 'socks': string - SOCKS host address. |
| 2575 'socksport': int - SOCKS host port. |
| 2576 |
| 2577 This setting sets 'type' to PROXY_TYPE_PAC: |
| 2578 'pacurl': string - Autoconfiguration URL. |
| 2579 |
| 2580 Examples: |
| 2581 # Sets direct internet connection, no proxy. |
| 2582 self.SetProxySettings('type', self.PROXY_TYPE_DIRECT) |
| 2583 |
| 2584 # Sets manual proxy configuration, same proxy for all protocols. |
| 2585 self.SetProxySettings('singlehttp', '24.27.78.152') |
| 2586 self.SetProxySettings('singlehttpport', 1728) |
| 2587 self.SetProxySettings('ignorelist', ['www.example.com', 'example2.com']) |
| 2588 |
| 2589 # Sets automatic proxy configuration with the specified PAC url. |
| 2590 self.SetProxySettings('pacurl', 'http://example.com/config.pac') |
| 2591 |
| 2592 Raises: |
| 2593 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 2594 """ |
| 2595 cmd_dict = { |
| 2596 'command': 'SetProxySettings', |
| 2597 'key': key, |
| 2598 'value': value, |
| 2599 } |
| 2600 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) |
| 2601 |
2509 def ConnectToWifiNetwork(self, service_path, | 2602 def ConnectToWifiNetwork(self, service_path, |
2510 password='', identity='', certpath=''): | 2603 password='', identity='', certpath=''): |
2511 """Connect to a wifi network by its service path. | 2604 """Connect to a wifi network by its service path. |
2512 | 2605 |
2513 Blocks until connection succeeds or fails. | 2606 Blocks until connection succeeds or fails. |
2514 | 2607 |
2515 Returns: | 2608 Returns: |
2516 A tuple. | 2609 A tuple. |
2517 The first element is True on success and False on failure. | 2610 The first element is True on success and False on failure. |
2518 The second element is None on success or an error string on failure. | 2611 The second element is None on success or an error string on failure. |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2937 if self._options.verbose: | 3030 if self._options.verbose: |
2938 verbosity = 2 | 3031 verbosity = 2 |
2939 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) | 3032 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) |
2940 del loaded_tests # Need to destroy test cases before the suite | 3033 del loaded_tests # Need to destroy test cases before the suite |
2941 del pyauto_suite | 3034 del pyauto_suite |
2942 sys.exit(not result.wasSuccessful()) | 3035 sys.exit(not result.wasSuccessful()) |
2943 | 3036 |
2944 | 3037 |
2945 if __name__ == '__main__': | 3038 if __name__ == '__main__': |
2946 Main() | 3039 Main() |
OLD | NEW |