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

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

Issue 563313004: [Password Manager] Unfriend PasswordAutofillAgentTest from PasswordAutofillAgent (clean-up). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review comments. Created 6 years, 3 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 "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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 public: 170 public:
171 PasswordAutofillAgentTest() { 171 PasswordAutofillAgentTest() {
172 } 172 }
173 173
174 // Simulates the fill password form message being sent to the renderer. 174 // Simulates the fill password form message being sent to the renderer.
175 // We use that so we don't have to make RenderView::OnFillPasswordForm() 175 // We use that so we don't have to make RenderView::OnFillPasswordForm()
176 // protected. 176 // protected.
177 void SimulateOnFillPasswordForm( 177 void SimulateOnFillPasswordForm(
178 const PasswordFormFillData& fill_data) { 178 const PasswordFormFillData& fill_data) {
179 AutofillMsg_FillPasswordForm msg(0, fill_data); 179 AutofillMsg_FillPasswordForm msg(0, fill_data);
180 password_autofill_->OnMessageReceived(msg); 180 static_cast<content::RenderViewObserver*>(password_autofill_agent_)
181 ->OnMessageReceived(msg);
181 } 182 }
182 183
183 void SendVisiblePasswordForms() { 184 void SendVisiblePasswordForms() {
184 password_autofill_->SendPasswordForms(GetMainFrame(), 185 static_cast<content::RenderViewObserver*>(password_autofill_agent_)
185 true /* only_visible */); 186 ->DidFinishLoad(GetMainFrame());
186 } 187 }
187 188
188 virtual void SetUp() { 189 virtual void SetUp() {
189 ChromeRenderViewTest::SetUp(); 190 ChromeRenderViewTest::SetUp();
190 191
191 // Add a preferred login and an additional login to the FillData. 192 // Add a preferred login and an additional login to the FillData.
192 username1_ = ASCIIToUTF16(kAliceUsername); 193 username1_ = ASCIIToUTF16(kAliceUsername);
193 password1_ = ASCIIToUTF16(kAlicePassword); 194 password1_ = ASCIIToUTF16(kAlicePassword);
194 username2_ = ASCIIToUTF16(kBobUsername); 195 username2_ = ASCIIToUTF16(kBobUsername);
195 password2_ = ASCIIToUTF16(kBobPassword); 196 password2_ = ASCIIToUTF16(kBobPassword);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 256 }
256 257
257 void ClearUsernameAndPasswordFields() { 258 void ClearUsernameAndPasswordFields() {
258 username_element_.setValue(""); 259 username_element_.setValue("");
259 username_element_.setAutofilled(false); 260 username_element_.setAutofilled(false);
260 password_element_.setValue(""); 261 password_element_.setValue("");
261 password_element_.setAutofilled(false); 262 password_element_.setAutofilled(false);
262 } 263 }
263 264
264 void SimulateDidEndEditing(WebFrame* input_frame, WebInputElement& input) { 265 void SimulateDidEndEditing(WebFrame* input_frame, WebInputElement& input) {
265 autofill_agent_->textFieldDidEndEditing(input); 266 static_cast<blink::WebAutofillClient*>(autofill_agent_)
267 ->textFieldDidEndEditing(input);
266 } 268 }
267 269
268 void SimulateInputChangeForElement(const std::string& new_value, 270 void SimulateInputChangeForElement(const std::string& new_value,
269 bool move_caret_to_end, 271 bool move_caret_to_end,
270 WebFrame* input_frame, 272 WebFrame* input_frame,
271 WebInputElement& input, 273 WebInputElement& input,
272 bool is_user_input) { 274 bool is_user_input) {
273 input.setValue(WebString::fromUTF8(new_value), is_user_input); 275 input.setValue(WebString::fromUTF8(new_value), is_user_input);
274 // The field must have focus or AutofillAgent will think the 276 // The field must have focus or AutofillAgent will think the
275 // change should be ignored. 277 // change should be ignored.
276 while (!input.focused()) 278 while (!input.focused())
277 input_frame->document().frame()->view()->advanceFocus(false); 279 input_frame->document().frame()->view()->advanceFocus(false);
278 if (move_caret_to_end) 280 if (move_caret_to_end)
279 input.setSelectionRange(new_value.length(), new_value.length()); 281 input.setSelectionRange(new_value.length(), new_value.length());
280 if (is_user_input) 282 if (is_user_input)
281 password_autofill_agent()->FirstUserGestureObserved(); 283 password_autofill_agent_->FirstUserGestureObserved();
282 autofill_agent_->textFieldDidChange(input); 284 static_cast<blink::WebAutofillClient*>(autofill_agent_)
285 ->textFieldDidChange(input);
283 // Processing is delayed because of a Blink bug: 286 // Processing is delayed because of a Blink bug:
284 // https://bugs.webkit.org/show_bug.cgi?id=16976 287 // https://bugs.webkit.org/show_bug.cgi?id=16976
285 // See PasswordAutofillAgent::TextDidChangeInTextField() for details. 288 // See PasswordAutofillAgent::TextDidChangeInTextField() for details.
286 289
287 // Autocomplete will trigger a style recalculation when we put up the next 290 // Autocomplete will trigger a style recalculation when we put up the next
288 // frame, but we don't want to wait that long. Instead, trigger a style 291 // frame, but we don't want to wait that long. Instead, trigger a style
289 // recalcuation manually after TextFieldDidChangeImpl runs. 292 // recalcuation manually after TextFieldDidChangeImpl runs.
290 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 293 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
291 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this))); 294 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this)));
292 295
293 base::MessageLoop::current()->RunUntilIdle(); 296 base::MessageLoop::current()->RunUntilIdle();
294 } 297 }
295 298
296 void SimulateSuggestionChoice(WebInputElement& username_input) { 299 void SimulateSuggestionChoice(WebInputElement& username_input) {
297 blink::WebString blink_username = 300 base::string16 username(base::ASCIIToUTF16(kAliceUsername));
298 blink::WebString::fromUTF8(kAliceUsername); 301 base::string16 password(base::ASCIIToUTF16(kAlicePassword));
299 blink::WebString blink_password =
300 blink::WebString::fromUTF8(kAlicePassword);
301 302
302 // This call is necessary to setup the autofill agent appropriate for the 303 // This call is necessary to setup the autofill agent appropriate for the
303 // user selection; simulates the menu actually popping up. 304 // user selection; simulates the menu actually popping up.
304 render_thread_->sink().ClearMessages(); 305 render_thread_->sink().ClearMessages();
305 autofill_agent_->FormControlElementClicked(username_input, false); 306 static_cast<autofill::PageClickListener*>(autofill_agent_)
307 ->FormControlElementClicked(username_input, false);
306 308
307 autofill_agent_->OnFillPasswordSuggestion(blink_username, blink_password); 309 AutofillMsg_FillPasswordSuggestion msg(0, username, password);
310 static_cast<content::RenderViewObserver*>(autofill_agent_)
311 ->OnMessageReceived(msg);
308 } 312 }
309 313
310 void LayoutMainFrame() { 314 void LayoutMainFrame() {
311 GetMainFrame()->view()->layout(); 315 GetMainFrame()->view()->layout();
312 } 316 }
313 317
314 void SimulateUsernameChange(const std::string& username, 318 void SimulateUsernameChange(const std::string& username,
315 bool move_caret_to_end, 319 bool move_caret_to_end,
316 bool is_user_input = false) { 320 bool is_user_input = false) {
317 SimulateInputChangeForElement(username, 321 SimulateInputChangeForElement(username,
(...skipping 20 matching lines...) Expand all
338 // sent to the browser on acceptance, and the DCHECK isn't hit (and nothing 342 // sent to the browser on acceptance, and the DCHECK isn't hit (and nothing
339 // is filled). 343 // is filled).
340 // 344 //
341 // These tests only make sense in the context of not ignoring 345 // These tests only make sense in the context of not ignoring
342 // autocomplete='off', so only test them if the disable autocomplete='off' 346 // autocomplete='off', so only test them if the disable autocomplete='off'
343 // flag is not enabled. 347 // flag is not enabled.
344 // TODO(jww): Remove this function and callers once autocomplete='off' is 348 // TODO(jww): Remove this function and callers once autocomplete='off' is
345 // permanently ignored. 349 // permanently ignored.
346 if (!ShouldIgnoreAutocompleteOffForPasswordFields()) { 350 if (!ShouldIgnoreAutocompleteOffForPasswordFields()) {
347 EXPECT_TRUE( 351 EXPECT_TRUE(
348 password_autofill_agent()->ShowSuggestions(username_element_, false)); 352 password_autofill_agent_->ShowSuggestions(username_element_, false));
349 353
350 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 354 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
351 AutofillHostMsg_ShowPasswordSuggestions::ID)); 355 AutofillHostMsg_ShowPasswordSuggestions::ID));
352 } 356 }
353 } 357 }
354 358
355 void SimulateKeyDownEvent(const WebInputElement& element, 359 void SimulateKeyDownEvent(const WebInputElement& element,
356 ui::KeyboardCode key_code) { 360 ui::KeyboardCode key_code) {
357 blink::WebKeyboardEvent key_event; 361 blink::WebKeyboardEvent key_event;
358 key_event.windowsKeyCode = key_code; 362 key_event.windowsKeyCode = key_code;
359 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); 363 static_cast<blink::WebAutofillClient*>(autofill_agent_)
364 ->textFieldDidReceiveKeyDown(element, key_event);
360 } 365 }
361 366
362 void CheckTextFieldsStateForElements(const WebInputElement& username_element, 367 void CheckTextFieldsStateForElements(const WebInputElement& username_element,
363 const std::string& username, 368 const std::string& username,
364 bool username_autofilled, 369 bool username_autofilled,
365 const WebInputElement& password_element, 370 const WebInputElement& password_element,
366 const std::string& password, 371 const std::string& password,
367 bool password_autofilled, 372 bool password_autofilled,
368 bool checkSuggestedValue) { 373 bool checkSuggestedValue) {
369 EXPECT_EQ(username, 374 EXPECT_EQ(username,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 EXPECT_TRUE(it != usernames.end()); 455 EXPECT_TRUE(it != usernames.end());
451 if (it != usernames.end()) 456 if (it != usernames.end())
452 usernames.erase(it); 457 usernames.erase(it);
453 } 458 }
454 459
455 EXPECT_TRUE(usernames.empty()); 460 EXPECT_TRUE(usernames.empty());
456 461
457 render_thread_->sink().ClearMessages(); 462 render_thread_->sink().ClearMessages();
458 } 463 }
459 464
460 PasswordAutofillAgent* password_autofill_agent() {
461 return autofill_agent_->password_autofill_agent_;
462 }
463
464 void ExpectFormSubmittedWithPasswords(const std::string& password_value, 465 void ExpectFormSubmittedWithPasswords(const std::string& password_value,
465 const std::string& new_password_value) { 466 const std::string& new_password_value) {
466 const IPC::Message* message = 467 const IPC::Message* message =
467 render_thread_->sink().GetFirstMessageMatching( 468 render_thread_->sink().GetFirstMessageMatching(
468 AutofillHostMsg_PasswordFormSubmitted::ID); 469 AutofillHostMsg_PasswordFormSubmitted::ID);
469 ASSERT_TRUE(message); 470 ASSERT_TRUE(message);
470 Tuple1<autofill::PasswordForm> args; 471 Tuple1<autofill::PasswordForm> args;
471 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); 472 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args);
472 EXPECT_EQ(ASCIIToUTF16(password_value), args.a.password_value); 473 EXPECT_EQ(ASCIIToUTF16(password_value), args.a.password_value);
473 EXPECT_EQ(ASCIIToUTF16(new_password_value), args.a.new_password_value); 474 EXPECT_EQ(ASCIIToUTF16(new_password_value), args.a.new_password_value);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 SimulateUsernameChange("a", true); 719 SimulateUsernameChange("a", true);
719 CheckTextFieldsState("a", false, std::string(), false); 720 CheckTextFieldsState("a", false, std::string(), false);
720 SimulateUsernameChange("al", true); 721 SimulateUsernameChange("al", true);
721 CheckTextFieldsState("al", false, std::string(), false); 722 CheckTextFieldsState("al", false, std::string(), false);
722 SimulateUsernameChange(kAliceUsername, true); 723 SimulateUsernameChange(kAliceUsername, true);
723 CheckTextFieldsState(kAliceUsername, false, std::string(), false); 724 CheckTextFieldsState(kAliceUsername, false, std::string(), false);
724 725
725 // Autocomplete should happen only when the username textfield is blurred with 726 // Autocomplete should happen only when the username textfield is blurred with
726 // a full match. 727 // a full match.
727 username_element_.setValue("a"); 728 username_element_.setValue("a");
728 autofill_agent_->textFieldDidEndEditing(username_element_); 729 static_cast<blink::WebAutofillClient*>(autofill_agent_)
730 ->textFieldDidEndEditing(username_element_);
729 CheckTextFieldsState("a", false, std::string(), false); 731 CheckTextFieldsState("a", false, std::string(), false);
730 username_element_.setValue("al"); 732 username_element_.setValue("al");
731 autofill_agent_->textFieldDidEndEditing(username_element_); 733 static_cast<blink::WebAutofillClient*>(autofill_agent_)
734 ->textFieldDidEndEditing(username_element_);
732 CheckTextFieldsState("al", false, std::string(), false); 735 CheckTextFieldsState("al", false, std::string(), false);
733 username_element_.setValue("alices"); 736 username_element_.setValue("alices");
734 autofill_agent_->textFieldDidEndEditing(username_element_); 737 static_cast<blink::WebAutofillClient*>(autofill_agent_)
738 ->textFieldDidEndEditing(username_element_);
735 CheckTextFieldsState("alices", false, std::string(), false); 739 CheckTextFieldsState("alices", false, std::string(), false);
736 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); 740 username_element_.setValue(ASCIIToUTF16(kAliceUsername));
737 autofill_agent_->textFieldDidEndEditing(username_element_); 741 static_cast<blink::WebAutofillClient*>(autofill_agent_)
742 ->textFieldDidEndEditing(username_element_);
738 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 743 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
739 } 744 }
740 745
741 // Tests that inline autocompletion works properly. 746 // Tests that inline autocompletion works properly.
742 TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) { 747 TEST_F(PasswordAutofillAgentTest, InlineAutocomplete) {
743 // Simulate the browser sending back the login info. 748 // Simulate the browser sending back the login info.
744 SimulateOnFillPasswordForm(fill_data_); 749 SimulateOnFillPasswordForm(fill_data_);
745 750
746 ClearUsernameAndPasswordFields(); 751 ClearUsernameAndPasswordFields();
747 752
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 1003
999 // Regression test for http://crbug.com/326679 1004 // Regression test for http://crbug.com/326679
1000 TEST_F(PasswordAutofillAgentTest, SelectUsernameWithPasswordAutofillOff) { 1005 TEST_F(PasswordAutofillAgentTest, SelectUsernameWithPasswordAutofillOff) {
1001 // Simulate the browser sending back the login info. 1006 // Simulate the browser sending back the login info.
1002 SimulateOnFillPasswordForm(fill_data_); 1007 SimulateOnFillPasswordForm(fill_data_);
1003 1008
1004 // Set the main password element to autocomplete='off' 1009 // Set the main password element to autocomplete='off'
1005 password_element_.setAttribute(WebString::fromUTF8("autocomplete"), 1010 password_element_.setAttribute(WebString::fromUTF8("autocomplete"),
1006 WebString::fromUTF8("off")); 1011 WebString::fromUTF8("off"));
1007 1012
1008 // Simulate the user changing the username to some known username. 1013 // Simulate the user changing the username to some known username.
1009 SimulateUsernameChange(kAliceUsername, true); 1014 SimulateUsernameChange(kAliceUsername, true);
1010 1015
1011 ExpectNoSuggestionsPopup(); 1016 ExpectNoSuggestionsPopup();
1012 } 1017 }
1013 1018
1014 // Regression test for http://crbug.com/326679 1019 // Regression test for http://crbug.com/326679
1015 TEST_F(PasswordAutofillAgentTest, 1020 TEST_F(PasswordAutofillAgentTest,
1016 SelectUnknownUsernameWithPasswordAutofillOff) { 1021 SelectUnknownUsernameWithPasswordAutofillOff) {
1017 // Simulate the browser sending back the login info. 1022 // Simulate the browser sending back the login info.
1018 SimulateOnFillPasswordForm(fill_data_); 1023 SimulateOnFillPasswordForm(fill_data_);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 // Simulate the browser sending the login info, but set |wait_for_username| 1130 // Simulate the browser sending the login info, but set |wait_for_username|
1126 // to prevent the form from being immediately filled. 1131 // to prevent the form from being immediately filled.
1127 fill_data_.wait_for_username = true; 1132 fill_data_.wait_for_username = true;
1128 SimulateOnFillPasswordForm(fill_data_); 1133 SimulateOnFillPasswordForm(fill_data_);
1129 1134
1130 // Neither field should have been autocompleted. 1135 // Neither field should have been autocompleted.
1131 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 1136 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1132 1137
1133 // If the password field is not autocompletable, it should not be affected. 1138 // If the password field is not autocompletable, it should not be affected.
1134 SetElementReadOnly(password_element_, true); 1139 SetElementReadOnly(password_element_, true);
1135 EXPECT_FALSE(password_autofill_->FillSuggestion( 1140 EXPECT_FALSE(password_autofill_agent_->FillSuggestion(
1136 username_element_, kAliceUsername, kAlicePassword)); 1141 username_element_, kAliceUsername, kAlicePassword));
1137 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 1142 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1138 SetElementReadOnly(password_element_, false); 1143 SetElementReadOnly(password_element_, false);
1139 1144
1140 // After filling with the suggestion, both fields should be autocompleted. 1145 // After filling with the suggestion, both fields should be autocompleted.
1141 EXPECT_TRUE(password_autofill_->FillSuggestion( 1146 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
1142 username_element_, kAliceUsername, kAlicePassword)); 1147 username_element_, kAliceUsername, kAlicePassword));
1143 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1148 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1144 int username_length = strlen(kAliceUsername); 1149 int username_length = strlen(kAliceUsername);
1145 CheckUsernameSelection(username_length, username_length); 1150 CheckUsernameSelection(username_length, username_length);
1146 1151
1147 // Try Filling with a suggestion with password different from the one that was 1152 // Try Filling with a suggestion with password different from the one that was
1148 // initially sent to the renderer. 1153 // initially sent to the renderer.
1149 EXPECT_TRUE(password_autofill_->FillSuggestion( 1154 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
1150 username_element_, kBobUsername, kCarolPassword)); 1155 username_element_, kBobUsername, kCarolPassword));
1151 CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true); 1156 CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true);
1152 username_length = strlen(kBobUsername); 1157 username_length = strlen(kBobUsername);
1153 CheckUsernameSelection(username_length, username_length); 1158 CheckUsernameSelection(username_length, username_length);
1154 } 1159 }
1155 1160
1156 // Tests that |PreviewSuggestion| properly previews the username and password. 1161 // Tests that |PreviewSuggestion| properly previews the username and password.
1157 TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) { 1162 TEST_F(PasswordAutofillAgentTest, PreviewSuggestion) {
1158 // Simulate the browser sending the login info, but set |wait_for_username| 1163 // Simulate the browser sending the login info, but set |wait_for_username|
1159 // to prevent the form from being immediately filled. 1164 // to prevent the form from being immediately filled.
1160 fill_data_.wait_for_username = true; 1165 fill_data_.wait_for_username = true;
1161 SimulateOnFillPasswordForm(fill_data_); 1166 SimulateOnFillPasswordForm(fill_data_);
1162 1167
1163 // Neither field should have been autocompleted. 1168 // Neither field should have been autocompleted.
1164 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 1169 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1165 1170
1166 // If the password field is not autocompletable, it should not be affected. 1171 // If the password field is not autocompletable, it should not be affected.
1167 SetElementReadOnly(password_element_, true); 1172 SetElementReadOnly(password_element_, true);
1168 EXPECT_FALSE(password_autofill_->PreviewSuggestion( 1173 EXPECT_FALSE(password_autofill_agent_->PreviewSuggestion(
1169 username_element_, kAliceUsername, kAlicePassword)); 1174 username_element_, kAliceUsername, kAlicePassword));
1170 EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8()); 1175 EXPECT_EQ(std::string(), username_element_.suggestedValue().utf8());
1171 EXPECT_FALSE(username_element_.isAutofilled()); 1176 EXPECT_FALSE(username_element_.isAutofilled());
1172 EXPECT_EQ(std::string(), password_element_.suggestedValue().utf8()); 1177 EXPECT_EQ(std::string(), password_element_.suggestedValue().utf8());
1173 EXPECT_FALSE(password_element_.isAutofilled()); 1178 EXPECT_FALSE(password_element_.isAutofilled());
1174 SetElementReadOnly(password_element_, false); 1179 SetElementReadOnly(password_element_, false);
1175 1180
1176 // After selecting the suggestion, both fields should be previewed 1181 // After selecting the suggestion, both fields should be previewed
1177 // with suggested values. 1182 // with suggested values.
1178 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1183 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1179 username_element_, kAliceUsername, kAlicePassword)); 1184 username_element_, kAliceUsername, kAlicePassword));
1180 EXPECT_EQ( 1185 EXPECT_EQ(
1181 kAliceUsername, 1186 kAliceUsername,
1182 static_cast<std::string>(username_element_.suggestedValue().utf8())); 1187 static_cast<std::string>(username_element_.suggestedValue().utf8()));
1183 EXPECT_TRUE(username_element_.isAutofilled()); 1188 EXPECT_TRUE(username_element_.isAutofilled());
1184 EXPECT_EQ( 1189 EXPECT_EQ(
1185 kAlicePassword, 1190 kAlicePassword,
1186 static_cast<std::string>(password_element_.suggestedValue().utf8())); 1191 static_cast<std::string>(password_element_.suggestedValue().utf8()));
1187 EXPECT_TRUE(password_element_.isAutofilled()); 1192 EXPECT_TRUE(password_element_.isAutofilled());
1188 int username_length = strlen(kAliceUsername); 1193 int username_length = strlen(kAliceUsername);
1189 CheckUsernameSelection(0, username_length); 1194 CheckUsernameSelection(0, username_length);
1190 1195
1191 // Try previewing with a password different from the one that was initially 1196 // Try previewing with a password different from the one that was initially
1192 // sent to the renderer. 1197 // sent to the renderer.
1193 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1198 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1194 username_element_, kBobUsername, kCarolPassword)); 1199 username_element_, kBobUsername, kCarolPassword));
1195 EXPECT_EQ( 1200 EXPECT_EQ(
1196 kBobUsername, 1201 kBobUsername,
1197 static_cast<std::string>(username_element_.suggestedValue().utf8())); 1202 static_cast<std::string>(username_element_.suggestedValue().utf8()));
1198 EXPECT_TRUE(username_element_.isAutofilled()); 1203 EXPECT_TRUE(username_element_.isAutofilled());
1199 EXPECT_EQ( 1204 EXPECT_EQ(
1200 kCarolPassword, 1205 kCarolPassword,
1201 static_cast<std::string>(password_element_.suggestedValue().utf8())); 1206 static_cast<std::string>(password_element_.suggestedValue().utf8()));
1202 EXPECT_TRUE(password_element_.isAutofilled()); 1207 EXPECT_TRUE(password_element_.isAutofilled());
1203 username_length = strlen(kBobUsername); 1208 username_length = strlen(kBobUsername);
1204 CheckUsernameSelection(0, username_length); 1209 CheckUsernameSelection(0, username_length);
1205 } 1210 }
1206 1211
1207 // Tests that |PreviewSuggestion| properly sets the username selection range. 1212 // Tests that |PreviewSuggestion| properly sets the username selection range.
1208 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) { 1213 TEST_F(PasswordAutofillAgentTest, PreviewSuggestionSelectionRange) {
1209 username_element_.setValue(WebString::fromUTF8("ali")); 1214 username_element_.setValue(WebString::fromUTF8("ali"));
1210 username_element_.setSelectionRange(3, 3); 1215 username_element_.setSelectionRange(3, 3);
1211 username_element_.setAutofilled(true); 1216 username_element_.setAutofilled(true);
1212 1217
1213 CheckTextFieldsDOMState("ali", true, std::string(), false); 1218 CheckTextFieldsDOMState("ali", true, std::string(), false);
1214 1219
1215 // Simulate the browser sending the login info, but set |wait_for_username| 1220 // Simulate the browser sending the login info, but set |wait_for_username|
1216 // to prevent the form from being immediately filled. 1221 // to prevent the form from being immediately filled.
1217 fill_data_.wait_for_username = true; 1222 fill_data_.wait_for_username = true;
1218 SimulateOnFillPasswordForm(fill_data_); 1223 SimulateOnFillPasswordForm(fill_data_);
1219 1224
1220 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1225 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1221 username_element_, kAliceUsername, kAlicePassword)); 1226 username_element_, kAliceUsername, kAlicePassword));
1222 EXPECT_EQ( 1227 EXPECT_EQ(
1223 kAliceUsername, 1228 kAliceUsername,
1224 static_cast<std::string>(username_element_.suggestedValue().utf8())); 1229 static_cast<std::string>(username_element_.suggestedValue().utf8()));
1225 EXPECT_TRUE(username_element_.isAutofilled()); 1230 EXPECT_TRUE(username_element_.isAutofilled());
1226 EXPECT_EQ( 1231 EXPECT_EQ(
1227 kAlicePassword, 1232 kAlicePassword,
1228 static_cast<std::string>(password_element_.suggestedValue().utf8())); 1233 static_cast<std::string>(password_element_.suggestedValue().utf8()));
1229 EXPECT_TRUE(password_element_.isAutofilled()); 1234 EXPECT_TRUE(password_element_.isAutofilled());
1230 int username_length = strlen(kAliceUsername); 1235 int username_length = strlen(kAliceUsername);
1231 CheckUsernameSelection(3, username_length); 1236 CheckUsernameSelection(3, username_length);
1232 } 1237 }
1233 1238
1234 // Tests that |ClearPreview| properly clears previewed username and password 1239 // Tests that |ClearPreview| properly clears previewed username and password
1235 // with password being previously autofilled. 1240 // with password being previously autofilled.
1236 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithPasswordAutofilled) { 1241 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithPasswordAutofilled) {
1237 password_element_.setValue(WebString::fromUTF8("sec")); 1242 password_element_.setValue(WebString::fromUTF8("sec"));
1238 password_element_.setAutofilled(true); 1243 password_element_.setAutofilled(true);
1239 1244
1240 // Simulate the browser sending the login info, but set |wait_for_username| 1245 // Simulate the browser sending the login info, but set |wait_for_username|
1241 // to prevent the form from being immediately filled. 1246 // to prevent the form from being immediately filled.
1242 fill_data_.wait_for_username = true; 1247 fill_data_.wait_for_username = true;
1243 SimulateOnFillPasswordForm(fill_data_); 1248 SimulateOnFillPasswordForm(fill_data_);
1244 1249
1245 CheckTextFieldsDOMState(std::string(), false, "sec", true); 1250 CheckTextFieldsDOMState(std::string(), false, "sec", true);
1246 1251
1247 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1252 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1248 username_element_, kAliceUsername, kAlicePassword)); 1253 username_element_, kAliceUsername, kAlicePassword));
1249 1254
1250 EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( 1255 EXPECT_TRUE(
1251 username_element_)); 1256 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1252 1257
1253 EXPECT_TRUE(username_element_.value().isEmpty()); 1258 EXPECT_TRUE(username_element_.value().isEmpty());
1254 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1259 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1255 EXPECT_FALSE(username_element_.isAutofilled()); 1260 EXPECT_FALSE(username_element_.isAutofilled());
1256 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value()); 1261 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value());
1257 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1262 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1258 EXPECT_TRUE(password_element_.isAutofilled()); 1263 EXPECT_TRUE(password_element_.isAutofilled());
1259 CheckUsernameSelection(0, 0); 1264 CheckUsernameSelection(0, 0);
1260 } 1265 }
1261 1266
1262 // Tests that |ClearPreview| properly clears previewed username and password 1267 // Tests that |ClearPreview| properly clears previewed username and password
1263 // with username being previously autofilled. 1268 // with username being previously autofilled.
1264 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) { 1269 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithUsernameAutofilled) {
1265 username_element_.setValue(WebString::fromUTF8("ali")); 1270 username_element_.setValue(WebString::fromUTF8("ali"));
1266 username_element_.setSelectionRange(3, 3); 1271 username_element_.setSelectionRange(3, 3);
1267 username_element_.setAutofilled(true); 1272 username_element_.setAutofilled(true);
1268 1273
1269 // Simulate the browser sending the login info, but set |wait_for_username| 1274 // Simulate the browser sending the login info, but set |wait_for_username|
1270 // to prevent the form from being immediately filled. 1275 // to prevent the form from being immediately filled.
1271 fill_data_.wait_for_username = true; 1276 fill_data_.wait_for_username = true;
1272 SimulateOnFillPasswordForm(fill_data_); 1277 SimulateOnFillPasswordForm(fill_data_);
1273 1278
1274 CheckTextFieldsDOMState("ali", true, std::string(), false); 1279 CheckTextFieldsDOMState("ali", true, std::string(), false);
1275 1280
1276 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1281 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1277 username_element_, kAliceUsername, kAlicePassword)); 1282 username_element_, kAliceUsername, kAlicePassword));
1278 1283
1279 EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( 1284 EXPECT_TRUE(
1280 username_element_)); 1285 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1281 1286
1282 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value()); 1287 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value());
1283 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1288 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1284 EXPECT_TRUE(username_element_.isAutofilled()); 1289 EXPECT_TRUE(username_element_.isAutofilled());
1285 EXPECT_TRUE(password_element_.value().isEmpty()); 1290 EXPECT_TRUE(password_element_.value().isEmpty());
1286 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1291 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1287 EXPECT_FALSE(password_element_.isAutofilled()); 1292 EXPECT_FALSE(password_element_.isAutofilled());
1288 CheckUsernameSelection(3, 3); 1293 CheckUsernameSelection(3, 3);
1289 } 1294 }
1290 1295
1291 // Tests that |ClearPreview| properly clears previewed username and password 1296 // Tests that |ClearPreview| properly clears previewed username and password
1292 // with username and password being previously autofilled. 1297 // with username and password being previously autofilled.
1293 TEST_F(PasswordAutofillAgentTest, 1298 TEST_F(PasswordAutofillAgentTest,
1294 ClearPreviewWithAutofilledUsernameAndPassword) { 1299 ClearPreviewWithAutofilledUsernameAndPassword) {
1295 username_element_.setValue(WebString::fromUTF8("ali")); 1300 username_element_.setValue(WebString::fromUTF8("ali"));
1296 username_element_.setSelectionRange(3, 3); 1301 username_element_.setSelectionRange(3, 3);
1297 username_element_.setAutofilled(true); 1302 username_element_.setAutofilled(true);
1298 password_element_.setValue(WebString::fromUTF8("sec")); 1303 password_element_.setValue(WebString::fromUTF8("sec"));
1299 password_element_.setAutofilled(true); 1304 password_element_.setAutofilled(true);
1300 1305
1301 // Simulate the browser sending the login info, but set |wait_for_username| 1306 // Simulate the browser sending the login info, but set |wait_for_username|
1302 // to prevent the form from being immediately filled. 1307 // to prevent the form from being immediately filled.
1303 fill_data_.wait_for_username = true; 1308 fill_data_.wait_for_username = true;
1304 SimulateOnFillPasswordForm(fill_data_); 1309 SimulateOnFillPasswordForm(fill_data_);
1305 1310
1306 CheckTextFieldsDOMState("ali", true, "sec", true); 1311 CheckTextFieldsDOMState("ali", true, "sec", true);
1307 1312
1308 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1313 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1309 username_element_, kAliceUsername, kAlicePassword)); 1314 username_element_, kAliceUsername, kAlicePassword));
1310 1315
1311 EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( 1316 EXPECT_TRUE(
1312 username_element_)); 1317 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1313 1318
1314 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value()); 1319 EXPECT_EQ(ASCIIToUTF16("ali"), username_element_.value());
1315 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1320 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1316 EXPECT_TRUE(username_element_.isAutofilled()); 1321 EXPECT_TRUE(username_element_.isAutofilled());
1317 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value()); 1322 EXPECT_EQ(ASCIIToUTF16("sec"), password_element_.value());
1318 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1323 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1319 EXPECT_TRUE(password_element_.isAutofilled()); 1324 EXPECT_TRUE(password_element_.isAutofilled());
1320 CheckUsernameSelection(3, 3); 1325 CheckUsernameSelection(3, 3);
1321 } 1326 }
1322 1327
1323 // Tests that |ClearPreview| properly clears previewed username and password 1328 // Tests that |ClearPreview| properly clears previewed username and password
1324 // with neither username nor password being previously autofilled. 1329 // with neither username nor password being previously autofilled.
1325 TEST_F(PasswordAutofillAgentTest, 1330 TEST_F(PasswordAutofillAgentTest,
1326 ClearPreviewWithNotAutofilledUsernameAndPassword) { 1331 ClearPreviewWithNotAutofilledUsernameAndPassword) {
1327 // Simulate the browser sending the login info, but set |wait_for_username| 1332 // Simulate the browser sending the login info, but set |wait_for_username|
1328 // to prevent the form from being immediately filled. 1333 // to prevent the form from being immediately filled.
1329 fill_data_.wait_for_username = true; 1334 fill_data_.wait_for_username = true;
1330 SimulateOnFillPasswordForm(fill_data_); 1335 SimulateOnFillPasswordForm(fill_data_);
1331 1336
1332 CheckTextFieldsDOMState(std::string(), false, std::string(), false); 1337 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1333 1338
1334 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1339 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1335 username_element_, kAliceUsername, kAlicePassword)); 1340 username_element_, kAliceUsername, kAlicePassword));
1336 1341
1337 EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( 1342 EXPECT_TRUE(
1338 username_element_)); 1343 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1339 1344
1340 EXPECT_TRUE(username_element_.value().isEmpty()); 1345 EXPECT_TRUE(username_element_.value().isEmpty());
1341 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1346 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1342 EXPECT_FALSE(username_element_.isAutofilled()); 1347 EXPECT_FALSE(username_element_.isAutofilled());
1343 EXPECT_TRUE(password_element_.value().isEmpty()); 1348 EXPECT_TRUE(password_element_.value().isEmpty());
1344 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1349 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1345 EXPECT_FALSE(password_element_.isAutofilled()); 1350 EXPECT_FALSE(password_element_.isAutofilled());
1346 CheckUsernameSelection(0, 0); 1351 CheckUsernameSelection(0, 0);
1347 } 1352 }
1348 1353
1349 // Tests that |ClearPreview| properly restores the original selection range of 1354 // Tests that |ClearPreview| properly restores the original selection range of
1350 // username field that has initially been filled by inline autocomplete. 1355 // username field that has initially been filled by inline autocomplete.
1351 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) { 1356 TEST_F(PasswordAutofillAgentTest, ClearPreviewWithInlineAutocompletedUsername) {
1352 // Simulate the browser sending back the login info. 1357 // Simulate the browser sending back the login info.
1353 SimulateOnFillPasswordForm(fill_data_); 1358 SimulateOnFillPasswordForm(fill_data_);
1354 1359
1355 // Clear the text fields to start fresh. 1360 // Clear the text fields to start fresh.
1356 ClearUsernameAndPasswordFields(); 1361 ClearUsernameAndPasswordFields();
1357 1362
1358 // Simulate the user typing in the first letter of 'alice', a stored username. 1363 // Simulate the user typing in the first letter of 'alice', a stored username.
1359 SimulateUsernameChange("a", true); 1364 SimulateUsernameChange("a", true);
1360 // Both the username and password text fields should reflect selection of the 1365 // Both the username and password text fields should reflect selection of the
1361 // stored login. 1366 // stored login.
1362 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 1367 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
1363 // The selection should have been set to 'lice', the last 4 letters. 1368 // The selection should have been set to 'lice', the last 4 letters.
1364 CheckUsernameSelection(1, 5); 1369 CheckUsernameSelection(1, 5);
1365 1370
1366 EXPECT_TRUE(password_autofill_->PreviewSuggestion( 1371 EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
1367 username_element_, "alicia", "secret")); 1372 username_element_, "alicia", "secret"));
1368 EXPECT_EQ( 1373 EXPECT_EQ(
1369 "alicia", 1374 "alicia",
1370 static_cast<std::string>(username_element_.suggestedValue().utf8())); 1375 static_cast<std::string>(username_element_.suggestedValue().utf8()));
1371 EXPECT_TRUE(username_element_.isAutofilled()); 1376 EXPECT_TRUE(username_element_.isAutofilled());
1372 EXPECT_EQ( 1377 EXPECT_EQ(
1373 "secret", 1378 "secret",
1374 static_cast<std::string>(password_element_.suggestedValue().utf8())); 1379 static_cast<std::string>(password_element_.suggestedValue().utf8()));
1375 EXPECT_TRUE(password_element_.isAutofilled()); 1380 EXPECT_TRUE(password_element_.isAutofilled());
1376 CheckUsernameSelection(1, 6); 1381 CheckUsernameSelection(1, 6);
1377 1382
1378 EXPECT_TRUE(password_autofill_->DidClearAutofillSelection( 1383 EXPECT_TRUE(
1379 username_element_)); 1384 password_autofill_agent_->DidClearAutofillSelection(username_element_));
1380 1385
1381 EXPECT_EQ(kAliceUsername, username_element_.value().utf8()); 1386 EXPECT_EQ(kAliceUsername, username_element_.value().utf8());
1382 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); 1387 EXPECT_TRUE(username_element_.suggestedValue().isEmpty());
1383 EXPECT_TRUE(username_element_.isAutofilled()); 1388 EXPECT_TRUE(username_element_.isAutofilled());
1384 EXPECT_TRUE(password_element_.value().isEmpty()); 1389 EXPECT_TRUE(password_element_.value().isEmpty());
1385 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); 1390 EXPECT_TRUE(password_element_.suggestedValue().isEmpty());
1386 EXPECT_TRUE(password_element_.isAutofilled()); 1391 EXPECT_TRUE(password_element_.isAutofilled());
1387 CheckUsernameSelection(1, 5); 1392 CheckUsernameSelection(1, 5);
1388 } 1393 }
1389 1394
1390 // Tests that logging is off by default. 1395 // Tests that logging is off by default.
1391 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { 1396 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) {
1392 render_thread_->sink().ClearMessages(); 1397 render_thread_->sink().ClearMessages();
1393 SendVisiblePasswordForms(); 1398 SendVisiblePasswordForms();
1394 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( 1399 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
1395 AutofillHostMsg_RecordSavePasswordProgress::ID); 1400 AutofillHostMsg_RecordSavePasswordProgress::ID);
1396 EXPECT_FALSE(message); 1401 EXPECT_FALSE(message);
1397 } 1402 }
1398 1403
1399 // Test that logging can be turned on by a message. 1404 // Test that logging can be turned on by a message.
1400 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { 1405 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) {
1401 // Turn the logging on. 1406 // Turn the logging on.
1402 AutofillMsg_SetLoggingState msg_activate(0, true); 1407 AutofillMsg_SetLoggingState msg_activate(0, true);
1403 // Up-cast to access OnMessageReceived, which is private in the agent. 1408 // Up-cast to access OnMessageReceived, which is private in the agent.
1404 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_) 1409 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_)
1405 ->OnMessageReceived(msg_activate)); 1410 ->OnMessageReceived(msg_activate));
1406 1411
1407 render_thread_->sink().ClearMessages(); 1412 render_thread_->sink().ClearMessages();
1408 SendVisiblePasswordForms(); 1413 SendVisiblePasswordForms();
1409 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( 1414 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
1410 AutofillHostMsg_RecordSavePasswordProgress::ID); 1415 AutofillHostMsg_RecordSavePasswordProgress::ID);
1411 EXPECT_TRUE(message); 1416 EXPECT_TRUE(message);
1412 } 1417 }
1413 1418
1414 // Test that logging can be turned off by a message. 1419 // Test that logging can be turned off by a message.
1415 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { 1420 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) {
1416 // Turn the logging on and then off. 1421 // Turn the logging on and then off.
1417 AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true); 1422 AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true);
1418 // Up-cast to access OnMessageReceived, which is private in the agent. 1423 // Up-cast to access OnMessageReceived, which is private in the agent.
1419 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_) 1424 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_)
1420 ->OnMessageReceived(msg_activate)); 1425 ->OnMessageReceived(msg_activate));
1421 AutofillMsg_SetLoggingState msg_deactivate(0, /*active=*/false); 1426 AutofillMsg_SetLoggingState msg_deactivate(0, /*active=*/false);
1422 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_) 1427 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_)
1423 ->OnMessageReceived(msg_deactivate)); 1428 ->OnMessageReceived(msg_deactivate));
1424 1429
1425 render_thread_->sink().ClearMessages(); 1430 render_thread_->sink().ClearMessages();
1426 SendVisiblePasswordForms(); 1431 SendVisiblePasswordForms();
1427 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( 1432 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
1428 AutofillHostMsg_RecordSavePasswordProgress::ID); 1433 AutofillHostMsg_RecordSavePasswordProgress::ID);
1429 EXPECT_FALSE(message); 1434 EXPECT_FALSE(message);
1430 } 1435 }
1431 1436
1432 // Test that the agent sends an IPC call to get the current activity state of 1437 // Test that the agent sends an IPC call to get the current activity state of
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 // Clear the text fields to start fresh. 1472 // Clear the text fields to start fresh.
1468 ClearUsernameAndPasswordFields(); 1473 ClearUsernameAndPasswordFields();
1469 1474
1470 // Call SimulateElementClick() to produce a user gesture on the page so 1475 // Call SimulateElementClick() to produce a user gesture on the page so
1471 // autofill will actually fill. 1476 // autofill will actually fill.
1472 SimulateElementClick(kUsernameName); 1477 SimulateElementClick(kUsernameName);
1473 1478
1474 // Simulate a user clicking on the username element. This should produce a 1479 // Simulate a user clicking on the username element. This should produce a
1475 // message with all the usernames. 1480 // message with all the usernames.
1476 render_thread_->sink().ClearMessages(); 1481 render_thread_->sink().ClearMessages();
1477 autofill_agent_->FormControlElementClicked(username_element_, false); 1482 static_cast<PageClickListener*>(autofill_agent_)
1483 ->FormControlElementClicked(username_element_, false);
1478 ExpectAllCredentials(); 1484 ExpectAllCredentials();
1479 1485
1480 // Now simulate a user typing in an unrecognized username and then 1486 // Now simulate a user typing in an unrecognized username and then
1481 // clicking on the username element. This should also produce a message with 1487 // clicking on the username element. This should also produce a message with
1482 // all the usernames. 1488 // all the usernames.
1483 SimulateUsernameChange("baz", true); 1489 SimulateUsernameChange("baz", true);
1484 render_thread_->sink().ClearMessages(); 1490 render_thread_->sink().ClearMessages();
1485 autofill_agent_->FormControlElementClicked(username_element_, true); 1491 static_cast<PageClickListener*>(autofill_agent_)
1492 ->FormControlElementClicked(username_element_, true);
1486 ExpectAllCredentials(); 1493 ExpectAllCredentials();
1487 1494
1488 // Now simulate a user typing in the first letter of the username and then 1495 // Now simulate a user typing in the first letter of the username and then
1489 // clicking on the username element. While the typing of the first letter will 1496 // clicking on the username element. While the typing of the first letter will
1490 // inline autocomplete, clicking on the element should still produce a full 1497 // inline autocomplete, clicking on the element should still produce a full
1491 // suggestion list. 1498 // suggestion list.
1492 SimulateUsernameChange("a", true); 1499 SimulateUsernameChange("a", true);
1493 render_thread_->sink().ClearMessages(); 1500 render_thread_->sink().ClearMessages();
1494 autofill_agent_->FormControlElementClicked(username_element_, true); 1501 static_cast<PageClickListener*>(autofill_agent_)
1502 ->FormControlElementClicked(username_element_, true);
1495 ExpectAllCredentials(); 1503 ExpectAllCredentials();
1496 } 1504 }
1497 1505
1498 // The user types in a password, but then just before sending the form off, a 1506 // The user types in a password, but then just before sending the form off, a
1499 // script clears that password. This test checks that PasswordAutofillAgent can 1507 // script clears that password. This test checks that PasswordAutofillAgent can
1500 // still remember the password typed by the user. 1508 // still remember the password typed by the user.
1501 TEST_F(PasswordAutofillAgentTest, 1509 TEST_F(PasswordAutofillAgentTest,
1502 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { 1510 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) {
1503 SimulateInputChangeForElement( 1511 SimulateInputChangeForElement(
1504 "temp", true, GetMainFrame(), username_element_, true); 1512 "temp", true, GetMainFrame(), username_element_, true);
1505 SimulateInputChangeForElement( 1513 SimulateInputChangeForElement(
1506 "random", true, GetMainFrame(), password_element_, true); 1514 "random", true, GetMainFrame(), password_element_, true);
1507 1515
1508 // Simulate that the password value was cleared by the site's JavaScript 1516 // Simulate that the password value was cleared by the site's JavaScript
1509 // before submit. 1517 // before submit.
1510 password_element_.setValue(WebString()); 1518 password_element_.setValue(WebString());
1511 static_cast<content::RenderViewObserver*>(password_autofill_agent()) 1519 static_cast<content::RenderViewObserver*>(password_autofill_agent_)
1512 ->WillSubmitForm(GetMainFrame(), username_element_.form()); 1520 ->WillSubmitForm(GetMainFrame(), username_element_.form());
1513 1521
1514 // Observe that the PasswordAutofillAgent still remembered the last non-empty 1522 // Observe that the PasswordAutofillAgent still remembered the last non-empty
1515 // password and sent that to the browser. 1523 // password and sent that to the browser.
1516 ExpectFormSubmittedWithPasswords("random", ""); 1524 ExpectFormSubmittedWithPasswords("random", "");
1517 } 1525 }
1518 1526
1519 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time 1527 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time
1520 // it's the user who clears the password. This test checks that in that case, 1528 // it's the user who clears the password. This test checks that in that case,
1521 // the last non-empty password is not remembered. 1529 // the last non-empty password is not remembered.
1522 TEST_F(PasswordAutofillAgentTest, 1530 TEST_F(PasswordAutofillAgentTest,
1523 RememberLastNonEmptyPasswordOnSubmit_UserCleared) { 1531 RememberLastNonEmptyPasswordOnSubmit_UserCleared) {
1524 SimulateInputChangeForElement( 1532 SimulateInputChangeForElement(
1525 "temp", true, GetMainFrame(), username_element_, true); 1533 "temp", true, GetMainFrame(), username_element_, true);
1526 SimulateInputChangeForElement( 1534 SimulateInputChangeForElement(
1527 "random", true, GetMainFrame(), password_element_, true); 1535 "random", true, GetMainFrame(), password_element_, true);
1528 1536
1529 // Simulate that the user actually cleared the password again. 1537 // Simulate that the user actually cleared the password again.
1530 SimulateInputChangeForElement( 1538 SimulateInputChangeForElement(
1531 "", true, GetMainFrame(), password_element_, true); 1539 "", true, GetMainFrame(), password_element_, true);
1532 static_cast<content::RenderViewObserver*>(password_autofill_agent()) 1540 static_cast<content::RenderViewObserver*>(password_autofill_agent_)
1533 ->WillSubmitForm(GetMainFrame(), username_element_.form()); 1541 ->WillSubmitForm(GetMainFrame(), username_element_.form());
1534 1542
1535 // Observe that the PasswordAutofillAgent respects the user having cleared the 1543 // Observe that the PasswordAutofillAgent respects the user having cleared the
1536 // password. 1544 // password.
1537 ExpectFormSubmittedWithPasswords("", ""); 1545 ExpectFormSubmittedWithPasswords("", "");
1538 } 1546 }
1539 1547
1540 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the 1548 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the
1541 // new password instead of the current password. 1549 // new password instead of the current password.
1542 TEST_F(PasswordAutofillAgentTest, 1550 TEST_F(PasswordAutofillAgentTest,
1543 RememberLastNonEmptyPasswordOnSubmit_NewPassword) { 1551 RememberLastNonEmptyPasswordOnSubmit_NewPassword) {
1544 const char kNewPasswordFormHTML[] = 1552 const char kNewPasswordFormHTML[] =
1545 "<FORM name='LoginTestForm'>" 1553 "<FORM name='LoginTestForm'>"
1546 " <INPUT type='text' id='username' autocomplete='username'/>" 1554 " <INPUT type='text' id='username' autocomplete='username'/>"
1547 " <INPUT type='password' id='password' autocomplete='new-password'/>" 1555 " <INPUT type='password' id='password' autocomplete='new-password'/>"
1548 " <INPUT type='submit' value='Login'/>" 1556 " <INPUT type='submit' value='Login'/>"
1549 "</FORM>"; 1557 "</FORM>";
1550 LoadHTML(kNewPasswordFormHTML); 1558 LoadHTML(kNewPasswordFormHTML);
1551 UpdateUsernameAndPasswordElements(); 1559 UpdateUsernameAndPasswordElements();
1552 1560
1553 SimulateInputChangeForElement( 1561 SimulateInputChangeForElement(
1554 "temp", true, GetMainFrame(), username_element_, true); 1562 "temp", true, GetMainFrame(), username_element_, true);
1555 SimulateInputChangeForElement( 1563 SimulateInputChangeForElement(
1556 "random", true, GetMainFrame(), password_element_, true); 1564 "random", true, GetMainFrame(), password_element_, true);
1557 1565
1558 // Simulate that the password value was cleared by the site's JavaScript 1566 // Simulate that the password value was cleared by the site's JavaScript
1559 // before submit. 1567 // before submit.
1560 password_element_.setValue(WebString()); 1568 password_element_.setValue(WebString());
1561 static_cast<content::RenderViewObserver*>(password_autofill_agent()) 1569 static_cast<content::RenderViewObserver*>(password_autofill_agent_)
1562 ->WillSubmitForm(GetMainFrame(), username_element_.form()); 1570 ->WillSubmitForm(GetMainFrame(), username_element_.form());
1563 1571
1564 // Observe that the PasswordAutofillAgent still remembered the last non-empty 1572 // Observe that the PasswordAutofillAgent still remembered the last non-empty
1565 // password and sent that to the browser. 1573 // password and sent that to the browser.
1566 ExpectFormSubmittedWithPasswords("", "random"); 1574 ExpectFormSubmittedWithPasswords("", "random");
1567 } 1575 }
1568 1576
1569 // The user first accepts a suggestion, but then overwrites the password. This 1577 // The user first accepts a suggestion, but then overwrites the password. This
1570 // test checks that the overwritten password is not reverted back if the user 1578 // test checks that the overwritten password is not reverted back if the user
1571 // triggers autofill through focusing (but not changing) the username again. 1579 // triggers autofill through focusing (but not changing) the username again.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 password_element_, 1626 password_element_,
1619 /*is_user_input=*/true); 1627 /*is_user_input=*/true);
1620 1628
1621 // Simulate the user typing a stored username. 1629 // Simulate the user typing a stored username.
1622 SimulateUsernameChange(kAliceUsername, true); 1630 SimulateUsernameChange(kAliceUsername, true);
1623 // The autofileld password should replace the typed one. 1631 // The autofileld password should replace the typed one.
1624 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); 1632 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1625 } 1633 }
1626 1634
1627 } // namespace autofill 1635 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/autofill_renderer_browsertest.cc ('k') | chrome/test/base/chrome_render_view_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698