blob: 89ddada28a4ad716e33cae73b548c931f166320a [file] [log] [blame]
[email protected]52476d92014-09-03 13:34:041# Copyright (c) 2013 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"""LayoutTests/ presubmit script for Blink.
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into gcl.
9"""
10
[email protected]ae39431a2015-07-09 01:12:1011import filecmp
12
[email protected]52476d92014-09-03 13:34:0413
14def _CheckTestharnessResults(input_api, output_api):
qyearsley98b84f72016-05-24 00:05:1015 """Checks for testharness.js test baseline files that contain only PASS lines.
16
17 In general these files are unnecessary because for testharness.js tests, if there is
18 no baseline file then the test is considered to pass when the output is all PASS.
19 """
20 baseline_files = _TestharnessBaselineFilesToCheck(input_api)
21 if not baseline_files:
[email protected]52476d92014-09-03 13:34:0422 return []
23
24 checker_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
25 '..', 'Tools', 'Scripts', 'check-testharness-expected-pass')
26
27 args = [input_api.python_executable, checker_path]
qyearsley98b84f72016-05-24 00:05:1028 args.extend(baseline_files)
[email protected]52476d92014-09-03 13:34:0429 _, errs = input_api.subprocess.Popen(args,
30 stdout=input_api.subprocess.PIPE,
31 stderr=input_api.subprocess.PIPE).communicate()
32 if errs:
33 return [output_api.PresubmitError(errs)]
34 return []
35
36
qyearsley98b84f72016-05-24 00:05:1037def _TestharnessBaselineFilesToCheck(input_api):
38 """Returns a list of paths of -expected.txt files for testharness.js tests."""
39 baseline_files = []
40 for f in input_api.AffectedFiles():
41 if f.Action() == 'D':
42 continue
43 path = f.AbsoluteLocalPath()
44 if not path.endswith('-expected.txt'):
45 continue
46 if (input_api.os_path.join('LayoutTests', 'platform') in path or
47 input_api.os_path.join('LayoutTests', 'virtual') in path):
48 # We want to ignore files in LayoutTests/platform, because some all-PASS
49 # platform specific baselines may be necessary to prevent fallback to a
50 # more general baseline; we also ignore files in LayoutTests/virtual
51 # for a similar reason; some all-pass baselines are necessary to
52 # prevent fallback to the corresponding non-virtual test baseline.
53 continue
54 baseline_files.append(path)
55 return baseline_files
56
57
lanweia15a2d82017-04-20 14:20:4758def _CheckFilesUsingEventSender(input_api, output_api):
59 """Check if any new layout tests still use eventSender. If they do, we encourage replacing them with
60 chrome.gpuBenchmarking.pointerActionSequence.
61 """
62 results = []
63 actions = ["eventSender.touch", "eventSender.mouse", "eventSender.gesture"]
64 for f in input_api.AffectedFiles():
65 if f.Action() == 'A':
66 for line_num, line in f.ChangedContents():
67 if any(action in line for action in actions):
xiaochengh57a05b2e2017-05-12 01:07:2068 results.append(output_api.PresubmitPromptWarning(
lanwei3e1724e2017-05-01 16:24:1169 'eventSender is deprecated, please use chrome.gpuBenchmarking.pointerActionSequence instead ' +
70 '(see https://crbug.com/711340 and http://goo.gl/BND75q).\n' +
71 'Files: %s:%d %s ' % (f.LocalPath(), line_num, line)))
lanweia15a2d82017-04-20 14:20:4772 return results
73
74
[email protected]52476d92014-09-03 13:34:0475def CheckChangeOnUpload(input_api, output_api):
76 results = []
77 results.extend(_CheckTestharnessResults(input_api, output_api))
lanweia15a2d82017-04-20 14:20:4778 results.extend(_CheckFilesUsingEventSender(input_api, output_api))
[email protected]52476d92014-09-03 13:34:0479 return results
80
81
82def CheckChangeOnCommit(input_api, output_api):
83 results = []
84 results.extend(_CheckTestharnessResults(input_api, output_api))
lanweia15a2d82017-04-20 14:20:4785 results.extend(_CheckFilesUsingEventSender(input_api, output_api))
[email protected]52476d92014-09-03 13:34:0486 return results