Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" |
| 8 #include "components/autofill/content/common/autofill_messages.h" | 8 #include "components/autofill/content/common/autofill_messages.h" |
| 9 #include "components/autofill/content/renderer/autofill_agent.h" | 9 #include "components/autofill/content/renderer/autofill_agent.h" |
| 10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 11 #include "components/autofill/content/renderer/password_autofill_agent.h" | 11 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 12 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 12 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
| 13 #include "components/autofill/core/common/form_data.h" | 13 #include "components/autofill/core/common/form_data.h" |
| 14 #include "components/autofill/core/common/form_field_data.h" | 14 #include "components/autofill/core/common/form_field_data.h" |
| 15 #include "content/public/renderer/render_frame.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 17 #include "third_party/WebKit/public/platform/WebVector.h" | 18 #include "third_party/WebKit/public/platform/WebVector.h" |
| 18 #include "third_party/WebKit/public/web/WebDocument.h" | 19 #include "third_party/WebKit/public/web/WebDocument.h" |
| 19 #include "third_party/WebKit/public/web/WebElement.h" | 20 #include "third_party/WebKit/public/web/WebElement.h" |
| 20 #include "third_party/WebKit/public/web/WebFormElement.h" | 21 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 21 #include "third_party/WebKit/public/web/WebInputElement.h" | 22 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 23 #include "third_party/WebKit/public/web/WebNode.h" | 24 #include "third_party/WebKit/public/web/WebNode.h" |
| 24 #include "third_party/WebKit/public/web/WebView.h" | 25 #include "third_party/WebKit/public/web/WebView.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 public: | 172 public: |
| 172 PasswordAutofillAgentTest() { | 173 PasswordAutofillAgentTest() { |
| 173 } | 174 } |
| 174 | 175 |
| 175 // Simulates the fill password form message being sent to the renderer. | 176 // Simulates the fill password form message being sent to the renderer. |
| 176 // We use that so we don't have to make RenderView::OnFillPasswordForm() | 177 // We use that so we don't have to make RenderView::OnFillPasswordForm() |
| 177 // protected. | 178 // protected. |
| 178 void SimulateOnFillPasswordForm( | 179 void SimulateOnFillPasswordForm( |
| 179 const PasswordFormFillData& fill_data) { | 180 const PasswordFormFillData& fill_data) { |
| 180 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); | 181 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); |
| 181 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 182 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 182 ->OnMessageReceived(msg); | 183 ->OnMessageReceived(msg); |
| 183 } | 184 } |
| 184 | 185 |
| 186 // As above, but fills for an iframe. | |
| 187 void SimulateOnFillPasswordFormForFrame( | |
| 188 WebFrame* frame, | |
| 189 const PasswordFormFillData& fill_data) { | |
| 190 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); | |
| 191 content::RenderFrame::FromWebFrame(frame)->OnMessageReceived(msg); | |
| 192 } | |
| 193 | |
| 185 void SendVisiblePasswordForms() { | 194 void SendVisiblePasswordForms() { |
| 186 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 195 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 187 ->DidFinishLoad(GetMainFrame()); | 196 ->DidFinishLoad(); |
| 188 } | 197 } |
| 189 | 198 |
| 190 void SetUp() override { | 199 void SetUp() override { |
| 191 ChromeRenderViewTest::SetUp(); | 200 ChromeRenderViewTest::SetUp(); |
| 192 | 201 |
| 193 // Add a preferred login and an additional login to the FillData. | 202 // Add a preferred login and an additional login to the FillData. |
| 194 username1_ = ASCIIToUTF16(kAliceUsername); | 203 username1_ = ASCIIToUTF16(kAliceUsername); |
| 195 password1_ = ASCIIToUTF16(kAlicePassword); | 204 password1_ = ASCIIToUTF16(kAlicePassword); |
| 196 username2_ = ASCIIToUTF16(kBobUsername); | 205 username2_ = ASCIIToUTF16(kBobUsername); |
| 197 password2_ = ASCIIToUTF16(kBobPassword); | 206 password2_ = ASCIIToUTF16(kBobPassword); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 WebFrame* input_frame, | 282 WebFrame* input_frame, |
| 274 WebInputElement& input, | 283 WebInputElement& input, |
| 275 bool is_user_input) { | 284 bool is_user_input) { |
| 276 input.setValue(WebString::fromUTF8(new_value), is_user_input); | 285 input.setValue(WebString::fromUTF8(new_value), is_user_input); |
| 277 // The field must have focus or AutofillAgent will think the | 286 // The field must have focus or AutofillAgent will think the |
| 278 // change should be ignored. | 287 // change should be ignored. |
| 279 while (!input.focused()) | 288 while (!input.focused()) |
| 280 input_frame->document().frame()->view()->advanceFocus(false); | 289 input_frame->document().frame()->view()->advanceFocus(false); |
| 281 if (move_caret_to_end) | 290 if (move_caret_to_end) |
| 282 input.setSelectionRange(new_value.length(), new_value.length()); | 291 input.setSelectionRange(new_value.length(), new_value.length()); |
| 283 if (is_user_input) | 292 if (is_user_input) { |
| 284 password_autofill_agent_->FirstUserGestureObserved(); | 293 AutofillMsg_FirstUserGestureObservedInTab msg(0); |
| 285 static_cast<blink::WebAutofillClient*>(autofill_agent_) | 294 content::RenderFrame::FromWebFrame(input_frame)->OnMessageReceived(msg); |
| 286 ->textFieldDidChange(input); | 295 } |
| 296 input_frame->toWebLocalFrame()->autofillClient()->textFieldDidChange(input); | |
| 287 // Processing is delayed because of a Blink bug: | 297 // Processing is delayed because of a Blink bug: |
| 288 // https://bugs.webkit.org/show_bug.cgi?id=16976 | 298 // https://bugs.webkit.org/show_bug.cgi?id=16976 |
| 289 // See PasswordAutofillAgent::TextDidChangeInTextField() for details. | 299 // See PasswordAutofillAgent::TextDidChangeInTextField() for details. |
| 290 | 300 |
| 291 // Autocomplete will trigger a style recalculation when we put up the next | 301 // Autocomplete will trigger a style recalculation when we put up the next |
| 292 // frame, but we don't want to wait that long. Instead, trigger a style | 302 // frame, but we don't want to wait that long. Instead, trigger a style |
| 293 // recalcuation manually after TextFieldDidChangeImpl runs. | 303 // recalcuation manually after TextFieldDidChangeImpl runs. |
| 294 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 304 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 295 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this))); | 305 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this))); |
| 296 | 306 |
| 297 base::MessageLoop::current()->RunUntilIdle(); | 307 base::MessageLoop::current()->RunUntilIdle(); |
| 298 } | 308 } |
| 299 | 309 |
| 300 void SimulateSuggestionChoice(WebInputElement& username_input) { | 310 void SimulateSuggestionChoice(WebInputElement& username_input) { |
| 301 base::string16 username(base::ASCIIToUTF16(kAliceUsername)); | 311 base::string16 username(base::ASCIIToUTF16(kAliceUsername)); |
| 302 base::string16 password(base::ASCIIToUTF16(kAlicePassword)); | 312 base::string16 password(base::ASCIIToUTF16(kAlicePassword)); |
| 303 | 313 |
| 304 // This call is necessary to setup the autofill agent appropriate for the | 314 // This call is necessary to setup the autofill agent appropriate for the |
| 305 // user selection; simulates the menu actually popping up. | 315 // user selection; simulates the menu actually popping up. |
| 306 render_thread_->sink().ClearMessages(); | 316 render_thread_->sink().ClearMessages(); |
| 307 static_cast<autofill::PageClickListener*>(autofill_agent_) | 317 static_cast<autofill::PageClickListener*>(autofill_agent_) |
| 308 ->FormControlElementClicked(username_input, false); | 318 ->FormControlElementClicked(username_input, false); |
| 309 | 319 |
| 310 AutofillMsg_FillPasswordSuggestion msg(0, username, password); | 320 AutofillMsg_FillPasswordSuggestion msg(0, username, password); |
| 311 static_cast<content::RenderViewObserver*>(autofill_agent_) | 321 static_cast<content::RenderFrameObserver*>(autofill_agent_) |
| 312 ->OnMessageReceived(msg); | 322 ->OnMessageReceived(msg); |
| 313 } | 323 } |
| 314 | 324 |
| 315 void LayoutMainFrame() { | 325 void LayoutMainFrame() { |
| 316 GetMainFrame()->view()->layout(); | 326 GetMainFrame()->view()->layout(); |
| 317 } | 327 } |
| 318 | 328 |
| 319 void SimulateUsernameChange(const std::string& username, | 329 void SimulateUsernameChange(const std::string& username, |
| 320 bool move_caret_to_end, | 330 bool move_caret_to_end, |
| 321 bool is_user_input = false) { | 331 bool is_user_input = false) { |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 std::string page_html(kWebpageWithIframeStart); | 855 std::string page_html(kWebpageWithIframeStart); |
| 846 page_html += origin; | 856 page_html += origin; |
| 847 page_html += kWebpageWithIframeEnd; | 857 page_html += kWebpageWithIframeEnd; |
| 848 | 858 |
| 849 LoadHTML(page_html.c_str()); | 859 LoadHTML(page_html.c_str()); |
| 850 | 860 |
| 851 // Set the expected form origin and action URLs. | 861 // Set the expected form origin and action URLs. |
| 852 fill_data_.origin = GURL(origin); | 862 fill_data_.origin = GURL(origin); |
| 853 fill_data_.action = GURL(origin); | 863 fill_data_.action = GURL(origin); |
| 854 | 864 |
| 855 SimulateOnFillPasswordForm(fill_data_); | |
| 856 | |
| 857 // Retrieve the input elements from the iframe since that is where we want to | 865 // Retrieve the input elements from the iframe since that is where we want to |
| 858 // test the autofill. | 866 // test the autofill. |
| 859 WebFrame* iframe = GetMainFrame()->findChildByName(kIframeName); | 867 WebFrame* iframe = GetMainFrame()->findChildByName(kIframeName); |
| 860 ASSERT_TRUE(iframe); | 868 ASSERT_TRUE(iframe); |
| 869 | |
| 870 SimulateOnFillPasswordFormForFrame(iframe, fill_data_); | |
| 871 | |
| 861 WebDocument document = iframe->document(); | 872 WebDocument document = iframe->document(); |
| 862 | 873 |
| 863 WebElement username_element = document.getElementById(kUsernameName); | 874 WebElement username_element = document.getElementById(kUsernameName); |
| 864 WebElement password_element = document.getElementById(kPasswordName); | 875 WebElement password_element = document.getElementById(kPasswordName); |
| 865 ASSERT_FALSE(username_element.isNull()); | 876 ASSERT_FALSE(username_element.isNull()); |
| 866 ASSERT_FALSE(password_element.isNull()); | 877 ASSERT_FALSE(password_element.isNull()); |
| 867 | 878 |
| 868 WebInputElement username_input = username_element.to<WebInputElement>(); | 879 WebInputElement username_input = username_element.to<WebInputElement>(); |
| 869 WebInputElement password_input = password_element.to<WebInputElement>(); | 880 WebInputElement password_input = password_element.to<WebInputElement>(); |
| 870 ASSERT_FALSE(username_element.isNull()); | 881 ASSERT_FALSE(username_element.isNull()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 894 | 905 |
| 895 // The username and password should have been autocompleted. | 906 // The username and password should have been autocompleted. |
| 896 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 907 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
| 897 | 908 |
| 898 // However, it should only have completed with the suggested value, as tested | 909 // However, it should only have completed with the suggested value, as tested |
| 899 // above, and it should not have completed into the DOM accessible value for | 910 // above, and it should not have completed into the DOM accessible value for |
| 900 // the password field. | 911 // the password field. |
| 901 CheckTextFieldsDOMState(kAliceUsername, true, std::string(), true); | 912 CheckTextFieldsDOMState(kAliceUsername, true, std::string(), true); |
| 902 | 913 |
| 903 // Simulate a user click so that the password field's real value is filled. | 914 // Simulate a user click so that the password field's real value is filled. |
| 904 SimulateElementClick(kUsernameName); | 915 password_autofill_agent_->FirstUserGestureObserved(); |
|
vabr (Chromium)
2014/11/25 15:56:57
This is decreasing the scope of the test: before i
Evan Stade
2014/11/25 21:07:40
turns out I can revert this.
| |
| 905 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 916 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
| 906 } | 917 } |
| 907 | 918 |
| 908 // Verfies that a DOM-activated UI event will not cause an autofill. | 919 // Verfies that a DOM-activated UI event will not cause an autofill. |
| 909 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { | 920 TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) { |
| 910 // Trigger the initial autocomplete. | 921 // Trigger the initial autocomplete. |
| 911 SimulateOnFillPasswordForm(fill_data_); | 922 SimulateOnFillPasswordForm(fill_data_); |
| 912 | 923 |
| 913 ExecuteJavaScript(kJavaScriptClick); | 924 ExecuteJavaScript(kJavaScriptClick); |
| 914 CheckTextFieldsDOMState(kAliceUsername, true, "", true); | 925 CheckTextFieldsDOMState(kAliceUsername, true, "", true); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 943 &username_onchange_called)); | 954 &username_onchange_called)); |
| 944 EXPECT_EQ(1, username_onchange_called); | 955 EXPECT_EQ(1, username_onchange_called); |
| 945 ASSERT_TRUE( | 956 ASSERT_TRUE( |
| 946 ExecuteJavaScriptAndReturnIntValue( | 957 ExecuteJavaScriptAndReturnIntValue( |
| 947 ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"), | 958 ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"), |
| 948 &password_onchange_called)); | 959 &password_onchange_called)); |
| 949 // TODO(isherman): Re-enable this check once http://crbug.com/333144 is fixed. | 960 // TODO(isherman): Re-enable this check once http://crbug.com/333144 is fixed. |
| 950 // EXPECT_EQ(0, password_onchange_called); | 961 // EXPECT_EQ(0, password_onchange_called); |
| 951 | 962 |
| 952 // Simulate a user click so that the password field's real value is filled. | 963 // Simulate a user click so that the password field's real value is filled. |
| 953 SimulateElementClick(kUsernameName); | 964 password_autofill_agent_->FirstUserGestureObserved(); |
| 954 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 965 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
| 955 | 966 |
| 956 // Now, a JavaScript onChange event should have been triggered for the | 967 // Now, a JavaScript onChange event should have been triggered for the |
| 957 // password as well. | 968 // password as well. |
| 958 ASSERT_TRUE( | 969 ASSERT_TRUE( |
| 959 ExecuteJavaScriptAndReturnIntValue( | 970 ExecuteJavaScriptAndReturnIntValue( |
| 960 ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"), | 971 ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"), |
| 961 &password_onchange_called)); | 972 &password_onchange_called)); |
| 962 EXPECT_EQ(1, password_onchange_called); | 973 EXPECT_EQ(1, password_onchange_called); |
| 963 } | 974 } |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1396 TEST_F(PasswordAutofillAgentTest, | 1407 TEST_F(PasswordAutofillAgentTest, |
| 1397 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { | 1408 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { |
| 1398 SimulateInputChangeForElement( | 1409 SimulateInputChangeForElement( |
| 1399 "temp", true, GetMainFrame(), username_element_, true); | 1410 "temp", true, GetMainFrame(), username_element_, true); |
| 1400 SimulateInputChangeForElement( | 1411 SimulateInputChangeForElement( |
| 1401 "random", true, GetMainFrame(), password_element_, true); | 1412 "random", true, GetMainFrame(), password_element_, true); |
| 1402 | 1413 |
| 1403 // Simulate that the password value was cleared by the site's JavaScript | 1414 // Simulate that the password value was cleared by the site's JavaScript |
| 1404 // before submit. | 1415 // before submit. |
| 1405 password_element_.setValue(WebString()); | 1416 password_element_.setValue(WebString()); |
| 1406 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 1417 static_cast<content::RenderViewObserver*>(&password_autofill_agent_->legacy_) |
| 1407 ->WillSubmitForm(GetMainFrame(), username_element_.form()); | 1418 ->WillSubmitForm(GetMainFrame(), username_element_.form()); |
| 1408 | 1419 |
| 1409 // Observe that the PasswordAutofillAgent still remembered the last non-empty | 1420 // Observe that the PasswordAutofillAgent still remembered the last non-empty |
| 1410 // password and sent that to the browser. | 1421 // password and sent that to the browser. |
| 1411 ExpectFormSubmittedWithPasswords("random", ""); | 1422 ExpectFormSubmittedWithPasswords("random", ""); |
| 1412 } | 1423 } |
| 1413 | 1424 |
| 1414 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time | 1425 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time |
| 1415 // it's the user who clears the password. This test checks that in that case, | 1426 // it's the user who clears the password. This test checks that in that case, |
| 1416 // the last non-empty password is not remembered. | 1427 // the last non-empty password is not remembered. |
| 1417 TEST_F(PasswordAutofillAgentTest, | 1428 TEST_F(PasswordAutofillAgentTest, |
| 1418 RememberLastNonEmptyPasswordOnSubmit_UserCleared) { | 1429 RememberLastNonEmptyPasswordOnSubmit_UserCleared) { |
| 1419 SimulateInputChangeForElement( | 1430 SimulateInputChangeForElement( |
| 1420 "temp", true, GetMainFrame(), username_element_, true); | 1431 "temp", true, GetMainFrame(), username_element_, true); |
| 1421 SimulateInputChangeForElement( | 1432 SimulateInputChangeForElement( |
| 1422 "random", true, GetMainFrame(), password_element_, true); | 1433 "random", true, GetMainFrame(), password_element_, true); |
| 1423 | 1434 |
| 1424 // Simulate that the user actually cleared the password again. | 1435 // Simulate that the user actually cleared the password again. |
| 1425 SimulateInputChangeForElement( | 1436 SimulateInputChangeForElement( |
| 1426 "", true, GetMainFrame(), password_element_, true); | 1437 "", true, GetMainFrame(), password_element_, true); |
| 1427 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 1438 static_cast<content::RenderViewObserver*>(&password_autofill_agent_->legacy_) |
| 1428 ->WillSubmitForm(GetMainFrame(), username_element_.form()); | 1439 ->WillSubmitForm(GetMainFrame(), username_element_.form()); |
| 1429 | 1440 |
| 1430 // Observe that the PasswordAutofillAgent respects the user having cleared the | 1441 // Observe that the PasswordAutofillAgent respects the user having cleared the |
| 1431 // password. | 1442 // password. |
| 1432 ExpectFormSubmittedWithPasswords("", ""); | 1443 ExpectFormSubmittedWithPasswords("", ""); |
| 1433 } | 1444 } |
| 1434 | 1445 |
| 1435 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the | 1446 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the |
| 1436 // new password instead of the current password. | 1447 // new password instead of the current password. |
| 1437 TEST_F(PasswordAutofillAgentTest, | 1448 TEST_F(PasswordAutofillAgentTest, |
| 1438 RememberLastNonEmptyPasswordOnSubmit_NewPassword) { | 1449 RememberLastNonEmptyPasswordOnSubmit_NewPassword) { |
| 1439 const char kNewPasswordFormHTML[] = | 1450 const char kNewPasswordFormHTML[] = |
| 1440 "<FORM name='LoginTestForm'>" | 1451 "<FORM name='LoginTestForm'>" |
| 1441 " <INPUT type='text' id='username' autocomplete='username'/>" | 1452 " <INPUT type='text' id='username' autocomplete='username'/>" |
| 1442 " <INPUT type='password' id='password' autocomplete='new-password'/>" | 1453 " <INPUT type='password' id='password' autocomplete='new-password'/>" |
| 1443 " <INPUT type='submit' value='Login'/>" | 1454 " <INPUT type='submit' value='Login'/>" |
| 1444 "</FORM>"; | 1455 "</FORM>"; |
| 1445 LoadHTML(kNewPasswordFormHTML); | 1456 LoadHTML(kNewPasswordFormHTML); |
| 1446 UpdateUsernameAndPasswordElements(); | 1457 UpdateUsernameAndPasswordElements(); |
| 1447 | 1458 |
| 1448 SimulateInputChangeForElement( | 1459 SimulateInputChangeForElement( |
| 1449 "temp", true, GetMainFrame(), username_element_, true); | 1460 "temp", true, GetMainFrame(), username_element_, true); |
| 1450 SimulateInputChangeForElement( | 1461 SimulateInputChangeForElement( |
| 1451 "random", true, GetMainFrame(), password_element_, true); | 1462 "random", true, GetMainFrame(), password_element_, true); |
| 1452 | 1463 |
| 1453 // Simulate that the password value was cleared by the site's JavaScript | 1464 // Simulate that the password value was cleared by the site's JavaScript |
| 1454 // before submit. | 1465 // before submit. |
| 1455 password_element_.setValue(WebString()); | 1466 password_element_.setValue(WebString()); |
| 1456 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 1467 static_cast<content::RenderViewObserver*>(&password_autofill_agent_->legacy_) |
| 1457 ->WillSubmitForm(GetMainFrame(), username_element_.form()); | 1468 ->WillSubmitForm(GetMainFrame(), username_element_.form()); |
| 1458 | 1469 |
| 1459 // Observe that the PasswordAutofillAgent still remembered the last non-empty | 1470 // Observe that the PasswordAutofillAgent still remembered the last non-empty |
| 1460 // password and sent that to the browser. | 1471 // password and sent that to the browser. |
| 1461 ExpectFormSubmittedWithPasswords("", "random"); | 1472 ExpectFormSubmittedWithPasswords("", "random"); |
| 1462 } | 1473 } |
| 1463 | 1474 |
| 1464 // The user first accepts a suggestion, but then overwrites the password. This | 1475 // The user first accepts a suggestion, but then overwrites the password. This |
| 1465 // test checks that the overwritten password is not reverted back if the user | 1476 // test checks that the overwritten password is not reverted back if the user |
| 1466 // triggers autofill through focusing (but not changing) the username again. | 1477 // triggers autofill through focusing (but not changing) the username again. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1500 } | 1511 } |
| 1501 | 1512 |
| 1502 TEST_F(PasswordAutofillAgentTest, | 1513 TEST_F(PasswordAutofillAgentTest, |
| 1503 InlineAutocompleteOverwritesManuallyEditedPassword) { | 1514 InlineAutocompleteOverwritesManuallyEditedPassword) { |
| 1504 // Simulate the browser sending back the login info. | 1515 // Simulate the browser sending back the login info. |
| 1505 SimulateOnFillPasswordForm(fill_data_); | 1516 SimulateOnFillPasswordForm(fill_data_); |
| 1506 | 1517 |
| 1507 ClearUsernameAndPasswordFields(); | 1518 ClearUsernameAndPasswordFields(); |
| 1508 | 1519 |
| 1509 // The user enters a password | 1520 // The user enters a password |
| 1521 password_autofill_agent_->FirstUserGestureObserved(); | |
|
vabr (Chromium)
2014/11/25 15:56:57
Why is this needed? User-entered passwords should
Evan Stade
2014/11/25 21:07:40
Setting the value doesn't call FirstUserGestureObs
| |
| 1510 SimulateInputChangeForElement("someOtherPassword", | 1522 SimulateInputChangeForElement("someOtherPassword", |
| 1511 /*move_caret_to_end=*/true, | 1523 /*move_caret_to_end=*/true, |
| 1512 GetMainFrame(), | 1524 GetMainFrame(), |
| 1513 password_element_, | 1525 password_element_, |
| 1514 /*is_user_input=*/true); | 1526 /*is_user_input=*/true); |
| 1515 | 1527 |
| 1516 // Simulate the user typing a stored username. | 1528 // Simulate the user typing a stored username. |
| 1517 SimulateUsernameChange(kAliceUsername, true); | 1529 SimulateUsernameChange(kAliceUsername, true); |
| 1518 // The autofileld password should replace the typed one. | 1530 // The autofileld password should replace the typed one. |
| 1519 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 1531 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
| 1520 } | 1532 } |
| 1521 | 1533 |
| 1522 } // namespace autofill | 1534 } // namespace autofill |
| OLD | NEW |