[email protected] | 52476d9 | 2014-09-03 13:34:04 | [diff] [blame] | 1 | # 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 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 | for more details about the presubmit API built into gcl. |
| 9 | """ |
| 10 | |
[email protected] | ae39431a | 2015-07-09 01:12:10 | [diff] [blame] | 11 | import filecmp |
| 12 | |
[email protected] | 52476d9 | 2014-09-03 13:34:04 | [diff] [blame] | 13 | |
| 14 | def _CheckTestharnessResults(input_api, output_api): |
qyearsley | 98b84f7 | 2016-05-24 00:05:10 | [diff] [blame] | 15 | """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] | 52476d9 | 2014-09-03 13:34:04 | [diff] [blame] | 22 | 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] |
qyearsley | 98b84f7 | 2016-05-24 00:05:10 | [diff] [blame] | 28 | args.extend(baseline_files) |
[email protected] | 52476d9 | 2014-09-03 13:34:04 | [diff] [blame] | 29 | _, 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 | |
qyearsley | 98b84f7 | 2016-05-24 00:05:10 | [diff] [blame] | 37 | def _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 | |
lanwei | a15a2d8 | 2017-04-20 14:20:47 | [diff] [blame] | 58 | def _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): |
xiaochengh | 57a05b2e | 2017-05-12 01:07:20 | [diff] [blame] | 68 | results.append(output_api.PresubmitPromptWarning( |
lanwei | 3e1724e | 2017-05-01 16:24:11 | [diff] [blame] | 69 | '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))) |
lanwei | a15a2d8 | 2017-04-20 14:20:47 | [diff] [blame] | 72 | return results |
| 73 | |
| 74 | |
[email protected] | 52476d9 | 2014-09-03 13:34:04 | [diff] [blame] | 75 | def CheckChangeOnUpload(input_api, output_api): |
| 76 | results = [] |
| 77 | results.extend(_CheckTestharnessResults(input_api, output_api)) |
lanwei | a15a2d8 | 2017-04-20 14:20:47 | [diff] [blame] | 78 | results.extend(_CheckFilesUsingEventSender(input_api, output_api)) |
[email protected] | 52476d9 | 2014-09-03 13:34:04 | [diff] [blame] | 79 | return results |
| 80 | |
| 81 | |
| 82 | def CheckChangeOnCommit(input_api, output_api): |
| 83 | results = [] |
| 84 | results.extend(_CheckTestharnessResults(input_api, output_api)) |
lanwei | a15a2d8 | 2017-04-20 14:20:47 | [diff] [blame] | 85 | results.extend(_CheckFilesUsingEventSender(input_api, output_api)) |
[email protected] | 52476d9 | 2014-09-03 13:34:04 | [diff] [blame] | 86 | return results |