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
9 from templates in script-tests/TEMPLATE*.html.
11 The following tokens in the template files are replaced:
13 - OPTIONS -> OPTIONS string (see README).
17 at this (/LayoutTests/http/tests/fetch/) directory, and
18 commit the generated files.
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'):
47 testname
= re
.sub(r
'\.js$', '', os
.path
.basename(script
))
48 options
= original_options
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
)
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
)
66 basic_contexts
= ['window', 'workers', 'serviceworker']
68 generate_directory('', ['window', 'workers', 'serviceworker'],
69 ['', '-base-https-other-https'])
72 ['window', 'workers', 'serviceworker', 'serviceworker-proxied'],
73 ['', '-other-https', '-base-https-other-https'])
76 if __name__
== "__main__":