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

Side by Side Diff: chrome/browser/password_manager/password_manager_browsertest.cc

Issue 1408423003: [Password Manager] Ignore autofilling invisible password fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added more handling. Created 5 years, 2 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 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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram_samples.h" 8 #include "base/metrics/histogram_samples.h"
9 #include "base/metrics/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 2535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 auth_needed_observer.Wait(); 2546 auth_needed_observer.Wait();
2547 2547
2548 // The auth dialog caused a query to PasswordStore, make sure it was 2548 // The auth dialog caused a query to PasswordStore, make sure it was
2549 // processed. 2549 // processed.
2550 base::RunLoop run_loop2; 2550 base::RunLoop run_loop2;
2551 run_loop2.RunUntilIdle(); 2551 run_loop2.RunUntilIdle();
2552 2552
2553 password_manager->RemoveObserver(&mock_login_model_observer); 2553 password_manager->RemoveObserver(&mock_login_model_observer);
2554 } 2554 }
2555 2555
2556 // Test whether the password form with the problematic invisible password field
2557 // gets autofilled correctly.
2558 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2559 AutofillSuggetionsForProblematicPasswordForm) {
2560 // At first let us save credentials to the PasswordManager.
2561 scoped_refptr<password_manager::PasswordStore> password_store =
2562 PasswordStoreFactory::GetForProfile(browser()->profile(),
2563 ServiceAccessType::IMPLICIT_ACCESS);
2564 autofill::PasswordForm login_form;
2565 login_form.signon_realm = embedded_test_server()->base_url().spec();
2566 login_form.action = embedded_test_server()->GetURL("/password/done.html");
2567 login_form.username_value = base::ASCIIToUTF16("myusername");
2568 login_form.password_value = base::ASCIIToUTF16("mypassword");
2569 password_store->AddLogin(login_form);
2570
2571 // Logins are added asynchronously to the password store. Spin the message
2572 // loop to make sure the |password_store| had a chance to store the
2573 // |login_form|.
2574 base::RunLoop run_loop;
2575 run_loop.RunUntilIdle();
2576
2577 // Now, navigate to the password form having ambiguous Ids for username and
2578 // password fields and verify whether username and password is autofilled.
2579 NavigateToFile("/password/password_form.html");
2580
2581 // Let the user interact with the page, so that DOM gets modification events,
2582 // needed for autofilling fields.
2583 content::SimulateMouseClickAt(
2584 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
2585
2586 std::string get_username =
2587 "window.domAutomationController.send("
2588 " document.getElementById('username').value);";
2589 std::string actual_username;
2590 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2591 RenderViewHost(), get_username, &actual_username));
2592 EXPECT_EQ("myusername", actual_username);
2593
2594 std::string get_password =
2595 "window.domAutomationController.send("
2596 " document.getElementById('password').value);";
2597 std::string actual_password;
2598 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2599 RenderViewHost(), get_password, &actual_password));
2600 EXPECT_EQ("mypassword", actual_password);
2601 }
2602
2603 // Test whether the password form with the problematic invisible password field
2604 // in ambiguous password form autofilled correctly.
vabr (Chromium) 2015/10/20 16:40:22 typo: missing "is" or "gets" between "form" and "a
Pritam Nikam 2015/10/22 09:00:08 Done.
2605 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2606 AutofillSuggetionsForProblematicAmbiguousPasswordForm) {
2607 // At first let us save credentials to the PasswordManager.
2608 scoped_refptr<password_manager::PasswordStore> password_store =
2609 PasswordStoreFactory::GetForProfile(browser()->profile(),
2610 ServiceAccessType::IMPLICIT_ACCESS);
2611 autofill::PasswordForm login_form;
2612 login_form.signon_realm = embedded_test_server()->base_url().spec();
2613 login_form.action = embedded_test_server()->GetURL("/password/done.html");
2614 login_form.username_value = base::ASCIIToUTF16("myusername");
2615 login_form.password_value = base::ASCIIToUTF16("mypassword");
2616 password_store->AddLogin(login_form);
2617
2618 // Logins are added asynchronously to the password store. Spin the message
2619 // loop to make sure the |password_store| had a chance to store the
2620 // |login_form|.
2621 base::RunLoop run_loop;
2622 run_loop.RunUntilIdle();
2623
2624 // Now, navigate to the password form having ambiguous Ids for username and
2625 // password fields and verify whether username and password is autofilled.
2626 NavigateToFile("/password/ambiguous_password_form.html");
2627
2628 // Let the user interact with the page, so that DOM gets modification events,
2629 // needed for autofilling fields.
2630 content::SimulateMouseClickAt(
2631 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
2632
2633 std::string get_username =
2634 "window.domAutomationController.send("
2635 " document.getElementById('hidden_password_form').elements[1].value);";
2636 std::string actual_username;
2637 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2638 RenderViewHost(), get_username, &actual_username));
2639 EXPECT_EQ("myusername", actual_username);
2640
2641 std::string get_password =
2642 "window.domAutomationController.send("
2643 " document.getElementById('hidden_password_form').elements[2].value);";
2644 std::string actual_password;
2645 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2646 RenderViewHost(), get_password, &actual_password));
2647 EXPECT_EQ("mypassword", actual_password);
2648 }
2649
2556 } // namespace password_manager 2650 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698