Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: LayoutTests/http/tests/fetch/generate.py

Issue 1267263003: Rename fetch layout tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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, original_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' 48 options = original_options
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 49
61 # Read OPTIONS list. 50 # Read OPTIONS list.
62 with open(os.path.join(script_tests_path, script), 'r') as script_file: 51 with open(os.path.join(directory_path, script), 'r') as script_file:
63 script = script_file.read() 52 script = script_file.read()
64 m = re.search(r'// *OPTIONS: *([a-z\-,]*)', script) 53 m = re.search(r'// *OPTIONS: *([a-z\-,]*)', script)
65 if m: 54 if m:
66 options = re.split(',', m.group(1)) 55 options = re.split(',', m.group(1))
67 56
68 for context in contexts: 57 for context in contexts:
58 template_path = os.path.join(
59 directory_path, 'TEMPLATE-' + context + '.html')
69 for option in options: 60 for option in options:
70 assert(option in ['', '-other-https', '-base-https', 61 generate(os.path.join(top_path, context, relative_path),
71 '-base-https-other-https']) 62 template_path, context, testname, option)
72 generate(templatename, context, testname, option)
73 63
64
65 def main():
66 basic_contexts = ['window', 'workers', 'serviceworker']
67
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 74 return 0
75 75
76 if __name__ == "__main__": 76 if __name__ == "__main__":
77 sys.exit(main()) 77 sys.exit(main())
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/fetch/README ('k') | LayoutTests/http/tests/fetch/resources/fetch-access-control-iframe.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698