1 # Copyright 2018 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 """Check the basic functionalities of WPT tools.
7 This PRESUBMIT guards against rolling a broken version of WPT tooling. It does
8 some smoke checks of WPT functionality.
13 def _TestWPTLint(input_api, output_api):
14 # We test 'wpt lint' by deferring to the web_tests/external presubmit test,
15 # which runs 'wpt lint' against web_tests/external/wpt.
16 abspath_to_test = input_api.os_path.join(
17 input_api.change.RepositoryRoot(),
18 'third_party', 'blink', 'web_tests', 'external', 'PRESUBMIT_test.py'
20 command = input_api.Command(
21 name='web_tests/external/PRESUBMIT_test.py',
22 cmd=[abspath_to_test],
24 message=output_api.PresubmitError,
28 print('Running ' + abspath_to_test)
29 return input_api.RunTests([command])
32 def _TestWPTManifest(input_api, output_api):
33 # We test 'wpt manifest' by making a copy of the base manifest and updating
34 # it. A copy is used so that this PRESUBMIT doesn't change files in the tree.
35 blink_path = input_api.os_path.join(
36 input_api.change.RepositoryRoot(), 'third_party', 'blink')
38 base_manifest = input_api.os_path.join(
39 blink_path, 'web_tests', 'external', 'WPT_BASE_MANIFEST_8.json')
40 with input_api.CreateTemporaryFile(mode = 'wt') as f:
41 f.write(input_api.ReadFile(base_manifest))
44 wpt_exec_path = input_api.os_path.join(
45 input_api.change.RepositoryRoot(), 'third_party', 'wpt_tools', 'wpt', 'wpt')
46 external_wpt = input_api.os_path.join(
47 blink_path, 'web_tests', 'external', 'wpt')
49 input_api.subprocess.check_output(
50 ['python3', wpt_exec_path, 'manifest', '--no-download',
51 '--path', f.name, '--tests-root', external_wpt])
52 except input_api.subprocess.CalledProcessError as exc:
53 return [output_api.PresubmitError('wpt manifest failed:', long_text=exc.output)]
58 def CheckChangeOnUpload(input_api, output_api):
60 results += _TestWPTLint(input_api, output_api)
61 results += _TestWPTManifest(input_api, output_api)
65 def CheckChangeOnCommit(input_api, output_api):
67 results += _TestWPTLint(input_api, output_api)
68 results += _TestWPTManifest(input_api, output_api)