Make hitting "Enter" submit the add/change profile dialog.
[chromium-blink-merge.git] / chrome / test / functional / pyauto_functional.py
blobf215dd4f17d5dff367318f9c3febe54a5e4cf0ff
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 """Setup for PyAuto functional tests.
8 Use the following in your scripts to run them standalone:
10 # This should be at the top
11 import pyauto_functional
13 if __name__ == '__main__':
14 pyauto_functional.Main()
16 This script can be used as an executable to fire off other scripts, similar
17 to unittest.py
18 python pyauto_functional.py test_script
19 """
21 import os
22 import subprocess
23 import sys
26 def _LocatePyAutoDir():
27 sys.path.append(os.path.join(os.path.dirname(__file__),
28 os.pardir, 'pyautolib'))
31 _LocatePyAutoDir()
32 import pyauto_paths
35 def RunWithCorrectPythonIfNecessary():
36 """Runs this script with the correct version of python if necessary.
38 Different platforms and versions of pyautolib use different python versions.
39 Instead of requiring testers and infrastructure to handle choosing the right
40 version (and architecture), this will rerun the script with the correct
41 version of python.
43 Note, this function will either return after doing nothing, or will exit with
44 the subprocess's return code.
45 """
46 def RunAgain():
47 """Run the script again with the correct version of python.
49 Note, this function does not return, but exits with the return code of the
50 child.
51 """
52 if sys.platform == 'cygwin' or sys.platform.startswith('win'):
53 cmd = [os.path.join(pyauto_paths.GetThirdPartyDir(), 'python_26',
54 'python_slave.exe')]
55 elif sys.platform.startswith('darwin'):
56 # Arch runs the specified architecture of a universal binary. Run
57 # the 32 bit one.
58 cmd = ['arch', '-i386', 'python2.6']
59 elif sys.platform.startswith('linux'):
60 cmd = ['python2.6']
62 cmd.extend(sys.argv)
63 print 'Running:', ' '.join(cmd)
64 proc = subprocess.Popen(cmd)
65 proc.wait()
66 sys.exit(proc.returncode)
68 # Check this is the right python version.
69 if sys.version_info[0:2] != (2, 6):
70 RunAgain()
72 # Check this is the right bitness on mac.
73 # platform.architecture() will not help us on mac, since multiple binaries
74 # are stuffed inside the universal python binary.
75 if sys.platform.startswith('darwin') and sys.maxint > 2**32:
76 # User is running 64-bit python, but we should use 32-bit.
77 RunAgain()
80 # Do not attempt to figure out python versions if
81 # DO_NOT_RESTART_PYTHON_FOR_PYAUTO is set.
82 if os.getenv('DO_NOT_RESTART_PYTHON_FOR_PYAUTO') is None:
83 RunWithCorrectPythonIfNecessary()
84 else:
85 print 'Will not try to restart with the correct version of python '\
86 'as DO_NOT_RESTART_PYTHON_FOR_PYAUTO is set.'
89 try:
90 import pyauto
91 except ImportError:
92 print >>sys.stderr, 'Cannot import pyauto from %s' % sys.path
93 raise
96 class Main(pyauto.Main):
97 """Main program for running PyAuto functional tests."""
99 def __init__(self):
100 # Make scripts in this dir importable
101 sys.path.append(os.path.dirname(__file__))
102 pyauto.Main.__init__(self)
104 def TestsDir(self):
105 return os.path.dirname(__file__)
108 if __name__ == '__main__':
109 Main()