Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / fetch / generate.py
blob52952bff8bc462d4f495377c677930032dccd8ff
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
3 # found in the LICENSE file.
5 '''Generator script that, for each script-tests/X.js, creates
6 - window/X.html
7 - worker/X.html
8 - serviceworker/X.html
9 from templates in script-tests/TEMPLATE*.html.
11 The following tokens in the template files are replaced:
12 - TESTNAME -> X
13 - OPTIONS -> OPTIONS string (see README).
15 Run
16 $ python generate.py
17 at this (/LayoutTests/http/tests/fetch/) directory, and
18 commit the generated files.
19 '''
21 import os
22 import os.path
23 import re
24 import sys
26 top_path = os.path.dirname(os.path.abspath(__file__))
27 script_tests_path = os.path.join(top_path, 'script-tests')
30 def generate(output_path, template_path, context, testname, options):
31 output_basename = testname + options + '.html'
33 with open(template_path, 'r') as template_file:
34 template_data = template_file.read()
35 output_data = re.sub(r'TESTNAME', testname, template_data)
36 output_data = re.sub(r'OPTIONS', options, output_data)
38 with open(os.path.join(output_path, output_basename), 'w') as output_file:
39 output_file.write(output_data)
42 def generate_directory(relative_path, contexts, original_options):
43 directory_path = os.path.join(script_tests_path, relative_path)
44 for script in os.listdir(directory_path):
45 if script.startswith('.') or not script.endswith('.js'):
46 continue
47 testname = re.sub(r'\.js$', '', os.path.basename(script))
48 options = original_options
50 # Read OPTIONS list.
51 with open(os.path.join(directory_path, script), 'r') as script_file:
52 script = script_file.read()
53 m = re.search(r'// *OPTIONS: *([a-z\-,]*)', script)
54 if m:
55 options = re.split(',', m.group(1))
57 for context in contexts:
58 template_path = os.path.join(
59 directory_path, 'TEMPLATE-' + context + '.html')
60 for option in options:
61 generate(os.path.join(top_path, context, relative_path),
62 template_path, context, testname, option)
65 def main():
66 basic_contexts = ['window', 'workers', 'serviceworker']
68 generate_directory('', ['window', 'workers', 'serviceworker'],
69 ['', '-base-https-other-https'])
70 generate_directory(
71 'thorough',
72 ['window', 'workers', 'serviceworker', 'serviceworker-proxied'],
73 ['', '-other-https', '-base-https-other-https'])
74 return 0
76 if __name__ == "__main__":
77 sys.exit(main())