Chromium Code Reviews| 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.get(proxy_type, 'Unknown proxy type') | |
|
Nirnimesh
2011/04/05 19:27:53
Remove the default arg. It should return None in c
dtu
2011/04/05 21:29:10
Done.
| |
| 2518 | |
| 2519 def GetProxySettings(self): | |
| 2520 """Get current proxy settings. | |
| 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 SetProxySettings(self, key, value): | |
| 2549 """Set a proxy setting. | |
| 2550 | |
| 2551 Owner must be logged in for these to take effect. | |
|
Nirnimesh
2011/04/05 19:27:53
Did you mean 'take effect' or persist?
So if a non
dtu
2011/04/05 21:29:10
Fixed.
| |
| 2552 | |
| 2553 Valid settings are: | |
| 2554 'type': int - Type of proxy. Should be one of: | |
| 2555 PROXY_TYPE_DIRECT, PROXY_TYPE_MANUAL, PROXY_TYPE_PAC. | |
| 2556 'ignorelist': list - The list of hosts and domains to ignore. | |
| 2557 | |
| 2558 These settings set 'type' to PROXY_TYPE_MANUAL: | |
| 2559 'single': boolean - Whether to use the same proxy for all protocols. | |
| 2560 | |
| 2561 These settings set 'single' to True: | |
| 2562 'singlehttp': string - If single is true, the proxy address to use. | |
| 2563 'singlehttpport': int - If single is true, the proxy port to use. | |
| 2564 | |
| 2565 These settings set 'single' to False: | |
| 2566 'httpurl': string - HTTP proxy address. | |
| 2567 'httpport': int - HTTP proxy port. | |
| 2568 'httpsurl': string - Secure HTTP proxy address. | |
| 2569 'httpsport': int - Secure HTTP proxy port. | |
| 2570 'ftpurl': string - FTP proxy address. | |
| 2571 'ftpport': int - FTP proxy port. | |
| 2572 'socks': string - SOCKS host address. | |
| 2573 'socksport': int - SOCKS host port. | |
| 2574 | |
| 2575 This setting sets 'type' to PROXY_TYPE_PAC: | |
| 2576 'pacurl': string - Autoconfiguration URL. | |
| 2577 | |
| 2578 Examples: | |
| 2579 # Sets direct internet connection, no proxy. | |
| 2580 self.SetProxySettings('type', self.PROXY_TYPE_DIRECT) | |
| 2581 | |
| 2582 # Sets manual proxy configuration, same proxy for all protocols. | |
| 2583 self.SetProxySettings('singlehttp', '24.27.78.152') | |
| 2584 self.SetProxySettings('singlehttpport', 1728) | |
| 2585 self.SetProxySettings('ignorelist', ['www.example.com', 'example2.com']) | |
| 2586 | |
| 2587 # Sets automatic proxy configuration with the specified PAC url. | |
| 2588 self.SetProxySettings('pacurl', 'http://example.com/config.pac') | |
| 2589 | |
| 2590 Raises: | |
| 2591 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
| 2592 """ | |
| 2593 cmd_dict = { | |
| 2594 'command': 'SetProxySettings', | |
| 2595 'key': key, | |
| 2596 'value': value, | |
| 2597 } | |
| 2598 return self._GetResultFromJSONRequest(cmd_dict, windex=-1) | |
| 2599 | |
| 2509 def ConnectToWifiNetwork(self, service_path, | 2600 def ConnectToWifiNetwork(self, service_path, |
| 2510 password='', identity='', certpath=''): | 2601 password='', identity='', certpath=''): |
| 2511 """Connect to a wifi network by its service path. | 2602 """Connect to a wifi network by its service path. |
| 2512 | 2603 |
| 2513 Blocks until connection succeeds or fails. | 2604 Blocks until connection succeeds or fails. |
| 2514 | 2605 |
| 2515 Returns: | 2606 Returns: |
| 2516 A tuple. | 2607 A tuple. |
| 2517 The first element is True on success and False on failure. | 2608 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. | 2609 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: | 3028 if self._options.verbose: |
| 2938 verbosity = 2 | 3029 verbosity = 2 |
| 2939 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) | 3030 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite) |
| 2940 del loaded_tests # Need to destroy test cases before the suite | 3031 del loaded_tests # Need to destroy test cases before the suite |
| 2941 del pyauto_suite | 3032 del pyauto_suite |
| 2942 sys.exit(not result.wasSuccessful()) | 3033 sys.exit(not result.wasSuccessful()) |
| 2943 | 3034 |
| 2944 | 3035 |
| 2945 if __name__ == '__main__': | 3036 if __name__ == '__main__': |
| 2946 Main() | 3037 Main() |
| OLD | NEW |