Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 '''Generator script that, for each script-tests/X.js, creates | 5 '''Generator script that, for each script-tests/X.js, creates |
| 6 - window/X.html | 6 - window/X.html |
| 7 - worker/X.html | 7 - worker/X.html |
| 8 - serviceworker/X.html | 8 - serviceworker/X.html |
| 9 from templates in script-tests/TEMPLATE*.html. | 9 from templates in script-tests/TEMPLATE*.html. |
| 10 | 10 |
| 11 The following tokens in the template files are replaced: | 11 The following tokens in the template files are replaced: |
| 12 - TESTNAME -> X | 12 - TESTNAME -> X |
| 13 - OPTIONS -> OPTIONS string (see README). | 13 - OPTIONS -> OPTIONS string (see README). |
| 14 | 14 |
| 15 Run | 15 Run |
| 16 $ python generate.py | 16 $ python generate.py |
| 17 at this (/LayoutTests/http/tests/fetch/) directory, and | 17 at this (/LayoutTests/http/tests/fetch/) directory, and |
| 18 commit the generated files. | 18 commit the generated files. |
| 19 ''' | 19 ''' |
| 20 | 20 |
| 21 import os | 21 import os |
| 22 import os.path | 22 import os.path |
| 23 import re | 23 import re |
| 24 import sys | 24 import sys |
| 25 | 25 |
| 26 top_path = os.path.dirname(os.path.abspath(__file__)) | 26 top_path = os.path.dirname(os.path.abspath(__file__)) |
| 27 script_tests_path = os.path.join(top_path, 'script-tests') | 27 script_tests_path = os.path.join(top_path, 'script-tests') |
| 28 | 28 |
| 29 def generate(templatename, context, testname, options): | |
| 30 template_path = os.path.join( | |
| 31 script_tests_path, templatename + '-' + context + '.html') | |
| 32 | 29 |
| 30 def generate(output_path, template_path, context, testname, options): | |
| 33 output_basename = testname + options + '.html' | 31 output_basename = testname + options + '.html' |
| 34 | 32 |
| 35 output_path = os.path.join(top_path, context, output_basename) | |
| 36 with open(template_path, 'r') as template_file: | 33 with open(template_path, 'r') as template_file: |
| 37 template_data = template_file.read() | 34 template_data = template_file.read() |
| 38 output_data = re.sub(r'TESTNAME', testname, template_data) | 35 output_data = re.sub(r'TESTNAME', testname, template_data) |
| 39 output_data = re.sub(r'OPTIONS', options, output_data) | 36 output_data = re.sub(r'OPTIONS', options, output_data) |
| 40 | 37 |
| 41 with open(output_path, 'w') as output_file: | 38 with open(os.path.join(output_path, output_basename), 'w') as output_file: |
| 42 output_file.write(output_data) | 39 output_file.write(output_data) |
| 43 | 40 |
| 44 def main(): | |
| 45 basic_contexts = ['window', 'workers', 'serviceworker'] | |
| 46 | 41 |
| 47 for script in os.listdir(script_tests_path): | 42 def generate_directory(relative_path, contexts, options): |
| 43 directory_path = os.path.join(script_tests_path, relative_path) | |
| 44 for script in os.listdir(directory_path): | |
| 48 if script.startswith('.') or not script.endswith('.js'): | 45 if script.startswith('.') or not script.endswith('.js'): |
| 49 continue | 46 continue |
| 50 testname = re.sub(r'\.js$', '', os.path.basename(script)) | 47 testname = re.sub(r'\.js$', '', os.path.basename(script)) |
| 51 templatename = 'TEMPLATE' | |
| 52 contexts = list(basic_contexts) | |
| 53 options = ['', '-base-https-other-https'] | |
| 54 | |
| 55 # fetch-access-control tests. | |
| 56 if script.startswith('fetch-access-control'): | |
| 57 templatename = 'TEMPLATE-fetch-access-control' | |
| 58 contexts.append('serviceworker-proxied') | |
| 59 options = ['', '-other-https', '-base-https-other-https'] | |
| 60 | 48 |
| 61 # Read OPTIONS list. | 49 # Read OPTIONS list. |
| 62 with open(os.path.join(script_tests_path, script), 'r') as script_file: | 50 with open(os.path.join(directory_path, script), 'r') as script_file: |
| 63 script = script_file.read() | 51 script = script_file.read() |
| 64 m = re.search(r'// *OPTIONS: *([a-z\-,]*)', script) | 52 m = re.search(r'// *OPTIONS: *([a-z\-,]*)', script) |
| 65 if m: | 53 if m: |
| 66 options = re.split(',', m.group(1)) | 54 options = re.split(',', m.group(1)) |
|
hiroshige
2015/08/05 04:55:52
Substituting to |options| here affects not only th
yhirano
2015/08/07 02:32:04
Done.
| |
| 67 | 55 |
| 68 for context in contexts: | 56 for context in contexts: |
| 57 template_path = os.path.join( | |
| 58 directory_path, 'TEMPLATE-' + context + '.html') | |
| 69 for option in options: | 59 for option in options: |
| 70 assert(option in ['', '-other-https', '-base-https', | 60 generate(os.path.join(top_path, context, relative_path), |
| 71 '-base-https-other-https']) | 61 template_path, context, testname, option) |
| 72 generate(templatename, context, testname, option) | |
| 73 | 62 |
| 63 | |
| 64 def main(): | |
| 65 basic_contexts = ['window', 'workers', 'serviceworker'] | |
| 66 | |
| 67 generate_directory('', ['window', 'workers', 'serviceworker'], | |
| 68 ['', '-base-https-other-https']) | |
| 69 generate_directory( | |
| 70 'thorough', | |
| 71 ['window', 'workers', 'serviceworker', 'serviceworker-proxied'], | |
| 72 ['', '-other-https', '-base-https-other-https']) | |
| 74 return 0 | 73 return 0 |
| 75 | 74 |
| 76 if __name__ == "__main__": | 75 if __name__ == "__main__": |
| 77 sys.exit(main()) | 76 sys.exit(main()) |
| OLD | NEW |