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

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

Issue 373023004: Explicitly set selection ranges in PasswordAutofillAgentTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing changes as per comments Created 6 years, 5 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 | « no previous file | no next file » | 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 "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"
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 kCarolPassword, 1103 kCarolPassword,
1104 static_cast<std::string>(password_element_.suggestedValue().utf8())); 1104 static_cast<std::string>(password_element_.suggestedValue().utf8()));
1105 EXPECT_TRUE(password_element_.isAutofilled()); 1105 EXPECT_TRUE(password_element_.isAutofilled());
1106 username_length = strlen(kBobUsername); 1106 username_length = strlen(kBobUsername);
1107 CheckUsernameSelection(0, username_length); 1107 CheckUsernameSelection(0, username_length);
1108 } 1108 }
1109 1109
1110 // Tests that |PreviewSuggestion| properly sets the username selection range. 1110 // Tests that |PreviewSuggestion| properly sets the username selection range.
1111 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) { 1111 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) {
1112 username_element_.setValue(WebString::fromUTF8("ali")); 1112 username_element_.setValue(WebString::fromUTF8("ali"));
1113 username_element_.setSelectionRange(3, 3);
1113 username_element_.setAutofilled(true); 1114 username_element_.setAutofilled(true);
1114 1115
1115 CheckTextFieldsDOMState("ali", true, std::string(), false); 1116 CheckTextFieldsDOMState("ali", true, std::string(), false);
1116 1117
1117 // Simulate the browser sending the login info, but set |wait_for_username| 1118 // Simulate the browser sending the login info, but set |wait_for_username|
1118 // to prevent the form from being immediately filled. 1119 // to prevent the form from being immediately filled.
1119 fill_data_.wait_for_username = true; 1120 fill_data_.wait_for_username = true;
1120 SimulateOnFillPasswordForm(fill_data_); 1121 SimulateOnFillPasswordForm(fill_data_);
1121 1122
1122 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1123 EXPECT_TRUE(password_autofill_->PreviewSuggestion(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value()); 1159 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value());
1159 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1160 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1160 EXPECT_TRUE(password_element_.isAutofilled()); 1161 EXPECT_TRUE(password_element_.isAutofilled());
1161 CheckUsernameSelection(0, 0); 1162 CheckUsernameSelection(0, 0);
1162 } 1163 }
1163 1164
1164 // Tests that |ClearPreview| properly clears previewed username and password 1165 // Tests that |ClearPreview| properly clears previewed username and password
1165 // with username being previously autofilled. 1166 // with username being previously autofilled.
1166 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) { 1167 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) {
1167 username_element_.setValue(WebString::fromUTF8("ali")); 1168 username_element_.setValue(WebString::fromUTF8("ali"));
1169 username_element_.setSelectionRange(3, 3);
1168 username_element_.setAutofilled(true); 1170 username_element_.setAutofilled(true);
1169 1171
1170 // Simulate the browser sending the login info, but set |wait_for_username| 1172 // Simulate the browser sending the login info, but set |wait_for_username|
1171 // to prevent the form from being immediately filled. 1173 // to prevent the form from being immediately filled.
1172 fill_data_.wait_for_username = true; 1174 fill_data_.wait_for_username = true;
1173 SimulateOnFillPasswordForm(fill_data_); 1175 SimulateOnFillPasswordForm(fill_data_);
1174 1176
1175 CheckTextFieldsDOMState("ali", true, std::string(), false); 1177 CheckTextFieldsDOMState("ali", true, std::string(), false);
1176 1178
1177 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1179 EXPECT_TRUE(password_autofill_->PreviewSuggestion(
1178 username_element_, kAliceUsername, kAlicePassword)); 1180 username_element_, kAliceUsername, kAlicePassword));
1179 1181
1180 EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( 1182 EXPECT_TRUE(password_autofill_->DidClearAutofillSelection(
1181 username_element_)); 1183 username_element_));
1182 1184
1183 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value()); 1185 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value());
1184 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1186 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1185 EXPECT_TRUE(username_element_.isAutofilled()); 1187 EXPECT_TRUE(username_element_.isAutofilled());
1186 EXPECT_TRUE(password_element_.value().isEmpty()); 1188 EXPECT_TRUE(password_element_.value().isEmpty());
1187 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1189 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1188 EXPECT_FALSE(password_element_.isAutofilled()); 1190 EXPECT_FALSE(password_element_.isAutofilled());
1189 CheckUsernameSelection(3, 3); 1191 CheckUsernameSelection(3, 3);
1190 } 1192 }
1191 1193
1192 // Tests that |ClearPreview| properly clears previewed username and password 1194 // Tests that |ClearPreview| properly clears previewed username and password
1193 // with username and password being previously autofilled. 1195 // with username and password being previously autofilled.
1194 TEST_F(PasswordAutofillAgentTest, 1196 TEST_F(PasswordAutofillAgentTest,
1195 ClearPreviewWithAutofilledUsernameAndPassword) { 1197 ClearPreviewWithAutofilledUsernameAndPassword) {
1196 username_element_.setValue(WebString::fromUTF8("ali")); 1198 username_element_.setValue(WebString::fromUTF8("ali"));
1199 username_element_.setSelectionRange(3, 3);
1197 username_element_.setAutofilled(true); 1200 username_element_.setAutofilled(true);
1198 password_element_.setValue(WebString::fromUTF8("sec")); 1201 password_element_.setValue(WebString::fromUTF8("sec"));
1199 password_element_.setAutofilled(true); 1202 password_element_.setAutofilled(true);
1200 1203
1201 // Simulate the browser sending the login info, but set |wait_for_username| 1204 // Simulate the browser sending the login info, but set |wait_for_username|
1202 // to prevent the form from being immediately filled. 1205 // to prevent the form from being immediately filled.
1203 fill_data_.wait_for_username = true; 1206 fill_data_.wait_for_username = true;
1204 SimulateOnFillPasswordForm(fill_data_); 1207 SimulateOnFillPasswordForm(fill_data_);
1205 1208
1206 CheckTextFieldsDOMState("ali", true, "sec", true); 1209 CheckTextFieldsDOMState("ali", true, "sec", true);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 1334
1332 // Test that the agent sends an IPC call to get the current activity state of 1335 // Test that the agent sends an IPC call to get the current activity state of
1333 // password saving logging soon after construction. 1336 // password saving logging soon after construction.
1334 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) { 1337 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) {
1335 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( 1338 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
1336 AutofillHostMsg_PasswordAutofillAgentConstructed::ID); 1339 AutofillHostMsg_PasswordAutofillAgentConstructed::ID);
1337 EXPECT_TRUE(message); 1340 EXPECT_TRUE(message);
1338 } 1341 }
1339 1342
1340 } // namespace autofill 1343 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698