| Index: chrome/browser/password_manager/password_manager_browsertest.cc
|
| diff --git a/chrome/browser/password_manager/password_manager_browsertest.cc b/chrome/browser/password_manager/password_manager_browsertest.cc
|
| index 535c2ed2476c69f0102e41214db007b9a88ec60e..08ece12abc6ccb122e8014a4760ddecd546b2f6f 100644
|
| --- a/chrome/browser/password_manager/password_manager_browsertest.cc
|
| +++ b/chrome/browser/password_manager/password_manager_browsertest.cc
|
| @@ -31,6 +31,7 @@
|
| #include "net/test/embedded_test_server/embedded_test_server.h"
|
| #include "net/url_request/test_url_fetcher_factory.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| +#include "third_party/WebKit/public/web/WebInputEvent.h"
|
| #include "ui/events/keycodes/keyboard_codes.h"
|
|
|
|
|
| @@ -174,10 +175,25 @@ class PasswordManagerBrowserTest : public InProcessBrowserTest {
|
| observer.Wait();
|
| }
|
|
|
| + // Executes |script| and uses the EXPECT macros to check the return value
|
| + // against |expected_return_value|.
|
| + void CheckScriptReturnValue(std::string& script, bool expected_return_value);
|
| +
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTest);
|
| };
|
|
|
| +void PasswordManagerBrowserTest::CheckScriptReturnValue(
|
| + std::string& script,
|
| + bool expected_return_value) {
|
| + const std::string wrapped_script =
|
| + std::string("window.domAutomationController.send(") + script + ");";
|
| + bool return_value = !expected_return_value;
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
|
| + RenderViewHost(), wrapped_script, &return_value));
|
| + EXPECT_EQ(expected_return_value, return_value) << "script = " << script;
|
| +}
|
| +
|
| // Actual tests ---------------------------------------------------------------
|
| IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
|
| PromptForNormalSubmit) {
|
| @@ -445,8 +461,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
|
|
|
| // Simulate a user click to force an autofill of the form's DOM value, not
|
| // just the suggested value.
|
| - std::string click = "document.getElementById('testform_no_name').click()";
|
| - ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), click));
|
| + content::SimulateMouseClick(
|
| + WebContents(), 0, blink::WebMouseEvent::ButtonLeft);
|
|
|
| // The form should be filled with the previously submitted username.
|
| std::string get_username =
|
| @@ -575,3 +591,43 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, DeleteFrameBeforeSubmit) {
|
| observer.Wait();
|
| // The only thing we check here is that there is no use-after-free reported.
|
| }
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PasswordValueAccessible) {
|
| + NavigateToFile("/password/form_and_link.html");
|
| +
|
| + // Click on a link to open a new tab, then switch back to the first one.
|
| + EXPECT_EQ(1, browser()->tab_strip_model()->count());
|
| + std::string click =
|
| + "document.getElementById('testlink').click();";
|
| + ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), click));
|
| + EXPECT_EQ(2, browser()->tab_strip_model()->count());
|
| + browser()->tab_strip_model()->ActivateTabAt(0, false);
|
| +
|
| + // Fill in the credentials, and make sure they are saved.
|
| + NavigationObserver form_submit_observer(WebContents());
|
| + std::string fill_and_submit =
|
| + "document.getElementById('username_field').value = 'temp';"
|
| + "document.getElementById('password_field').value = 'random';"
|
| + "document.getElementById('input_submit_button').click();";
|
| + ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
|
| + form_submit_observer.Wait();
|
| + EXPECT_TRUE(form_submit_observer.infobar_shown());
|
| +
|
| + // Reload the original page to have the saved credentials autofilled.
|
| + NavigationObserver reload_observer(WebContents());
|
| + NavigateToFile("/password/form_and_link.html");
|
| + reload_observer.Wait();
|
| +
|
| + // Check that while the username is immediately available, the password value
|
| + // needs a user interaction to show up.
|
| + std::string check_username =
|
| + "document.getElementById('username_field').value == 'temp'";
|
| + std::string check_password =
|
| + "document.getElementById('password_field').value == 'random'";
|
| + CheckScriptReturnValue(check_username, true);
|
| + CheckScriptReturnValue(check_password, false);
|
| + content::SimulateMouseClick(
|
| + WebContents(), 0, blink::WebMouseEvent::ButtonLeft);
|
| + CheckScriptReturnValue(check_username, true);
|
| + CheckScriptReturnValue(check_password, true);
|
| +}
|
|
|