2 # Copyright 2014 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 """Launches the remoting webapp unit test in chrome with the appropriate flags.
17 """Locates the chrome binary on the system."""
19 if platform
.system() == 'Darwin': # Darwin == MacOSX
21 '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')
22 elif platform
.system() == 'Linux':
23 chrome_path
= '/usr/bin/google-chrome'
25 # TODO(kelvinp): Support chrome path location on Windows.
26 print 'Unsupported OS.'
30 def BuildTestPageUri(opt_module
=None, opt_coverage
=False):
31 """Builds the Uri for the test page with params."""
32 script_path
= os
.path
.dirname(__file__
)
34 test_page_path
= os
.path
.join(script_path
,
35 '../../out/Debug/remoting/unittests/unittest.html')
36 test_page_path
= 'file://' + os
.path
.abspath(test_page_path
)
40 test_page_params
['coverage'] = 'true'
42 test_page_params
['module'] = opt_module
44 test_page_path
= test_page_path
+ '?%s' % urllib
.urlencode(test_page_params
)
45 return '"' + test_page_path
+ '"'
48 def BuildCommandLine(chrome_path
, opt_module
, opt_coverage
):
49 """Builds the command line to execute."""
51 command
.append('"' + chrome_path
+ '"')
52 command
.append('--user-data-dir=' + tempfile
.gettempdir())
53 # The flag |--allow-file-access-from-files| is required so that we can open
54 # JavaScript files using XHR and instrument them for code coverage.
55 command
.append(' --allow-file-access-from-files')
56 test_page_path
= BuildTestPageUri(opt_module
, opt_coverage
)
57 command
.append(test_page_path
)
58 return ' '.join(command
)
62 parser
= argparse
.ArgumentParser()
63 chrome_path
= GetChromePath()
67 help='The path of the chrome binary to run the test.',
70 '--module', help='only run tests that belongs to MODULE')
72 '--coverage', help='run the test with code coverage', action
='store_true')
74 return parser
.parse_args(sys
.argv
[1:])
81 if not os
.path
.exists(args
.chrome_path
):
82 print 'Cannot locate the chrome binary in your system.'
83 print 'Please use the flag --chrome_path=CHROME_PATH to specify the chrome '
84 print 'binary to run the test.'
87 command_line
= BuildCommandLine(args
.chrome_path
, args
.module
, args
.coverage
)
88 os
.system(command_line
)
92 if __name__
== '__main__':