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

[Autofill] Use TestPatternProvider in unit tests.

This CL fixes several unit tests that use the PatternProvider.

Tbr: koerber@google.com
Change-Id: Ia809f85015601a3fe8147209ea8c073875a50935
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489081Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Commit-Queue: Christoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/master@{#819308}
parent bcba3ee5
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/form_parsing/autofill_scanner.h" #include "components/autofill/core/browser/form_parsing/autofill_scanner.h"
#include "components/autofill/core/browser/pattern_provider/test_pattern_provider.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/form_field_data.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -24,13 +25,11 @@ namespace autofill { ...@@ -24,13 +25,11 @@ namespace autofill {
class AddressFieldTest : public testing::Test { class AddressFieldTest : public testing::Test {
public: public:
AddressFieldTest() {} AddressFieldTest() = default;
AddressFieldTest(const AddressFieldTest&) = delete;
AddressFieldTest& operator=(const AddressFieldTest&) = delete;
protected: protected:
std::vector<std::unique_ptr<AutofillField>> list_;
std::unique_ptr<AddressField> field_;
FieldCandidatesMap field_candidates_map_;
// Downcast for tests. // Downcast for tests.
static std::unique_ptr<AddressField> Parse(AutofillScanner* scanner) { static std::unique_ptr<AddressField> Parse(AutofillScanner* scanner) {
// An empty page_language means the language is unknown and patterns of all // An empty page_language means the language is unknown and patterns of all
...@@ -41,8 +40,12 @@ class AddressFieldTest : public testing::Test { ...@@ -41,8 +40,12 @@ class AddressFieldTest : public testing::Test {
static_cast<AddressField*>(field.release())); static_cast<AddressField*>(field.release()));
} }
private: std::vector<std::unique_ptr<AutofillField>> list_;
DISALLOW_COPY_AND_ASSIGN(AddressFieldTest); std::unique_ptr<AddressField> field_;
FieldCandidatesMap field_candidates_map_;
// RAII object to mock the the PatternProvider.
TestPatternProvider test_pattern_provider_;
}; };
TEST_F(AddressFieldTest, Empty) { TEST_F(AddressFieldTest, Empty) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/form_parsing/autofill_scanner.h" #include "components/autofill/core/browser/form_parsing/autofill_scanner.h"
#include "components/autofill/core/browser/pattern_provider/test_pattern_provider.h"
#include "components/autofill/core/common/autofill_clock.h" #include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/form_field_data.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -23,14 +24,11 @@ namespace autofill { ...@@ -23,14 +24,11 @@ namespace autofill {
class CreditCardFieldTestBase { class CreditCardFieldTestBase {
public: public:
CreditCardFieldTestBase() {} CreditCardFieldTestBase() = default;
~CreditCardFieldTestBase() {} CreditCardFieldTestBase(const CreditCardFieldTestBase&) = delete;
CreditCardFieldTestBase& operator=(const CreditCardFieldTestBase&) = delete;
protected: protected:
std::vector<std::unique_ptr<AutofillField>> list_;
std::unique_ptr<const CreditCardField> field_;
FieldCandidatesMap field_candidates_map_;
// Parses the contents of |list_| as a form, and stores the result into // Parses the contents of |list_| as a form, and stores the result into
// |field_|. // |field_|.
void Parse() { void Parse() {
...@@ -67,17 +65,20 @@ class CreditCardFieldTestBase { ...@@ -67,17 +65,20 @@ class CreditCardFieldTestBase {
return field_->AddClassifications(&field_candidates_map_); return field_->AddClassifications(&field_candidates_map_);
} }
private: std::vector<std::unique_ptr<AutofillField>> list_;
DISALLOW_COPY_AND_ASSIGN(CreditCardFieldTestBase); std::unique_ptr<const CreditCardField> field_;
FieldCandidatesMap field_candidates_map_;
// RAII object to mock the the PatternProvider.
TestPatternProvider test_pattern_provider_;
}; };
class CreditCardFieldTest : public CreditCardFieldTestBase, class CreditCardFieldTest : public CreditCardFieldTestBase,
public testing::Test { public testing::Test {
public: public:
CreditCardFieldTest() {} CreditCardFieldTest() = default;
CreditCardFieldTest(const CreditCardFieldTest&) = delete;
private: CreditCardFieldTest& operator=(const CreditCardFieldTest&) = delete;
DISALLOW_COPY_AND_ASSIGN(CreditCardFieldTest);
}; };
TEST_F(CreditCardFieldTest, Empty) { TEST_F(CreditCardFieldTest, Empty) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/form_parsing/autofill_scanner.h" #include "components/autofill/core/browser/form_parsing/autofill_scanner.h"
#include "components/autofill/core/browser/pattern_provider/test_pattern_provider.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_regex_constants.h" #include "components/autofill/core/common/autofill_regex_constants.h"
#include "components/autofill/core/common/autofill_regexes.h" #include "components/autofill/core/common/autofill_regexes.h"
...@@ -25,13 +26,11 @@ namespace autofill { ...@@ -25,13 +26,11 @@ namespace autofill {
class NameFieldTest : public testing::Test { class NameFieldTest : public testing::Test {
public: public:
NameFieldTest() {} NameFieldTest() = default;
NameFieldTest(const NameFieldTest&) = delete;
NameFieldTest& operator=(const NameFieldTest&) = delete;
protected: protected:
std::vector<std::unique_ptr<AutofillField>> list_;
std::unique_ptr<NameField> field_;
FieldCandidatesMap field_candidates_map_;
// Downcast for tests. // Downcast for tests.
static std::unique_ptr<NameField> Parse(AutofillScanner* scanner) { static std::unique_ptr<NameField> Parse(AutofillScanner* scanner) {
// An empty page_language means the language is unknown and patterns of all // An empty page_language means the language is unknown and patterns of all
...@@ -41,8 +40,12 @@ class NameFieldTest : public testing::Test { ...@@ -41,8 +40,12 @@ class NameFieldTest : public testing::Test {
return std::unique_ptr<NameField>(static_cast<NameField*>(field.release())); return std::unique_ptr<NameField>(static_cast<NameField*>(field.release()));
} }
private: std::vector<std::unique_ptr<AutofillField>> list_;
DISALLOW_COPY_AND_ASSIGN(NameFieldTest); std::unique_ptr<NameField> field_;
FieldCandidatesMap field_candidates_map_;
// RAII object to mock the the PatternProvider.
TestPatternProvider test_pattern_provider_;
}; };
TEST_F(NameFieldTest, FirstMiddleLast) { TEST_F(NameFieldTest, FirstMiddleLast) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/form_parsing/autofill_scanner.h" #include "components/autofill/core/browser/form_parsing/autofill_scanner.h"
#include "components/autofill/core/browser/pattern_provider/test_pattern_provider.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/form_field_data.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -83,6 +84,9 @@ class PhoneFieldTest : public testing::Test { ...@@ -83,6 +84,9 @@ class PhoneFieldTest : public testing::Test {
std::vector<std::unique_ptr<AutofillField>> list_; std::vector<std::unique_ptr<AutofillField>> list_;
std::unique_ptr<PhoneField> field_; std::unique_ptr<PhoneField> field_;
FieldCandidatesMap field_candidates_map_; FieldCandidatesMap field_candidates_map_;
// RAII object to mock the the PatternProvider.
TestPatternProvider test_pattern_provider_;
}; };
TEST_F(PhoneFieldTest, Empty) { TEST_F(PhoneFieldTest, Empty) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/form_parsing/autofill_scanner.h" #include "components/autofill/core/browser/form_parsing/autofill_scanner.h"
#include "components/autofill/core/browser/pattern_provider/test_pattern_provider.h"
#include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/form_field_data.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -22,13 +23,11 @@ namespace autofill { ...@@ -22,13 +23,11 @@ namespace autofill {
class PriceFieldTest : public testing::Test { class PriceFieldTest : public testing::Test {
public: public:
PriceFieldTest() {} PriceFieldTest() = default;
PriceFieldTest(const PriceFieldTest&) = delete;
PriceFieldTest& operator=(const PriceFieldTest&) = delete;
protected: protected:
std::vector<std::unique_ptr<AutofillField>> list_;
std::unique_ptr<PriceField> field_;
FieldCandidatesMap field_candidates_map_;
// Downcast for tests. // Downcast for tests.
static std::unique_ptr<PriceField> Parse(AutofillScanner* scanner) { static std::unique_ptr<PriceField> Parse(AutofillScanner* scanner) {
// An empty page_language means the language is unknown and patterns of all // An empty page_language means the language is unknown and patterns of all
...@@ -39,8 +38,12 @@ class PriceFieldTest : public testing::Test { ...@@ -39,8 +38,12 @@ class PriceFieldTest : public testing::Test {
static_cast<PriceField*>(field.release())); static_cast<PriceField*>(field.release()));
} }
private: std::vector<std::unique_ptr<AutofillField>> list_;
DISALLOW_COPY_AND_ASSIGN(PriceFieldTest); std::unique_ptr<PriceField> field_;
FieldCandidatesMap field_candidates_map_;
// RAII object to mock the the PatternProvider.
TestPatternProvider test_pattern_provider_;
}; };
TEST_F(PriceFieldTest, ParsePrice) { TEST_F(PriceFieldTest, ParsePrice) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/form_parsing/autofill_scanner.h" #include "components/autofill/core/browser/form_parsing/autofill_scanner.h"
#include "components/autofill/core/browser/pattern_provider/test_pattern_provider.h"
#include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/form_field_data.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -22,13 +23,11 @@ namespace autofill { ...@@ -22,13 +23,11 @@ namespace autofill {
class SearchFieldTest : public testing::Test { class SearchFieldTest : public testing::Test {
public: public:
SearchFieldTest() {} SearchFieldTest() = default;
SearchFieldTest(const SearchFieldTest&) = delete;
SearchFieldTest& operator=(const SearchFieldTest&) = delete;
protected: protected:
std::vector<std::unique_ptr<AutofillField>> list_;
std::unique_ptr<SearchField> field_;
FieldCandidatesMap field_candidates_map_;
// Downcast for tests. // Downcast for tests.
static std::unique_ptr<SearchField> Parse(AutofillScanner* scanner) { static std::unique_ptr<SearchField> Parse(AutofillScanner* scanner) {
// An empty page_language means the language is unknown and patterns of all // An empty page_language means the language is unknown and patterns of all
...@@ -39,8 +38,12 @@ class SearchFieldTest : public testing::Test { ...@@ -39,8 +38,12 @@ class SearchFieldTest : public testing::Test {
static_cast<SearchField*>(field.release())); static_cast<SearchField*>(field.release()));
} }
private: std::vector<std::unique_ptr<AutofillField>> list_;
DISALLOW_COPY_AND_ASSIGN(SearchFieldTest); std::unique_ptr<SearchField> field_;
FieldCandidatesMap field_candidates_map_;
// RAII object to mock the the PatternProvider.
TestPatternProvider test_pattern_provider_;
}; };
TEST_F(SearchFieldTest, ParseSearchTerm) { TEST_F(SearchFieldTest, ParseSearchTerm) {
......
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