| 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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 | 844 |
| 845 def StartFTPServer(self, data_dir): | 845 def StartFTPServer(self, data_dir): |
| 846 """Start a local file server hosting data files over ftp:// | 846 """Start a local file server hosting data files over ftp:// |
| 847 | 847 |
| 848 Args: | 848 Args: |
| 849 data_dir: path where ftp files should be served | 849 data_dir: path where ftp files should be served |
| 850 | 850 |
| 851 Returns: | 851 Returns: |
| 852 handle to FTP Server, an instance of TestServer | 852 handle to FTP Server, an instance of TestServer |
| 853 """ | 853 """ |
| 854 source_dir = os.path.normpath(pyauto_paths.GetSourceDir()) |
| 855 path = os.path.join(source_dir, data_dir) |
| 854 ftp_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_FTP, | 856 ftp_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_FTP, |
| 855 '127.0.0.1', | 857 '127.0.0.1', |
| 856 pyautolib.FilePath(data_dir)) | 858 pyautolib.FilePath(path)) |
| 857 assert ftp_server.Start(), 'Could not start ftp server' | 859 assert ftp_server.Start(), 'Could not start ftp server' |
| 858 logging.debug('Started ftp server at "%s".', data_dir) | 860 logging.debug('Started ftp server at "%s".', data_dir) |
| 859 return ftp_server | 861 return ftp_server |
| 860 | 862 |
| 861 def StopFTPServer(self, ftp_server): | 863 def StopFTPServer(self, ftp_server): |
| 862 """Stop the local ftp server.""" | 864 """Stop the local ftp server.""" |
| 863 assert ftp_server, 'FTP Server not yet started' | 865 assert ftp_server, 'FTP Server not yet started' |
| 864 assert ftp_server.Stop(), 'Could not stop ftp server' | 866 assert ftp_server.Stop(), 'Could not stop ftp server' |
| 865 logging.debug('Stopped ftp server.') | 867 logging.debug('Stopped ftp server.') |
| 866 | 868 |
| 867 def StartHTTPServer(self, data_dir): | 869 def StartHTTPServer(self, data_dir): |
| 868 """Starts a local HTTP TestServer serving files from |data_dir|. | 870 """Starts a local HTTP TestServer serving files from |data_dir|. |
| 869 | 871 |
| 870 Args: | 872 Args: |
| 871 data_dir: path where the TestServer should serve files from. This will be | 873 data_dir: path where the TestServer should serve files from. This will be |
| 872 appended to the source dir to get the final document root. | 874 appended to the source dir to get the final document root. |
| 873 | 875 |
| 874 Returns: | 876 Returns: |
| 875 handle to the HTTP TestServer | 877 handle to the HTTP TestServer |
| 876 """ | 878 """ |
| 879 source_dir = os.path.normpath(pyauto_paths.GetSourceDir()) |
| 880 path = os.path.join(source_dir, data_dir) |
| 877 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, | 881 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, |
| 878 '127.0.0.1', | 882 '127.0.0.1', |
| 879 pyautolib.FilePath(data_dir)) | 883 pyautolib.FilePath(path)) |
| 880 assert http_server.Start(), 'Could not start HTTP server' | 884 assert http_server.Start(), 'Could not start HTTP server' |
| 881 logging.debug('Started HTTP server at "%s".', data_dir) | 885 logging.debug('Started HTTP server at "%s".', data_dir) |
| 882 return http_server | 886 return http_server |
| 883 | 887 |
| 884 def StopHTTPServer(self, http_server): | 888 def StopHTTPServer(self, http_server): |
| 885 assert http_server, 'HTTP server not yet started' | 889 assert http_server, 'HTTP server not yet started' |
| 886 assert http_server.Stop(), 'Cloud not stop the HTTP server' | 890 assert http_server.Stop(), 'Cloud not stop the HTTP server' |
| 887 logging.debug('Stopped HTTP server.') | 891 logging.debug('Stopped HTTP server.') |
| 888 | 892 |
| 889 def StartHttpsServer(self, cert_type, data_dir): | 893 def StartHttpsServer(self, cert_type, data_dir): |
| 890 """Starts a local HTTPS TestServer serving files from |data_dir|. | 894 """Starts a local HTTPS TestServer serving files from |data_dir|. |
| 891 | 895 |
| 892 Args: | 896 Args: |
| 893 cert_type: An instance of SSLOptions.ServerCertificate for three | 897 cert_type: An instance of SSLOptions.ServerCertificate for three |
| 894 certificate types: ok, expired, or mismatch. | 898 certificate types: ok, expired, or mismatch. |
| 895 data_dir: The path where TestServer should serve files from. This is | 899 data_dir: The path where TestServer should serve files from. This is |
| 896 appended to the source dir to get the final document root. | 900 appended to the source dir to get the final document root. |
| 897 | 901 |
| 898 Returns: | 902 Returns: |
| 899 Handle to the HTTPS TestServer | 903 Handle to the HTTPS TestServer |
| 900 """ | 904 """ |
| 905 source_dir = os.path.normpath(pyauto_paths.GetSourceDir()) |
| 906 path = os.path.join(source_dir, data_dir) |
| 901 https_server = pyautolib.TestServer( | 907 https_server = pyautolib.TestServer( |
| 902 pyautolib.TestServer.TYPE_HTTPS, | 908 pyautolib.TestServer.TYPE_HTTPS, |
| 903 pyautolib.SSLOptions(cert_type), | 909 pyautolib.SSLOptions(cert_type), |
| 904 pyautolib.FilePath(data_dir)) | 910 pyautolib.FilePath(path)) |
| 905 assert https_server.Start(), 'Could not start HTTPS server.' | 911 assert https_server.Start(), 'Could not start HTTPS server.' |
| 906 logging.debug('Start HTTPS server at "%s".' % data_dir) | 912 logging.debug('Start HTTPS server at "%s".' % data_dir) |
| 907 return https_server | 913 return https_server |
| 908 | 914 |
| 909 def StopHttpsServer(self, https_server): | 915 def StopHttpsServer(self, https_server): |
| 910 assert https_server, 'HTTPS server not yet started.' | 916 assert https_server, 'HTTPS server not yet started.' |
| 911 assert https_server.Stop(), 'Could not stop the HTTPS server.' | 917 assert https_server.Stop(), 'Could not stop the HTTPS server.' |
| 912 logging.debug('Stopped HTTPS server.') | 918 logging.debug('Stopped HTTPS server.') |
| 913 | 919 |
| 914 class ActionTimeoutChanger(object): | 920 class ActionTimeoutChanger(object): |
| (...skipping 4929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5844 | 5850 |
| 5845 global _CHROME_DRIVER_FACTORY | 5851 global _CHROME_DRIVER_FACTORY |
| 5846 if _CHROME_DRIVER_FACTORY is not None: | 5852 if _CHROME_DRIVER_FACTORY is not None: |
| 5847 _CHROME_DRIVER_FACTORY.Stop() | 5853 _CHROME_DRIVER_FACTORY.Stop() |
| 5848 | 5854 |
| 5849 def _StartHTTPServer(self): | 5855 def _StartHTTPServer(self): |
| 5850 """Start a local file server hosting data files over http://""" | 5856 """Start a local file server hosting data files over http://""" |
| 5851 global _HTTP_SERVER | 5857 global _HTTP_SERVER |
| 5852 assert not _HTTP_SERVER, 'HTTP Server already started' | 5858 assert not _HTTP_SERVER, 'HTTP Server already started' |
| 5853 http_data_dir = _OPTIONS.http_data_dir | 5859 http_data_dir = _OPTIONS.http_data_dir |
| 5860 source_dir = os.path.normpath(pyauto_paths.GetSourceDir()) |
| 5861 path = os.path.join(source_dir, http_data_dir) |
| 5854 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, | 5862 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, |
| 5855 '127.0.0.1', | 5863 '127.0.0.1', |
| 5856 pyautolib.FilePath(http_data_dir)) | 5864 pyautolib.FilePath(path)) |
| 5857 assert http_server.Start(), 'Could not start http server' | 5865 assert http_server.Start(), 'Could not start http server' |
| 5858 _HTTP_SERVER = http_server | 5866 _HTTP_SERVER = http_server |
| 5859 logging.debug('Started http server at "%s".', http_data_dir) | 5867 logging.debug('Started http server at "%s".', http_data_dir) |
| 5860 | 5868 |
| 5861 def _StopHTTPServer(self): | 5869 def _StopHTTPServer(self): |
| 5862 """Stop the local http server.""" | 5870 """Stop the local http server.""" |
| 5863 global _HTTP_SERVER | 5871 global _HTTP_SERVER |
| 5864 assert _HTTP_SERVER, 'HTTP Server not yet started' | 5872 assert _HTTP_SERVER, 'HTTP Server not yet started' |
| 5865 assert _HTTP_SERVER.Stop(), 'Could not stop http server' | 5873 assert _HTTP_SERVER.Stop(), 'Could not stop http server' |
| 5866 _HTTP_SERVER = None | 5874 _HTTP_SERVER = None |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6253 successful = result.wasSuccessful() | 6261 successful = result.wasSuccessful() |
| 6254 if not successful: | 6262 if not successful: |
| 6255 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6263 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
| 6256 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6264 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
| 6257 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6265 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
| 6258 sys.exit(not successful) | 6266 sys.exit(not successful) |
| 6259 | 6267 |
| 6260 | 6268 |
| 6261 if __name__ == '__main__': | 6269 if __name__ == '__main__': |
| 6262 Main() | 6270 Main() |
| OLD | NEW |