| 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 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); | 2306 {internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}}}); |
| 2307 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| | 2307 // Expect |NON_FILLABLE_FORM_OR_NEW_DATA| in |AutofillFormSubmittedState| |
| 2308 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. | 2308 // because |field.value| is empty in |DeterminePossibleFieldTypesForUpload|. |
| 2309 VerifySubmitFormUkm(form, ukm_service, | 2309 VerifySubmitFormUkm(form, ukm_service, |
| 2310 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); | 2310 AutofillMetrics::NON_FILLABLE_FORM_OR_NEW_DATA); |
| 2311 } | 2311 } |
| 2312 | 2312 |
| 2313 // Tests that the Autofill_PolledCreditCardSuggestions user action is only | 2313 // Tests that the Autofill_PolledCreditCardSuggestions user action is only |
| 2314 // logged once if the field is queried repeatedly. | 2314 // logged once if the field is queried repeatedly. |
| 2315 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { | 2315 TEST_F(AutofillMetricsTest, PolledCreditCardSuggestions_DebounceLogs) { |
| 2316 EnableUkmLogging(); |
| 2317 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 2318 |
| 2316 personal_data_->RecreateCreditCards( | 2319 personal_data_->RecreateCreditCards( |
| 2317 true /* include_local_credit_card */, | 2320 true /* include_local_credit_card */, |
| 2318 false /* include_masked_server_credit_card */, | 2321 false /* include_masked_server_credit_card */, |
| 2319 false /* include_full_server_credit_card */); | 2322 false /* include_full_server_credit_card */); |
| 2320 | 2323 |
| 2321 // Set up the form data. | 2324 // Set up the form data. |
| 2322 FormData form; | 2325 FormData form; |
| 2323 form.name = ASCIIToUTF16("TestForm"); | 2326 form.name = ASCIIToUTF16("TestForm"); |
| 2327 form.origin = GURL("http://example.com/form.html"); |
| 2328 form.action = GURL("http://example.com/submit.html"); |
| 2324 | 2329 |
| 2325 FormFieldData field; | 2330 FormFieldData field; |
| 2326 std::vector<ServerFieldType> field_types; | 2331 std::vector<ServerFieldType> field_types; |
| 2327 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field); | 2332 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field); |
| 2328 form.fields.push_back(field); | 2333 form.fields.push_back(field); |
| 2329 field_types.push_back(CREDIT_CARD_NAME_FULL); | 2334 field_types.push_back(CREDIT_CARD_NAME_FULL); |
| 2330 test::CreateTestFormField("Credit card", "card", "", "text", &field); | 2335 test::CreateTestFormField("Credit card", "card", "", "text", &field); |
| 2331 form.fields.push_back(field); | 2336 form.fields.push_back(field); |
| 2332 field_types.push_back(CREDIT_CARD_NUMBER); | 2337 field_types.push_back(CREDIT_CARD_NUMBER); |
| 2333 test::CreateTestFormField("Month", "card_month", "", "text", &field); | 2338 test::CreateTestFormField("Month", "card_month", "", "text", &field); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2357 gfx::RectF()); | 2362 gfx::RectF()); |
| 2358 EXPECT_EQ(2, user_action_tester.GetActionCount( | 2363 EXPECT_EQ(2, user_action_tester.GetActionCount( |
| 2359 "Autofill_PolledCreditCardSuggestions")); | 2364 "Autofill_PolledCreditCardSuggestions")); |
| 2360 | 2365 |
| 2361 // Simulate a query back to the initial field. There should be a third poll | 2366 // Simulate a query back to the initial field. There should be a third poll |
| 2362 // logged. | 2367 // logged. |
| 2363 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0], | 2368 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0], |
| 2364 gfx::RectF()); | 2369 gfx::RectF()); |
| 2365 EXPECT_EQ(3, user_action_tester.GetActionCount( | 2370 EXPECT_EQ(3, user_action_tester.GetActionCount( |
| 2366 "Autofill_PolledCreditCardSuggestions")); | 2371 "Autofill_PolledCreditCardSuggestions")); |
| 2372 |
| 2373 VerifyFormInteractionUkm( |
| 2374 form, ukm_service, internal::kUKMPollSuggestionsEntryName, |
| 2375 {{{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}, |
| 2376 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NAME_FULL}, |
| 2377 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NAME_FULL}, |
| 2378 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}}, |
| 2379 {{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}, |
| 2380 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NUMBER}, |
| 2381 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NUMBER}, |
| 2382 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}}, |
| 2383 {{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}, |
| 2384 {internal::kUKMHeuristicTypeMetricName, CREDIT_CARD_NAME_FULL}, |
| 2385 {internal::kUKMServerTypeMetricName, CREDIT_CARD_NAME_FULL}, |
| 2386 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}}}); |
| 2367 } | 2387 } |
| 2368 | 2388 |
| 2369 // Tests that the Autofill.QueriedCreditCardFormIsSecure histogram is logged | 2389 // Tests that the Autofill.QueriedCreditCardFormIsSecure histogram is logged |
| 2370 // properly. | 2390 // properly. |
| 2371 TEST_F(AutofillMetricsTest, QueriedCreditCardFormIsSecure) { | 2391 TEST_F(AutofillMetricsTest, QueriedCreditCardFormIsSecure) { |
| 2372 personal_data_->RecreateCreditCards( | 2392 personal_data_->RecreateCreditCards( |
| 2373 true /* include_local_credit_card */, | 2393 true /* include_local_credit_card */, |
| 2374 false /* include_masked_server_credit_card */, | 2394 false /* include_masked_server_credit_card */, |
| 2375 false /* include_full_server_credit_card */); | 2395 false /* include_full_server_credit_card */); |
| 2376 | 2396 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2421 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], | 2441 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[1], |
| 2422 gfx::RectF()); | 2442 gfx::RectF()); |
| 2423 histogram_tester.ExpectUniqueSample( | 2443 histogram_tester.ExpectUniqueSample( |
| 2424 "Autofill.QueriedCreditCardFormIsSecure", true, 1); | 2444 "Autofill.QueriedCreditCardFormIsSecure", true, 1); |
| 2425 } | 2445 } |
| 2426 } | 2446 } |
| 2427 | 2447 |
| 2428 // Tests that the Autofill_PolledProfileSuggestions user action is only logged | 2448 // Tests that the Autofill_PolledProfileSuggestions user action is only logged |
| 2429 // once if the field is queried repeatedly. | 2449 // once if the field is queried repeatedly. |
| 2430 TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) { | 2450 TEST_F(AutofillMetricsTest, PolledProfileSuggestions_DebounceLogs) { |
| 2451 EnableUkmLogging(); |
| 2452 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); |
| 2453 |
| 2431 personal_data_->RecreateProfile(); | 2454 personal_data_->RecreateProfile(); |
| 2432 | 2455 |
| 2433 // Set up the form data. | 2456 // Set up the form data. |
| 2434 FormData form; | 2457 FormData form; |
| 2435 form.name = ASCIIToUTF16("TestForm"); | 2458 form.name = ASCIIToUTF16("TestForm"); |
| 2436 form.origin = GURL("http://example.com/form.html"); | 2459 form.origin = GURL("http://example.com/form.html"); |
| 2437 form.action = GURL("http://example.com/submit.html"); | 2460 form.action = GURL("http://example.com/submit.html"); |
| 2438 | 2461 |
| 2439 FormFieldData field; | 2462 FormFieldData field; |
| 2440 std::vector<ServerFieldType> field_types; | 2463 std::vector<ServerFieldType> field_types; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2471 gfx::RectF()); | 2494 gfx::RectF()); |
| 2472 EXPECT_EQ(2, user_action_tester.GetActionCount( | 2495 EXPECT_EQ(2, user_action_tester.GetActionCount( |
| 2473 "Autofill_PolledProfileSuggestions")); | 2496 "Autofill_PolledProfileSuggestions")); |
| 2474 | 2497 |
| 2475 // Simulate a query back to the initial field. There should be a third poll | 2498 // Simulate a query back to the initial field. There should be a third poll |
| 2476 // logged. | 2499 // logged. |
| 2477 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0], | 2500 autofill_manager_->OnQueryFormFieldAutofill(0, form, form.fields[0], |
| 2478 gfx::RectF()); | 2501 gfx::RectF()); |
| 2479 EXPECT_EQ(3, user_action_tester.GetActionCount( | 2502 EXPECT_EQ(3, user_action_tester.GetActionCount( |
| 2480 "Autofill_PolledProfileSuggestions")); | 2503 "Autofill_PolledProfileSuggestions")); |
| 2504 |
| 2505 VerifyFormInteractionUkm( |
| 2506 form, ukm_service, internal::kUKMPollSuggestionsEntryName, |
| 2507 {{{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}, |
| 2508 {internal::kUKMHeuristicTypeMetricName, ADDRESS_HOME_STATE}, |
| 2509 {internal::kUKMServerTypeMetricName, ADDRESS_HOME_STATE}, |
| 2510 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}}, |
| 2511 {{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}, |
| 2512 {internal::kUKMHeuristicTypeMetricName, ADDRESS_HOME_CITY}, |
| 2513 {internal::kUKMServerTypeMetricName, ADDRESS_HOME_CITY}, |
| 2514 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}}, |
| 2515 {{internal::kUKMMillisecondsSinceFormLoadedMetricName, 0}, |
| 2516 {internal::kUKMHeuristicTypeMetricName, ADDRESS_HOME_STATE}, |
| 2517 {internal::kUKMServerTypeMetricName, ADDRESS_HOME_STATE}, |
| 2518 {internal::kUKMHtmlFieldTypeMetricName, HTML_TYPE_UNSPECIFIED}}}); |
| 2481 } | 2519 } |
| 2482 | 2520 |
| 2483 // Test that we log interacted form event for credit cards related. | 2521 // Test that we log interacted form event for credit cards related. |
| 2484 TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) { | 2522 TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) { |
| 2485 // Set up our form data. | 2523 // Set up our form data. |
| 2486 FormData form; | 2524 FormData form; |
| 2487 form.name = ASCIIToUTF16("TestForm"); | 2525 form.name = ASCIIToUTF16("TestForm"); |
| 2488 form.origin = GURL("http://example.com/form.html"); | 2526 form.origin = GURL("http://example.com/form.html"); |
| 2489 form.action = GURL("http://example.com/submit.html"); | 2527 form.action = GURL("http://example.com/submit.html"); |
| 2490 | 2528 |
| (...skipping 2681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5172 ukm::UkmServiceTestingHarness ukm_service_test_harness; | 5210 ukm::UkmServiceTestingHarness ukm_service_test_harness; |
| 5173 GURL url("https://www.google.com"); | 5211 GURL url("https://www.google.com"); |
| 5174 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; | 5212 std::vector<std::pair<const char*, int>> metrics = {{"metric", 1}}; |
| 5175 | 5213 |
| 5176 EXPECT_FALSE(AutofillMetrics::LogUkm( | 5214 EXPECT_FALSE(AutofillMetrics::LogUkm( |
| 5177 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); | 5215 ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics)); |
| 5178 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); | 5216 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count()); |
| 5179 } | 5217 } |
| 5180 | 5218 |
| 5181 } // namespace autofill | 5219 } // namespace autofill |
| OLD | NEW |