Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 2859243004: Add metrics for PasswordForm submission types (Closed)
Patch Set: addressed reviewer comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_types.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/content/renderer/password_autofill_agent.h" 5 #include "components/autofill/content/renderer/password_autofill_agent.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 const std::string& password_value, 500 const std::string& password_value,
501 const std::string& new_password_value) { 501 const std::string& new_password_value) {
502 base::RunLoop().RunUntilIdle(); 502 base::RunLoop().RunUntilIdle();
503 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); 503 ASSERT_TRUE(fake_driver_.called_password_form_submitted());
504 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted())); 504 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted()));
505 const autofill::PasswordForm& form = 505 const autofill::PasswordForm& form =
506 *(fake_driver_.password_form_submitted()); 506 *(fake_driver_.password_form_submitted());
507 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); 507 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value);
508 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); 508 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value);
509 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); 509 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value);
510 EXPECT_EQ(PasswordForm::SubmissionIndicatorEvent::HTML_FORM_SUBMISSION,
511 form.submission_event);
510 } 512 }
511 513
512 void ExpectFieldPropertiesMasks( 514 void ExpectFieldPropertiesMasks(
513 PasswordFormSourceType expected_type, 515 PasswordFormSourceType expected_type,
514 const std::map<base::string16, FieldPropertiesMask>& 516 const std::map<base::string16, FieldPropertiesMask>&
515 expected_properties_masks) { 517 expected_properties_masks) {
516 base::RunLoop().RunUntilIdle(); 518 base::RunLoop().RunUntilIdle();
517 autofill::PasswordForm form; 519 autofill::PasswordForm form;
518 if (expected_type == PasswordFormSubmitted) { 520 if (expected_type == PasswordFormSubmitted) {
519 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); 521 ASSERT_TRUE(fake_driver_.called_password_form_submitted());
(...skipping 16 matching lines...) Expand all
536 << "Wrong mask for the field " << field.name; 538 << "Wrong mask for the field " << field.name;
537 unchecked_masks--; 539 unchecked_masks--;
538 } 540 }
539 EXPECT_TRUE(unchecked_masks == 0) 541 EXPECT_TRUE(unchecked_masks == 0)
540 << "Some expected masks are missed in FormData"; 542 << "Some expected masks are missed in FormData";
541 } 543 }
542 544
543 void ExpectInPageNavigationWithUsernameAndPasswords( 545 void ExpectInPageNavigationWithUsernameAndPasswords(
544 const std::string& username_value, 546 const std::string& username_value,
545 const std::string& password_value, 547 const std::string& password_value,
546 const std::string& new_password_value) { 548 const std::string& new_password_value,
549 PasswordForm::SubmissionIndicatorEvent event) {
547 base::RunLoop().RunUntilIdle(); 550 base::RunLoop().RunUntilIdle();
548 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); 551 ASSERT_TRUE(fake_driver_.called_inpage_navigation());
549 ASSERT_TRUE( 552 ASSERT_TRUE(
550 static_cast<bool>(fake_driver_.password_form_inpage_navigation())); 553 static_cast<bool>(fake_driver_.password_form_inpage_navigation()));
551 const autofill::PasswordForm& form = 554 const autofill::PasswordForm& form =
552 *(fake_driver_.password_form_inpage_navigation()); 555 *(fake_driver_.password_form_inpage_navigation());
553 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); 556 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value);
554 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); 557 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value);
555 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); 558 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value);
559 EXPECT_EQ(event, form.submission_event);
556 } 560 }
557 561
558 void CheckIfEventsAreCalled(const std::vector<base::string16>& checkers, 562 void CheckIfEventsAreCalled(const std::vector<base::string16>& checkers,
559 bool expected) { 563 bool expected) {
560 for (const base::string16& variable : checkers) { 564 for (const base::string16& variable : checkers) {
561 int value; 565 int value;
562 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(variable, &value)) 566 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(variable, &value))
563 << variable; 567 << variable;
564 EXPECT_EQ(expected, value == 1) << variable; 568 EXPECT_EQ(expected, value == 1) << variable;
565 } 569 }
(...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after
2242 UpdateUsernameAndPasswordElements(); 2246 UpdateUsernameAndPasswordElements();
2243 2247
2244 SimulateUsernameChange("Bob"); 2248 SimulateUsernameChange("Bob");
2245 SimulatePasswordChange("mypassword"); 2249 SimulatePasswordChange("mypassword");
2246 2250
2247 username_element_.SetAttribute("style", "display:none;"); 2251 username_element_.SetAttribute("style", "display:none;");
2248 password_element_.SetAttribute("style", "display:none;"); 2252 password_element_.SetAttribute("style", "display:none;");
2249 2253
2250 password_autofill_agent_->AJAXSucceeded(); 2254 password_autofill_agent_->AJAXSucceeded();
2251 2255
2252 ExpectInPageNavigationWithUsernameAndPasswords("Bob", "mypassword", ""); 2256 ExpectInPageNavigationWithUsernameAndPasswords(
2257 "Bob", "mypassword", "",
2258 PasswordForm::SubmissionIndicatorEvent::XHR_SUCCEEDED);
2253 } 2259 }
2254 2260
2255 TEST_F(PasswordAutofillAgentTest, 2261 TEST_F(PasswordAutofillAgentTest,
2256 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) { 2262 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) {
2257 LoadHTML(kNoFormHTML); 2263 LoadHTML(kNoFormHTML);
2258 UpdateUsernameAndPasswordElements(); 2264 UpdateUsernameAndPasswordElements();
2259 2265
2260 SimulateUsernameChange("Bob"); 2266 SimulateUsernameChange("Bob");
2261 SimulatePasswordChange("mypassword"); 2267 SimulatePasswordChange("mypassword");
2262 2268
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 SimulateUsernameChange("Bob"); 2539 SimulateUsernameChange("Bob");
2534 SimulatePasswordChange("mypassword"); 2540 SimulatePasswordChange("mypassword");
2535 SimulateUsernameChange("Alice"); 2541 SimulateUsernameChange("Alice");
2536 2542
2537 // Hide form elements to simulate successful login. 2543 // Hide form elements to simulate successful login.
2538 username_element_.SetAttribute("style", "display:none;"); 2544 username_element_.SetAttribute("style", "display:none;");
2539 password_element_.SetAttribute("style", "display:none;"); 2545 password_element_.SetAttribute("style", "display:none;");
2540 2546
2541 password_autofill_agent_->AJAXSucceeded(); 2547 password_autofill_agent_->AJAXSucceeded();
2542 2548
2543 ExpectInPageNavigationWithUsernameAndPasswords("Alice", "mypassword", ""); 2549 ExpectInPageNavigationWithUsernameAndPasswords(
2550 "Alice", "mypassword", "",
2551 PasswordForm::SubmissionIndicatorEvent::XHR_SUCCEEDED);
2544 } 2552 }
2545 2553
2546 TEST_F(PasswordAutofillAgentTest, 2554 TEST_F(PasswordAutofillAgentTest,
2547 UsernameChangedAfterPasswordInput_FormSubmitted) { 2555 UsernameChangedAfterPasswordInput_FormSubmitted) {
2548 SimulateUsernameChange("Bob"); 2556 SimulateUsernameChange("Bob");
2549 SimulatePasswordChange("mypassword"); 2557 SimulatePasswordChange("mypassword");
2550 SimulateUsernameChange("Alice"); 2558 SimulateUsernameChange("Alice");
2551 2559
2552 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 2560 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
2553 ->WillSendSubmitEvent(username_element_.Form()); 2561 ->WillSendSubmitEvent(username_element_.Form());
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2695 2703
2696 // Simulate that JavaScript removes the submitted form from DOM. That means 2704 // Simulate that JavaScript removes the submitted form from DOM. That means
2697 // that a submission was successful. 2705 // that a submission was successful.
2698 std::string remove_form = 2706 std::string remove_form =
2699 "var form = document.getElementById('LoginTestForm');" 2707 "var form = document.getElementById('LoginTestForm');"
2700 "form.parentNode.removeChild(form);"; 2708 "form.parentNode.removeChild(form);";
2701 ExecuteJavaScriptForTests(remove_form.c_str()); 2709 ExecuteJavaScriptForTests(remove_form.c_str());
2702 2710
2703 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 2711 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
2704 ->DidCommitProvisionalLoad(false, true); 2712 ->DidCommitProvisionalLoad(false, true);
2705 base::RunLoop().RunUntilIdle(); 2713 ExpectInPageNavigationWithUsernameAndPasswords(
2706 2714 std::string(), "random", std::string(),
2707 // Chect that the form was submitted with in-page navigation. 2715 PasswordForm::SubmissionIndicatorEvent::SAME_DOCUMENT_NAVIGATION);
2708 EXPECT_TRUE(fake_driver_.called_inpage_navigation());
2709 EXPECT_EQ(base::string16(),
2710 fake_driver_.password_form_inpage_navigation()->username_value);
2711 EXPECT_EQ(ASCIIToUTF16("random"),
2712 fake_driver_.password_form_inpage_navigation()->password_value);
2713 } 2716 }
2714 2717
2715 #if defined(SAFE_BROWSING_DB_LOCAL) 2718 #if defined(SAFE_BROWSING_DB_LOCAL)
2716 // Verify CheckSafeBrowsingReputation() is called when user starts filling 2719 // Verify CheckSafeBrowsingReputation() is called when user starts filling
2717 // username or password field, and that this function is only called once. 2720 // username or password field, and that this function is only called once.
2718 TEST_F(PasswordAutofillAgentTest, 2721 TEST_F(PasswordAutofillAgentTest,
2719 CheckSafeBrowsingReputationWhenUserStartsFillingUsernamePassword) { 2722 CheckSafeBrowsingReputationWhenUserStartsFillingUsernamePassword) {
2720 ASSERT_EQ(0, fake_driver_.called_check_safe_browsing_reputation_cnt()); 2723 ASSERT_EQ(0, fake_driver_.called_check_safe_browsing_reputation_cnt());
2721 // Simulate a click on password field to set its on focus, 2724 // Simulate a click on password field to set its on focus,
2722 // CheckSafeBrowsingReputation() should be called. 2725 // CheckSafeBrowsingReputation() should be called.
(...skipping 11 matching lines...) Expand all
2734 2737
2735 // Navigate to another page and click on username field, 2738 // Navigate to another page and click on username field,
2736 // CheckSafeBrowsingReputation() should be triggered again. 2739 // CheckSafeBrowsingReputation() should be triggered again.
2737 LoadHTML(kFormHTML); 2740 LoadHTML(kFormHTML);
2738 SimulateElementClick(kUsernameName); 2741 SimulateElementClick(kUsernameName);
2739 base::RunLoop().RunUntilIdle(); 2742 base::RunLoop().RunUntilIdle();
2740 EXPECT_EQ(2, fake_driver_.called_check_safe_browsing_reputation_cnt()); 2743 EXPECT_EQ(2, fake_driver_.called_check_safe_browsing_reputation_cnt());
2741 } 2744 }
2742 #endif 2745 #endif
2743 } // namespace autofill 2746 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_types.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698