| 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_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 {internal::kUKMFormSignatureMetricName, form_signature}, | 455 {internal::kUKMFormSignatureMetricName, form_signature}, |
| 456 {internal::kUKMFieldSignatureMetricName, field_signature}, | 456 {internal::kUKMFieldSignatureMetricName, field_signature}, |
| 457 {internal::kUKMValidationEventMetricName, metric_type}, | 457 {internal::kUKMValidationEventMetricName, metric_type}, |
| 458 {internal::kUKMPredictionSourceMetricName, source}, | 458 {internal::kUKMPredictionSourceMetricName, source}, |
| 459 {internal::kUKMPredictedTypeMetricName, predicted_type}, | 459 {internal::kUKMPredictedTypeMetricName, predicted_type}, |
| 460 {internal::kUKMActualTypeMetricName, actual_type}}); | 460 {internal::kUKMActualTypeMetricName, actual_type}}); |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 } | 463 } |
| 464 | 464 |
| 465 class MockAutofillClient : public TestAutofillClient { |
| 466 public: |
| 467 MockAutofillClient() {} |
| 468 MOCK_METHOD1(ExecuteCommand, void(int)); |
| 469 }; |
| 470 |
| 465 } // namespace | 471 } // namespace |
| 466 | 472 |
| 467 // This is defined in the autofill_metrics.cc implementation file. | 473 // This is defined in the autofill_metrics.cc implementation file. |
| 468 int GetFieldTypeGroupMetric(ServerFieldType field_type, | 474 int GetFieldTypeGroupMetric(ServerFieldType field_type, |
| 469 AutofillMetrics::FieldTypeQualityMetric metric); | 475 AutofillMetrics::FieldTypeQualityMetric metric); |
| 470 | 476 |
| 471 class AutofillMetricsTest : public testing::Test { | 477 class AutofillMetricsTest : public testing::Test { |
| 472 public: | 478 public: |
| 473 ~AutofillMetricsTest() override; | 479 ~AutofillMetricsTest() override; |
| 474 | 480 |
| 475 void SetUp() override; | 481 void SetUp() override; |
| 476 void TearDown() override; | 482 void TearDown() override; |
| 477 | 483 |
| 478 protected: | 484 protected: |
| 479 void EnableWalletSync(); | 485 void EnableWalletSync(); |
| 480 | 486 |
| 481 base::test::ScopedTaskEnvironment scoped_task_environment_; | 487 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 482 ukm::TestAutoSetUkmRecorder test_ukm_recorder_; | 488 ukm::TestAutoSetUkmRecorder test_ukm_recorder_; |
| 483 TestAutofillClient autofill_client_; | 489 MockAutofillClient autofill_client_; |
| 484 std::unique_ptr<AccountTrackerService> account_tracker_; | 490 std::unique_ptr<AccountTrackerService> account_tracker_; |
| 485 std::unique_ptr<FakeSigninManagerBase> signin_manager_; | 491 std::unique_ptr<FakeSigninManagerBase> signin_manager_; |
| 486 std::unique_ptr<TestSigninClient> signin_client_; | 492 std::unique_ptr<TestSigninClient> signin_client_; |
| 487 std::unique_ptr<TestAutofillDriver> autofill_driver_; | 493 std::unique_ptr<TestAutofillDriver> autofill_driver_; |
| 488 std::unique_ptr<TestAutofillManager> autofill_manager_; | 494 std::unique_ptr<TestAutofillManager> autofill_manager_; |
| 489 std::unique_ptr<TestPersonalDataManager> personal_data_; | 495 std::unique_ptr<TestPersonalDataManager> personal_data_; |
| 490 std::unique_ptr<AutofillExternalDelegate> external_delegate_; | 496 std::unique_ptr<AutofillExternalDelegate> external_delegate_; |
| 491 base::test::ScopedFeatureList scoped_feature_list_; | 497 base::test::ScopedFeatureList scoped_feature_list_; |
| 492 }; | 498 }; |
| 493 | 499 |
| (...skipping 4686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5180 | 5186 |
| 5181 base::HistogramTester histogram_tester; | 5187 base::HistogramTester histogram_tester; |
| 5182 FormStructure::ParseQueryResponse(response_string, forms_); | 5188 FormStructure::ParseQueryResponse(response_string, forms_); |
| 5183 EXPECT_THAT( | 5189 EXPECT_THAT( |
| 5184 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 5190 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
| 5185 ElementsAre(Bucket(true, 2))); | 5191 ElementsAre(Bucket(true, 2))); |
| 5186 } | 5192 } |
| 5187 | 5193 |
| 5188 // Test that the Form-Not-Secure warning user action is recorded. | 5194 // Test that the Form-Not-Secure warning user action is recorded. |
| 5189 TEST_F(AutofillMetricsTest, ShowHttpNotSecureExplanationUserAction) { | 5195 TEST_F(AutofillMetricsTest, ShowHttpNotSecureExplanationUserAction) { |
| 5190 base::UserActionTester user_action_tester; | 5196 EXPECT_CALL(autofill_client_, |
| 5197 ExecuteCommand(POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE)); |
| 5191 external_delegate_->DidAcceptSuggestion( | 5198 external_delegate_->DidAcceptSuggestion( |
| 5192 ASCIIToUTF16("Test"), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0); | 5199 ASCIIToUTF16("Test"), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0); |
| 5193 EXPECT_EQ(1, user_action_tester.GetActionCount( | |
| 5194 "Autofill_ShowedHttpNotSecureExplanation")); | |
| 5195 } | 5200 } |
| 5196 | 5201 |
| 5197 // Tests that credit card form submissions are logged specially when the form is | 5202 // Tests that credit card form submissions are logged specially when the form is |
| 5198 // on a non-secure page. | 5203 // on a non-secure page. |
| 5199 TEST_F(AutofillMetricsTest, NonsecureCreditCardForm) { | 5204 TEST_F(AutofillMetricsTest, NonsecureCreditCardForm) { |
| 5200 personal_data_->RecreateCreditCards( | 5205 personal_data_->RecreateCreditCards( |
| 5201 true /* include_local_credit_card */, | 5206 true /* include_local_credit_card */, |
| 5202 false /* include_masked_server_credit_card */, | 5207 false /* include_masked_server_credit_card */, |
| 5203 false /* include_full_server_credit_card */); | 5208 false /* include_full_server_credit_card */); |
| 5204 | 5209 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5393 // Tests that no UKM is logged when the ukm service is null. | 5398 // Tests that no UKM is logged when the ukm service is null. |
| 5394 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { | 5399 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) { |
| 5395 GURL url("https://www.google.com"); | 5400 GURL url("https://www.google.com"); |
| 5396 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; | 5401 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
| 5397 | 5402 |
| 5398 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); | 5403 EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics)); |
| 5399 ASSERT_EQ(0U, test_ukm_recorder_.sources_count()); | 5404 ASSERT_EQ(0U, test_ukm_recorder_.sources_count()); |
| 5400 } | 5405 } |
| 5401 | 5406 |
| 5402 } // namespace autofill | 5407 } // namespace autofill |
| OLD | NEW |