| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 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. |
| 11 | 11 |
| 12 Ref: http://dev.chromium.org/developers/testing/pyauto | 12 Ref: http://dev.chromium.org/developers/testing/pyauto |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 """Terminate the given pid. | 753 """Terminate the given pid. |
| 754 | 754 |
| 755 If the pid refers to a renderer, use KillRendererProcess instead. | 755 If the pid refers to a renderer, use KillRendererProcess instead. |
| 756 """ | 756 """ |
| 757 if PyUITest.IsWin(): | 757 if PyUITest.IsWin(): |
| 758 subprocess.call(['taskkill.exe', '/T', '/F', '/PID', str(pid)]) | 758 subprocess.call(['taskkill.exe', '/T', '/F', '/PID', str(pid)]) |
| 759 else: | 759 else: |
| 760 os.kill(pid, signal.SIGTERM) | 760 os.kill(pid, signal.SIGTERM) |
| 761 | 761 |
| 762 @staticmethod | 762 @staticmethod |
| 763 def ChromeFlagsForSyncTestServer(port, xmpp_port): | |
| 764 """Creates the flags list for the browser to connect to the sync server. | |
| 765 | |
| 766 Use the |ExtraBrowser| class to launch a new browser with these flags. | |
| 767 | |
| 768 Args: | |
| 769 port: The HTTP port number. | |
| 770 xmpp_port: The XMPP port number. | |
| 771 | |
| 772 Returns: | |
| 773 A list with the flags. | |
| 774 """ | |
| 775 return [ | |
| 776 '--sync-url=http://127.0.0.1:%s/chromiumsync' % port, | |
| 777 '--sync-allow-insecure-xmpp-connection', | |
| 778 '--sync-notification-host-port=127.0.0.1:%s' % xmpp_port, | |
| 779 '--sync-notification-method=p2p', | |
| 780 ] | |
| 781 | |
| 782 @staticmethod | |
| 783 def GetPrivateInfo(): | 763 def GetPrivateInfo(): |
| 784 """Fetch info from private_tests_info.txt in private dir. | 764 """Fetch info from private_tests_info.txt in private dir. |
| 785 | 765 |
| 786 Returns: | 766 Returns: |
| 787 a dictionary of items from private_tests_info.txt | 767 a dictionary of items from private_tests_info.txt |
| 788 """ | 768 """ |
| 789 private_file = os.path.join( | 769 private_file = os.path.join( |
| 790 PyUITest.DataDir(), 'pyauto_private', 'private_tests_info.txt') | 770 PyUITest.DataDir(), 'pyauto_private', 'private_tests_info.txt') |
| 791 assert os.path.exists(private_file), '%s missing' % private_file | 771 assert os.path.exists(private_file), '%s missing' % private_file |
| 792 return PyUITest.EvalDataFrom(private_file) | 772 return PyUITest.EvalDataFrom(private_file) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 logging.debug('WaitUntil(%s:%d %s) still waiting. ' | 835 logging.debug('WaitUntil(%s:%d %s) still waiting. ' |
| 856 'Expecting %s. Last returned %s.', | 836 'Expecting %s. Last returned %s.', |
| 857 os.path.basename(inspect.getsourcefile(function)), | 837 os.path.basename(inspect.getsourcefile(function)), |
| 858 inspect.getsourcelines(function)[1], | 838 inspect.getsourcelines(function)[1], |
| 859 function_info, | 839 function_info, |
| 860 True if expect_retval is None else expect_retval, | 840 True if expect_retval is None else expect_retval, |
| 861 retval) | 841 retval) |
| 862 time.sleep(retry_sleep) | 842 time.sleep(retry_sleep) |
| 863 return retval if return_retval else False | 843 return retval if return_retval else False |
| 864 | 844 |
| 865 def StartSyncServer(self): | |
| 866 """Start a local sync server. | |
| 867 | |
| 868 Adds a dictionary attribute 'ports' in returned object. | |
| 869 | |
| 870 Returns: | |
| 871 A handle to Sync Server, an instance of TestServer | |
| 872 """ | |
| 873 sync_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_SYNC, | |
| 874 '127.0.0.1', | |
| 875 pyautolib.FilePath('')) | |
| 876 assert sync_server.Start(), 'Could not start sync server' | |
| 877 sync_server.ports = dict(port=sync_server.GetPort(), | |
| 878 xmpp_port=sync_server.GetSyncXmppPort()) | |
| 879 logging.debug('Started sync server at ports %s.', sync_server.ports) | |
| 880 return sync_server | |
| 881 | |
| 882 def StopSyncServer(self, sync_server): | |
| 883 """Stop the local sync server.""" | |
| 884 assert sync_server, 'Sync Server not yet started' | |
| 885 assert sync_server.Stop(), 'Could not stop sync server' | |
| 886 logging.debug('Stopped sync server at ports %s.', sync_server.ports) | |
| 887 | |
| 888 def StartFTPServer(self, data_dir): | 845 def StartFTPServer(self, data_dir): |
| 889 """Start a local file server hosting data files over ftp:// | 846 """Start a local file server hosting data files over ftp:// |
| 890 | 847 |
| 891 Args: | 848 Args: |
| 892 data_dir: path where ftp files should be served | 849 data_dir: path where ftp files should be served |
| 893 | 850 |
| 894 Returns: | 851 Returns: |
| 895 handle to FTP Server, an instance of TestServer | 852 handle to FTP Server, an instance of TestServer |
| 896 """ | 853 """ |
| 897 ftp_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_FTP, | 854 ftp_server = pyautolib.TestServer(pyautolib.TestServer.TYPE_FTP, |
| (...skipping 5599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6497 successful = result.wasSuccessful() | 6454 successful = result.wasSuccessful() |
| 6498 if not successful: | 6455 if not successful: |
| 6499 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6456 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
| 6500 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6457 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
| 6501 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6458 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
| 6502 sys.exit(not successful) | 6459 sys.exit(not successful) |
| 6503 | 6460 |
| 6504 | 6461 |
| 6505 if __name__ == '__main__': | 6462 if __name__ == '__main__': |
| 6506 Main() | 6463 Main() |
| OLD | NEW |