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

Side by Side Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 2080263002: Change fill-on-account-select to use Features API, not a custom flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused GRD strings Created 4 years, 6 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 | « chrome/renderer/DEPS ('k') | components/autofill/core/common/autofill_switches.h » ('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 (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/feature_list.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/renderer/autofill/password_generation_test_utils.h" 11 #include "chrome/renderer/autofill/password_generation_test_utils.h"
12 #include "chrome/test/base/chrome_render_view_test.h" 12 #include "chrome/test/base/chrome_render_view_test.h"
13 #include "components/autofill/content/common/autofill_messages.h" 13 #include "components/autofill/content/common/autofill_messages.h"
14 #include "components/autofill/content/renderer/autofill_agent.h" 14 #include "components/autofill/content/renderer/autofill_agent.h"
15 #include "components/autofill/content/renderer/form_autofill_util.h" 15 #include "components/autofill/content/renderer/form_autofill_util.h"
16 #include "components/autofill/content/renderer/password_autofill_agent.h" 16 #include "components/autofill/content/renderer/password_autofill_agent.h"
17 #include "components/autofill/content/renderer/test_password_autofill_agent.h" 17 #include "components/autofill/content/renderer/test_password_autofill_agent.h"
18 #include "components/autofill/content/renderer/test_password_generation_agent.h" 18 #include "components/autofill/content/renderer/test_password_generation_agent.h"
19 #include "components/autofill/core/common/autofill_constants.h" 19 #include "components/autofill/core/common/autofill_constants.h"
20 #include "components/autofill/core/common/autofill_switches.h"
21 #include "components/autofill/core/common/form_data.h" 20 #include "components/autofill/core/common/form_data.h"
22 #include "components/autofill/core/common/form_field_data.h" 21 #include "components/autofill/core/common/form_field_data.h"
23 #include "components/autofill/core/common/password_form_field_prediction_map.h" 22 #include "components/autofill/core/common/password_form_field_prediction_map.h"
23 #include "components/password_manager/core/common/password_manager_features.h"
24 #include "content/public/renderer/render_frame.h" 24 #include "content/public/renderer/render_frame.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "third_party/WebKit/public/platform/WebString.h" 26 #include "third_party/WebKit/public/platform/WebString.h"
27 #include "third_party/WebKit/public/platform/WebVector.h" 27 #include "third_party/WebKit/public/platform/WebVector.h"
28 #include "third_party/WebKit/public/web/WebDocument.h" 28 #include "third_party/WebKit/public/web/WebDocument.h"
29 #include "third_party/WebKit/public/web/WebElement.h" 29 #include "third_party/WebKit/public/web/WebElement.h"
30 #include "third_party/WebKit/public/web/WebFormControlElement.h" 30 #include "third_party/WebKit/public/web/WebFormControlElement.h"
31 #include "third_party/WebKit/public/web/WebFormElement.h" 31 #include "third_party/WebKit/public/web/WebFormElement.h"
32 #include "third_party/WebKit/public/web/WebInputElement.h" 32 #include "third_party/WebKit/public/web/WebInputElement.h"
33 #include "third_party/WebKit/public/web/WebLocalFrame.h" 33 #include "third_party/WebKit/public/web/WebLocalFrame.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // Now retrieve the input elements so the test can access them. 320 // Now retrieve the input elements so the test can access them.
321 UpdateUsernameAndPasswordElements(); 321 UpdateUsernameAndPasswordElements();
322 } 322 }
323 323
324 void TearDown() override { 324 void TearDown() override {
325 username_element_.reset(); 325 username_element_.reset();
326 password_element_.reset(); 326 password_element_.reset();
327 ChromeRenderViewTest::TearDown(); 327 ChromeRenderViewTest::TearDown();
328 } 328 }
329 329
330 void SetFillOnAccountSelect() {
331 base::FeatureList::ClearInstanceForTesting();
332 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
333 feature_list->InitializeFromCommandLine(
334 password_manager::features::kFillOnAccountSelect.name, "");
335 base::FeatureList::SetInstance(std::move(feature_list));
336 }
337
330 void UpdateOriginForHTML(const std::string& html) { 338 void UpdateOriginForHTML(const std::string& html) {
331 std::string origin = "data:text/html;charset=utf-8," + html; 339 std::string origin = "data:text/html;charset=utf-8," + html;
332 fill_data_.origin = GURL(origin); 340 fill_data_.origin = GURL(origin);
333 } 341 }
334 342
335 void UpdateUsernameAndPasswordElements() { 343 void UpdateUsernameAndPasswordElements() {
336 WebDocument document = GetMainFrame()->document(); 344 WebDocument document = GetMainFrame()->document();
337 WebElement element = 345 WebElement element =
338 document.getElementById(WebString::fromUTF8(kUsernameName)); 346 document.getElementById(WebString::fromUTF8(kUsernameName));
339 ASSERT_FALSE(element.isNull()); 347 ASSERT_FALSE(element.isNull());
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 static_cast<PageClickListener*>(autofill_agent_) 1291 static_cast<PageClickListener*>(autofill_agent_)
1284 ->FormControlElementClicked(username_element_, true); 1292 ->FormControlElementClicked(username_element_, true);
1285 CheckSuggestions("baz", true); 1293 CheckSuggestions("baz", true);
1286 ClearUsernameAndPasswordFields(); 1294 ClearUsernameAndPasswordFields();
1287 } 1295 }
1288 1296
1289 // Tests that there is an autosuggestion from the password manager when the 1297 // Tests that there is an autosuggestion from the password manager when the
1290 // user clicks on the password field when FillOnAccountSelect is enabled. 1298 // user clicks on the password field when FillOnAccountSelect is enabled.
1291 TEST_F(PasswordAutofillAgentTest, 1299 TEST_F(PasswordAutofillAgentTest,
1292 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { 1300 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) {
1293 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1301 SetFillOnAccountSelect();
1294 autofill::switches::kEnableFillOnAccountSelect);
1295 1302
1296 // Simulate the browser sending back the login info. 1303 // Simulate the browser sending back the login info.
1297 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); 1304 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_);
1298 1305
1299 // Clear the text fields to start fresh. 1306 // Clear the text fields to start fresh.
1300 ClearUsernameAndPasswordFields(); 1307 ClearUsernameAndPasswordFields();
1301 1308
1302 // Call SimulateElementClick() to produce a user gesture on the page so 1309 // Call SimulateElementClick() to produce a user gesture on the page so
1303 // autofill will actually fill. 1310 // autofill will actually fill.
1304 SimulateElementClick(kUsernameName); 1311 SimulateElementClick(kUsernameName);
1305 1312
1306 // Simulate a user clicking on the password element. This should produce no 1313 // Simulate a user clicking on the password element. This should produce no
1307 // message. 1314 // message.
1308 render_thread_->sink().ClearMessages(); 1315 render_thread_->sink().ClearMessages();
1309 static_cast<PageClickListener*>(autofill_agent_) 1316 static_cast<PageClickListener*>(autofill_agent_)
1310 ->FormControlElementClicked(password_element_, false); 1317 ->FormControlElementClicked(password_element_, false);
1311 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( 1318 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
1312 AutofillHostMsg_ShowPasswordSuggestions::ID)); 1319 AutofillHostMsg_ShowPasswordSuggestions::ID));
1313 } 1320 }
1314 1321
1315 // Tests the autosuggestions that are given when a password element is clicked, 1322 // Tests the autosuggestions that are given when a password element is clicked,
1316 // the username element is not editable, and FillOnAccountSelect is enabled. 1323 // the username element is not editable, and FillOnAccountSelect is enabled.
1317 // Specifically, tests when the user clicks on the password element after page 1324 // Specifically, tests when the user clicks on the password element after page
1318 // load, and the corresponding username element is readonly (and thus 1325 // load, and the corresponding username element is readonly (and thus
1319 // uneditable), that the credentials for the already-filled username are 1326 // uneditable), that the credentials for the already-filled username are
1320 // suggested. 1327 // suggested.
1321 TEST_F(PasswordAutofillAgentTest, 1328 TEST_F(PasswordAutofillAgentTest,
1322 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { 1329 FillOnAccountSelectOnlyCredentialsOnPasswordClick) {
1323 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1330 SetFillOnAccountSelect();
1324 autofill::switches::kEnableFillOnAccountSelect);
1325 1331
1326 // Simulate the browser sending back the login info. 1332 // Simulate the browser sending back the login info.
1327 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); 1333 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_);
1328 1334
1329 // Clear the text fields to start fresh. 1335 // Clear the text fields to start fresh.
1330 ClearUsernameAndPasswordFields(); 1336 ClearUsernameAndPasswordFields();
1331 1337
1332 // Simulate the page loading with a prefilled username element that is 1338 // Simulate the page loading with a prefilled username element that is
1333 // uneditable. 1339 // uneditable.
1334 username_element_.setValue("alicia"); 1340 username_element_.setValue("alicia");
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 1569
1564 PasswordFormFillData no_username_fill_data = fill_data_; 1570 PasswordFormFillData no_username_fill_data = fill_data_;
1565 no_username_fill_data.username_field.name = base::string16(); 1571 no_username_fill_data.username_field.name = base::string16();
1566 SimulateOnFillPasswordForm(no_username_fill_data); 1572 SimulateOnFillPasswordForm(no_username_fill_data);
1567 1573
1568 // The username and password should not have been autocompleted. 1574 // The username and password should not have been autocompleted.
1569 CheckTextFieldsState("", false, "", false); 1575 CheckTextFieldsState("", false, "", false);
1570 } 1576 }
1571 1577
1572 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnly) { 1578 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnly) {
1573 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1579 SetFillOnAccountSelect();
1574 autofill::switches::kEnableFillOnAccountSelect);
1575 1580
1576 ClearUsernameAndPasswordFields(); 1581 ClearUsernameAndPasswordFields();
1577 1582
1578 // Simulate the browser sending back the login info for an initial page load. 1583 // Simulate the browser sending back the login info for an initial page load.
1579 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); 1584 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_);
1580 1585
1581 CheckTextFieldsState(std::string(), false, std::string(), false); 1586 CheckTextFieldsState(std::string(), false, std::string(), false);
1582 CheckSuggestions(std::string(), true); 1587 CheckSuggestions(std::string(), true);
1583 } 1588 }
1584 1589
1585 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyReadonlyUsername) { 1590 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyReadonlyUsername) {
1586 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1591 SetFillOnAccountSelect();
1587 autofill::switches::kEnableFillOnAccountSelect);
1588 1592
1589 ClearUsernameAndPasswordFields(); 1593 ClearUsernameAndPasswordFields();
1590 1594
1591 username_element_.setValue("alice"); 1595 username_element_.setValue("alice");
1592 SetElementReadOnly(username_element_, true); 1596 SetElementReadOnly(username_element_, true);
1593 1597
1594 // Simulate the browser sending back the login info for an initial page load. 1598 // Simulate the browser sending back the login info for an initial page load.
1595 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); 1599 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_);
1596 1600
1597 CheckTextFieldsState(std::string("alice"), false, std::string(), false); 1601 CheckTextFieldsState(std::string("alice"), false, std::string(), false);
1598 } 1602 }
1599 1603
1600 TEST_F(PasswordAutofillAgentTest, 1604 TEST_F(PasswordAutofillAgentTest,
1601 FillOnAccountSelectOnlyReadonlyNotPreferredUsername) { 1605 FillOnAccountSelectOnlyReadonlyNotPreferredUsername) {
1602 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1606 SetFillOnAccountSelect();
1603 autofill::switches::kEnableFillOnAccountSelect);
1604 1607
1605 ClearUsernameAndPasswordFields(); 1608 ClearUsernameAndPasswordFields();
1606 1609
1607 username_element_.setValue("Carol"); 1610 username_element_.setValue("Carol");
1608 SetElementReadOnly(username_element_, true); 1611 SetElementReadOnly(username_element_, true);
1609 1612
1610 // Simulate the browser sending back the login info for an initial page load. 1613 // Simulate the browser sending back the login info for an initial page load.
1611 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); 1614 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_);
1612 1615
1613 CheckTextFieldsState(std::string("Carol"), false, std::string(), false); 1616 CheckTextFieldsState(std::string("Carol"), false, std::string(), false);
1614 } 1617 }
1615 1618
1616 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyNoUsername) { 1619 TEST_F(PasswordAutofillAgentTest, FillOnAccountSelectOnlyNoUsername) {
1617 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1620 SetFillOnAccountSelect();
1618 autofill::switches::kEnableFillOnAccountSelect);
1619 1621
1620 // Load a form with no username and update test data. 1622 // Load a form with no username and update test data.
1621 LoadHTML(kVisibleFormWithNoUsernameHTML); 1623 LoadHTML(kVisibleFormWithNoUsernameHTML);
1622 username_element_.reset(); 1624 username_element_.reset();
1623 WebDocument document = GetMainFrame()->document(); 1625 WebDocument document = GetMainFrame()->document();
1624 WebElement element = 1626 WebElement element =
1625 document.getElementById(WebString::fromUTF8(kPasswordName)); 1627 document.getElementById(WebString::fromUTF8(kPasswordName));
1626 ASSERT_FALSE(element.isNull()); 1628 ASSERT_FALSE(element.isNull());
1627 password_element_ = element.to<blink::WebInputElement>(); 1629 password_element_ = element.to<blink::WebInputElement>();
1628 fill_data_.username_field = FormFieldData(); 1630 fill_data_.username_field = FormFieldData();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); 1734 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword));
1733 ASSERT_FALSE(render_thread_->sink().GetFirstMessageMatching( 1735 ASSERT_FALSE(render_thread_->sink().GetFirstMessageMatching(
1734 AutofillHostMsg_ShowPasswordSuggestions::ID)); 1736 AutofillHostMsg_ShowPasswordSuggestions::ID));
1735 } 1737 }
1736 1738
1737 // Tests with fill-on-account-select enabled that if the username element is 1739 // Tests with fill-on-account-select enabled that if the username element is
1738 // read-only and filled with an unknown username, then the password field is not 1740 // read-only and filled with an unknown username, then the password field is not
1739 // highlighted as autofillable (regression test for https://crbug.com/442564). 1741 // highlighted as autofillable (regression test for https://crbug.com/442564).
1740 TEST_F(PasswordAutofillAgentTest, 1742 TEST_F(PasswordAutofillAgentTest,
1741 FillOnAccountSelectOnlyReadonlyUnknownUsername) { 1743 FillOnAccountSelectOnlyReadonlyUnknownUsername) {
1742 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1744 SetFillOnAccountSelect();
1743 autofill::switches::kEnableFillOnAccountSelect);
1744 1745
1745 ClearUsernameAndPasswordFields(); 1746 ClearUsernameAndPasswordFields();
1746 1747
1747 username_element_.setValue("foobar"); 1748 username_element_.setValue("foobar");
1748 SetElementReadOnly(username_element_, true); 1749 SetElementReadOnly(username_element_, true);
1749 1750
1750 CheckTextFieldsState(std::string("foobar"), false, std::string(), false); 1751 CheckTextFieldsState(std::string("foobar"), false, std::string(), false);
1751 } 1752 }
1752 1753
1753 // Test that the last plain text field before a password field is chosen as a 1754 // Test that the last plain text field before a password field is chosen as a
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 2374 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
2374 AutofillHostMsg_ShowPasswordSuggestions::ID)); 2375 AutofillHostMsg_ShowPasswordSuggestions::ID));
2375 2376
2376 // But when the user clicks on the autofilled password field again it should 2377 // But when the user clicks on the autofilled password field again it should
2377 // still produce a suggestion dropdown. 2378 // still produce a suggestion dropdown.
2378 SimulateElementClick("password"); 2379 SimulateElementClick("password");
2379 CheckSuggestions("", false); 2380 CheckSuggestions("", false);
2380 } 2381 }
2381 2382
2382 } // namespace autofill 2383 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/DEPS ('k') | components/autofill/core/common/autofill_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698