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

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: Addresses Vaclav's inputs. 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
« no previous file with comments | « no previous file | chrome/test/data/password/ambiguous_password_form.html » ('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 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 2534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2545 auth_needed_observer.Wait(); 2545 auth_needed_observer.Wait();
2546 2546
2547 // The auth dialog caused a query to PasswordStore, make sure it was 2547 // The auth dialog caused a query to PasswordStore, make sure it was
2548 // processed. 2548 // processed.
2549 base::RunLoop run_loop2; 2549 base::RunLoop run_loop2;
2550 run_loop2.RunUntilIdle(); 2550 run_loop2.RunUntilIdle();
2551 2551
2552 password_manager->RemoveObserver(&mock_login_model_observer); 2552 password_manager->RemoveObserver(&mock_login_model_observer);
2553 } 2553 }
2554 2554
2555 // Test whether the password form with the problematic invisible password field
2556 // gets autofilled correctly.
2557 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2558 AutofillSuggetionsForProblematicPasswordForm) {
2559 // At first let us save credentials to the PasswordManager.
2560 scoped_refptr<password_manager::PasswordStore> password_store =
2561 PasswordStoreFactory::GetForProfile(browser()->profile(),
2562 ServiceAccessType::IMPLICIT_ACCESS);
2563 autofill::PasswordForm login_form;
2564 login_form.signon_realm = embedded_test_server()->base_url().spec();
2565 login_form.action = embedded_test_server()->GetURL("/password/done.html");
2566 login_form.username_value = base::ASCIIToUTF16("myusername");
2567 login_form.password_value = base::ASCIIToUTF16("mypassword");
2568 password_store->AddLogin(login_form);
2569
2570 // Logins are added asynchronously to the password store. Spin the message
2571 // loop to make sure the |password_store| had a chance to store the
2572 // |login_form|.
2573 base::RunLoop run_loop;
2574 run_loop.RunUntilIdle();
2575
2576 // Now, navigate to the password form having ambiguous Ids for username and
2577 // password fields and verify whether username and password is autofilled.
2578 NavigateToFile("/password/password_form.html");
2579
2580 // Let the user interact with the page, so that DOM gets modification events,
2581 // needed for autofilling fields.
2582 content::SimulateMouseClickAt(
2583 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
2584
2585 std::string get_username =
2586 "window.domAutomationController.send("
2587 " document.getElementById('username').value);";
2588 std::string actual_username;
2589 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2590 RenderViewHost(), get_username, &actual_username));
2591 EXPECT_EQ("myusername", actual_username);
2592
2593 std::string get_password =
2594 "window.domAutomationController.send("
2595 " document.getElementById('password').value);";
2596 std::string actual_password;
2597 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2598 RenderViewHost(), get_password, &actual_password));
2599 EXPECT_EQ("mypassword", actual_password);
2600 }
2601
2602 // Test whether the password form with the problematic invisible password field
2603 // in ambiguous password form gets autofilled correctly.
2604 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2605 AutofillSuggetionsForProblematicAmbiguousPasswordForm) {
2606 // At first let us save credentials to the PasswordManager.
2607 scoped_refptr<password_manager::PasswordStore> password_store =
2608 PasswordStoreFactory::GetForProfile(browser()->profile(),
2609 ServiceAccessType::IMPLICIT_ACCESS);
2610 autofill::PasswordForm login_form;
2611 login_form.signon_realm = embedded_test_server()->base_url().spec();
2612 login_form.action = embedded_test_server()->GetURL("/password/done.html");
2613 login_form.username_value = base::ASCIIToUTF16("myusername");
2614 login_form.password_value = base::ASCIIToUTF16("mypassword");
2615 password_store->AddLogin(login_form);
2616
2617 // Logins are added asynchronously to the password store. Spin the message
2618 // loop to make sure the |password_store| had a chance to store the
2619 // |login_form|.
2620 base::RunLoop run_loop;
2621 run_loop.RunUntilIdle();
2622
2623 // Now, navigate to the password form having ambiguous Ids for username and
2624 // password fields and verify whether username and password is autofilled.
2625 NavigateToFile("/password/ambiguous_password_form.html");
2626
2627 // Let the user interact with the page, so that DOM gets modification events,
2628 // needed for autofilling fields.
2629 content::SimulateMouseClickAt(
2630 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
2631
2632 std::string get_username =
2633 "window.domAutomationController.send("
2634 " document.getElementById('hidden_password_form').elements[0].value);";
2635 std::string actual_username;
2636 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2637 RenderViewHost(), get_username, &actual_username));
2638 EXPECT_EQ("myusername", actual_username);
2639
2640 std::string get_password =
2641 "window.domAutomationController.send("
2642 " document.getElementById('hidden_password_form').elements[2].value);";
2643 std::string actual_password;
2644 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2645 RenderViewHost(), get_password, &actual_password));
2646 EXPECT_EQ("mypassword", actual_password);
2647 }
2648
2555 } // namespace password_manager 2649 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/password/ambiguous_password_form.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698