Chromium Code Reviews| 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 <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 form.fields.push_back(field); | 759 form.fields.push_back(field); |
| 760 | 760 |
| 761 // No autocomplete attribute. No metric logged. | 761 // No autocomplete attribute. No metric logged. |
| 762 test::CreateTestFormField("Address", "address", "", "text", &field); | 762 test::CreateTestFormField("Address", "address", "", "text", &field); |
| 763 field.autocomplete_attribute = ""; | 763 field.autocomplete_attribute = ""; |
| 764 form.fields.push_back(field); | 764 form.fields.push_back(field); |
| 765 | 765 |
| 766 std::unique_ptr<TestFormStructure> form_structure = | 766 std::unique_ptr<TestFormStructure> form_structure = |
| 767 base::MakeUnique<TestFormStructure>(form); | 767 base::MakeUnique<TestFormStructure>(form); |
| 768 TestFormStructure* form_structure_ptr = form_structure.get(); | 768 TestFormStructure* form_structure_ptr = form_structure.get(); |
| 769 form_structure->DetermineHeuristicTypes(); | 769 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */, GURL()); |
| 770 autofill_manager_->form_structures()->push_back(std::move(form_structure)); | 770 autofill_manager_->form_structures()->push_back(std::move(form_structure)); |
| 771 | 771 |
| 772 AutofillQueryResponseContents response; | 772 AutofillQueryResponseContents response; |
| 773 // Server response will match with autocomplete. | 773 // Server response will match with autocomplete. |
| 774 response.add_field()->set_autofill_type(NAME_LAST); | 774 response.add_field()->set_autofill_type(NAME_LAST); |
| 775 // Server response will NOT match with autocomplete. | 775 // Server response will NOT match with autocomplete. |
| 776 response.add_field()->set_autofill_type(NAME_FIRST); | 776 response.add_field()->set_autofill_type(NAME_FIRST); |
| 777 // Server response will have no data. | 777 // Server response will have no data. |
| 778 response.add_field()->set_autofill_type(NO_SERVER_DATA); | 778 response.add_field()->set_autofill_type(NO_SERVER_DATA); |
| 779 // Not logged. | 779 // Not logged. |
| (...skipping 3579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4359 "Autofill.FormEvents.CreditCard", | 4359 "Autofill.FormEvents.CreditCard", |
| 4360 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); | 4360 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); |
| 4361 // Check that the nonsecure histogram was not recorded. ExpectBucketCount() | 4361 // Check that the nonsecure histogram was not recorded. ExpectBucketCount() |
| 4362 // can't be used here because it expects the histogram to exist. | 4362 // can't be used here because it expects the histogram to exist. |
| 4363 EXPECT_EQ( | 4363 EXPECT_EQ( |
| 4364 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard") | 4364 0, histograms.GetTotalCountsForPrefix("Autofill.FormEvents.CreditCard") |
| 4365 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); | 4365 ["Autofill.FormEvents.CreditCard.OnNonsecurePage"]); |
| 4366 } | 4366 } |
| 4367 } | 4367 } |
| 4368 | 4368 |
| 4369 // Tests that logging a UKM works as expected. | 4369 // Tests that logging CardUploadDecision UKM works as expected. |
| 4370 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { | 4370 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) { |
| 4371 EnableUkmLogging(); | 4371 EnableUkmLogging(); |
| 4372 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4372 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
| 4373 GURL url("https://www.google.com"); | 4373 GURL url("https://www.google.com"); |
| 4374 int upload_decision = 1; | 4374 int upload_decision = 1; |
| 4375 std::map<std::string, int> metrics; | 4375 std::map<std::string, int> metrics; |
| 4376 metrics.insert(std::make_pair(internal::kUKMCardUploadDecisionMetricName, | 4376 metrics.insert(std::make_pair(internal::kUKMCardUploadDecisionMetricName, |
| 4377 upload_decision)); | 4377 upload_decision)); |
| 4378 | 4378 |
| 4379 EXPECT_TRUE(AutofillMetrics::LogUkm( | 4379 EXPECT_TRUE(AutofillMetrics::LogUkm( |
| 4380 ukm_service_test_harness.test_ukm_service(), url, | 4380 ukm_service_test_harness.test_ukm_service(), url, |
| 4381 internal::kUKMCardUploadDecisionEntryName, metrics)); | 4381 internal::kUKMCardUploadDecisionEntryName, metrics)); |
| 4382 | 4382 |
| 4383 // Make sure that the UKM was logged correctly. | 4383 // Make sure that the UKM was logged correctly. |
| 4384 ukm::TestUkmService* ukm_service = | 4384 ukm::TestUkmService* ukm_service = |
| 4385 ukm_service_test_harness.test_ukm_service(); | 4385 ukm_service_test_harness.test_ukm_service(); |
| 4386 | 4386 |
| 4387 ASSERT_EQ(1U, ukm_service->sources_count()); | 4387 ASSERT_EQ(1U, ukm_service->sources_count()); |
| 4388 const ukm::UkmSource* source = | 4388 const ukm::UkmSource* source = |
| 4389 ukm_service->GetSourceForUrl(url.spec().c_str()); | 4389 ukm_service->GetSourceForUrl(url.spec().c_str()); |
| 4390 EXPECT_EQ(url.spec(), source->url().spec()); | 4390 EXPECT_EQ(url.spec(), source->url().spec()); |
| 4391 | 4391 |
| 4392 EXPECT_EQ(1U, ukm_service->entries_count()); | 4392 EXPECT_EQ(1U, ukm_service->entries_count()); |
| 4393 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | 4393 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); |
| 4394 EXPECT_EQ(source->id(), entry->source_id()); | 4394 EXPECT_EQ(source->id(), entry->source_id()); |
| 4395 | 4395 |
| 4396 // Make sure that an card upload decision entry was logged. | 4396 // Make sure that a card upload decision entry was logged. |
| 4397 ukm::Entry entry_proto; | 4397 ukm::Entry entry_proto; |
| 4398 entry->PopulateProto(&entry_proto); | 4398 entry->PopulateProto(&entry_proto); |
| 4399 EXPECT_EQ(source->id(), entry_proto.source_id()); | 4399 EXPECT_EQ(source->id(), entry_proto.source_id()); |
| 4400 EXPECT_EQ(base::HashMetricName(internal::kUKMCardUploadDecisionEntryName), | 4400 EXPECT_EQ(base::HashMetricName(internal::kUKMCardUploadDecisionEntryName), |
| 4401 entry_proto.event_hash()); | 4401 entry_proto.event_hash()); |
| 4402 EXPECT_EQ(1, entry_proto.metrics_size()); | 4402 EXPECT_EQ(1, entry_proto.metrics_size()); |
| 4403 | 4403 |
| 4404 // Make sure that the correct upload decision was logged. | 4404 // Make sure that the correct upload decision was logged. |
| 4405 const ukm::Entry_Metric* metric = FindMetric( | 4405 const ukm::Entry_Metric* metric = FindMetric( |
| 4406 internal::kUKMCardUploadDecisionMetricName, entry_proto.metrics()); | 4406 internal::kUKMCardUploadDecisionMetricName, entry_proto.metrics()); |
| 4407 ASSERT_NE(nullptr, metric); | 4407 ASSERT_NE(nullptr, metric); |
| 4408 EXPECT_EQ(upload_decision, metric->value()); | 4408 EXPECT_EQ(upload_decision, metric->value()); |
| 4409 } | 4409 } |
| 4410 | 4410 |
| 4411 // Tests that logging DeveloperEngagement UKM works as expected. | |
| 4412 TEST_F(AutofillMetricsTest, RecordDeveloperEnagementMetric) { | |
|
Mathieu
2017/03/27 18:58:55
*engagement
Mathieu
2017/03/27 18:58:55
This is not a sufficient test. You should also add
csashi
2017/03/27 23:37:43
Done.
| |
| 4413 EnableUkmLogging(); | |
| 4414 ukm::UkmServiceTestingHarness ukm_service_test_harness; | |
| 4415 GURL url("https://www.google.com"); | |
| 4416 int form_structure_metric = 1; | |
| 4417 std::map<std::string, int> metrics; | |
| 4418 metrics.insert(std::make_pair(internal::kUKMDeveloperEngagementMetricName, | |
| 4419 form_structure_metric)); | |
| 4420 | |
| 4421 EXPECT_TRUE(AutofillMetrics::LogUkm( | |
| 4422 ukm_service_test_harness.test_ukm_service(), url, | |
| 4423 internal::kUKMDeveloperEngagementEntryName, metrics)); | |
| 4424 | |
| 4425 // Make sure that the UKM was logged correctly. | |
| 4426 ukm::TestUkmService* ukm_service = | |
| 4427 ukm_service_test_harness.test_ukm_service(); | |
| 4428 | |
| 4429 ASSERT_EQ(1U, ukm_service->sources_count()); | |
| 4430 const ukm::UkmSource* source = | |
| 4431 ukm_service->GetSourceForUrl(url.spec().c_str()); | |
| 4432 EXPECT_EQ(url.spec(), source->url().spec()); | |
| 4433 | |
| 4434 EXPECT_EQ(1U, ukm_service->entries_count()); | |
| 4435 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); | |
| 4436 EXPECT_EQ(source->id(), entry->source_id()); | |
| 4437 | |
| 4438 // Make sure that a developer engagement entry was logged. | |
| 4439 ukm::Entry entry_proto; | |
| 4440 entry->PopulateProto(&entry_proto); | |
| 4441 EXPECT_EQ(source->id(), entry_proto.source_id()); | |
| 4442 EXPECT_EQ(base::HashMetricName(internal::kUKMDeveloperEngagementEntryName), | |
| 4443 entry_proto.event_hash()); | |
| 4444 EXPECT_EQ(1, entry_proto.metrics_size()); | |
| 4445 | |
| 4446 // Make sure that the correct developer engagement metric was logged. | |
| 4447 const ukm::Entry_Metric* metric = FindMetric( | |
| 4448 internal::kUKMDeveloperEngagementMetricName, entry_proto.metrics()); | |
| 4449 ASSERT_NE(nullptr, metric); | |
| 4450 EXPECT_EQ(form_structure_metric, metric->value()); | |
| 4451 } | |
| 4452 | |
| 4411 // Tests that no UKM is logged when the URL is not valid. | 4453 // Tests that no UKM is logged when the URL is not valid. |
| 4412 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { | 4454 TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) { |
| 4413 EnableUkmLogging(); | 4455 EnableUkmLogging(); |
| 4414 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 4456 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
| 4415 GURL url(""); | 4457 GURL url(""); |
| 4416 std::map<std::string, int> metrics; | 4458 std::map<std::string, int> metrics; |
| 4417 metrics.insert(std::make_pair("metric", 1)); | 4459 metrics.insert(std::make_pair("metric", 1)); |
| 4418 | 4460 |
| 4419 EXPECT_FALSE(AutofillMetrics::LogUkm( | 4461 EXPECT_FALSE(AutofillMetrics::LogUkm( |
| 4420 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 4462 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 4451 GURL url("https://www.google.com"); | 4493 GURL url("https://www.google.com"); |
| 4452 std::map<std::string, int> metrics; | 4494 std::map<std::string, int> metrics; |
| 4453 metrics.insert(std::make_pair("metric", 1)); | 4495 metrics.insert(std::make_pair("metric", 1)); |
| 4454 | 4496 |
| 4455 EXPECT_FALSE(AutofillMetrics::LogUkm( | 4497 EXPECT_FALSE(AutofillMetrics::LogUkm( |
| 4456 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 4498 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
| 4457 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 4499 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
| 4458 } | 4500 } |
| 4459 | 4501 |
| 4460 } // namespace autofill | 4502 } // namespace autofill |
| OLD | NEW |