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 <tuple> | 5 #include <tuple> |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/macros.h" | 8 #include "base/macros.h" |
8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/renderer/autofill/password_generation_test_utils.h" | 11 #include "chrome/renderer/autofill/password_generation_test_utils.h" |
11 #include "chrome/test/base/chrome_render_view_test.h" | 12 #include "chrome/test/base/chrome_render_view_test.h" |
12 #include "components/autofill/content/common/autofill_messages.h" | 13 #include "components/autofill/content/common/autofill_messages.h" |
13 #include "components/autofill/content/renderer/autofill_agent.h" | 14 #include "components/autofill/content/renderer/autofill_agent.h" |
14 #include "components/autofill/content/renderer/form_autofill_util.h" | 15 #include "components/autofill/content/renderer/form_autofill_util.h" |
15 #include "components/autofill/content/renderer/password_autofill_agent.h" | 16 #include "components/autofill/content/renderer/password_autofill_agent.h" |
16 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 17 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 247 } |
247 | 248 |
248 // As above, but fills for an iframe. | 249 // As above, but fills for an iframe. |
249 void SimulateOnFillPasswordFormForFrame( | 250 void SimulateOnFillPasswordFormForFrame( |
250 WebFrame* frame, | 251 WebFrame* frame, |
251 const PasswordFormFillData& fill_data) { | 252 const PasswordFormFillData& fill_data) { |
252 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); | 253 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); |
253 content::RenderFrame::FromWebFrame(frame)->OnMessageReceived(msg); | 254 content::RenderFrame::FromWebFrame(frame)->OnMessageReceived(msg); |
254 } | 255 } |
255 | 256 |
| 257 // Simulates the show initial password account suggestions message being sent |
| 258 // to the renderer. We use that so we don't have to make |
| 259 // RenderView::OnShowInitialPasswordAccountSuggestions() protected. |
| 260 void SimulateOnShowInitialPasswordAccountSuggestions( |
| 261 const PasswordFormFillData& fill_data) { |
| 262 AutofillMsg_ShowInitialPasswordAccountSuggestions msg( |
| 263 0, kPasswordFillFormDataId, fill_data); |
| 264 static_cast<content::RenderFrameObserver*>(autofill_agent_) |
| 265 ->OnMessageReceived(msg); |
| 266 } |
| 267 |
256 void SendVisiblePasswordForms() { | 268 void SendVisiblePasswordForms() { |
257 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 269 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
258 ->DidFinishLoad(); | 270 ->DidFinishLoad(); |
259 } | 271 } |
260 | 272 |
261 void SetUp() override { | 273 void SetUp() override { |
262 ChromeRenderViewTest::SetUp(); | 274 ChromeRenderViewTest::SetUp(); |
263 | 275 |
264 // Add a preferred login and an additional login to the FillData. | 276 // Add a preferred login and an additional login to the FillData. |
265 username1_ = ASCIIToUTF16(kAliceUsername); | 277 username1_ = ASCIIToUTF16(kAliceUsername); |
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 } | 1287 } |
1276 | 1288 |
1277 // Tests that there is an autosuggestion from the password manager when the | 1289 // Tests that there is an autosuggestion from the password manager when the |
1278 // user clicks on the password field when FillOnAccountSelect is enabled. | 1290 // user clicks on the password field when FillOnAccountSelect is enabled. |
1279 TEST_F(PasswordAutofillAgentTest, | 1291 TEST_F(PasswordAutofillAgentTest, |
1280 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { | 1292 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { |
1281 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1293 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1282 autofill::switches::kEnableFillOnAccountSelect); | 1294 autofill::switches::kEnableFillOnAccountSelect); |
1283 | 1295 |
1284 // Simulate the browser sending back the login info. | 1296 // Simulate the browser sending back the login info. |
1285 SimulateOnFillPasswordForm(fill_data_); | 1297 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
1286 | 1298 |
1287 // Clear the text fields to start fresh. | 1299 // Clear the text fields to start fresh. |
1288 ClearUsernameAndPasswordFields(); | 1300 ClearUsernameAndPasswordFields(); |
1289 | 1301 |
1290 // Call SimulateElementClick() to produce a user gesture on the page so | 1302 // Call SimulateElementClick() to produce a user gesture on the page so |
1291 // autofill will actually fill. | 1303 // autofill will actually fill. |
1292 SimulateElementClick(kUsernameName); | 1304 SimulateElementClick(kUsernameName); |
1293 | 1305 |
1294 // Simulate a user clicking on the password element. This should produce no | 1306 // Simulate a user clicking on the password element. This should produce no |
1295 // message. | 1307 // message. |
1296 render_thread_->sink().ClearMessages(); | 1308 render_thread_->sink().ClearMessages(); |
1297 static_cast<PageClickListener*>(autofill_agent_) | 1309 static_cast<PageClickListener*>(autofill_agent_) |
1298 ->FormControlElementClicked(password_element_, false); | 1310 ->FormControlElementClicked(password_element_, false); |
1299 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1311 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
1300 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 1312 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
1301 } | 1313 } |
1302 | 1314 |
1303 // Tests the autosuggestions that are given when a password element is clicked, | 1315 // Tests the autosuggestions that are given when a password element is clicked, |
1304 // the username element is not editable, and FillOnAccountSelect is enabled. | 1316 // the username element is not editable, and FillOnAccountSelect is enabled. |
1305 // Specifically, tests when the user clicks on the password element after page | 1317 // Specifically, tests when the user clicks on the password element after page |
1306 // load, and the corresponding username element is readonly (and thus | 1318 // load, and the corresponding username element is readonly (and thus |
1307 // uneditable), that the credentials for the already-filled username are | 1319 // uneditable), that the credentials for the already-filled username are |
1308 // suggested. | 1320 // suggested. |
1309 TEST_F(PasswordAutofillAgentTest, | 1321 TEST_F(PasswordAutofillAgentTest, |
1310 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { | 1322 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { |
1311 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1323 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1312 autofill::switches::kEnableFillOnAccountSelect); | 1324 autofill::switches::kEnableFillOnAccountSelect); |
1313 | 1325 |
1314 // Simulate the browser sending back the login info. | 1326 // Simulate the browser sending back the login info. |
1315 SimulateOnFillPasswordForm(fill_data_); | 1327 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
1316 | 1328 |
1317 // Clear the text fields to start fresh. | 1329 // Clear the text fields to start fresh. |
1318 ClearUsernameAndPasswordFields(); | 1330 ClearUsernameAndPasswordFields(); |
1319 | 1331 |
1320 // Simulate the page loading with a prefilled username element that is | 1332 // Simulate the page loading with a prefilled username element that is |
1321 // uneditable. | 1333 // uneditable. |
1322 username_element_.setValue("alicia"); | 1334 username_element_.setValue("alicia"); |
1323 SetElementReadOnly(username_element_, true); | 1335 SetElementReadOnly(username_element_, true); |
1324 | 1336 |
1325 // Call SimulateElementClick() to produce a user gesture on the page so | 1337 // Call SimulateElementClick() to produce a user gesture on the page so |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 CheckTextFieldsState("", false, "", false); | 1569 CheckTextFieldsState("", false, "", false); |
1558 } | 1570 } |
1559 | 1571 |
1560 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnly) { | 1572 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnly) { |
1561 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1573 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1562 autofill::switches::kEnableFillOnAccountSelect); | 1574 autofill::switches::kEnableFillOnAccountSelect); |
1563 | 1575 |
1564 ClearUsernameAndPasswordFields(); | 1576 ClearUsernameAndPasswordFields(); |
1565 | 1577 |
1566 // Simulate the browser sending back the login info for an initial page load. | 1578 // Simulate the browser sending back the login info for an initial page load. |
1567 SimulateOnFillPasswordForm(fill_data_); | 1579 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
1568 | 1580 |
1569 CheckTextFieldsState(std::string(), true, std::string(), false); | 1581 CheckTextFieldsState(std::string(), false, std::string(), false); |
| 1582 CheckSuggestions(std::string(), true); |
1570 } | 1583 } |
1571 | 1584 |
1572 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyReadonlyUsername) { | 1585 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyReadonlyUsername) { |
1573 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1586 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1574 autofill::switches::kEnableFillOnAccountSelect); | 1587 autofill::switches::kEnableFillOnAccountSelect); |
1575 | 1588 |
1576 ClearUsernameAndPasswordFields(); | 1589 ClearUsernameAndPasswordFields(); |
1577 | 1590 |
1578 username_element_.setValue("alice"); | 1591 username_element_.setValue("alice"); |
1579 SetElementReadOnly(username_element_, true); | 1592 SetElementReadOnly(username_element_, true); |
1580 | 1593 |
1581 // Simulate the browser sending back the login info for an initial page load. | 1594 // Simulate the browser sending back the login info for an initial page load. |
1582 SimulateOnFillPasswordForm(fill_data_); | 1595 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
1583 | 1596 |
1584 CheckTextFieldsState(std::string("alice"), false, std::string(), true); | 1597 CheckTextFieldsState(std::string("alice"), false, std::string(), false); |
1585 } | 1598 } |
1586 | 1599 |
1587 TEST_F(PasswordAutofillAgentTest, | 1600 TEST_F(PasswordAutofillAgentTest, |
1588 FillOnAccountSelectOnlyReadonlyNotPreferredUsername) { | 1601 FillOnAccountSelectOnlyReadonlyNotPreferredUsername) { |
1589 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1602 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1590 autofill::switches::kEnableFillOnAccountSelect); | 1603 autofill::switches::kEnableFillOnAccountSelect); |
1591 | 1604 |
1592 ClearUsernameAndPasswordFields(); | 1605 ClearUsernameAndPasswordFields(); |
1593 | 1606 |
1594 username_element_.setValue("Carol"); | 1607 username_element_.setValue("Carol"); |
1595 SetElementReadOnly(username_element_, true); | 1608 SetElementReadOnly(username_element_, true); |
1596 | 1609 |
1597 // Simulate the browser sending back the login info for an initial page load. | 1610 // Simulate the browser sending back the login info for an initial page load. |
1598 SimulateOnFillPasswordForm(fill_data_); | 1611 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
1599 | 1612 |
1600 CheckTextFieldsState(std::string("Carol"), false, std::string(), true); | 1613 CheckTextFieldsState(std::string("Carol"), false, std::string(), false); |
1601 } | 1614 } |
1602 | 1615 |
1603 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyNoUsername) { | 1616 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyNoUsername) { |
1604 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1617 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1605 autofill::switches::kEnableFillOnAccountSelect); | 1618 autofill::switches::kEnableFillOnAccountSelect); |
1606 | 1619 |
1607 // Load a form with no username and update test data. | 1620 // Load a form with no username and update test data. |
1608 LoadHTML(kVisibleFormWithNoUsernameHTML); | 1621 LoadHTML(kVisibleFormWithNoUsernameHTML); |
1609 username_element_.reset(); | 1622 username_element_.reset(); |
1610 WebDocument document = GetMainFrame()->document(); | 1623 WebDocument document = GetMainFrame()->document(); |
1611 WebElement element = | 1624 WebElement element = |
1612 document.getElementById(WebString::fromUTF8(kPasswordName)); | 1625 document.getElementById(WebString::fromUTF8(kPasswordName)); |
1613 ASSERT_FALSE(element.isNull()); | 1626 ASSERT_FALSE(element.isNull()); |
1614 password_element_ = element.to<blink::WebInputElement>(); | 1627 password_element_ = element.to<blink::WebInputElement>(); |
1615 fill_data_.username_field = FormFieldData(); | 1628 fill_data_.username_field = FormFieldData(); |
1616 UpdateOriginForHTML(kVisibleFormWithNoUsernameHTML); | 1629 UpdateOriginForHTML(kVisibleFormWithNoUsernameHTML); |
1617 fill_data_.additional_logins.clear(); | 1630 fill_data_.additional_logins.clear(); |
1618 fill_data_.other_possible_usernames.clear(); | 1631 fill_data_.other_possible_usernames.clear(); |
1619 | 1632 |
1620 password_element_.setValue(""); | 1633 password_element_.setValue(""); |
1621 password_element_.setAutofilled(false); | 1634 password_element_.setAutofilled(false); |
1622 | 1635 |
1623 // Simulate the browser sending back the login info for an initial page load. | 1636 // Simulate the browser sending back the login info for an initial page load. |
1624 SimulateOnFillPasswordForm(fill_data_); | 1637 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
1625 | 1638 |
1626 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); | 1639 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); |
1627 EXPECT_TRUE(password_element_.isAutofilled()); | 1640 EXPECT_FALSE(password_element_.isAutofilled()); |
| 1641 CheckSuggestions(std::string(), false); |
1628 } | 1642 } |
1629 | 1643 |
1630 TEST_F(PasswordAutofillAgentTest, ShowPopupOnEmptyPasswordField) { | 1644 TEST_F(PasswordAutofillAgentTest, ShowPopupOnEmptyPasswordField) { |
1631 // Load a form with no username and update test data. | 1645 // Load a form with no username and update test data. |
1632 LoadHTML(kVisibleFormWithNoUsernameHTML); | 1646 LoadHTML(kVisibleFormWithNoUsernameHTML); |
1633 username_element_.reset(); | 1647 username_element_.reset(); |
1634 WebDocument document = GetMainFrame()->document(); | 1648 WebDocument document = GetMainFrame()->document(); |
1635 WebElement element = | 1649 WebElement element = |
1636 document.getElementById(WebString::fromUTF8(kPasswordName)); | 1650 document.getElementById(WebString::fromUTF8(kPasswordName)); |
1637 ASSERT_FALSE(element.isNull()); | 1651 ASSERT_FALSE(element.isNull()); |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2359 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 2373 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
2360 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 2374 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
2361 | 2375 |
2362 // But when the user clicks on the autofilled password field again it should | 2376 // But when the user clicks on the autofilled password field again it should |
2363 // still produce a suggestion dropdown. | 2377 // still produce a suggestion dropdown. |
2364 SimulateElementClick("password"); | 2378 SimulateElementClick("password"); |
2365 CheckSuggestions("", false); | 2379 CheckSuggestions("", false); |
2366 } | 2380 } |
2367 | 2381 |
2368 } // namespace autofill | 2382 } // namespace autofill |
OLD | NEW |