Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CoF] CVC single field detection implementation
This change adds a new logic to our field detection heuristics to uniquely identify the card-on-file case through single field CVC detection. Bug: 1347288, 1341387 Change-Id: Ifebe68f413744690b50c3fc6bac5898e0375f608 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3786871 Reviewed-by: Dominic Battré <battre@chromium.org> Reviewed-by: Alexander Tekle <alexandertekle@google.com> Commit-Queue: Nakul Vaidya <nakulvaidya@google.com> Cr-Commit-Position: refs/heads/main@{#1034252}
- Loading branch information
Nakul Vaidya
authored and
Chromium LUCI CQ
committed
Aug 12, 2022
1 parent
d90a71d
commit 8597763
Showing
12 changed files
with
244 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
components/autofill/core/browser/form_parsing/standalone_cvc_field.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2022 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. | ||
|
||
#include "components/autofill/core/browser/form_parsing/standalone_cvc_field.h" | ||
|
||
#include "components/autofill/core/browser/autofill_field.h" | ||
#include "components/autofill/core/browser/autofill_regex_constants.h" | ||
#include "components/autofill/core/browser/autofill_regexes.h" | ||
#include "components/autofill/core/browser/form_parsing/autofill_scanner.h" | ||
#include "components/autofill/core/common/autofill_payments_features.h" | ||
|
||
namespace autofill { | ||
|
||
// static | ||
std::unique_ptr<FormField> StandaloneCvcField::Parse( | ||
AutofillScanner* scanner, | ||
const LanguageCode& page_language, | ||
PatternSource pattern_source, | ||
LogManager* log_manager) { | ||
if (!base::FeatureList::IsEnabled( | ||
features::kAutofillParseVcnCardOnFileStandaloneCvcFields)) { | ||
return nullptr; | ||
} | ||
|
||
// Ignore gift card fields as both |kGiftCardRe| and |kCardCvcRe| matches | ||
// "gift card pin" and "gift card code" but it should only match | ||
// |kGiftCardRe|. | ||
if (MatchGiftCard(scanner, log_manager, page_language, pattern_source)) { | ||
return nullptr; | ||
} | ||
|
||
AutofillField* field; | ||
base::span<const MatchPatternRef> cvc_patterns = GetMatchPatterns( | ||
CREDIT_CARD_VERIFICATION_CODE, page_language, pattern_source); | ||
|
||
// CVC fields can occur in many different field types so we check for each | ||
const auto kMatchNumTelAndPwd = | ||
kDefaultMatchParamsWith<MatchFieldType::kNumber, | ||
MatchFieldType::kTelephone, | ||
MatchFieldType::kPassword>; | ||
if (ParseFieldSpecifics(scanner, kCardCvcRe, kMatchNumTelAndPwd, cvc_patterns, | ||
&field, {log_manager, "kCardCvcRe(standalone)"})) { | ||
return std::make_unique<StandaloneCvcField>(field); | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
StandaloneCvcField::~StandaloneCvcField() = default; | ||
|
||
// static | ||
bool StandaloneCvcField::MatchGiftCard(AutofillScanner* scanner, | ||
LogManager* log_manager, | ||
const LanguageCode& page_language, | ||
PatternSource pattern_source) { | ||
if (scanner->IsEnd()) | ||
return false; | ||
|
||
const auto kMatchFieldType = kDefaultMatchParamsWith< | ||
MatchFieldType::kNumber, MatchFieldType::kTelephone, | ||
MatchFieldType::kSearch, MatchFieldType::kPassword>; | ||
base::span<const MatchPatternRef> gift_card_patterns = | ||
GetMatchPatterns("GIFT_CARD", page_language, pattern_source); | ||
|
||
return ParseFieldSpecifics(scanner, kGiftCardRe, kMatchFieldType, | ||
gift_card_patterns, nullptr, | ||
{log_manager, "kGiftCardRe"}); | ||
} | ||
|
||
StandaloneCvcField::StandaloneCvcField(const AutofillField* field) | ||
: field_(field) {} | ||
|
||
void StandaloneCvcField::AddClassifications( | ||
FieldCandidatesMap& field_candidates) const { | ||
AddClassification(field_, CREDIT_CARD_STANDALONE_VERIFICATION_CODE, | ||
kBaseCreditCardParserScore, field_candidates); | ||
} | ||
|
||
} // namespace autofill |
50 changes: 50 additions & 0 deletions
50
components/autofill/core/browser/form_parsing/standalone_cvc_field.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2022 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. | ||
|
||
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_PARSING_STANDALONE_CVC_FIELD_H_ | ||
#define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_PARSING_STANDALONE_CVC_FIELD_H_ | ||
|
||
#include <memory> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "components/autofill/core/browser/form_parsing/form_field.h" | ||
#include "components/autofill/core/common/language_code.h" | ||
|
||
namespace autofill { | ||
|
||
class AutofillField; | ||
class AutofillScanner; | ||
class LogManager; | ||
|
||
// A form field that accepts a standalone cvc. | ||
class StandaloneCvcField : public FormField { | ||
public: | ||
static std::unique_ptr<FormField> Parse(AutofillScanner* scanner, | ||
const LanguageCode& page_language, | ||
PatternSource pattern_source, | ||
LogManager* log_manager); | ||
|
||
explicit StandaloneCvcField(const AutofillField* field); | ||
|
||
~StandaloneCvcField() override; | ||
|
||
StandaloneCvcField(const StandaloneCvcField&) = delete; | ||
StandaloneCvcField& operator=(const StandaloneCvcField&) = delete; | ||
|
||
protected: | ||
void AddClassifications(FieldCandidatesMap& field_candidates) const override; | ||
|
||
private: | ||
raw_ptr<const AutofillField> field_; | ||
|
||
// static | ||
static bool MatchGiftCard(AutofillScanner* scanner, | ||
LogManager* log_manager, | ||
const LanguageCode& page_language, | ||
PatternSource pattern_source); | ||
}; | ||
|
||
} // namespace autofill | ||
|
||
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_PARSING_STANDALONE_CVC_FIELD_H_ |
78 changes: 78 additions & 0 deletions
78
components/autofill/core/browser/form_parsing/standalone_cvc_field_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2022 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. | ||
|
||
#include "components/autofill/core/browser/form_parsing/standalone_cvc_field.h" | ||
|
||
#include "base/test/scoped_feature_list.h" | ||
#include "components/autofill/core/browser/form_parsing/parsing_test_utils.h" | ||
#include "components/autofill/core/common/autofill_payments_features.h" | ||
|
||
namespace autofill { | ||
|
||
class StandaloneCvcFieldTest | ||
: public FormFieldTestBase, | ||
public testing::TestWithParam<PatternProviderFeatureState> { | ||
public: | ||
StandaloneCvcFieldTest() : FormFieldTestBase(GetParam()) {} | ||
StandaloneCvcFieldTest(const StandaloneCvcFieldTest&) = delete; | ||
StandaloneCvcFieldTest& operator=(const StandaloneCvcFieldTest&) = delete; | ||
|
||
protected: | ||
std::unique_ptr<FormField> Parse( | ||
AutofillScanner* scanner, | ||
const LanguageCode& page_language = LanguageCode("en")) override { | ||
return StandaloneCvcField::Parse(scanner, page_language, | ||
GetActivePatternSource(), | ||
/*log_manager=*/nullptr); | ||
} | ||
|
||
base::test::ScopedFeatureList scoped_feature_list_; | ||
}; | ||
|
||
INSTANTIATE_TEST_SUITE_P( | ||
StandaloneCvcFieldTest, | ||
StandaloneCvcFieldTest, | ||
::testing::ValuesIn(PatternProviderFeatureState::All())); | ||
|
||
// Match standalone cvc. | ||
TEST_P(StandaloneCvcFieldTest, ParseStandaloneCvc) { | ||
scoped_feature_list_.InitAndEnableFeature( | ||
features::kAutofillParseVcnCardOnFileStandaloneCvcFields); | ||
|
||
AddTextFormFieldData("cvc", "CVC:", CREDIT_CARD_STANDALONE_VERIFICATION_CODE); | ||
|
||
ClassifyAndVerify(ParseResult::PARSED); | ||
} | ||
|
||
// Do not parse non cvc standalone fields. | ||
TEST_P(StandaloneCvcFieldTest, ParseNonStandaloneCvc) { | ||
scoped_feature_list_.InitAndEnableFeature( | ||
features::kAutofillParseVcnCardOnFileStandaloneCvcFields); | ||
|
||
AddTextFormFieldData("other-field", "Other Field:", UNKNOWN_TYPE); | ||
|
||
ClassifyAndVerify(ParseResult::NOT_PARSED); | ||
} | ||
|
||
// Do not parse when standalone cvc flag is disabled. | ||
TEST_P(StandaloneCvcFieldTest, ParseStandaloneCvcFlagOff) { | ||
scoped_feature_list_.InitAndDisableFeature( | ||
features::kAutofillParseVcnCardOnFileStandaloneCvcFields); | ||
|
||
AddTextFormFieldData("cvc", "CVC:", CREDIT_CARD_STANDALONE_VERIFICATION_CODE); | ||
|
||
ClassifyAndVerify(ParseResult::NOT_PARSED); | ||
} | ||
|
||
// Do not parse gift card as standalone cvc fields. | ||
TEST_P(StandaloneCvcFieldTest, NotParseGiftCardAsStandaloneCvc) { | ||
scoped_feature_list_.InitAndEnableFeature( | ||
features::kAutofillParseVcnCardOnFileStandaloneCvcFields); | ||
|
||
AddTextFormFieldData("gift-card", "Gift Card Pin:", UNKNOWN_TYPE); | ||
|
||
ClassifyAndVerify(ParseResult::NOT_PARSED); | ||
} | ||
|
||
} // namespace autofill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters