| 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/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "build/build_config.h" | 34 #include "build/build_config.h" |
| 35 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 35 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
| 36 #include "components/autofill/core/browser/autofill_download_manager.h" | 36 #include "components/autofill/core/browser/autofill_download_manager.h" |
| 37 #include "components/autofill/core/browser/autofill_experiments.h" | 37 #include "components/autofill/core/browser/autofill_experiments.h" |
| 38 #include "components/autofill/core/browser/autofill_profile.h" | 38 #include "components/autofill/core/browser/autofill_profile.h" |
| 39 #include "components/autofill/core/browser/autofill_test_utils.h" | 39 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 40 #include "components/autofill/core/browser/credit_card.h" | 40 #include "components/autofill/core/browser/credit_card.h" |
| 41 #include "components/autofill/core/browser/personal_data_manager.h" | 41 #include "components/autofill/core/browser/personal_data_manager.h" |
| 42 #include "components/autofill/core/browser/popup_item_ids.h" | 42 #include "components/autofill/core/browser/popup_item_ids.h" |
| 43 #include "components/autofill/core/browser/test_autofill_client.h" | 43 #include "components/autofill/core/browser/test_autofill_client.h" |
| 44 #include "components/autofill/core/browser/test_autofill_clock.h" |
| 44 #include "components/autofill/core/browser/test_autofill_driver.h" | 45 #include "components/autofill/core/browser/test_autofill_driver.h" |
| 45 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 46 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
| 46 #include "components/autofill/core/browser/validation.h" | 47 #include "components/autofill/core/browser/validation.h" |
| 47 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 48 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 49 #include "components/autofill/core/common/autofill_clock.h" |
| 48 #include "components/autofill/core/common/autofill_pref_names.h" | 50 #include "components/autofill/core/common/autofill_pref_names.h" |
| 49 #include "components/autofill/core/common/autofill_switches.h" | 51 #include "components/autofill/core/common/autofill_switches.h" |
| 50 #include "components/autofill/core/common/autofill_util.h" | 52 #include "components/autofill/core/common/autofill_util.h" |
| 51 #include "components/autofill/core/common/form_data.h" | 53 #include "components/autofill/core/common/form_data.h" |
| 52 #include "components/autofill/core/common/form_field_data.h" | 54 #include "components/autofill/core/common/form_field_data.h" |
| 53 #include "components/metrics/proto/ukm/entry.pb.h" | 55 #include "components/metrics/proto/ukm/entry.pb.h" |
| 54 #include "components/prefs/pref_service.h" | 56 #include "components/prefs/pref_service.h" |
| 55 #include "components/rappor/test_rappor_service.h" | 57 #include "components/rappor/test_rappor_service.h" |
| 56 #include "components/security_state/core/security_state.h" | 58 #include "components/security_state/core/security_state.h" |
| 57 #include "components/strings/grit/components_strings.h" | 59 #include "components/strings/grit/components_strings.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 69 #include "url/gurl.h" | 71 #include "url/gurl.h" |
| 70 | 72 |
| 71 using base::ASCIIToUTF16; | 73 using base::ASCIIToUTF16; |
| 72 using base::UTF8ToUTF16; | 74 using base::UTF8ToUTF16; |
| 73 using testing::_; | 75 using testing::_; |
| 74 using testing::AtLeast; | 76 using testing::AtLeast; |
| 75 using testing::Return; | 77 using testing::Return; |
| 76 using testing::SaveArg; | 78 using testing::SaveArg; |
| 77 | 79 |
| 78 namespace autofill { | 80 namespace autofill { |
| 79 | |
| 80 namespace { | 81 namespace { |
| 81 | 82 |
| 82 const int kDefaultPageID = 137; | 83 const int kDefaultPageID = 137; |
| 83 | 84 |
| 84 const char kUTF8MidlineEllipsis[] = | 85 const char kUTF8MidlineEllipsis[] = |
| 85 " " | 86 " " |
| 86 "\xE2\x80\xA2\xE2\x80\x86" | 87 "\xE2\x80\xA2\xE2\x80\x86" |
| 87 "\xE2\x80\xA2\xE2\x80\x86" | 88 "\xE2\x80\xA2\xE2\x80\x86" |
| 88 "\xE2\x80\xA2\xE2\x80\x86" | 89 "\xE2\x80\xA2\xE2\x80\x86" |
| 89 "\xE2\x80\xA2\xE2\x80\x86"; | 90 "\xE2\x80\xA2\xE2\x80\x86"; |
| 90 | 91 |
| 92 const base::Time kArbitraryTime = base::Time::FromDoubleT(25); |
| 93 const base::Time kMuchLaterTime = base::Time::FromDoubleT(5000); |
| 94 |
| 91 class MockAutofillClient : public TestAutofillClient { | 95 class MockAutofillClient : public TestAutofillClient { |
| 92 public: | 96 public: |
| 93 MockAutofillClient() {} | 97 MockAutofillClient() {} |
| 94 | 98 |
| 95 ~MockAutofillClient() override {} | 99 ~MockAutofillClient() override {} |
| 96 | 100 |
| 97 MOCK_METHOD2(ConfirmSaveCreditCardLocally, | 101 MOCK_METHOD2(ConfirmSaveCreditCardLocally, |
| 98 void(const CreditCard& card, const base::Closure& callback)); | 102 void(const CreditCard& card, const base::Closure& callback)); |
| 99 | 103 |
| 100 MOCK_METHOD0(ShouldShowSigninPromo, bool()); | 104 MOCK_METHOD0(ShouldShowSigninPromo, bool()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 169 |
| 166 CreditCard* GetCreditCardWithGUID(const char* guid) { | 170 CreditCard* GetCreditCardWithGUID(const char* guid) { |
| 167 for (CreditCard* card : GetCreditCards()) { | 171 for (CreditCard* card : GetCreditCards()) { |
| 168 if (!card->guid().compare(guid)) | 172 if (!card->guid().compare(guid)) |
| 169 return card; | 173 return card; |
| 170 } | 174 } |
| 171 return NULL; | 175 return NULL; |
| 172 } | 176 } |
| 173 | 177 |
| 174 void AddProfile(std::unique_ptr<AutofillProfile> profile) { | 178 void AddProfile(std::unique_ptr<AutofillProfile> profile) { |
| 175 profile->set_modification_date(base::Time::Now()); | 179 profile->set_modification_date(AutofillClock::Now()); |
| 176 web_profiles_.push_back(std::move(profile)); | 180 web_profiles_.push_back(std::move(profile)); |
| 177 } | 181 } |
| 178 | 182 |
| 179 void AddCreditCard(const CreditCard& credit_card) override { | 183 void AddCreditCard(const CreditCard& credit_card) override { |
| 180 std::unique_ptr<CreditCard> local_credit_card = | 184 std::unique_ptr<CreditCard> local_credit_card = |
| 181 base::MakeUnique<CreditCard>(credit_card); | 185 base::MakeUnique<CreditCard>(credit_card); |
| 182 local_credit_card->set_modification_date(base::Time::Now()); | 186 local_credit_card->set_modification_date(base::Time::Now()); |
| 183 local_credit_cards_.push_back(std::move(local_credit_card)); | 187 local_credit_cards_.push_back(std::move(local_credit_card)); |
| 184 } | 188 } |
| 185 | 189 |
| (...skipping 5004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5190 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 5194 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5191 | 5195 |
| 5192 base::HistogramTester histogram_tester; | 5196 base::HistogramTester histogram_tester; |
| 5193 | 5197 |
| 5194 // Neither a local save nor an upload should happen in this case. | 5198 // Neither a local save nor an upload should happen in this case. |
| 5195 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 5199 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5196 FormSubmitted(credit_card_form); | 5200 FormSubmitted(credit_card_form); |
| 5197 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 5201 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
| 5198 | 5202 |
| 5199 // Verify that the correct histogram entries are logged. | 5203 // Verify that the correct histogram entries are logged. |
| 5200 ExpectCardUploadDecision(histogram_tester, | 5204 ExpectUniqueCardUploadDecision( |
| 5201 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS); | 5205 histogram_tester, AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS_PROFILE); |
| 5202 ExpectCardUploadDecision(histogram_tester, | |
| 5203 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); | |
| 5204 // Verify that the correct UKM was logged. | 5206 // Verify that the correct UKM was logged. |
| 5205 ExpectMetric(internal::kUKMCardUploadDecisionMetricName, | 5207 ExpectCardUploadDecisionUkm( |
| 5206 internal::kUKMCardUploadDecisionEntryName, | 5208 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS_PROFILE); |
| 5207 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS | | |
| 5208 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE, | |
| 5209 1 /* expected_num_matching_entries */); | |
| 5210 | 5209 |
| 5211 rappor::TestRapporServiceImpl* rappor_service = | 5210 rappor::TestRapporServiceImpl* rappor_service = |
| 5212 autofill_client_.test_rappor_service(); | 5211 autofill_client_.test_rappor_service(); |
| 5213 EXPECT_EQ(1, rappor_service->GetReportsCount()); | 5212 EXPECT_EQ(1, rappor_service->GetReportsCount()); |
| 5214 std::string sample; | 5213 std::string sample; |
| 5215 rappor::RapporType type; | 5214 rappor::RapporType type; |
| 5216 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( | 5215 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 5217 "Autofill.CardUploadNotOfferedNoAddress", &sample, &type)); | 5216 "Autofill.CardUploadNotOfferedNoAddress", &sample, &type)); |
| 5218 EXPECT_EQ("myform.com", sample); | 5217 EXPECT_EQ("myform.com", sample); |
| 5219 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 5218 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
| 5220 } | 5219 } |
| 5221 | 5220 |
| 5222 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5221 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5223 #if defined(OS_ANDROID) | 5222 #if defined(OS_ANDROID) |
| 5223 #define MAYBE_UploadCreditCard_NoRecentlyUsedProfile \ |
| 5224 DISABLED_UploadCreditCard_NoRecentlyUsedProfile |
| 5225 #else |
| 5226 #define MAYBE_UploadCreditCard_NoRecentlyUsedProfile \ |
| 5227 UploadCreditCard_NoRecentlyUsedProfile |
| 5228 #endif |
| 5229 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoRecentlyUsedProfile) { |
| 5230 // Create the test clock and set the time to a specific value. |
| 5231 TestAutofillClock test_clock; |
| 5232 test_clock.SetNow(kArbitraryTime); |
| 5233 |
| 5234 EnableUkmLogging(); |
| 5235 personal_data_.ClearAutofillProfiles(); |
| 5236 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5237 |
| 5238 // Create, fill and submit an address form in order to establish a profile. |
| 5239 FormData address_form; |
| 5240 test::CreateTestAddressFormData(&address_form); |
| 5241 FormsSeen({address_form}); |
| 5242 |
| 5243 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); |
| 5244 FormSubmitted(address_form); |
| 5245 |
| 5246 // Set the current time to another value. |
| 5247 test_clock.SetNow(kMuchLaterTime); |
| 5248 |
| 5249 // Set up our credit card form data. |
| 5250 FormData credit_card_form; |
| 5251 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 5252 FormsSeen(std::vector<FormData>(1, credit_card_form)); |
| 5253 |
| 5254 // Edit the data, and submit. |
| 5255 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
| 5256 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 5257 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| 5258 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| 5259 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5260 |
| 5261 base::HistogramTester histogram_tester; |
| 5262 |
| 5263 // Neither a local save nor an upload should happen in this case. |
| 5264 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5265 FormSubmitted(credit_card_form); |
| 5266 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
| 5267 |
| 5268 // Verify that the correct histogram entry (and only that) was logged. |
| 5269 ExpectUniqueCardUploadDecision( |
| 5270 histogram_tester, |
| 5271 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_RECENTLY_USED_ADDRESS); |
| 5272 // Verify that the correct UKM was logged. |
| 5273 ExpectCardUploadDecisionUkm( |
| 5274 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_RECENTLY_USED_ADDRESS); |
| 5275 } |
| 5276 |
| 5277 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5278 #if defined(OS_ANDROID) |
| 5224 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable \ | 5279 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable \ |
| 5225 DISABLED_UploadCreditCard_CvcUnavailableAndNoProfileAvailable | 5280 DISABLED_UploadCreditCard_CvcUnavailableAndNoProfileAvailable |
| 5226 #else | 5281 #else |
| 5227 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable \ | 5282 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable \ |
| 5228 UploadCreditCard_CvcUnavailableAndNoProfileAvailable | 5283 UploadCreditCard_CvcUnavailableAndNoProfileAvailable |
| 5229 #endif | 5284 #endif |
| 5230 TEST_F(AutofillManagerTest, | 5285 TEST_F(AutofillManagerTest, |
| 5231 MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable) { | 5286 MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable) { |
| 5232 EnableUkmLogging(); | 5287 EnableUkmLogging(); |
| 5233 personal_data_.ClearAutofillProfiles(); | 5288 personal_data_.ClearAutofillProfiles(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 5252 // Neither a local save nor an upload should happen in this case. | 5307 // Neither a local save nor an upload should happen in this case. |
| 5253 // Note that AutofillManager should *check* for both no CVC and no address | 5308 // Note that AutofillManager should *check* for both no CVC and no address |
| 5254 // profile, but the no CVC case should have priority over being reported. | 5309 // profile, but the no CVC case should have priority over being reported. |
| 5255 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 5310 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5256 FormSubmitted(credit_card_form); | 5311 FormSubmitted(credit_card_form); |
| 5257 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 5312 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
| 5258 | 5313 |
| 5259 // Verify that the correct histogram entries were logged. | 5314 // Verify that the correct histogram entries were logged. |
| 5260 ExpectCardUploadDecision(histogram_tester, | 5315 ExpectCardUploadDecision(histogram_tester, |
| 5261 AutofillMetrics::CVC_VALUE_NOT_FOUND); | 5316 AutofillMetrics::CVC_VALUE_NOT_FOUND); |
| 5262 ExpectCardUploadDecision(histogram_tester, | 5317 ExpectCardUploadDecision( |
| 5263 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS); | 5318 histogram_tester, AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS_PROFILE); |
| 5264 ExpectCardUploadDecision(histogram_tester, | |
| 5265 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); | |
| 5266 // Verify that the correct UKM was logged. | 5319 // Verify that the correct UKM was logged. |
| 5267 ExpectMetric(internal::kUKMCardUploadDecisionMetricName, | 5320 ExpectMetric(internal::kUKMCardUploadDecisionMetricName, |
| 5268 internal::kUKMCardUploadDecisionEntryName, | 5321 internal::kUKMCardUploadDecisionEntryName, |
| 5269 AutofillMetrics::CVC_VALUE_NOT_FOUND | | 5322 AutofillMetrics::CVC_VALUE_NOT_FOUND | |
| 5270 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS | | 5323 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS_PROFILE, |
| 5271 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE, | |
| 5272 1 /* expected_num_matching_entries */); | 5324 1 /* expected_num_matching_entries */); |
| 5273 | 5325 |
| 5274 rappor::TestRapporServiceImpl* rappor_service = | 5326 rappor::TestRapporServiceImpl* rappor_service = |
| 5275 autofill_client_.test_rappor_service(); | 5327 autofill_client_.test_rappor_service(); |
| 5276 EXPECT_EQ(1, rappor_service->GetReportsCount()); | 5328 EXPECT_EQ(1, rappor_service->GetReportsCount()); |
| 5277 std::string sample; | 5329 std::string sample; |
| 5278 rappor::RapporType type; | 5330 rappor::RapporType type; |
| 5279 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( | 5331 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 5280 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); | 5332 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); |
| 5281 EXPECT_EQ("myform.com", sample); | 5333 EXPECT_EQ("myform.com", sample); |
| (...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6335 | 6387 |
| 6336 // Wait for upload to complete (will check expected types as well). | 6388 // Wait for upload to complete (will check expected types as well). |
| 6337 autofill_manager_->WaitForAsyncUploadProcess(); | 6389 autofill_manager_->WaitForAsyncUploadProcess(); |
| 6338 | 6390 |
| 6339 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 6391 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
| 6340 EXPECT_NE(uploaded_available_types.end(), | 6392 EXPECT_NE(uploaded_available_types.end(), |
| 6341 uploaded_available_types.find(autofill::PASSWORD)); | 6393 uploaded_available_types.find(autofill::PASSWORD)); |
| 6342 } | 6394 } |
| 6343 | 6395 |
| 6344 } // namespace autofill | 6396 } // namespace autofill |
| OLD | NEW |