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..7cc38b38fcc3c8c0bbe74d47d2a9ecc30db0433f 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,38 @@ 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); |
+ |
+ // Simulate a user clicking somewhere in the page. |
+ void SimulateClick(); |
+ |
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; |
+} |
+ |
+void PasswordManagerBrowserTest::SimulateClick() { |
+ blink::WebMouseEvent mouse_event; |
+ mouse_event.type = blink::WebInputEvent::MouseDown; |
+ mouse_event.button = blink::WebMouseEvent::ButtonLeft; |
+ mouse_event.x = 1; |
+ mouse_event.y = 1; |
+ mouse_event.clickCount = 1; |
+ WebContents()->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
+} |
Ilya Sherman
2014/02/19 23:54:57
Drive-by nit: Can you use SimulateMouseClick() fro
vabr (Chromium)
2014/02/20 09:54:21
Done, thanks for making me aware of SimulateMouseC
|
+ |
// Actual tests --------------------------------------------------------------- |
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
PromptForNormalSubmit) { |
@@ -445,8 +474,7 @@ 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)); |
+ SimulateClick(); |
// The form should be filled with the previously submitted username. |
std::string get_username = |
@@ -575,3 +603,42 @@ 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); |
+ SimulateClick(); |
+ CheckScriptReturnValue(check_username, true); |
+ CheckScriptReturnValue(check_password, true); |
+} |