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 25 matching lines...) Expand all Loading... |
36 #include "components/autofill/core/browser/test_autofill_driver.h" | 36 #include "components/autofill/core/browser/test_autofill_driver.h" |
37 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 37 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
38 #include "components/autofill/core/browser/validation.h" | 38 #include "components/autofill/core/browser/validation.h" |
39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
40 #include "components/autofill/core/common/autofill_pref_names.h" | 40 #include "components/autofill/core/common/autofill_pref_names.h" |
41 #include "components/autofill/core/common/autofill_switches.h" | 41 #include "components/autofill/core/common/autofill_switches.h" |
42 #include "components/autofill/core/common/autofill_util.h" | 42 #include "components/autofill/core/common/autofill_util.h" |
43 #include "components/autofill/core/common/form_data.h" | 43 #include "components/autofill/core/common/form_data.h" |
44 #include "components/autofill/core/common/form_field_data.h" | 44 #include "components/autofill/core/common/form_field_data.h" |
45 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
| 46 #include "components/rappor/test_rappor_service.h" |
46 #include "grit/components_strings.h" | 47 #include "grit/components_strings.h" |
47 #include "net/url_request/url_request_test_util.h" | 48 #include "net/url_request/url_request_test_util.h" |
48 #include "testing/gmock/include/gmock/gmock.h" | 49 #include "testing/gmock/include/gmock/gmock.h" |
49 #include "testing/gtest/include/gtest/gtest.h" | 50 #include "testing/gtest/include/gtest/gtest.h" |
50 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
51 #include "ui/gfx/geometry/rect.h" | 52 #include "ui/gfx/geometry/rect.h" |
52 #include "url/gurl.h" | 53 #include "url/gurl.h" |
53 | 54 |
54 using base::ASCIIToUTF16; | 55 using base::ASCIIToUTF16; |
55 using base::UTF8ToUTF16; | 56 using base::UTF8ToUTF16; |
(...skipping 4291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4347 | 4348 |
4348 // Neither a local save nor an upload should happen in this case. | 4349 // Neither a local save nor an upload should happen in this case. |
4349 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 4350 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
4350 FormSubmitted(credit_card_form); | 4351 FormSubmitted(credit_card_form); |
4351 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 4352 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
4352 | 4353 |
4353 // Verify that the correct histogram entry (and only that) was logged. | 4354 // Verify that the correct histogram entry (and only that) was logged. |
4354 histogram_tester.ExpectUniqueSample( | 4355 histogram_tester.ExpectUniqueSample( |
4355 "Autofill.CardUploadDecisionExpanded", | 4356 "Autofill.CardUploadDecisionExpanded", |
4356 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1); | 4357 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1); |
| 4358 |
| 4359 rappor::TestRapporService* rappor_service = |
| 4360 autofill_client_.test_rappor_service(); |
| 4361 EXPECT_EQ(1, rappor_service->GetReportsCount()); |
| 4362 std::string sample; |
| 4363 rappor::RapporType type; |
| 4364 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 4365 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); |
| 4366 EXPECT_EQ("myform.com", sample); |
| 4367 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
4357 } | 4368 } |
4358 | 4369 |
4359 TEST_F(AutofillManagerTest, UploadCreditCard_MultipleCvcFields) { | 4370 TEST_F(AutofillManagerTest, UploadCreditCard_MultipleCvcFields) { |
4360 autofill_manager_->set_credit_card_upload_enabled(true); | 4371 autofill_manager_->set_credit_card_upload_enabled(true); |
4361 | 4372 |
4362 // Remove the profiles that were created in the TestPersonalDataManager | 4373 // Remove the profiles that were created in the TestPersonalDataManager |
4363 // constructor because they would result in conflicting names that would | 4374 // constructor because they would result in conflicting names that would |
4364 // prevent the upload. | 4375 // prevent the upload. |
4365 personal_data_.ClearAutofillProfiles(); | 4376 personal_data_.ClearAutofillProfiles(); |
4366 | 4377 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4437 | 4448 |
4438 // Neither a local save nor an upload should happen in this case. | 4449 // Neither a local save nor an upload should happen in this case. |
4439 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 4450 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
4440 FormSubmitted(credit_card_form); | 4451 FormSubmitted(credit_card_form); |
4441 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 4452 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
4442 | 4453 |
4443 // Verify that the correct histogram entry (and only that) was logged. | 4454 // Verify that the correct histogram entry (and only that) was logged. |
4444 histogram_tester.ExpectUniqueSample( | 4455 histogram_tester.ExpectUniqueSample( |
4445 "Autofill.CardUploadDecisionExpanded", | 4456 "Autofill.CardUploadDecisionExpanded", |
4446 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS, 1); | 4457 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS, 1); |
| 4458 |
| 4459 rappor::TestRapporService* rappor_service = |
| 4460 autofill_client_.test_rappor_service(); |
| 4461 EXPECT_EQ(1, rappor_service->GetReportsCount()); |
| 4462 std::string sample; |
| 4463 rappor::RapporType type; |
| 4464 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 4465 "Autofill.CardUploadNotOfferedNoAddress", &sample, &type)); |
| 4466 EXPECT_EQ("myform.com", sample); |
| 4467 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
4447 } | 4468 } |
4448 | 4469 |
4449 TEST_F(AutofillManagerTest, UploadCreditCard_NoNameAvailable) { | 4470 TEST_F(AutofillManagerTest, UploadCreditCard_NoNameAvailable) { |
4450 personal_data_.ClearAutofillProfiles(); | 4471 personal_data_.ClearAutofillProfiles(); |
4451 autofill_manager_->set_credit_card_upload_enabled(true); | 4472 autofill_manager_->set_credit_card_upload_enabled(true); |
4452 | 4473 |
4453 // Create, fill and submit an address form in order to establish a recent | 4474 // Create, fill and submit an address form in order to establish a recent |
4454 // profile which can be selected for the upload request. | 4475 // profile which can be selected for the upload request. |
4455 FormData address_form; | 4476 FormData address_form; |
4456 test::CreateTestAddressFormData(&address_form); | 4477 test::CreateTestAddressFormData(&address_form); |
(...skipping 17 matching lines...) Expand all Loading... |
4474 | 4495 |
4475 // Neither a local save nor an upload should happen in this case. | 4496 // Neither a local save nor an upload should happen in this case. |
4476 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 4497 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
4477 FormSubmitted(credit_card_form); | 4498 FormSubmitted(credit_card_form); |
4478 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 4499 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
4479 | 4500 |
4480 // Verify that the correct histogram entry (and only that) was logged. | 4501 // Verify that the correct histogram entry (and only that) was logged. |
4481 histogram_tester.ExpectUniqueSample( | 4502 histogram_tester.ExpectUniqueSample( |
4482 "Autofill.CardUploadDecisionExpanded", | 4503 "Autofill.CardUploadDecisionExpanded", |
4483 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME, 1); | 4504 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME, 1); |
| 4505 |
| 4506 rappor::TestRapporService* rappor_service = |
| 4507 autofill_client_.test_rappor_service(); |
| 4508 EXPECT_EQ(1, rappor_service->GetReportsCount()); |
| 4509 std::string sample; |
| 4510 rappor::RapporType type; |
| 4511 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 4512 "Autofill.CardUploadNotOfferedNoName", &sample, &type)); |
| 4513 EXPECT_EQ("myform.com", sample); |
| 4514 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
4484 } | 4515 } |
4485 | 4516 |
4486 TEST_F(AutofillManagerTest, UploadCreditCard_ZipCodesConflict) { | 4517 TEST_F(AutofillManagerTest, UploadCreditCard_ZipCodesConflict) { |
4487 personal_data_.ClearAutofillProfiles(); | 4518 personal_data_.ClearAutofillProfiles(); |
4488 autofill_manager_->set_credit_card_upload_enabled(true); | 4519 autofill_manager_->set_credit_card_upload_enabled(true); |
4489 | 4520 |
4490 // Create, fill and submit two address forms with different zip codes. | 4521 // Create, fill and submit two address forms with different zip codes. |
4491 FormData address_form1, address_form2; | 4522 FormData address_form1, address_form2; |
4492 test::CreateTestAddressFormData(&address_form1); | 4523 test::CreateTestAddressFormData(&address_form1); |
4493 test::CreateTestAddressFormData(&address_form2); | 4524 test::CreateTestAddressFormData(&address_form2); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4701 | 4732 |
4702 // Names are required to match, upload should not happen. | 4733 // Names are required to match, upload should not happen. |
4703 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 4734 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
4704 FormSubmitted(credit_card_form); | 4735 FormSubmitted(credit_card_form); |
4705 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 4736 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
4706 | 4737 |
4707 // Verify that the correct histogram entry (and only that) was logged. | 4738 // Verify that the correct histogram entry (and only that) was logged. |
4708 histogram_tester.ExpectUniqueSample( | 4739 histogram_tester.ExpectUniqueSample( |
4709 "Autofill.CardUploadDecisionExpanded", | 4740 "Autofill.CardUploadDecisionExpanded", |
4710 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES, 1); | 4741 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES, 1); |
| 4742 |
| 4743 rappor::TestRapporService* rappor_service = |
| 4744 autofill_client_.test_rappor_service(); |
| 4745 EXPECT_EQ(1, rappor_service->GetReportsCount()); |
| 4746 std::string sample; |
| 4747 rappor::RapporType type; |
| 4748 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( |
| 4749 "Autofill.CardUploadNotOfferedConflictingNames", &sample, &type)); |
| 4750 EXPECT_EQ("myform.com", sample); |
| 4751 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
4711 } | 4752 } |
4712 | 4753 |
4713 TEST_F(AutofillManagerTest, UploadCreditCard_UploadDetailsFails) { | 4754 TEST_F(AutofillManagerTest, UploadCreditCard_UploadDetailsFails) { |
4714 personal_data_.ClearAutofillProfiles(); | 4755 personal_data_.ClearAutofillProfiles(); |
4715 autofill_manager_->set_credit_card_upload_enabled(true); | 4756 autofill_manager_->set_credit_card_upload_enabled(true); |
4716 | 4757 |
4717 // Anything other than "en-US" will cause GetUploadDetails to return a failure | 4758 // Anything other than "en-US" will cause GetUploadDetails to return a failure |
4718 // response. | 4759 // response. |
4719 autofill_manager_->set_app_locale("pt-BR"); | 4760 autofill_manager_->set_app_locale("pt-BR"); |
4720 | 4761 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5035 FormsSeen(mixed_forms); | 5076 FormsSeen(mixed_forms); |
5036 | 5077 |
5037 // Suggestions should always be displayed. | 5078 // Suggestions should always be displayed. |
5038 for (const FormFieldData& field : mixed_form.fields) { | 5079 for (const FormFieldData& field : mixed_form.fields) { |
5039 GetAutofillSuggestions(mixed_form, field); | 5080 GetAutofillSuggestions(mixed_form, field); |
5040 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 5081 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
5041 } | 5082 } |
5042 } | 5083 } |
5043 | 5084 |
5044 } // namespace autofill | 5085 } // namespace autofill |
OLD | NEW |