Upload upstream chromium 94.0.4606.31
[platform/framework/web/chromium-efl.git] / third_party / wpt_tools / PRESUBMIT.py
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.
4
5 """Check the basic functionalities of WPT tools.
6
7 This PRESUBMIT guards against rolling a broken version of WPT tooling. It does
8 some smoke checks of WPT functionality.
9 """
10
11 USE_PYTHON3 = True
12
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'
19   )
20   command = input_api.Command(
21     name='web_tests/external/PRESUBMIT_test.py',
22     cmd=[abspath_to_test],
23     kwargs={},
24     message=output_api.PresubmitError,
25     python3=True
26   )
27   if input_api.verbose:
28     print('Running ' + abspath_to_test)
29   return input_api.RunTests([command])
30
31
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')
37
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))
42     f.close()
43
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')
48     try:
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)]
54
55   return []
56
57
58 def CheckChangeOnUpload(input_api, output_api):
59   results = []
60   results += _TestWPTLint(input_api, output_api)
61   results += _TestWPTManifest(input_api, output_api)
62   return results
63
64
65 def CheckChangeOnCommit(input_api, output_api):
66   results = []
67   results += _TestWPTLint(input_api, output_api)
68   results += _TestWPTManifest(input_api, output_api)
69   return results