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

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

Issue 2833193002: Trigger Password Protection ping on username/password field on focus (Closed)
Patch Set: fix build 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
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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 GetWebWidget()->Resize(blink::WebSize(500, 500)); 322 GetWebWidget()->Resize(blink::WebSize(500, 500));
323 GetWebWidget()->SetFocus(true); 323 GetWebWidget()->SetFocus(true);
324 324
325 // Now retrieve the input elements so the test can access them. 325 // Now retrieve the input elements so the test can access them.
326 UpdateUsernameAndPasswordElements(); 326 UpdateUsernameAndPasswordElements();
327 } 327 }
328 328
329 void TearDown() override { 329 void TearDown() override {
330 username_element_.Reset(); 330 username_element_.Reset();
331 password_element_.Reset(); 331 password_element_.Reset();
332 dummy_element_.Reset();
332 ChromeRenderViewTest::TearDown(); 333 ChromeRenderViewTest::TearDown();
333 } 334 }
334 335
335 void RegisterMainFrameRemoteInterfaces() override { 336 void RegisterMainFrameRemoteInterfaces() override {
336 // We only use the fake driver for main frame 337 // We only use the fake driver for main frame
337 // because our test cases only involve the main frame. 338 // because our test cases only involve the main frame.
338 service_manager::InterfaceProvider* remote_interfaces = 339 service_manager::InterfaceProvider* remote_interfaces =
339 view_->GetMainRenderFrame()->GetRemoteInterfaces(); 340 view_->GetMainRenderFrame()->GetRemoteInterfaces();
340 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces); 341 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces);
341 test_api.SetBinderForName( 342 test_api.SetBinderForName(
(...skipping 28 matching lines...) Expand all
370 371
371 void UpdateUsernameAndPasswordElements() { 372 void UpdateUsernameAndPasswordElements() {
372 WebDocument document = GetMainFrame()->GetDocument(); 373 WebDocument document = GetMainFrame()->GetDocument();
373 WebElement element = 374 WebElement element =
374 document.GetElementById(WebString::FromUTF8(kUsernameName)); 375 document.GetElementById(WebString::FromUTF8(kUsernameName));
375 ASSERT_FALSE(element.IsNull()); 376 ASSERT_FALSE(element.IsNull());
376 username_element_ = element.To<blink::WebInputElement>(); 377 username_element_ = element.To<blink::WebInputElement>();
377 element = document.GetElementById(WebString::FromUTF8(kPasswordName)); 378 element = document.GetElementById(WebString::FromUTF8(kPasswordName));
378 ASSERT_FALSE(element.IsNull()); 379 ASSERT_FALSE(element.IsNull());
379 password_element_ = element.To<blink::WebInputElement>(); 380 password_element_ = element.To<blink::WebInputElement>();
381 dummy_element_ = element.To<blink::WebInputElement>();
380 } 382 }
381 383
382 blink::WebInputElement GetInputElementByID(const std::string& id) { 384 blink::WebInputElement GetInputElementByID(const std::string& id) {
383 WebDocument document = GetMainFrame()->GetDocument(); 385 WebDocument document = GetMainFrame()->GetDocument();
384 WebElement element = 386 WebElement element =
385 document.GetElementById(WebString::FromUTF8(id.c_str())); 387 document.GetElementById(WebString::FromUTF8(id.c_str()));
386 return element.To<blink::WebInputElement>(); 388 return element.To<blink::WebInputElement>();
387 } 389 }
388 390
389 void ClearUsernameAndPasswordFields() { 391 void ClearUsernameAndPasswordFields() {
390 username_element_.SetValue(""); 392 username_element_.SetValue("");
391 username_element_.SetAutofilled(false); 393 username_element_.SetAutofilled(false);
392 password_element_.SetValue(""); 394 password_element_.SetValue("");
393 password_element_.SetAutofilled(false); 395 password_element_.SetAutofilled(false);
396 dummy_element_.SetValue("");
397 dummy_element_.SetAutofilled(false);
394 } 398 }
395 399
396 void SimulateSuggestionChoice(WebInputElement& username_input) { 400 void SimulateSuggestionChoice(WebInputElement& username_input) {
397 base::string16 username(base::ASCIIToUTF16(kAliceUsername)); 401 base::string16 username(base::ASCIIToUTF16(kAliceUsername));
398 base::string16 password(base::ASCIIToUTF16(kAlicePassword)); 402 base::string16 password(base::ASCIIToUTF16(kAlicePassword));
399 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, 403 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username,
400 password); 404 password);
401 } 405 }
402 406
403 void SimulateSuggestionChoiceOfUsernameAndPassword( 407 void SimulateSuggestionChoiceOfUsernameAndPassword(
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 base::string16 username2_; 592 base::string16 username2_;
589 base::string16 username3_; 593 base::string16 username3_;
590 base::string16 password1_; 594 base::string16 password1_;
591 base::string16 password2_; 595 base::string16 password2_;
592 base::string16 password3_; 596 base::string16 password3_;
593 base::string16 alternate_username3_; 597 base::string16 alternate_username3_;
594 PasswordFormFillData fill_data_; 598 PasswordFormFillData fill_data_;
595 599
596 WebInputElement username_element_; 600 WebInputElement username_element_;
597 WebInputElement password_element_; 601 WebInputElement password_element_;
602 WebInputElement dummy_element_;
Mathieu 2017/05/01 13:40:00 Could you comment why this is needed? I don't see
Jialiu Lin 2017/05/01 18:59:09 Oops, sorry. Forgot to remove this one.
598 base::test::ScopedFeatureList scoped_feature_list_; 603 base::test::ScopedFeatureList scoped_feature_list_;
599 604
600 private: 605 private:
601 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgentTest); 606 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgentTest);
602 }; 607 };
603 608
604 // Tests that the password login is autocompleted as expected when the browser 609 // Tests that the password login is autocompleted as expected when the browser
605 // sends back the password info. 610 // sends back the password info.
606 TEST_F(PasswordAutofillAgentTest, InitialAutocomplete) { 611 TEST_F(PasswordAutofillAgentTest, InitialAutocomplete) {
607 /* 612 /*
(...skipping 2097 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 base::RunLoop().RunUntilIdle(); 2710 base::RunLoop().RunUntilIdle();
2706 2711
2707 // Chect that the form was submitted with in-page navigation. 2712 // Chect that the form was submitted with in-page navigation.
2708 EXPECT_TRUE(fake_driver_.called_inpage_navigation()); 2713 EXPECT_TRUE(fake_driver_.called_inpage_navigation());
2709 EXPECT_EQ(base::string16(), 2714 EXPECT_EQ(base::string16(),
2710 fake_driver_.password_form_inpage_navigation()->username_value); 2715 fake_driver_.password_form_inpage_navigation()->username_value);
2711 EXPECT_EQ(ASCIIToUTF16("random"), 2716 EXPECT_EQ(ASCIIToUTF16("random"),
2712 fake_driver_.password_form_inpage_navigation()->password_value); 2717 fake_driver_.password_form_inpage_navigation()->password_value);
2713 } 2718 }
2714 2719
2720 #if defined(SAFE_BROWSING_DB_LOCAL)
2721 // Verify CheckSafeBrowsingReputation() is called when user start filling
Mathieu 2017/05/01 13:40:00 *starts
Jialiu Lin 2017/05/01 18:59:09 Done
2722 // username or password field, and this function is only called once.
Mathieu 2017/05/01 13:40:00 *and that this function
Jialiu Lin 2017/05/01 18:59:09 Done
2723 TEST_F(PasswordAutofillAgentTest,
2724 CheckSafeBrowsingReputationWhenUserStartsFillingUsernamePassword) {
2725 ASSERT_EQ(0, fake_driver_.called_check_safe_browsing_reputation_cnt());
2726 // Simulate a click on password field to set is on focus,
Mathieu 2017/05/01 13:40:00 *to set its focus
Jialiu Lin 2017/05/01 18:59:09 Done
2727 // CheckSafeBrowsingReputation() should be called.
2728 SimulateElementClick(kPasswordName);
2729 base::RunLoop().RunUntilIdle();
2730 EXPECT_EQ(1, fake_driver_.called_check_safe_browsing_reputation_cnt());
2731
2732 // Subsequent editing will not trigger CheckSafeBrowsingReputation.
2733 SimulatePasswordChange("modify");
2734 base::RunLoop().RunUntilIdle();
2735 EXPECT_EQ(1, fake_driver_.called_check_safe_browsing_reputation_cnt());
2736 SimulateElementClick(kUsernameName);
2737 base::RunLoop().RunUntilIdle();
2738 EXPECT_EQ(1, fake_driver_.called_check_safe_browsing_reputation_cnt());
2739
2740 // Navigate to another page and click on username field,
2741 // CheckSafeBrowsingReputation() should be triggered again.
2742 LoadHTML(kFormHTML);
2743 SimulateElementClick(kUsernameName);
2744 base::RunLoop().RunUntilIdle();
2745 EXPECT_EQ(2, fake_driver_.called_check_safe_browsing_reputation_cnt());
2746 }
2747
Mathieu 2017/05/01 13:40:00 nit: remove extra line
Jialiu Lin 2017/05/01 18:59:09 Done.
2748 #endif
2715 } // namespace autofill 2749 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698