OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 | 741 |
742 def StartSyncServer(self): | 742 def StartSyncServer(self): |
743 """Start a local sync server. | 743 """Start a local sync server. |
744 | 744 |
745 Adds a dictionary attribute 'ports' in returned object. | 745 Adds a dictionary attribute 'ports' in returned object. |
746 | 746 |
747 Returns: | 747 Returns: |
748 A handle to Sync Server, an instance of TestServer | 748 A handle to Sync Server, an instance of TestServer |
749 """ | 749 """ |
750 sync_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_SYNC, | 750 sync_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_SYNC, |
751 pyautolib.FilePath('')) | 751 '127.0.0.1', |
| 752 pyautolib.FilePath('')) |
752 assert sync_server.Start(), 'Could not start sync server' | 753 assert sync_server.Start(), 'Could not start sync server' |
753 sync_server.ports = dict(port=sync_server.GetPort(), | 754 sync_server.ports = dict(port=sync_server.GetPort(), |
754 xmpp_port=sync_server.GetSyncXmppPort()) | 755 xmpp_port=sync_server.GetSyncXmppPort()) |
755 logging.debug('Started sync server at ports %s.', sync_server.ports) | 756 logging.debug('Started sync server at ports %s.', sync_server.ports) |
756 return sync_server | 757 return sync_server |
757 | 758 |
758 def StopSyncServer(self, sync_server): | 759 def StopSyncServer(self, sync_server): |
759 """Stop the local sync server.""" | 760 """Stop the local sync server.""" |
760 assert sync_server, 'Sync Server not yet started' | 761 assert sync_server, 'Sync Server not yet started' |
761 assert sync_server.Stop(), 'Could not stop sync server' | 762 assert sync_server.Stop(), 'Could not stop sync server' |
762 logging.debug('Stopped sync server at ports %s.', sync_server.ports) | 763 logging.debug('Stopped sync server at ports %s.', sync_server.ports) |
763 | 764 |
764 def StartFTPServer(self, data_dir): | 765 def StartFTPServer(self, data_dir): |
765 """Start a local file server hosting data files over ftp:// | 766 """Start a local file server hosting data files over ftp:// |
766 | 767 |
767 Args: | 768 Args: |
768 data_dir: path where ftp files should be served | 769 data_dir: path where ftp files should be served |
769 | 770 |
770 Returns: | 771 Returns: |
771 handle to FTP Server, an instance of TestServer | 772 handle to FTP Server, an instance of TestServer |
772 """ | 773 """ |
773 ftp_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_FTP, | 774 ftp_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_FTP, |
774 pyautolib.FilePath(data_dir)) | 775 '127.0.0.1', |
| 776 pyautolib.FilePath(data_dir)) |
775 assert ftp_server.Start(), 'Could not start ftp server' | 777 assert ftp_server.Start(), 'Could not start ftp server' |
776 logging.debug('Started ftp server at "%s".', data_dir) | 778 logging.debug('Started ftp server at "%s".', data_dir) |
777 return ftp_server | 779 return ftp_server |
778 | 780 |
779 def StopFTPServer(self, ftp_server): | 781 def StopFTPServer(self, ftp_server): |
780 """Stop the local ftp server.""" | 782 """Stop the local ftp server.""" |
781 assert ftp_server, 'FTP Server not yet started' | 783 assert ftp_server, 'FTP Server not yet started' |
782 assert ftp_server.Stop(), 'Could not stop ftp server' | 784 assert ftp_server.Stop(), 'Could not stop ftp server' |
783 logging.debug('Stopped ftp server.') | 785 logging.debug('Stopped ftp server.') |
784 | 786 |
785 def StartHTTPServer(self, data_dir): | 787 def StartHTTPServer(self, data_dir): |
786 """Starts a local HTTP TestServer serving files from |data_dir|. | 788 """Starts a local HTTP TestServer serving files from |data_dir|. |
787 | 789 |
788 Args: | 790 Args: |
789 data_dir: path where the TestServer should serve files from. This will be | 791 data_dir: path where the TestServer should serve files from. This will be |
790 appended to the source dir to get the final document root. | 792 appended to the source dir to get the final document root. |
791 | 793 |
792 Returns: | 794 Returns: |
793 handle to the HTTP TestServer | 795 handle to the HTTP TestServer |
794 """ | 796 """ |
795 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, | 797 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, |
796 pyautolib.FilePath(data_dir)) | 798 '127.0.0.1', |
| 799 pyautolib.FilePath(data_dir)) |
797 assert http_server.Start(), 'Could not start HTTP server' | 800 assert http_server.Start(), 'Could not start HTTP server' |
798 logging.debug('Started HTTP server at "%s".', data_dir) | 801 logging.debug('Started HTTP server at "%s".', data_dir) |
799 return http_server | 802 return http_server |
800 | 803 |
801 def StopHTTPServer(self, http_server): | 804 def StopHTTPServer(self, http_server): |
802 assert http_server, 'HTTP server not yet started' | 805 assert http_server, 'HTTP server not yet started' |
803 assert http_server.Stop(), 'Cloud not stop the HTTP server' | 806 assert http_server.Stop(), 'Cloud not stop the HTTP server' |
804 logging.debug('Stopped HTTP server.') | 807 logging.debug('Stopped HTTP server.') |
805 | 808 |
806 def StartHttpsServer(self, cert_type, data_dir): | 809 def StartHttpsServer(self, cert_type, data_dir): |
(...skipping 3823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4630 global _CHROME_DRIVER_FACTORY | 4633 global _CHROME_DRIVER_FACTORY |
4631 if _CHROME_DRIVER_FACTORY is not None: | 4634 if _CHROME_DRIVER_FACTORY is not None: |
4632 _CHROME_DRIVER_FACTORY.Stop() | 4635 _CHROME_DRIVER_FACTORY.Stop() |
4633 | 4636 |
4634 def _StartHTTPServer(self): | 4637 def _StartHTTPServer(self): |
4635 """Start a local file server hosting data files over http://""" | 4638 """Start a local file server hosting data files over http://""" |
4636 global _HTTP_SERVER | 4639 global _HTTP_SERVER |
4637 assert not _HTTP_SERVER, 'HTTP Server already started' | 4640 assert not _HTTP_SERVER, 'HTTP Server already started' |
4638 http_data_dir = _OPTIONS.http_data_dir | 4641 http_data_dir = _OPTIONS.http_data_dir |
4639 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, | 4642 http_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_HTTP, |
4640 pyautolib.FilePath(http_data_dir)) | 4643 '127.0.0.1', |
| 4644 pyautolib.FilePath(http_data_dir)) |
4641 assert http_server.Start(), 'Could not start http server' | 4645 assert http_server.Start(), 'Could not start http server' |
4642 _HTTP_SERVER = http_server | 4646 _HTTP_SERVER = http_server |
4643 logging.debug('Started http server at "%s".', http_data_dir) | 4647 logging.debug('Started http server at "%s".', http_data_dir) |
4644 | 4648 |
4645 def _StopHTTPServer(self): | 4649 def _StopHTTPServer(self): |
4646 """Stop the local http server.""" | 4650 """Stop the local http server.""" |
4647 global _HTTP_SERVER | 4651 global _HTTP_SERVER |
4648 assert _HTTP_SERVER, 'HTTP Server not yet started' | 4652 assert _HTTP_SERVER, 'HTTP Server not yet started' |
4649 assert _HTTP_SERVER.Stop(), 'Could not stop http server' | 4653 assert _HTTP_SERVER.Stop(), 'Could not stop http server' |
4650 _HTTP_SERVER = None | 4654 _HTTP_SERVER = None |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5024 successful = result.wasSuccessful() | 5028 successful = result.wasSuccessful() |
5025 if not successful: | 5029 if not successful: |
5026 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5030 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
5027 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5031 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
5028 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5032 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
5029 sys.exit(not successful) | 5033 sys.exit(not successful) |
5030 | 5034 |
5031 | 5035 |
5032 if __name__ == '__main__': | 5036 if __name__ == '__main__': |
5033 Main() | 5037 Main() |
OLD | NEW |