| # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """LayoutTests/ presubmit script for Blink. |
| |
| See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| for more details about the presubmit API built into gcl. |
| """ |
| |
| import filecmp |
| |
| |
| def _CheckTestharnessResults(input_api, output_api): |
| """Checks for testharness.js test baseline files that contain only PASS lines. |
| |
| In general these files are unnecessary because for testharness.js tests, if there is |
| no baseline file then the test is considered to pass when the output is all PASS. |
| """ |
| baseline_files = _TestharnessBaselineFilesToCheck(input_api) |
| if not baseline_files: |
| return [] |
| |
| checker_path = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| '..', 'Tools', 'Scripts', 'check-testharness-expected-pass') |
| |
| args = [input_api.python_executable, checker_path] |
| args.extend(baseline_files) |
| _, errs = input_api.subprocess.Popen(args, |
| stdout=input_api.subprocess.PIPE, |
| stderr=input_api.subprocess.PIPE).communicate() |
| if errs: |
| return [output_api.PresubmitError(errs)] |
| return [] |
| |
| |
| def _TestharnessBaselineFilesToCheck(input_api): |
| """Returns a list of paths of -expected.txt files for testharness.js tests.""" |
| baseline_files = [] |
| for f in input_api.AffectedFiles(): |
| if f.Action() == 'D': |
| continue |
| path = f.AbsoluteLocalPath() |
| if not path.endswith('-expected.txt'): |
| continue |
| if (input_api.os_path.join('LayoutTests', 'platform') in path or |
| input_api.os_path.join('LayoutTests', 'virtual') in path): |
| # We want to ignore files in LayoutTests/platform, because some all-PASS |
| # platform specific baselines may be necessary to prevent fallback to a |
| # more general baseline; we also ignore files in LayoutTests/virtual |
| # for a similar reason; some all-pass baselines are necessary to |
| # prevent fallback to the corresponding non-virtual test baseline. |
| continue |
| baseline_files.append(path) |
| return baseline_files |
| |
| |
| def _CheckFilesUsingEventSender(input_api, output_api): |
| """Check if any new layout tests still use eventSender. If they do, we encourage replacing them with |
| chrome.gpuBenchmarking.pointerActionSequence. |
| """ |
| results = [] |
| actions = ["eventSender.touch", "eventSender.mouse", "eventSender.gesture"] |
| for f in input_api.AffectedFiles(): |
| if f.Action() == 'A': |
| for line_num, line in f.ChangedContents(): |
| if any(action in line for action in actions): |
| results.append(output_api.PresubmitPromptWarning( |
| 'eventSender is deprecated, please use chrome.gpuBenchmarking.pointerActionSequence instead ' + |
| '(see https://crbug.com/711340 and http://goo.gl/BND75q).\n' + |
| 'Files: %s:%d %s ' % (f.LocalPath(), line_num, line))) |
| return results |
| |
| |
| def CheckChangeOnUpload(input_api, output_api): |
| results = [] |
| results.extend(_CheckTestharnessResults(input_api, output_api)) |
| results.extend(_CheckFilesUsingEventSender(input_api, output_api)) |
| return results |
| |
| |
| def CheckChangeOnCommit(input_api, output_api): |
| results = [] |
| results.extend(_CheckTestharnessResults(input_api, output_api)) |
| results.extend(_CheckFilesUsingEventSender(input_api, output_api)) |
| return results |