Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: components/autofill/core/browser/webdata/autofill_table_unittest.cc

Issue 2744933004: [Autofill] Rewrite Autofill unitttests to use INSTANTIATE_TEST_CASE_P (Closed)
Patch Set: More unit tests rewrites Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/webdata/autofill_table.h" 5 #include "components/autofill/core/browser/webdata/autofill_table.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <tuple> 9 #include <tuple>
10 #include <utility> 10 #include <utility>
(...skipping 1937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1948 base::Time(), base::Time::Max(), &profile_guids, &credit_card_guids)); 1948 base::Time(), base::Time::Max(), &profile_guids, &credit_card_guids));
1949 1949
1950 // Should be masked again. 1950 // Should be masked again.
1951 ASSERT_TRUE(table_->GetServerCreditCards(&outputs)); 1951 ASSERT_TRUE(table_->GetServerCreditCards(&outputs));
1952 ASSERT_EQ(1u, outputs.size()); 1952 ASSERT_EQ(1u, outputs.size());
1953 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, outputs[0]->record_type()); 1953 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, outputs[0]->record_type());
1954 EXPECT_EQ(masked_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); 1954 EXPECT_EQ(masked_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1955 outputs.clear(); 1955 outputs.clear();
1956 } 1956 }
1957 1957
1958 TEST_F(AutofillTableTest, GetFormValuesForElementName_SubstringMatchEnabled) { 1958 const size_t kMaxCount = 2;
1959 struct GetFormValuesTestCase {
1960 const char* const field_suggestion[kMaxCount];
sebsg 2017/03/13 14:56:10 Could you add a constructor here too? You did it i
wuandy 2017/03/14 19:05:36 As discussed offline, i removed constructor from a
1961 const char* const field_contents;
1962 size_t expected_suggestion_count;
1963 const char* const expected_suggestion[kMaxCount];
1964 };
1965
1966 class GetFormValuesTest : public testing::TestWithParam<GetFormValuesTestCase> {
1967 public:
1968 GetFormValuesTest() {}
1969 ~GetFormValuesTest() override {}
1970
1971 protected:
1972 void SetUp() override {
1973 OSCryptMocker::SetUpWithSingleton();
1974 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
1975 file_ = temp_dir_.GetPath().AppendASCII("TestWebDatabase");
1976
1977 table_.reset(new AutofillTable);
1978 db_.reset(new WebDatabase);
1979 db_->AddTable(table_.get());
1980 ASSERT_EQ(sql::INIT_OK, db_->Init(file_));
1981 }
1982
1983 void TearDown() override { OSCryptMocker::TearDown(); }
1984
1985 base::FilePath file_;
1986 base::ScopedTempDir temp_dir_;
1987 std::unique_ptr<AutofillTable> table_;
1988 std::unique_ptr<WebDatabase> db_;
1989
1990 private:
1991 DISALLOW_COPY_AND_ASSIGN(GetFormValuesTest);
1992 };
1993
1994 TEST_P(GetFormValuesTest, GetFormValuesForElementName_SubstringMatchEnabled) {
1959 // Token matching is currently behind a flag. 1995 // Token matching is currently behind a flag.
1960 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1996 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1961 switches::kEnableSuggestionsWithSubstringMatch); 1997 switches::kEnableSuggestionsWithSubstringMatch);
1962 1998
1963 const size_t kMaxCount = 2; 1999 auto test_case = GetParam();
1964 const struct { 2000 SCOPED_TRACE(testing::Message()
1965 const char* const field_suggestion[kMaxCount]; 2001 << "suggestion = " << test_case.field_suggestion[0]
1966 const char* const field_contents; 2002 << ", contents = " << test_case.field_contents);
1967 size_t expected_suggestion_count;
1968 const char* const expected_suggestion[kMaxCount];
1969 } kTestCases[] = {
1970 {{"user.test", "test_user"}, "TEST", 2, {"test_user", "user.test"}},
1971 {{"user test", "test-user"}, "user", 2, {"user test", "test-user"}},
1972 {{"user test", "test-rest"}, "user", 1, {"user test", nullptr}},
1973 {{"user@test", "test_user"}, "user@t", 1, {"user@test", nullptr}},
1974 {{"user.test", "test_user"}, "er.tes", 0, {nullptr, nullptr}},
1975 {{"user test", "test_user"}, "_ser", 0, {nullptr, nullptr}},
1976 {{"user.test", "test_user"}, "%ser", 0, {nullptr, nullptr}},
1977 {{"user.test", "test_user"},
1978 "; DROP TABLE autofill;",
1979 0,
1980 {nullptr, nullptr}},
1981 };
1982 2003
1983 for (const auto& test_case : kTestCases) { 2004 Time t1 = Time::Now();
1984 SCOPED_TRACE(testing::Message()
1985 << "suggestion = " << test_case.field_suggestion[0]
1986 << ", contents = " << test_case.field_contents);
1987 2005
1988 Time t1 = Time::Now(); 2006 // Simulate the submission of a handful of entries in a field called "Name".
2007 AutofillChangeList changes;
2008 FormFieldData field;
2009 for (size_t k = 0; k < kMaxCount; ++k) {
2010 field.name = ASCIIToUTF16("Name");
2011 field.value = ASCIIToUTF16(test_case.field_suggestion[k]);
2012 table_->AddFormFieldValue(field, &changes);
2013 }
1989 2014
1990 // Simulate the submission of a handful of entries in a field called "Name". 2015 std::vector<base::string16> v;
1991 AutofillChangeList changes; 2016 table_->GetFormValuesForElementName(
1992 FormFieldData field; 2017 ASCIIToUTF16("Name"), ASCIIToUTF16(test_case.field_contents), &v, 6);
1993 for (size_t k = 0; k < kMaxCount; ++k) {
1994 field.name = ASCIIToUTF16("Name");
1995 field.value = ASCIIToUTF16(test_case.field_suggestion[k]);
1996 table_->AddFormFieldValue(field, &changes);
1997 }
1998 2018
1999 std::vector<base::string16> v; 2019 EXPECT_EQ(test_case.expected_suggestion_count, v.size());
2000 table_->GetFormValuesForElementName( 2020 for (size_t j = 0; j < test_case.expected_suggestion_count; ++j) {
2001 ASCIIToUTF16("Name"), ASCIIToUTF16(test_case.field_contents), &v, 6); 2021 EXPECT_EQ(ASCIIToUTF16(test_case.expected_suggestion[j]), v[j]);
2022 }
2002 2023
2003 EXPECT_EQ(test_case.expected_suggestion_count, v.size()); 2024 changes.clear();
2004 for (size_t j = 0; j < test_case.expected_suggestion_count; ++j) { 2025 table_->RemoveFormElementsAddedBetween(t1, Time(), &changes);
2005 EXPECT_EQ(ASCIIToUTF16(test_case.expected_suggestion[j]), v[j]); 2026 }
2006 }
2007 2027
2008 changes.clear(); 2028 INSTANTIATE_TEST_CASE_P(
2009 table_->RemoveFormElementsAddedBetween(t1, Time(), &changes); 2029 AutofillTableTest,
2010 } 2030 GetFormValuesTest,
2011 } 2031 testing::Values(GetFormValuesTestCase{{"user.test", "test_user"},
2032 "TEST",
2033 2,
2034 {"test_user", "user.test"}},
2035 GetFormValuesTestCase{{"user test", "test-user"},
2036 "user",
2037 2,
2038 {"user test", "test-user"}},
2039 GetFormValuesTestCase{{"user test", "test-rest"},
2040 "user",
2041 1,
2042 {"user test", nullptr}},
2043 GetFormValuesTestCase{{"user@test", "test_user"},
2044 "user@t",
2045 1,
2046 {"user@test", nullptr}},
2047 GetFormValuesTestCase{{"user.test", "test_user"},
2048 "er.tes",
2049 0,
2050 {nullptr, nullptr}},
2051 GetFormValuesTestCase{{"user test", "test_user"},
2052 "_ser",
2053 0,
2054 {nullptr, nullptr}},
2055 GetFormValuesTestCase{{"user.test", "test_user"},
2056 "%ser",
2057 0,
2058 {nullptr, nullptr}},
2059 GetFormValuesTestCase{{"user.test", "test_user"},
2060 "; DROP TABLE autofill;",
2061 0,
2062 {nullptr, nullptr}}));
2012 2063
2013 TEST_F(AutofillTableTest, AutofillNoMetadata) { 2064 TEST_F(AutofillTableTest, AutofillNoMetadata) {
2014 MetadataBatch metadata_batch; 2065 MetadataBatch metadata_batch;
2015 EXPECT_TRUE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); 2066 EXPECT_TRUE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch));
2016 EXPECT_EQ(0u, metadata_batch.TakeAllMetadata().size()); 2067 EXPECT_EQ(0u, metadata_batch.TakeAllMetadata().size());
2017 EXPECT_EQ(ModelTypeState().SerializeAsString(), 2068 EXPECT_EQ(ModelTypeState().SerializeAsString(),
2018 metadata_batch.GetModelTypeState().SerializeAsString()); 2069 metadata_batch.GetModelTypeState().SerializeAsString());
2019 } 2070 }
2020 2071
2021 TEST_F(AutofillTableTest, AutofillGetAllSyncMetadata) { 2072 TEST_F(AutofillTableTest, AutofillGetAllSyncMetadata) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 sql::Statement s(db_->GetSQLConnection()->GetUniqueStatement( 2152 sql::Statement s(db_->GetSQLConnection()->GetUniqueStatement(
2102 "INSERT OR REPLACE INTO autofill_model_type_state " 2153 "INSERT OR REPLACE INTO autofill_model_type_state "
2103 "(rowid, value) VALUES(1, ?)")); 2154 "(rowid, value) VALUES(1, ?)"));
2104 s.BindString(0, "unparseable"); 2155 s.BindString(0, "unparseable");
2105 EXPECT_TRUE(s.Run()); 2156 EXPECT_TRUE(s.Run());
2106 2157
2107 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); 2158 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch));
2108 } 2159 }
2109 2160
2110 } // namespace autofill 2161 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698