Commit 82457287 authored by Christoph Schwering's avatar Christoph Schwering Committed by Commit Bot

Added presubmit script that checks for clock usage in Autofill.

Autofill uses AutofillClock and AutofillTickClock to allow for
manipulating the clock for testing purposes. This presubmit script
warns about usage of base::Time::Now() and base::TimeTicks::Now().

Bug: 1009364
Change-Id: I314303fde19edfc623cba96a01ed3a5e00c6815e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007048Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Christoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/master@{#732756}
parent a0f464eb
# Copyright 2020 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.
"""Chromium presubmit script for src/components/autofill.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details on the presubmit API built into depot_tools.
"""
def _CheckNoBaseTimeCalls(input_api, output_api):
"""Checks that no files call base::Time::Now() or base::TimeTicks::Now()."""
pattern = input_api.re.compile(
r'(base::(Time|TimeTicks)::Now)\(\)',
input_api.re.MULTILINE)
files = []
for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
if (f.LocalPath().startswith('components/autofill/') and
not f.LocalPath().endswith("PRESUBMIT.py")):
contents = input_api.ReadFile(f)
if pattern.search(contents):
files.append(f)
if len(files):
return [ output_api.PresubmitPromptWarning(
'Consider to not call base::Time::Now() or base::TimeTicks::Now() ' +
'directly but use AutofillClock::Now() and '+
'Autofill::TickClock::NowTicks(), respectively. These clocks can be ' +
'manipulated through TestAutofillClock and TestAutofillTickClock '+
'for testing purposes, and using AutofillClock and AutofillTickClock '+
'throughout Autofill code makes sure Autofill tests refers to the '+
'same (potentially manipulated) clock.',
files) ]
return []
def _CommonChecks(input_api, output_api):
"""Checks common to both upload and commit."""
results = []
results.extend(_CheckNoBaseTimeCalls(input_api, output_api))
return results
def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CommonChecks(input_api, output_api))
return results
def CheckChangeOnCommit(input_api, output_api):
results = []
results.extend(_CommonChecks(input_api, output_api))
return results
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment