Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2011 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. | |
| 5 | |
| 6 """This script is used by chrome_tests.gypi's js2webui action to maintain the | |
| 7 argument lists and to generate inlinable tests for webui testing. | |
| 8 | |
| 9 Usage: | |
| 10 python tools/js2webui.py -p product_dir path/to/javascript2webui.js | |
| 11 python tools/js2webui.py -t # print test_harnesses | |
| 12 python tools/js2webui.py -i # print inputs | |
| 13 python tools/js2webui.py -o # print outputs | |
| 14 """ | |
| 15 | |
| 16 try: | |
| 17 import json | |
| 18 except ImportError: | |
| 19 import simplejson as json | |
| 20 import optparse | |
| 21 import os | |
| 22 import subprocess | |
| 23 import sys | |
| 24 | |
| 25 # Please adjust the following to edit or add new javascript webui tests. | |
| 26 rules = [ | |
| 27 [ | |
| 28 'WebUIBrowserTestPass', | |
| 29 'test/data/webui/sample_pass.js', | |
| 30 'browser/ui/webui/web_ui_browsertest-inl.h', | |
| 31 ], | |
| 32 ] | |
| 33 | |
| 34 def main (): | |
| 35 """Run the program""" | |
|
M-A Ruel
2011/06/20 16:38:46
Please remove.
Sheridan Rawlins
2011/06/22 06:49:22
Done.
| |
| 36 # For options -t, -i, & -o, we print the "column" of the |rules|. We keep a | |
| 37 # set of indices to print in |print_rule_indices| and print them in sorted | |
| 38 # order if non-empty. | |
| 39 parser = optparse.OptionParser() | |
| 40 parser.set_usage( | |
| 41 "%prog [-v][-n] --product_dir PRODUCT_DIR -or- " | |
| 42 "%prog [-v][-n] (-i|-t|-o)") | |
| 43 parser.add_option('-v', '--verbose', action='store_true') | |
| 44 parser.add_option('-n', '--impotent', action='store_true', | |
| 45 help="don't execute; just print (as if verbose)") | |
| 46 parser.add_option( | |
| 47 '-p', '--product_dir', | |
| 48 help='for gyp to set the <(PRODUCT_DIR) for running v8_shell') | |
| 49 parser.add_option('-t', '--test_fixture', action='store_const', const=0, | |
| 50 dest='print_rule_index', help='print test_fixtures') | |
| 51 parser.add_option('-i', '--in', action='store_const', const=1, | |
| 52 dest='print_rule_index', help='print inputs') | |
| 53 parser.add_option('-o', '--out', action='store_const', const=2, | |
| 54 dest='print_rule_index', help='print outputs') | |
| 55 (opts, args) = parser.parse_args() | |
| 56 | |
| 57 if (opts.print_rule_index != None): | |
|
M-A Ruel
2011/06/20 16:38:46
if opts.print_rule_index is not None:
Sheridan Rawlins
2011/06/22 06:49:22
Done.
| |
| 58 for rule in rules: | |
| 59 print rule[opts.print_rule_index] | |
|
M-A Ruel
2011/06/20 16:38:46
optioanl: You can add a return 0, so you don't nee
Sheridan Rawlins
2011/06/22 06:49:22
Done.
| |
| 60 else: | |
| 61 if not opts.product_dir: | |
| 62 parser.error("--product_dir option is required") | |
| 63 v8_shell = os.path.join(opts.product_dir, 'v8_shell') | |
| 64 for (test_fixture, input_js, output_cc) in rules: | |
| 65 cmd = [v8_shell, '--print_json_ast', input_js] | |
| 66 if opts.verbose or opts.impotent: | |
| 67 print cmd | |
| 68 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) | |
| 69 ast = json.load(proc.stdout) | |
| 70 if not opts.impotent: | |
| 71 sys.stdout = open(output_cc, 'w') | |
| 72 print '// GENERATED FILE' | |
| 73 print '// ', ' '.join(sys.argv) | |
| 74 print '// PLEASE DO NOT HAND EDIT!\n' | |
| 75 for declaration in ast[2:]: | |
| 76 try: | |
| 77 function_literal = declaration[3] | |
| 78 function_name = function_literal[1]['name'] | |
| 79 print 'IN_PROC_BROWSER_TEST_F(%s, %s) {' % ( | |
| 80 test_fixture, function_name) | |
| 81 print ' AddLibrary(FilePath(FILE_PATH_LITERAL("%s")));' % ( | |
| 82 os.path.basename(input_js)) | |
| 83 print ' ASSERT_TRUE(RunJavascriptTest("%s"));' % (function_name) | |
| 84 print '}\n' | |
| 85 except IndexError: | |
| 86 if opts.verbose or opts.impotent: | |
| 87 print "skipping declaration ", declaration | |
| 88 | |
| 89 if __name__ == '__main__': | |
| 90 sys.exit(main()) | |
| OLD | NEW |