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

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

Issue 2650623002: Use explicit WebString conversions in autofill (Closed)
Patch Set: . Created 3 years, 11 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
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 "components/autofill/content/renderer/password_autofill_agent.h" 5 #include "components/autofill/content/renderer/password_autofill_agent.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.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"
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 // autocomplete. 664 // autocomplete.
665 SimulateOnFillPasswordForm(fill_data_); 665 SimulateOnFillPasswordForm(fill_data_);
666 666
667 CheckTextFieldsState(std::string(), false, std::string(), false); 667 CheckTextFieldsState(std::string(), false, std::string(), false);
668 } 668 }
669 669
670 // Can still fill a password field if the username is set to a value that 670 // Can still fill a password field if the username is set to a value that
671 // matches. 671 // matches.
672 TEST_F(PasswordAutofillAgentTest, 672 TEST_F(PasswordAutofillAgentTest,
673 AutocompletePasswordForReadonlyUsernameMatched) { 673 AutocompletePasswordForReadonlyUsernameMatched) {
674 username_element_.setValue(username3_); 674 username_element_.setValue(WebString::fromUTF16(username3_));
675 SetElementReadOnly(username_element_, true); 675 SetElementReadOnly(username_element_, true);
676 676
677 // Filled even though username is not the preferred match. 677 // Filled even though username is not the preferred match.
678 SimulateOnFillPasswordForm(fill_data_); 678 SimulateOnFillPasswordForm(fill_data_);
679 CheckTextFieldsState(UTF16ToUTF8(username3_), false, 679 CheckTextFieldsState(UTF16ToUTF8(username3_), false,
680 UTF16ToUTF8(password3_), true); 680 UTF16ToUTF8(password3_), true);
681 } 681 }
682 682
683 // If a username field is empty and readonly, don't autofill. 683 // If a username field is empty and readonly, don't autofill.
684 TEST_F(PasswordAutofillAgentTest, 684 TEST_F(PasswordAutofillAgentTest,
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 1182
1183 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1183 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1184 username_element_, kAliceUsername, kAlicePassword)); 1184 username_element_, kAliceUsername, kAlicePassword));
1185 1185
1186 EXPECT_TRUE( 1186 EXPECT_TRUE(
1187 password_autofill_agent_->DidClearAutofillSelection(username_element_)); 1187 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1188 1188
1189 EXPECT_TRUE(username_element_.value().isEmpty()); 1189 EXPECT_TRUE(username_element_.value().isEmpty());
1190 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1190 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1191 EXPECT_FALSE(username_element_.isAutofilled()); 1191 EXPECT_FALSE(username_element_.isAutofilled());
1192 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value()); 1192 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value().utf16());
1193 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1193 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1194 EXPECT_TRUE(password_element_.isAutofilled()); 1194 EXPECT_TRUE(password_element_.isAutofilled());
1195 CheckUsernameSelection(0, 0); 1195 CheckUsernameSelection(0, 0);
1196 } 1196 }
1197 1197
1198 // Tests that |ClearPreview| properly clears previewed username and password 1198 // Tests that |ClearPreview| properly clears previewed username and password
1199 // with username being previously autofilled. 1199 // with username being previously autofilled.
1200 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) { 1200 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) {
1201 username_element_.setValue(WebString::fromUTF8("ali")); 1201 username_element_.setValue(WebString::fromUTF8("ali"));
1202 username_element_.setSelectionRange(3, 3); 1202 username_element_.setSelectionRange(3, 3);
1203 username_element_.setAutofilled(true); 1203 username_element_.setAutofilled(true);
1204 1204
1205 // Simulate the browser sending the login info, but set |wait_for_username| 1205 // Simulate the browser sending the login info, but set |wait_for_username|
1206 // to prevent the form from being immediately filled. 1206 // to prevent the form from being immediately filled.
1207 fill_data_.wait_for_username = true; 1207 fill_data_.wait_for_username = true;
1208 SimulateOnFillPasswordForm(fill_data_); 1208 SimulateOnFillPasswordForm(fill_data_);
1209 1209
1210 CheckTextFieldsDOMState("ali", true, std::string(), false); 1210 CheckTextFieldsDOMState("ali", true, std::string(), false);
1211 1211
1212 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1212 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1213 username_element_, kAliceUsername, kAlicePassword)); 1213 username_element_, kAliceUsername, kAlicePassword));
1214 1214
1215 EXPECT_TRUE( 1215 EXPECT_TRUE(
1216 password_autofill_agent_->DidClearAutofillSelection(username_element_)); 1216 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1217 1217
1218 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value()); 1218 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value().utf16());
1219 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1219 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1220 EXPECT_TRUE(username_element_.isAutofilled()); 1220 EXPECT_TRUE(username_element_.isAutofilled());
1221 EXPECT_TRUE(password_element_.value().isEmpty()); 1221 EXPECT_TRUE(password_element_.value().isEmpty());
1222 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1222 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1223 EXPECT_FALSE(password_element_.isAutofilled()); 1223 EXPECT_FALSE(password_element_.isAutofilled());
1224 CheckUsernameSelection(3, 3); 1224 CheckUsernameSelection(3, 3);
1225 } 1225 }
1226 1226
1227 // Tests that |ClearPreview| properly clears previewed username and password 1227 // Tests that |ClearPreview| properly clears previewed username and password
1228 // with username and password being previously autofilled. 1228 // with username and password being previously autofilled.
(...skipping 11 matching lines...) Expand all
1240 SimulateOnFillPasswordForm(fill_data_); 1240 SimulateOnFillPasswordForm(fill_data_);
1241 1241
1242 CheckTextFieldsDOMState("ali", true, "sec", true); 1242 CheckTextFieldsDOMState("ali", true, "sec", true);
1243 1243
1244 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion( 1244 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1245 username_element_, kAliceUsername, kAlicePassword)); 1245 username_element_, kAliceUsername, kAlicePassword));
1246 1246
1247 EXPECT_TRUE( 1247 EXPECT_TRUE(
1248 password_autofill_agent_->DidClearAutofillSelection(username_element_)); 1248 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1249 1249
1250 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value()); 1250 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value().utf16());
1251 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1251 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1252 EXPECT_TRUE(username_element_.isAutofilled()); 1252 EXPECT_TRUE(username_element_.isAutofilled());
1253 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value()); 1253 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value().utf16());
1254 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1254 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1255 EXPECT_TRUE(password_element_.isAutofilled()); 1255 EXPECT_TRUE(password_element_.isAutofilled());
1256 CheckUsernameSelection(3, 3); 1256 CheckUsernameSelection(3, 3);
1257 } 1257 }
1258 1258
1259 // Tests that |ClearPreview| properly clears previewed username and password 1259 // Tests that |ClearPreview| properly clears previewed username and password
1260 // with neither username nor password being previously autofilled. 1260 // with neither username nor password being previously autofilled.
1261 TEST_F(PasswordAutofillAgentTest, 1261 TEST_F(PasswordAutofillAgentTest,
1262 ClearPreviewWithNotAutofilledUsernameAndPassword) { 1262 ClearPreviewWithNotAutofilledUsernameAndPassword) {
1263 // Simulate the browser sending the login info, but set |wait_for_username| 1263 // Simulate the browser sending the login info, but set |wait_for_username|
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 // Simulate the browser sending back the login info for an initial page load. 1798 // Simulate the browser sending back the login info for an initial page load.
1799 SimulateOnFillPasswordForm(fill_data_); 1799 SimulateOnFillPasswordForm(fill_data_);
1800 1800
1801 // Show popup suggesstion when the password field is empty. 1801 // Show popup suggesstion when the password field is empty.
1802 password_element_.setValue(""); 1802 password_element_.setValue("");
1803 password_element_.setAutofilled(false); 1803 password_element_.setAutofilled(false);
1804 1804
1805 SimulateSuggestionChoiceOfUsernameAndPassword( 1805 SimulateSuggestionChoiceOfUsernameAndPassword(
1806 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); 1806 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword));
1807 CheckSuggestions(std::string(), false); 1807 CheckSuggestions(std::string(), false);
1808 EXPECT_EQ(ASCIIToUTF16(kAlicePassword), password_element_.value()); 1808 EXPECT_EQ(ASCIIToUTF16(kAlicePassword), password_element_.value().utf16());
1809 EXPECT_TRUE(password_element_.isAutofilled()); 1809 EXPECT_TRUE(password_element_.isAutofilled());
1810 } 1810 }
1811 1811
1812 TEST_F(PasswordAutofillAgentTest, ShowPopupOnAutofilledPasswordField) { 1812 TEST_F(PasswordAutofillAgentTest, ShowPopupOnAutofilledPasswordField) {
1813 // Load a form with no username and update test data. 1813 // Load a form with no username and update test data.
1814 LoadHTML(kVisibleFormWithNoUsernameHTML); 1814 LoadHTML(kVisibleFormWithNoUsernameHTML);
1815 username_element_.reset(); 1815 username_element_.reset();
1816 WebDocument document = GetMainFrame()->document(); 1816 WebDocument document = GetMainFrame()->document();
1817 WebElement element = 1817 WebElement element =
1818 document.getElementById(WebString::fromUTF8(kPasswordName)); 1818 document.getElementById(WebString::fromUTF8(kPasswordName));
(...skipping 10 matching lines...) Expand all
1829 // Simulate the browser sending back the login info for an initial page load. 1829 // Simulate the browser sending back the login info for an initial page load.
1830 SimulateOnFillPasswordForm(fill_data_); 1830 SimulateOnFillPasswordForm(fill_data_);
1831 1831
1832 // Show popup suggesstion when the password field is autofilled. 1832 // Show popup suggesstion when the password field is autofilled.
1833 password_element_.setValue("123"); 1833 password_element_.setValue("123");
1834 password_element_.setAutofilled(true); 1834 password_element_.setAutofilled(true);
1835 1835
1836 SimulateSuggestionChoiceOfUsernameAndPassword( 1836 SimulateSuggestionChoiceOfUsernameAndPassword(
1837 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); 1837 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword));
1838 CheckSuggestions(std::string(), false); 1838 CheckSuggestions(std::string(), false);
1839 EXPECT_EQ(ASCIIToUTF16(kAlicePassword), password_element_.value()); 1839 EXPECT_EQ(ASCIIToUTF16(kAlicePassword), password_element_.value().utf16());
1840 EXPECT_TRUE(password_element_.isAutofilled()); 1840 EXPECT_TRUE(password_element_.isAutofilled());
1841 } 1841 }
1842 1842
1843 TEST_F(PasswordAutofillAgentTest, NotShowPopupPasswordField) { 1843 TEST_F(PasswordAutofillAgentTest, NotShowPopupPasswordField) {
1844 // Load a form with no username and update test data. 1844 // Load a form with no username and update test data.
1845 LoadHTML(kVisibleFormWithNoUsernameHTML); 1845 LoadHTML(kVisibleFormWithNoUsernameHTML);
1846 username_element_.reset(); 1846 username_element_.reset();
1847 WebDocument document = GetMainFrame()->document(); 1847 WebDocument document = GetMainFrame()->document();
1848 WebElement element = 1848 WebElement element =
1849 document.getElementById(WebString::fromUTF8(kPasswordName)); 1849 document.getElementById(WebString::fromUTF8(kPasswordName));
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
2496 SimulateElementClick("confirmpassword"); 2496 SimulateElementClick("confirmpassword");
2497 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); 2497 EXPECT_FALSE(GetCalledShowPasswordSuggestions());
2498 2498
2499 // But when the user clicks on the autofilled password field again it should 2499 // But when the user clicks on the autofilled password field again it should
2500 // still produce a suggestion dropdown. 2500 // still produce a suggestion dropdown.
2501 SimulateElementClick("password"); 2501 SimulateElementClick("password");
2502 CheckSuggestions("", false); 2502 CheckSuggestions("", false);
2503 } 2503 }
2504 2504
2505 } // namespace autofill 2505 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698