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 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1959 if isinstance(url, GURL): | 1959 if isinstance(url, GURL): |
1960 url = url.spec() | 1960 url = url.spec() |
1961 cmd_dict = { | 1961 cmd_dict = { |
1962 'command': 'SetCookieInBrowserContext', | 1962 'command': 'SetCookieInBrowserContext', |
1963 'url': url, | 1963 'url': url, |
1964 'value': value, | 1964 'value': value, |
1965 'windex': windex, | 1965 'windex': windex, |
1966 } | 1966 } |
1967 self._GetResultFromJSONRequest(cmd_dict, windex=None) | 1967 self._GetResultFromJSONRequest(cmd_dict, windex=None) |
1968 | 1968 |
1969 def GetInstantInfo(self, windex=0): | |
1970 """Return info about the instant overlay tab. | |
1971 | |
1972 Args: | |
1973 windex: The window index, default is 0. | |
1974 | |
1975 Returns: | |
1976 A dictionary. | |
1977 Examples: | |
1978 { u'enabled': True, | |
1979 u'active': True, | |
1980 u'current': True, | |
1981 u'loading': True, | |
1982 u'location': u'http://cnn.com/', | |
1983 u'showing': False, | |
1984 u'title': u'CNN.com - Breaking News'}, | |
1985 | |
1986 { u'enabled': False } | |
1987 """ | |
1988 cmd_dict = {'command': 'GetInstantInfo'} | |
1989 return self._GetResultFromJSONRequest(cmd_dict, windex=windex)['instant'] | |
1990 | |
1991 def GetSearchEngineInfo(self, windex=0): | 1969 def GetSearchEngineInfo(self, windex=0): |
1992 """Return info about search engines. | 1970 """Return info about search engines. |
1993 | 1971 |
1994 Args: | 1972 Args: |
1995 windex: The window index, default is 0. | 1973 windex: The window index, default is 0. |
1996 | 1974 |
1997 Returns: | 1975 Returns: |
1998 An ordered list of dictionaries describing info about each search engine. | 1976 An ordered list of dictionaries describing info about each search engine. |
1999 | 1977 |
2000 Example: | 1978 Example: |
(...skipping 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3684 'command': 'HeapProfilerDump', | 3662 'command': 'HeapProfilerDump', |
3685 'process_type': process_type, | 3663 'process_type': process_type, |
3686 'reason': reason, | 3664 'reason': reason, |
3687 'windex': windex, | 3665 'windex': windex, |
3688 'tab_index': tab_index, | 3666 'tab_index': tab_index, |
3689 } | 3667 } |
3690 self._GetResultFromJSONRequest(cmd_dict) | 3668 self._GetResultFromJSONRequest(cmd_dict) |
3691 else: | 3669 else: |
3692 logging.warn('Heap-profiling is not supported in this OS.') | 3670 logging.warn('Heap-profiling is not supported in this OS.') |
3693 | 3671 |
3694 def AppendSwitchASCIIToCommandLine(self, switch, value): | |
3695 """Appends --switch=value to the command line. | |
3696 | |
3697 NOTE: This doesn't change the startup commandline, i.e., flags used to | |
3698 launch the browser. Use ExtraChromeFlags() if you want to do that. Instead, | |
3699 use this if you want to alter flags dynamically, say to affect a feature | |
3700 that looks at the flags everytime, instead of only at program startup. | |
3701 | |
3702 Note that although this appends the switch, CommandLine::Get*() methods | |
3703 generally return only the most recently added value, so this effectively | |
3704 overrides any existing switch with the same name. | |
3705 | |
3706 Args: | |
3707 switch: the name of the switch to be set. | |
3708 value: the value to be set for the switch. | |
3709 """ | |
3710 cmd_dict = { | |
3711 'command': 'AppendSwitchASCIIToCommandLine', | |
3712 'switch': switch, | |
3713 'value': value, | |
3714 } | |
3715 self._GetResultFromJSONRequest(cmd_dict, windex=None) | |
3716 | |
3717 def GetNTPThumbnails(self): | 3672 def GetNTPThumbnails(self): |
3718 """Return a list of info about the sites in the NTP most visited section. | 3673 """Return a list of info about the sites in the NTP most visited section. |
3719 SAMPLE: | 3674 SAMPLE: |
3720 [{ u'title': u'Google', | 3675 [{ u'title': u'Google', |
3721 u'url': u'http://www.google.com'}, | 3676 u'url': u'http://www.google.com'}, |
3722 { | 3677 { |
3723 u'title': u'Yahoo', | 3678 u'title': u'Yahoo', |
3724 u'url': u'http://www.yahoo.com'}] | 3679 u'url': u'http://www.yahoo.com'}] |
3725 """ | 3680 """ |
3726 return self._GetNTPInfo()['most_visited'] | 3681 return self._GetNTPInfo()['most_visited'] |
(...skipping 2526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6253 successful = result.wasSuccessful() | 6208 successful = result.wasSuccessful() |
6254 if not successful: | 6209 if not successful: |
6255 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6210 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
6256 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6211 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
6257 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6212 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
6258 sys.exit(not successful) | 6213 sys.exit(not successful) |
6259 | 6214 |
6260 | 6215 |
6261 if __name__ == '__main__': | 6216 if __name__ == '__main__': |
6262 Main() | 6217 Main() |
OLD | NEW |