| OLD | NEW |
| 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/phone_field.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 | 8 |
| 9 #include <memory> |
| 10 |
| 7 #include "base/macros.h" | 11 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/autofill/core/browser/autofill_field.h" | 15 #include "components/autofill/core/browser/autofill_field.h" |
| 12 #include "components/autofill/core/browser/autofill_scanner.h" | 16 #include "components/autofill/core/browser/autofill_scanner.h" |
| 13 #include "components/autofill/core/browser/phone_field.h" | |
| 14 #include "components/autofill/core/common/form_field_data.h" | 17 #include "components/autofill/core/common/form_field_data.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 19 |
| 17 using base::ASCIIToUTF16; | 20 using base::ASCIIToUTF16; |
| 18 | 21 |
| 19 namespace autofill { | 22 namespace autofill { |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 const char* const kFieldTypes[] = { | 26 const char* const kFieldTypes[] = { |
| 24 "text", | 27 "text", |
| 25 "tel", | 28 "tel", |
| 26 "number", | 29 "number", |
| 27 }; | 30 }; |
| 28 | 31 |
| 29 } // namespace | 32 } // namespace |
| 30 | 33 |
| 31 class PhoneFieldTest : public testing::Test { | 34 class PhoneFieldTest : public testing::Test { |
| 32 public: | 35 public: |
| 33 PhoneFieldTest() {} | 36 PhoneFieldTest() {} |
| 34 | 37 |
| 35 protected: | 38 protected: |
| 36 // Downcast for tests. | 39 // Downcast for tests. |
| 37 static scoped_ptr<PhoneField> Parse(AutofillScanner* scanner) { | 40 static std::unique_ptr<PhoneField> Parse(AutofillScanner* scanner) { |
| 38 scoped_ptr<FormField> field = PhoneField::Parse(scanner); | 41 std::unique_ptr<FormField> field = PhoneField::Parse(scanner); |
| 39 return make_scoped_ptr(static_cast<PhoneField*>(field.release())); | 42 return base::WrapUnique(static_cast<PhoneField*>(field.release())); |
| 40 } | 43 } |
| 41 | 44 |
| 42 void Clear() { | 45 void Clear() { |
| 43 list_.clear(); | 46 list_.clear(); |
| 44 field_.reset(); | 47 field_.reset(); |
| 45 field_candidates_map_.clear(); | 48 field_candidates_map_.clear(); |
| 46 } | 49 } |
| 47 | 50 |
| 48 void CheckField(const std::string& name, | 51 void CheckField(const std::string& name, |
| 49 ServerFieldType expected_type) const { | 52 ServerFieldType expected_type) const { |
| 50 auto it = field_candidates_map_.find(ASCIIToUTF16(name)); | 53 auto it = field_candidates_map_.find(ASCIIToUTF16(name)); |
| 51 ASSERT_TRUE(it != field_candidates_map_.end()) << name; | 54 ASSERT_TRUE(it != field_candidates_map_.end()) << name; |
| 52 EXPECT_EQ(expected_type, it->second.BestHeuristicType()) << name; | 55 EXPECT_EQ(expected_type, it->second.BestHeuristicType()) << name; |
| 53 } | 56 } |
| 54 | 57 |
| 55 ScopedVector<AutofillField> list_; | 58 ScopedVector<AutofillField> list_; |
| 56 scoped_ptr<PhoneField> field_; | 59 std::unique_ptr<PhoneField> field_; |
| 57 FieldCandidatesMap field_candidates_map_; | 60 FieldCandidatesMap field_candidates_map_; |
| 58 | 61 |
| 59 private: | 62 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(PhoneFieldTest); | 63 DISALLOW_COPY_AND_ASSIGN(PhoneFieldTest); |
| 61 }; | 64 }; |
| 62 | 65 |
| 63 TEST_F(PhoneFieldTest, Empty) { | 66 TEST_F(PhoneFieldTest, Empty) { |
| 64 AutofillScanner scanner(list_.get()); | 67 AutofillScanner scanner(list_.get()); |
| 65 field_ = Parse(&scanner); | 68 field_ = Parse(&scanner); |
| 66 ASSERT_EQ(nullptr, field_.get()); | 69 ASSERT_EQ(nullptr, field_.get()); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 AutofillScanner scanner(list_.get()); | 248 AutofillScanner scanner(list_.get()); |
| 246 field_ = Parse(&scanner); | 249 field_ = Parse(&scanner); |
| 247 ASSERT_NE(nullptr, field_.get()); | 250 ASSERT_NE(nullptr, field_.get()); |
| 248 field_->AddClassifications(&field_candidates_map_); | 251 field_->AddClassifications(&field_candidates_map_); |
| 249 CheckField("country", PHONE_HOME_COUNTRY_CODE); | 252 CheckField("country", PHONE_HOME_COUNTRY_CODE); |
| 250 CheckField("phone", PHONE_HOME_CITY_AND_NUMBER); | 253 CheckField("phone", PHONE_HOME_CITY_AND_NUMBER); |
| 251 } | 254 } |
| 252 } | 255 } |
| 253 | 256 |
| 254 } // namespace autofill | 257 } // namespace autofill |
| OLD | NEW |