| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/test/scoped_feature_list.h" | 20 #include "base/test/scoped_feature_list.h" |
| 20 #include "components/autofill/core/browser/autofill_experiments.h" | 21 #include "components/autofill/core/browser/autofill_experiments.h" |
| 21 #include "components/autofill/core/browser/autofill_test_utils.h" | 22 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 22 #include "components/autofill/core/browser/autofill_type.h" | 23 #include "components/autofill/core/browser/autofill_type.h" |
| 23 #include "components/autofill/core/browser/country_names.h" | 24 #include "components/autofill/core/browser/country_names.h" |
| 24 #include "components/autofill/core/browser/data_driven_test.h" | 25 #include "components/autofill/core/browser/data_driven_test.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 class PersonalDataManagerMock : public PersonalDataManager { | 113 class PersonalDataManagerMock : public PersonalDataManager { |
| 113 public: | 114 public: |
| 114 PersonalDataManagerMock(); | 115 PersonalDataManagerMock(); |
| 115 ~PersonalDataManagerMock() override; | 116 ~PersonalDataManagerMock() override; |
| 116 | 117 |
| 117 // Reset the saved profiles. | 118 // Reset the saved profiles. |
| 118 void Reset(); | 119 void Reset(); |
| 119 | 120 |
| 120 // PersonalDataManager: | 121 // PersonalDataManager: |
| 121 std::string SaveImportedProfile(const AutofillProfile& profile) override; | 122 std::string SaveImportedProfile(const AutofillProfile& profile) override; |
| 122 const std::vector<AutofillProfile*>& web_profiles() const override; | 123 std::vector<AutofillProfile*> web_profiles() const override; |
| 123 | 124 |
| 124 private: | 125 private: |
| 125 ScopedVector<AutofillProfile> profiles_; | 126 std::vector<std::unique_ptr<AutofillProfile>> profiles_; |
| 126 | 127 |
| 127 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerMock); | 128 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerMock); |
| 128 }; | 129 }; |
| 129 | 130 |
| 130 PersonalDataManagerMock::PersonalDataManagerMock() | 131 PersonalDataManagerMock::PersonalDataManagerMock() |
| 131 : PersonalDataManager("en-US") { | 132 : PersonalDataManager("en-US") { |
| 132 } | 133 } |
| 133 | 134 |
| 134 PersonalDataManagerMock::~PersonalDataManagerMock() { | 135 PersonalDataManagerMock::~PersonalDataManagerMock() { |
| 135 } | 136 } |
| 136 | 137 |
| 137 void PersonalDataManagerMock::Reset() { | 138 void PersonalDataManagerMock::Reset() { |
| 138 profiles_.clear(); | 139 profiles_.clear(); |
| 139 } | 140 } |
| 140 | 141 |
| 141 std::string PersonalDataManagerMock::SaveImportedProfile( | 142 std::string PersonalDataManagerMock::SaveImportedProfile( |
| 142 const AutofillProfile& profile) { | 143 const AutofillProfile& profile) { |
| 143 std::vector<AutofillProfile> profiles; | 144 std::vector<AutofillProfile> profiles; |
| 144 std::string merged_guid = | 145 std::string merged_guid = |
| 145 MergeProfile(profile, profiles_.get(), "en-US", &profiles); | 146 MergeProfile(profile, &profiles_, "en-US", &profiles); |
| 146 if (merged_guid == profile.guid()) | 147 if (merged_guid == profile.guid()) |
| 147 profiles_.push_back(new AutofillProfile(profile)); | 148 profiles_.push_back(base::MakeUnique<AutofillProfile>(profile)); |
| 148 return merged_guid; | 149 return merged_guid; |
| 149 } | 150 } |
| 150 | 151 |
| 151 const std::vector<AutofillProfile*>& PersonalDataManagerMock::web_profiles() | 152 std::vector<AutofillProfile*> PersonalDataManagerMock::web_profiles() const { |
| 152 const { | 153 std::vector<AutofillProfile*> result; |
| 153 return profiles_.get(); | 154 for (const auto& profile : profiles_) |
| 155 result.push_back(profile.get()); |
| 156 return result; |
| 154 } | 157 } |
| 155 | 158 |
| 156 } // namespace | 159 } // namespace |
| 157 | 160 |
| 158 // A data-driven test for verifying merging of Autofill profiles. Each input is | 161 // A data-driven test for verifying merging of Autofill profiles. Each input is |
| 159 // a structured dump of a set of implicitly detected autofill profiles. The | 162 // a structured dump of a set of implicitly detected autofill profiles. The |
| 160 // corresponding output file is a dump of the saved profiles that result from | 163 // corresponding output file is a dump of the saved profiles that result from |
| 161 // importing the input profiles. The output file format is identical to the | 164 // importing the input profiles. The output file format is identical to the |
| 162 // input format. | 165 // input format. |
| 163 class AutofillMergeTest : public DataDrivenTest, | 166 class AutofillMergeTest : public DataDrivenTest, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 return string_to_field_type_map_[str]; | 292 return string_to_field_type_map_[str]; |
| 290 } | 293 } |
| 291 | 294 |
| 292 TEST_P(AutofillMergeTest, DataDrivenMergeProfiles) { | 295 TEST_P(AutofillMergeTest, DataDrivenMergeProfiles) { |
| 293 RunOneDataDrivenTest(GetParam(), GetOutputDirectory(kTestName)); | 296 RunOneDataDrivenTest(GetParam(), GetOutputDirectory(kTestName)); |
| 294 } | 297 } |
| 295 | 298 |
| 296 INSTANTIATE_TEST_CASE_P(, AutofillMergeTest, testing::ValuesIn(GetTestFiles())); | 299 INSTANTIATE_TEST_CASE_P(, AutofillMergeTest, testing::ValuesIn(GetTestFiles())); |
| 297 | 300 |
| 298 } // namespace autofill | 301 } // namespace autofill |
| OLD | NEW |