OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <tuple> |
| 6 |
5 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
6 #include "base/macros.h" | 8 #include "base/macros.h" |
7 #include "base/run_loop.h" | |
8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/renderer/autofill/fake_content_password_manager_driver.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/form_data.h" | 20 #include "components/autofill/core/common/form_data.h" |
21 #include "components/autofill/core/common/form_field_data.h" | 21 #include "components/autofill/core/common/form_field_data.h" |
22 #include <components/autofill/core/common/password_form.h> | 22 #include <components/autofill/core/common/password_form.h> |
23 #include "components/autofill/core/common/password_form_field_prediction_map.h" | 23 #include "components/autofill/core/common/password_form_field_prediction_map.h" |
24 #include "components/password_manager/core/common/password_manager_features.h" | 24 #include "components/password_manager/core/common/password_manager_features.h" |
25 #include "content/public/renderer/render_frame.h" | 25 #include "content/public/renderer/render_frame.h" |
26 #include "content/public/renderer/render_view.h" | |
27 #include "services/shell/public/cpp/interface_provider.h" | |
28 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
29 #include "third_party/WebKit/public/platform/WebString.h" | 27 #include "third_party/WebKit/public/platform/WebString.h" |
30 #include "third_party/WebKit/public/platform/WebVector.h" | 28 #include "third_party/WebKit/public/platform/WebVector.h" |
31 #include "third_party/WebKit/public/web/WebDocument.h" | 29 #include "third_party/WebKit/public/web/WebDocument.h" |
32 #include "third_party/WebKit/public/web/WebElement.h" | 30 #include "third_party/WebKit/public/web/WebElement.h" |
33 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 31 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
34 #include "third_party/WebKit/public/web/WebFormElement.h" | 32 #include "third_party/WebKit/public/web/WebFormElement.h" |
35 #include "third_party/WebKit/public/web/WebInputElement.h" | 33 #include "third_party/WebKit/public/web/WebInputElement.h" |
36 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 34 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
37 #include "third_party/WebKit/public/web/WebNode.h" | 35 #include "third_party/WebKit/public/web/WebNode.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 " <INPUT type='password' id='password2' name='password'/>" | 221 " <INPUT type='password' id='password2' name='password'/>" |
224 " <INPUT type='submit' value='Login'/>" | 222 " <INPUT type='submit' value='Login'/>" |
225 "</FORM>"; | 223 "</FORM>"; |
226 | 224 |
227 // Sets the "readonly" attribute of |element| to the value given by |read_only|. | 225 // Sets the "readonly" attribute of |element| to the value given by |read_only|. |
228 void SetElementReadOnly(WebInputElement& element, bool read_only) { | 226 void SetElementReadOnly(WebInputElement& element, bool read_only) { |
229 element.setAttribute(WebString::fromUTF8("readonly"), | 227 element.setAttribute(WebString::fromUTF8("readonly"), |
230 read_only ? WebString::fromUTF8("true") : WebString()); | 228 read_only ? WebString::fromUTF8("true") : WebString()); |
231 } | 229 } |
232 | 230 |
233 enum PasswordFormSourceType { | |
234 PasswordFormSubmitted, | |
235 PasswordFormInPageNavigation, | |
236 }; | |
237 | |
238 } // namespace | 231 } // namespace |
239 | 232 |
240 namespace autofill { | 233 namespace autofill { |
241 | 234 |
242 class PasswordAutofillAgentTest : public ChromeRenderViewTest { | 235 class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
243 public: | 236 public: |
244 PasswordAutofillAgentTest() { | 237 PasswordAutofillAgentTest() { |
245 } | 238 } |
246 | 239 |
247 // Simulates the fill password form message being sent to the renderer. | 240 // Simulates the fill password form message being sent to the renderer. |
248 // We use that so we don't have to make RenderView::OnFillPasswordForm() | 241 // We use that so we don't have to make RenderView::OnFillPasswordForm() |
249 // protected. | 242 // protected. |
250 void SimulateOnFillPasswordForm( | 243 void SimulateOnFillPasswordForm( |
251 const PasswordFormFillData& fill_data) { | 244 const PasswordFormFillData& fill_data) { |
252 password_autofill_agent_->FillPasswordForm(kPasswordFillFormDataId, | 245 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); |
253 fill_data); | 246 static_cast<IPC::Listener*>(password_autofill_agent_) |
| 247 ->OnMessageReceived(msg); |
| 248 } |
| 249 |
| 250 // As above, but fills for an iframe. |
| 251 void SimulateOnFillPasswordFormForFrame( |
| 252 WebFrame* frame, |
| 253 const PasswordFormFillData& fill_data) { |
| 254 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); |
| 255 content::RenderFrame::FromWebFrame(frame)->OnMessageReceived(msg); |
254 } | 256 } |
255 | 257 |
256 // Simulates the show initial password account suggestions message being sent | 258 // Simulates the show initial password account suggestions message being sent |
257 // to the renderer. | 259 // to the renderer. |
258 void SimulateOnShowInitialPasswordAccountSuggestions( | 260 void SimulateOnShowInitialPasswordAccountSuggestions( |
259 const PasswordFormFillData& fill_data) { | 261 const PasswordFormFillData& fill_data) { |
260 autofill_agent_->ShowInitialPasswordAccountSuggestions( | 262 autofill_agent_->ShowInitialPasswordAccountSuggestions( |
261 kPasswordFillFormDataId, fill_data); | 263 kPasswordFillFormDataId, fill_data); |
262 } | 264 } |
263 | 265 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 // Now retrieve the input elements so the test can access them. | 318 // Now retrieve the input elements so the test can access them. |
317 UpdateUsernameAndPasswordElements(); | 319 UpdateUsernameAndPasswordElements(); |
318 } | 320 } |
319 | 321 |
320 void TearDown() override { | 322 void TearDown() override { |
321 username_element_.reset(); | 323 username_element_.reset(); |
322 password_element_.reset(); | 324 password_element_.reset(); |
323 ChromeRenderViewTest::TearDown(); | 325 ChromeRenderViewTest::TearDown(); |
324 } | 326 } |
325 | 327 |
326 void RegisterMainFrameRemoteInterfaces() override { | |
327 // We only use the fake driver for main frame | |
328 // because our test cases only involve the main frame. | |
329 shell::InterfaceProvider* remote_interfaces = | |
330 view_->GetMainRenderFrame()->GetRemoteInterfaces(); | |
331 shell::InterfaceProvider::TestApi test_api(remote_interfaces); | |
332 test_api.SetBinderForName( | |
333 mojom::PasswordManagerDriver::Name_, | |
334 base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerDriver, | |
335 base::Unretained(this))); | |
336 } | |
337 | |
338 void SetFillOnAccountSelect() { | 328 void SetFillOnAccountSelect() { |
339 base::FeatureList::ClearInstanceForTesting(); | 329 base::FeatureList::ClearInstanceForTesting(); |
340 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 330 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
341 feature_list->InitializeFromCommandLine( | 331 feature_list->InitializeFromCommandLine( |
342 password_manager::features::kFillOnAccountSelect.name, ""); | 332 password_manager::features::kFillOnAccountSelect.name, ""); |
343 base::FeatureList::SetInstance(std::move(feature_list)); | 333 base::FeatureList::SetInstance(std::move(feature_list)); |
344 } | 334 } |
345 | 335 |
346 void UpdateOriginForHTML(const std::string& html) { | 336 void UpdateOriginForHTML(const std::string& html) { |
347 std::string origin = "data:text/html;charset=utf-8," + html; | 337 std::string origin = "data:text/html;charset=utf-8," + html; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, | 374 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, |
385 password); | 375 password); |
386 } | 376 } |
387 | 377 |
388 void SimulateSuggestionChoiceOfUsernameAndPassword( | 378 void SimulateSuggestionChoiceOfUsernameAndPassword( |
389 WebInputElement& input, | 379 WebInputElement& input, |
390 const base::string16& username, | 380 const base::string16& username, |
391 const base::string16& password) { | 381 const base::string16& password) { |
392 // This call is necessary to setup the autofill agent appropriate for the | 382 // This call is necessary to setup the autofill agent appropriate for the |
393 // user selection; simulates the menu actually popping up. | 383 // user selection; simulates the menu actually popping up. |
| 384 render_thread_->sink().ClearMessages(); |
394 static_cast<autofill::PageClickListener*>(autofill_agent_) | 385 static_cast<autofill::PageClickListener*>(autofill_agent_) |
395 ->FormControlElementClicked(input, false); | 386 ->FormControlElementClicked(input, false); |
396 | 387 |
397 autofill_agent_->FillPasswordSuggestion(username, password); | 388 autofill_agent_->FillPasswordSuggestion(username, password); |
398 } | 389 } |
399 | 390 |
400 void SimulateUsernameChange(const std::string& username) { | 391 void SimulateUsernameChange(const std::string& username) { |
401 SimulateUserInputChangeForElement(&username_element_, username); | 392 SimulateUserInputChangeForElement(&username_element_, username); |
402 } | 393 } |
403 | 394 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 void CheckUsernameSelection(int start, int end) { | 447 void CheckUsernameSelection(int start, int end) { |
457 EXPECT_EQ(start, username_element_.selectionStart()); | 448 EXPECT_EQ(start, username_element_.selectionStart()); |
458 EXPECT_EQ(end, username_element_.selectionEnd()); | 449 EXPECT_EQ(end, username_element_.selectionEnd()); |
459 } | 450 } |
460 | 451 |
461 // Checks the message sent to PasswordAutofillManager to build the suggestion | 452 // Checks the message sent to PasswordAutofillManager to build the suggestion |
462 // list. |username| is the expected username field value, and |show_all| is | 453 // list. |username| is the expected username field value, and |show_all| is |
463 // the expected flag for the PasswordAutofillManager, whether to show all | 454 // the expected flag for the PasswordAutofillManager, whether to show all |
464 // suggestions, or only those starting with |username|. | 455 // suggestions, or only those starting with |username|. |
465 void CheckSuggestions(const std::string& username, bool show_all) { | 456 void CheckSuggestions(const std::string& username, bool show_all) { |
466 base::RunLoop().RunUntilIdle(); | 457 const IPC::Message* message = |
| 458 render_thread_->sink().GetFirstMessageMatching( |
| 459 AutofillHostMsg_ShowPasswordSuggestions::ID); |
| 460 ASSERT_TRUE(message); |
| 461 std::tuple<int, base::i18n::TextDirection, base::string16, int, gfx::RectF> |
| 462 args; |
| 463 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); |
| 464 EXPECT_EQ(kPasswordFillFormDataId, std::get<0>(args)); |
| 465 EXPECT_EQ(ASCIIToUTF16(username), std::get<2>(args)); |
| 466 EXPECT_EQ(show_all, |
| 467 static_cast<bool>(std::get<3>(args) & autofill::SHOW_ALL)); |
467 | 468 |
468 ASSERT_TRUE(fake_driver_.called_show_pw_suggestions()); | 469 render_thread_->sink().ClearMessages(); |
469 EXPECT_EQ(kPasswordFillFormDataId, fake_driver_.show_pw_suggestions_key()); | |
470 ASSERT_TRUE(static_cast<bool>(fake_driver_.show_pw_suggestions_username())); | |
471 EXPECT_EQ(ASCIIToUTF16(username), | |
472 *(fake_driver_.show_pw_suggestions_username())); | |
473 EXPECT_EQ(show_all, | |
474 static_cast<bool>(fake_driver_.show_pw_suggestions_options() & | |
475 autofill::SHOW_ALL)); | |
476 | |
477 fake_driver_.reset_show_pw_suggestions(); | |
478 } | |
479 | |
480 bool GetCalledShowPasswordSuggestions() { | |
481 base::RunLoop().RunUntilIdle(); | |
482 return fake_driver_.called_show_pw_suggestions(); | |
483 } | 470 } |
484 | 471 |
485 void ExpectFormSubmittedWithUsernameAndPasswords( | 472 void ExpectFormSubmittedWithUsernameAndPasswords( |
486 const std::string& username_value, | 473 const std::string& username_value, |
487 const std::string& password_value, | 474 const std::string& password_value, |
488 const std::string& new_password_value) { | 475 const std::string& new_password_value) { |
489 base::RunLoop().RunUntilIdle(); | 476 const IPC::Message* message = |
490 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); | 477 render_thread_->sink().GetFirstMessageMatching( |
491 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted())); | 478 AutofillHostMsg_PasswordFormSubmitted::ID); |
492 const autofill::PasswordForm& form = | 479 ASSERT_TRUE(message); |
493 *(fake_driver_.password_form_submitted()); | 480 std::tuple<autofill::PasswordForm> args; |
494 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); | 481 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); |
495 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); | 482 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); |
496 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); | 483 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); |
| 484 EXPECT_EQ(ASCIIToUTF16(new_password_value), |
| 485 std::get<0>(args).new_password_value); |
497 } | 486 } |
498 | 487 |
499 void ExpectFieldPropertiesMasks( | 488 void ExpectFieldPropertiesMasks( |
500 PasswordFormSourceType expected_type, | 489 uint32_t expected_message_id, |
501 const std::map<base::string16, FieldPropertiesMask>& | 490 const std::map<base::string16, FieldPropertiesMask>& |
502 expected_properties_masks) { | 491 expected_properties_masks) { |
503 base::RunLoop().RunUntilIdle(); | 492 const IPC::Message* message = |
504 autofill::PasswordForm form; | 493 render_thread_->sink().GetFirstMessageMatching(expected_message_id); |
505 if (expected_type == PasswordFormSubmitted) { | 494 ASSERT_TRUE(message); |
506 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); | 495 std::tuple<autofill::PasswordForm> args; |
507 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted())); | 496 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); |
508 form = *(fake_driver_.password_form_submitted()); | 497 const autofill::PasswordForm& form = std::get<0>(args); |
509 } else { | |
510 ASSERT_EQ(PasswordFormInPageNavigation, expected_type); | |
511 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); | |
512 ASSERT_TRUE( | |
513 static_cast<bool>(fake_driver_.password_form_inpage_navigation())); | |
514 form = *(fake_driver_.password_form_inpage_navigation()); | |
515 } | |
516 | 498 |
517 size_t unchecked_masks = expected_properties_masks.size(); | 499 size_t unchecked_masks = expected_properties_masks.size(); |
518 for (const FormFieldData& field : form.form_data.fields) { | 500 for (const FormFieldData& field : form.form_data.fields) { |
519 const auto& it = expected_properties_masks.find(field.name); | 501 const auto& it = expected_properties_masks.find(field.name); |
520 if (it == expected_properties_masks.end()) | 502 if (it == expected_properties_masks.end()) |
521 continue; | 503 continue; |
522 EXPECT_EQ(field.properties_mask, it->second) | 504 EXPECT_EQ(field.properties_mask, it->second) |
523 << "Wrong mask for the field " << field.name; | 505 << "Wrong mask for the field " << field.name; |
524 unchecked_masks--; | 506 unchecked_masks--; |
525 } | 507 } |
526 EXPECT_TRUE(unchecked_masks == 0) | 508 EXPECT_TRUE(unchecked_masks == 0) |
527 << "Some expected masks are missed in FormData"; | 509 << "Some expected masks are missed in FormData"; |
528 } | 510 } |
529 | 511 |
530 void ExpectInPageNavigationWithUsernameAndPasswords( | 512 void ExpectInPageNavigationWithUsernameAndPasswords( |
531 const std::string& username_value, | 513 const std::string& username_value, |
532 const std::string& password_value, | 514 const std::string& password_value, |
533 const std::string& new_password_value) { | 515 const std::string& new_password_value) { |
534 base::RunLoop().RunUntilIdle(); | 516 const IPC::Message* message = |
535 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); | 517 render_thread_->sink().GetFirstMessageMatching( |
536 ASSERT_TRUE( | 518 AutofillHostMsg_InPageNavigation::ID); |
537 static_cast<bool>(fake_driver_.password_form_inpage_navigation())); | 519 ASSERT_TRUE(message); |
538 const autofill::PasswordForm& form = | 520 std::tuple<autofill::PasswordForm> args; |
539 *(fake_driver_.password_form_inpage_navigation()); | 521 AutofillHostMsg_InPageNavigation::Read(message, &args); |
540 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); | 522 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); |
541 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); | 523 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); |
542 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); | 524 EXPECT_EQ(ASCIIToUTF16(new_password_value), |
| 525 std::get<0>(args).new_password_value); |
543 } | 526 } |
544 | 527 |
545 void BindPasswordManagerDriver(mojo::ScopedMessagePipeHandle handle) { | |
546 fake_driver_.BindRequest( | |
547 mojo::MakeRequest<mojom::PasswordManagerDriver>(std::move(handle))); | |
548 } | |
549 | |
550 FakeContentPasswordManagerDriver fake_driver_; | |
551 | |
552 base::string16 username1_; | 528 base::string16 username1_; |
553 base::string16 username2_; | 529 base::string16 username2_; |
554 base::string16 username3_; | 530 base::string16 username3_; |
555 base::string16 password1_; | 531 base::string16 password1_; |
556 base::string16 password2_; | 532 base::string16 password2_; |
557 base::string16 password3_; | 533 base::string16 password3_; |
558 base::string16 alternate_username3_; | 534 base::string16 alternate_username3_; |
559 PasswordFormFillData fill_data_; | 535 PasswordFormFillData fill_data_; |
560 | 536 |
561 WebInputElement username_element_; | 537 WebInputElement username_element_; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 EXPECT_FALSE(form_util::IsWebNodeVisible(forms2[0])); | 810 EXPECT_FALSE(form_util::IsWebNodeVisible(forms2[0])); |
835 | 811 |
836 LoadHTML(kNonVisibleFormHTML); | 812 LoadHTML(kNonVisibleFormHTML); |
837 frame = GetMainFrame(); | 813 frame = GetMainFrame(); |
838 frame->document().forms(forms3); | 814 frame->document().forms(forms3); |
839 ASSERT_EQ(1u, forms3.size()); | 815 ASSERT_EQ(1u, forms3.size()); |
840 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); | 816 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); |
841 } | 817 } |
842 | 818 |
843 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { | 819 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { |
844 fake_driver_.reset_password_forms_rendered(); | 820 render_thread_->sink().ClearMessages(); |
845 LoadHTML(kVisibleFormWithNoUsernameHTML); | 821 LoadHTML(kVisibleFormWithNoUsernameHTML); |
846 base::RunLoop().RunUntilIdle(); | 822 const IPC::Message* message = render_thread_->sink() |
847 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); | 823 .GetFirstMessageMatching(AutofillHostMsg_PasswordFormsRendered::ID); |
848 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered())); | 824 EXPECT_TRUE(message); |
849 EXPECT_FALSE(fake_driver_.password_forms_rendered()->empty()); | 825 std::tuple<std::vector<autofill::PasswordForm>, bool> param; |
| 826 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); |
| 827 EXPECT_TRUE(std::get<0>(param).size()); |
850 | 828 |
851 fake_driver_.reset_password_forms_rendered(); | 829 render_thread_->sink().ClearMessages(); |
852 LoadHTML(kEmptyFormHTML); | 830 LoadHTML(kEmptyFormHTML); |
853 base::RunLoop().RunUntilIdle(); | 831 message = render_thread_->sink().GetFirstMessageMatching( |
854 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); | 832 AutofillHostMsg_PasswordFormsRendered::ID); |
855 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered())); | 833 EXPECT_TRUE(message); |
856 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); | 834 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); |
| 835 EXPECT_FALSE(std::get<0>(param).size()); |
857 | 836 |
858 fake_driver_.reset_password_forms_rendered(); | 837 render_thread_->sink().ClearMessages(); |
859 LoadHTML(kNonVisibleFormHTML); | 838 LoadHTML(kNonVisibleFormHTML); |
860 base::RunLoop().RunUntilIdle(); | 839 message = render_thread_->sink().GetFirstMessageMatching( |
861 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); | 840 AutofillHostMsg_PasswordFormsRendered::ID); |
862 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered())); | 841 EXPECT_TRUE(message); |
863 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); | 842 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); |
| 843 EXPECT_FALSE(std::get<0>(param).size()); |
864 } | 844 } |
865 | 845 |
866 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { | 846 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { |
867 fake_driver_.reset_password_forms_rendered(); | 847 render_thread_->sink().ClearMessages(); |
868 LoadHTML(kEmptyWebpage); | 848 LoadHTML(kEmptyWebpage); |
869 base::RunLoop().RunUntilIdle(); | 849 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
870 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); | 850 AutofillHostMsg_PasswordFormsRendered::ID)); |
871 | 851 |
872 fake_driver_.reset_password_forms_rendered(); | 852 render_thread_->sink().ClearMessages(); |
873 LoadHTML(kRedirectionWebpage); | 853 LoadHTML(kRedirectionWebpage); |
874 base::RunLoop().RunUntilIdle(); | 854 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
875 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); | 855 AutofillHostMsg_PasswordFormsRendered::ID)); |
876 | 856 |
877 fake_driver_.reset_password_forms_rendered(); | 857 render_thread_->sink().ClearMessages(); |
878 LoadHTML(kSimpleWebpage); | 858 LoadHTML(kSimpleWebpage); |
879 base::RunLoop().RunUntilIdle(); | 859 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
880 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); | 860 AutofillHostMsg_PasswordFormsRendered::ID)); |
881 | 861 |
882 fake_driver_.reset_password_forms_rendered(); | 862 render_thread_->sink().ClearMessages(); |
883 LoadHTML(kWebpageWithDynamicContent); | 863 LoadHTML(kWebpageWithDynamicContent); |
884 base::RunLoop().RunUntilIdle(); | 864 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
885 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); | 865 AutofillHostMsg_PasswordFormsRendered::ID)); |
886 } | 866 } |
887 | 867 |
888 // Tests that a password will only be filled as a suggested and will not be | 868 // Tests that a password will only be filled as a suggested and will not be |
889 // accessible by the DOM until a user gesture has occurred. | 869 // accessible by the DOM until a user gesture has occurred. |
890 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { | 870 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { |
891 // Trigger the initial autocomplete. | 871 // Trigger the initial autocomplete. |
892 SimulateOnFillPasswordForm(fill_data_); | 872 SimulateOnFillPasswordForm(fill_data_); |
893 | 873 |
894 // The username and password should have been autocompleted. | 874 // The username and password should have been autocompleted. |
895 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 875 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); | 1210 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); |
1231 EXPECT_FALSE(username_element_.isAutofilled()); | 1211 EXPECT_FALSE(username_element_.isAutofilled()); |
1232 EXPECT_TRUE(password_element_.value().isEmpty()); | 1212 EXPECT_TRUE(password_element_.value().isEmpty()); |
1233 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); | 1213 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); |
1234 EXPECT_FALSE(password_element_.isAutofilled()); | 1214 EXPECT_FALSE(password_element_.isAutofilled()); |
1235 CheckUsernameSelection(0, 0); | 1215 CheckUsernameSelection(0, 0); |
1236 } | 1216 } |
1237 | 1217 |
1238 // Tests that logging is off by default. | 1218 // Tests that logging is off by default. |
1239 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { | 1219 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { |
| 1220 render_thread_->sink().ClearMessages(); |
1240 SendVisiblePasswordForms(); | 1221 SendVisiblePasswordForms(); |
1241 base::RunLoop().RunUntilIdle(); | 1222 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
1242 EXPECT_FALSE(fake_driver_.called_record_save_progress()); | 1223 AutofillHostMsg_RecordSavePasswordProgress::ID); |
| 1224 EXPECT_FALSE(message); |
1243 } | 1225 } |
1244 | 1226 |
1245 // Test that logging can be turned on by a message. | 1227 // Test that logging can be turned on by a message. |
1246 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { | 1228 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { |
1247 // Turn the logging on. | 1229 // Turn the logging on. |
1248 password_autofill_agent_->SetLoggingState(true); | 1230 AutofillMsg_SetLoggingState msg_activate(0, true); |
| 1231 // Up-cast to access OnMessageReceived, which is private in the agent. |
| 1232 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_) |
| 1233 ->OnMessageReceived(msg_activate)); |
1249 | 1234 |
| 1235 render_thread_->sink().ClearMessages(); |
1250 SendVisiblePasswordForms(); | 1236 SendVisiblePasswordForms(); |
1251 base::RunLoop().RunUntilIdle(); | 1237 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
1252 EXPECT_TRUE(fake_driver_.called_record_save_progress()); | 1238 AutofillHostMsg_RecordSavePasswordProgress::ID); |
| 1239 EXPECT_TRUE(message); |
1253 } | 1240 } |
1254 | 1241 |
1255 // Test that logging can be turned off by a message. | 1242 // Test that logging can be turned off by a message. |
1256 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { | 1243 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { |
1257 // Turn the logging on and then off. | 1244 // Turn the logging on and then off. |
1258 password_autofill_agent_->SetLoggingState(true); | 1245 AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true); |
1259 password_autofill_agent_->SetLoggingState(false); | 1246 // Up-cast to access OnMessageReceived, which is private in the agent. |
| 1247 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_) |
| 1248 ->OnMessageReceived(msg_activate)); |
| 1249 AutofillMsg_SetLoggingState msg_deactivate(0, /*active=*/false); |
| 1250 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_) |
| 1251 ->OnMessageReceived(msg_deactivate)); |
1260 | 1252 |
| 1253 render_thread_->sink().ClearMessages(); |
1261 SendVisiblePasswordForms(); | 1254 SendVisiblePasswordForms(); |
1262 base::RunLoop().RunUntilIdle(); | 1255 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
1263 EXPECT_FALSE(fake_driver_.called_record_save_progress()); | 1256 AutofillHostMsg_RecordSavePasswordProgress::ID); |
| 1257 EXPECT_FALSE(message); |
1264 } | 1258 } |
1265 | 1259 |
1266 // Test that the agent sends an IPC call to get the current activity state of | 1260 // Test that the agent sends an IPC call to get the current activity state of |
1267 // password saving logging soon after construction. | 1261 // password saving logging soon after construction. |
1268 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) { | 1262 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) { |
1269 base::RunLoop().RunUntilIdle(); | 1263 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
1270 EXPECT_TRUE(fake_driver_.called_agent_constructed()); | 1264 AutofillHostMsg_PasswordAutofillAgentConstructed::ID); |
| 1265 EXPECT_TRUE(message); |
1271 } | 1266 } |
1272 | 1267 |
1273 // Tests that one user click on a username field is sufficient to bring up a | 1268 // Tests that one user click on a username field is sufficient to bring up a |
1274 // credential suggestion popup, and the user can autocomplete the password by | 1269 // credential suggestion popup, and the user can autocomplete the password by |
1275 // selecting the credential from the popup. | 1270 // selecting the credential from the popup. |
1276 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { | 1271 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { |
1277 // SimulateElementClick() is called so that a user gesture is actually made | 1272 // SimulateElementClick() is called so that a user gesture is actually made |
1278 // and the password can be filled. However, SimulateElementClick() does not | 1273 // and the password can be filled. However, SimulateElementClick() does not |
1279 // actually lead to the AutofillAgent's InputElementClicked() method being | 1274 // actually lead to the AutofillAgent's InputElementClicked() method being |
1280 // called, so SimulateSuggestionChoice has to manually call | 1275 // called, so SimulateSuggestionChoice has to manually call |
(...skipping 18 matching lines...) Expand all Loading... |
1299 | 1294 |
1300 // Clear the text fields to start fresh. | 1295 // Clear the text fields to start fresh. |
1301 ClearUsernameAndPasswordFields(); | 1296 ClearUsernameAndPasswordFields(); |
1302 | 1297 |
1303 // Call SimulateElementClick() to produce a user gesture on the page so | 1298 // Call SimulateElementClick() to produce a user gesture on the page so |
1304 // autofill will actually fill. | 1299 // autofill will actually fill. |
1305 SimulateElementClick(kUsernameName); | 1300 SimulateElementClick(kUsernameName); |
1306 | 1301 |
1307 // Simulate a user clicking on the username element. This should produce a | 1302 // Simulate a user clicking on the username element. This should produce a |
1308 // message with all the usernames. | 1303 // message with all the usernames. |
| 1304 render_thread_->sink().ClearMessages(); |
1309 static_cast<PageClickListener*>(autofill_agent_) | 1305 static_cast<PageClickListener*>(autofill_agent_) |
1310 ->FormControlElementClicked(username_element_, false); | 1306 ->FormControlElementClicked(username_element_, false); |
1311 CheckSuggestions(std::string(), false); | 1307 CheckSuggestions(std::string(), false); |
1312 | 1308 |
1313 // Now simulate a user typing in an unrecognized username and then | 1309 // Now simulate a user typing in an unrecognized username and then |
1314 // clicking on the username element. This should also produce a message with | 1310 // clicking on the username element. This should also produce a message with |
1315 // all the usernames. | 1311 // all the usernames. |
1316 SimulateUsernameChange("baz"); | 1312 SimulateUsernameChange("baz"); |
| 1313 render_thread_->sink().ClearMessages(); |
1317 static_cast<PageClickListener*>(autofill_agent_) | 1314 static_cast<PageClickListener*>(autofill_agent_) |
1318 ->FormControlElementClicked(username_element_, true); | 1315 ->FormControlElementClicked(username_element_, true); |
1319 CheckSuggestions("baz", true); | 1316 CheckSuggestions("baz", true); |
1320 ClearUsernameAndPasswordFields(); | 1317 ClearUsernameAndPasswordFields(); |
1321 } | 1318 } |
1322 | 1319 |
1323 // Tests that there is an autosuggestion from the password manager when the | 1320 // Tests that there is an autosuggestion from the password manager when the |
1324 // user clicks on the password field when FillOnAccountSelect is enabled. | 1321 // user clicks on the password field when FillOnAccountSelect is enabled. |
1325 TEST_F(PasswordAutofillAgentTest, | 1322 TEST_F(PasswordAutofillAgentTest, |
1326 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { | 1323 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { |
1327 SetFillOnAccountSelect(); | 1324 SetFillOnAccountSelect(); |
1328 | 1325 |
1329 // Simulate the browser sending back the login info. | 1326 // Simulate the browser sending back the login info. |
1330 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); | 1327 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
1331 | 1328 |
1332 // Clear the text fields to start fresh. | 1329 // Clear the text fields to start fresh. |
1333 ClearUsernameAndPasswordFields(); | 1330 ClearUsernameAndPasswordFields(); |
1334 | 1331 |
1335 // Call SimulateElementClick() to produce a user gesture on the page so | 1332 // Call SimulateElementClick() to produce a user gesture on the page so |
1336 // autofill will actually fill. | 1333 // autofill will actually fill. |
1337 SimulateElementClick(kUsernameName); | 1334 SimulateElementClick(kUsernameName); |
1338 | 1335 |
1339 // Simulate a user clicking on the password element. This should produce no | 1336 // Simulate a user clicking on the password element. This should produce no |
1340 // message. | 1337 // message. |
1341 fake_driver_.reset_show_pw_suggestions(); | 1338 render_thread_->sink().ClearMessages(); |
1342 static_cast<PageClickListener*>(autofill_agent_) | 1339 static_cast<PageClickListener*>(autofill_agent_) |
1343 ->FormControlElementClicked(password_element_, false); | 1340 ->FormControlElementClicked(password_element_, false); |
1344 EXPECT_TRUE(GetCalledShowPasswordSuggestions()); | 1341 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 1342 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
1345 } | 1343 } |
1346 | 1344 |
1347 // Tests the autosuggestions that are given when a password element is clicked, | 1345 // Tests the autosuggestions that are given when a password element is clicked, |
1348 // the username element is not editable, and FillOnAccountSelect is enabled. | 1346 // the username element is not editable, and FillOnAccountSelect is enabled. |
1349 // Specifically, tests when the user clicks on the password element after page | 1347 // Specifically, tests when the user clicks on the password element after page |
1350 // load, and the corresponding username element is readonly (and thus | 1348 // load, and the corresponding username element is readonly (and thus |
1351 // uneditable), that the credentials for the already-filled username are | 1349 // uneditable), that the credentials for the already-filled username are |
1352 // suggested. | 1350 // suggested. |
1353 TEST_F(PasswordAutofillAgentTest, | 1351 TEST_F(PasswordAutofillAgentTest, |
1354 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { | 1352 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { |
(...skipping 10 matching lines...) Expand all Loading... |
1365 username_element_.setValue("alicia"); | 1363 username_element_.setValue("alicia"); |
1366 SetElementReadOnly(username_element_, true); | 1364 SetElementReadOnly(username_element_, true); |
1367 | 1365 |
1368 // Call SimulateElementClick() to produce a user gesture on the page so | 1366 // Call SimulateElementClick() to produce a user gesture on the page so |
1369 // autofill will actually fill. | 1367 // autofill will actually fill. |
1370 SimulateElementClick(kUsernameName); | 1368 SimulateElementClick(kUsernameName); |
1371 | 1369 |
1372 // Simulate a user clicking on the password element. This should produce a | 1370 // Simulate a user clicking on the password element. This should produce a |
1373 // dropdown with suggestion of all available usernames and so username | 1371 // dropdown with suggestion of all available usernames and so username |
1374 // filter will be the empty string. | 1372 // filter will be the empty string. |
| 1373 render_thread_->sink().ClearMessages(); |
1375 static_cast<PageClickListener*>(autofill_agent_) | 1374 static_cast<PageClickListener*>(autofill_agent_) |
1376 ->FormControlElementClicked(password_element_, false); | 1375 ->FormControlElementClicked(password_element_, false); |
1377 CheckSuggestions("", false); | 1376 CheckSuggestions("", false); |
1378 } | 1377 } |
1379 | 1378 |
1380 // Tests that there is an autosuggestion from the password manager when the | 1379 // Tests that there is an autosuggestion from the password manager when the |
1381 // user clicks on the password field. | 1380 // user clicks on the password field. |
1382 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { | 1381 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { |
1383 // Simulate the browser sending back the login info. | 1382 // Simulate the browser sending back the login info. |
1384 SimulateOnFillPasswordForm(fill_data_); | 1383 SimulateOnFillPasswordForm(fill_data_); |
1385 | 1384 |
1386 // Clear the text fields to start fresh. | 1385 // Clear the text fields to start fresh. |
1387 ClearUsernameAndPasswordFields(); | 1386 ClearUsernameAndPasswordFields(); |
1388 | 1387 |
1389 // Call SimulateElementClick() to produce a user gesture on the page so | 1388 // Call SimulateElementClick() to produce a user gesture on the page so |
1390 // autofill will actually fill. | 1389 // autofill will actually fill. |
1391 SimulateElementClick(kUsernameName); | 1390 SimulateElementClick(kUsernameName); |
1392 | 1391 |
1393 // Simulate a user clicking on the password element. This should produce no | 1392 // Simulate a user clicking on the password element. This should produce no |
1394 // message. | 1393 // message. |
1395 fake_driver_.reset_show_pw_suggestions(); | 1394 render_thread_->sink().ClearMessages(); |
1396 static_cast<PageClickListener*>(autofill_agent_) | 1395 static_cast<PageClickListener*>(autofill_agent_) |
1397 ->FormControlElementClicked(password_element_, false); | 1396 ->FormControlElementClicked(password_element_, false); |
1398 EXPECT_TRUE(GetCalledShowPasswordSuggestions()); | 1397 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 1398 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
1399 } | 1399 } |
1400 | 1400 |
1401 // The user types in a username and a password, but then just before sending | 1401 // The user types in a username and a password, but then just before sending |
1402 // the form off, a script clears them. This test checks that | 1402 // the form off, a script clears them. This test checks that |
1403 // PasswordAutofillAgent can still remember the username and the password | 1403 // PasswordAutofillAgent can still remember the username and the password |
1404 // typed by the user. | 1404 // typed by the user. |
1405 TEST_F(PasswordAutofillAgentTest, | 1405 TEST_F(PasswordAutofillAgentTest, |
1406 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { | 1406 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { |
1407 SimulateUsernameChange("temp"); | 1407 SimulateUsernameChange("temp"); |
1408 SimulatePasswordChange("random"); | 1408 SimulatePasswordChange("random"); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 ->WillSubmitForm(username_element_.form()); | 1534 ->WillSubmitForm(username_element_.form()); |
1535 | 1535 |
1536 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; | 1536 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; |
1537 expected_properties_masks[ASCIIToUTF16("random_field")] = | 1537 expected_properties_masks[ASCIIToUTF16("random_field")] = |
1538 FieldPropertiesFlags::NO_FLAGS; | 1538 FieldPropertiesFlags::NO_FLAGS; |
1539 expected_properties_masks[ASCIIToUTF16("username")] = | 1539 expected_properties_masks[ASCIIToUTF16("username")] = |
1540 FieldPropertiesFlags::USER_TYPED; | 1540 FieldPropertiesFlags::USER_TYPED; |
1541 expected_properties_masks[ASCIIToUTF16("password")] = | 1541 expected_properties_masks[ASCIIToUTF16("password")] = |
1542 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; | 1542 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; |
1543 | 1543 |
1544 ExpectFieldPropertiesMasks(PasswordFormSubmitted, expected_properties_masks); | 1544 ExpectFieldPropertiesMasks(AutofillHostMsg_PasswordFormSubmitted::ID, |
| 1545 expected_properties_masks); |
1545 } | 1546 } |
1546 | 1547 |
1547 TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) { | 1548 TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) { |
1548 LoadHTML(kNoFormHTML); | 1549 LoadHTML(kNoFormHTML); |
1549 UpdateUsernameAndPasswordElements(); | 1550 UpdateUsernameAndPasswordElements(); |
1550 | 1551 |
1551 SimulateUsernameChange("Bob"); | 1552 SimulateUsernameChange("Bob"); |
1552 SimulatePasswordChange("mypassword"); | 1553 SimulatePasswordChange("mypassword"); |
1553 | 1554 |
1554 username_element_.setAttribute("style", "display:none;"); | 1555 username_element_.setAttribute("style", "display:none;"); |
1555 password_element_.setAttribute("style", "display:none;"); | 1556 password_element_.setAttribute("style", "display:none;"); |
1556 | 1557 |
1557 password_autofill_agent_->AJAXSucceeded(); | 1558 password_autofill_agent_->AJAXSucceeded(); |
1558 | 1559 |
1559 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; | 1560 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; |
1560 expected_properties_masks[ASCIIToUTF16("username")] = | 1561 expected_properties_masks[ASCIIToUTF16("username")] = |
1561 FieldPropertiesFlags::USER_TYPED; | 1562 FieldPropertiesFlags::USER_TYPED; |
1562 expected_properties_masks[ASCIIToUTF16("password")] = | 1563 expected_properties_masks[ASCIIToUTF16("password")] = |
1563 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; | 1564 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; |
1564 | 1565 |
1565 ExpectFieldPropertiesMasks(PasswordFormInPageNavigation, | 1566 ExpectFieldPropertiesMasks(AutofillHostMsg_InPageNavigation::ID, |
1566 expected_properties_masks); | 1567 expected_properties_masks); |
1567 } | 1568 } |
1568 | 1569 |
1569 // The username/password is autofilled by password manager then just before | 1570 // The username/password is autofilled by password manager then just before |
1570 // sending the form off, a script changes them. This test checks that | 1571 // sending the form off, a script changes them. This test checks that |
1571 // PasswordAutofillAgent can still get the username and the password autofilled. | 1572 // PasswordAutofillAgent can still get the username and the password autofilled. |
1572 TEST_F(PasswordAutofillAgentTest, | 1573 TEST_F(PasswordAutofillAgentTest, |
1573 RememberLastAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { | 1574 RememberLastAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { |
1574 SimulateOnFillPasswordForm(fill_data_); | 1575 SimulateOnFillPasswordForm(fill_data_); |
1575 | 1576 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 // Simulate the browser sending back the login info for an initial page load. | 1795 // Simulate the browser sending back the login info for an initial page load. |
1795 SimulateOnFillPasswordForm(fill_data_); | 1796 SimulateOnFillPasswordForm(fill_data_); |
1796 | 1797 |
1797 // Do not show popup suggesstion when the password field is not-empty and not | 1798 // Do not show popup suggesstion when the password field is not-empty and not |
1798 // autofilled. | 1799 // autofilled. |
1799 password_element_.setValue("123"); | 1800 password_element_.setValue("123"); |
1800 password_element_.setAutofilled(false); | 1801 password_element_.setAutofilled(false); |
1801 | 1802 |
1802 SimulateSuggestionChoiceOfUsernameAndPassword( | 1803 SimulateSuggestionChoiceOfUsernameAndPassword( |
1803 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); | 1804 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); |
1804 ASSERT_FALSE(GetCalledShowPasswordSuggestions()); | 1805 ASSERT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 1806 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
1805 } | 1807 } |
1806 | 1808 |
1807 // Tests with fill-on-account-select enabled that if the username element is | 1809 // Tests with fill-on-account-select enabled that if the username element is |
1808 // read-only and filled with an unknown username, then the password field is not | 1810 // read-only and filled with an unknown username, then the password field is not |
1809 // highlighted as autofillable (regression test for https://crbug.com/442564). | 1811 // highlighted as autofillable (regression test for https://crbug.com/442564). |
1810 TEST_F(PasswordAutofillAgentTest, | 1812 TEST_F(PasswordAutofillAgentTest, |
1811 FillOnAccountSelectOnlyReadonlyUnknownUsername) { | 1813 FillOnAccountSelectOnlyReadonlyUnknownUsername) { |
1812 SetFillOnAccountSelect(); | 1814 SetFillOnAccountSelect(); |
1813 | 1815 |
1814 ClearUsernameAndPasswordFields(); | 1816 ClearUsernameAndPasswordFields(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 blink::WebFormElement form_element = username_element_.form(); | 1853 blink::WebFormElement form_element = username_element_.form(); |
1852 FormData form_data; | 1854 FormData form_data; |
1853 ASSERT_TRUE(WebFormElementToFormData( | 1855 ASSERT_TRUE(WebFormElementToFormData( |
1854 form_element, blink::WebFormControlElement(), nullptr, | 1856 form_element, blink::WebFormControlElement(), nullptr, |
1855 form_util::EXTRACT_NONE, &form_data, nullptr)); | 1857 form_util::EXTRACT_NONE, &form_data, nullptr)); |
1856 // Simulate Autofill predictions: the first field is username, the third | 1858 // Simulate Autofill predictions: the first field is username, the third |
1857 // one is password. | 1859 // one is password. |
1858 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; | 1860 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
1859 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME; | 1861 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME; |
1860 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD; | 1862 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD; |
1861 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( | 1863 AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions); |
1862 predictions); | 1864 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 1865 ->OnMessageReceived(msg); |
1863 | 1866 |
1864 // The predictions should still match even if the form changes, as long | 1867 // The predictions should still match even if the form changes, as long |
1865 // as the particular elements don't change. | 1868 // as the particular elements don't change. |
1866 std::string add_field_to_form = | 1869 std::string add_field_to_form = |
1867 "var form = document.getElementById('LoginTestForm');" | 1870 "var form = document.getElementById('LoginTestForm');" |
1868 "var new_input = document.createElement('input');" | 1871 "var new_input = document.createElement('input');" |
1869 "new_input.setAttribute('type', 'text');" | 1872 "new_input.setAttribute('type', 'text');" |
1870 "new_input.setAttribute('id', 'other_field');" | 1873 "new_input.setAttribute('id', 'other_field');" |
1871 "form.appendChild(new_input);"; | 1874 "form.appendChild(new_input);"; |
1872 ExecuteJavaScriptForTests(add_field_to_form.c_str()); | 1875 ExecuteJavaScriptForTests(add_field_to_form.c_str()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 // generation both trigger. Regression test for https://crbug.com/493455. | 1927 // generation both trigger. Regression test for https://crbug.com/493455. |
1925 TEST_F(PasswordAutofillAgentTest, | 1928 TEST_F(PasswordAutofillAgentTest, |
1926 PasswordGenerationTriggered_GeneratedPassword) { | 1929 PasswordGenerationTriggered_GeneratedPassword) { |
1927 SimulateOnFillPasswordForm(fill_data_); | 1930 SimulateOnFillPasswordForm(fill_data_); |
1928 | 1931 |
1929 SetNotBlacklistedMessage(password_generation_, kFormHTML); | 1932 SetNotBlacklistedMessage(password_generation_, kFormHTML); |
1930 SetAccountCreationFormsDetectedMessage(password_generation_, | 1933 SetAccountCreationFormsDetectedMessage(password_generation_, |
1931 GetMainFrame()->document(), 0, 2); | 1934 GetMainFrame()->document(), 0, 2); |
1932 | 1935 |
1933 base::string16 password = base::ASCIIToUTF16("NewPass22"); | 1936 base::string16 password = base::ASCIIToUTF16("NewPass22"); |
1934 password_generation_->GeneratedPasswordAccepted(password); | 1937 AutofillMsg_GeneratedPasswordAccepted msg(0, password); |
| 1938 static_cast<IPC::Listener*>(password_generation_)->OnMessageReceived(msg); |
1935 | 1939 |
1936 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1940 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1937 ->WillSendSubmitEvent(username_element_.form()); | 1941 ->WillSendSubmitEvent(username_element_.form()); |
1938 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1942 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1939 ->WillSubmitForm(username_element_.form()); | 1943 ->WillSubmitForm(username_element_.form()); |
1940 | 1944 |
1941 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); | 1945 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); |
1942 } | 1946 } |
1943 | 1947 |
1944 // If password generation is enabled for a field, password autofill should not | 1948 // If password generation is enabled for a field, password autofill should not |
(...skipping 20 matching lines...) Expand all Loading... |
1965 // Simulate generation triggering. | 1969 // Simulate generation triggering. |
1966 SetNotBlacklistedMessage(password_generation_, | 1970 SetNotBlacklistedMessage(password_generation_, |
1967 kSignupFormHTML); | 1971 kSignupFormHTML); |
1968 SetAccountCreationFormsDetectedMessage(password_generation_, | 1972 SetAccountCreationFormsDetectedMessage(password_generation_, |
1969 GetMainFrame()->document(), 0, 1); | 1973 GetMainFrame()->document(), 0, 1); |
1970 | 1974 |
1971 // Simulate the field being clicked to start typing. This should trigger | 1975 // Simulate the field being clicked to start typing. This should trigger |
1972 // generation but not password autofill. | 1976 // generation but not password autofill. |
1973 SetFocused(password_element_); | 1977 SetFocused(password_element_); |
1974 SimulateElementClick("new_password"); | 1978 SimulateElementClick("new_password"); |
1975 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); | 1979 EXPECT_EQ(nullptr, |
| 1980 render_thread_->sink().GetFirstMessageMatching( |
| 1981 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
1976 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1982 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
1977 AutofillHostMsg_ShowPasswordGenerationPopup::ID)); | 1983 AutofillHostMsg_ShowPasswordGenerationPopup::ID)); |
1978 } | 1984 } |
1979 | 1985 |
1980 // Tests that a password change form is properly filled with the username and | 1986 // Tests that a password change form is properly filled with the username and |
1981 // password. | 1987 // password. |
1982 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { | 1988 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { |
1983 LoadHTML(kPasswordChangeFormHTML); | 1989 LoadHTML(kPasswordChangeFormHTML); |
1984 UpdateOriginForHTML(kPasswordChangeFormHTML); | 1990 UpdateOriginForHTML(kPasswordChangeFormHTML); |
1985 UpdateUsernameAndPasswordElements(); | 1991 UpdateUsernameAndPasswordElements(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2027 LoadHTML(kPasswordChangeFormHTML); | 2033 LoadHTML(kPasswordChangeFormHTML); |
2028 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2034 UpdateOriginForHTML(kPasswordChangeFormHTML); |
2029 UpdateUsernameAndPasswordElements(); | 2035 UpdateUsernameAndPasswordElements(); |
2030 | 2036 |
2031 ClearUsernameAndPasswordFields(); | 2037 ClearUsernameAndPasswordFields(); |
2032 fill_data_.wait_for_username = true; | 2038 fill_data_.wait_for_username = true; |
2033 fill_data_.is_possible_change_password_form = true; | 2039 fill_data_.is_possible_change_password_form = true; |
2034 SimulateOnFillPasswordForm(fill_data_); | 2040 SimulateOnFillPasswordForm(fill_data_); |
2035 // Simulate a user clicking on the username element. This should produce a | 2041 // Simulate a user clicking on the username element. This should produce a |
2036 // message. | 2042 // message. |
| 2043 render_thread_->sink().ClearMessages(); |
2037 static_cast<PageClickListener*>(autofill_agent_) | 2044 static_cast<PageClickListener*>(autofill_agent_) |
2038 ->FormControlElementClicked(username_element_, true); | 2045 ->FormControlElementClicked(username_element_, true); |
2039 CheckSuggestions("", true); | 2046 CheckSuggestions("", true); |
2040 } | 2047 } |
2041 | 2048 |
2042 // Tests that one user click on a password field is sufficient to bring up a | 2049 // Tests that one user click on a password field is sufficient to bring up a |
2043 // credential suggestion popup on a change password form. | 2050 // credential suggestion popup on a change password form. |
2044 TEST_F(PasswordAutofillAgentTest, | 2051 TEST_F(PasswordAutofillAgentTest, |
2045 SuggestionsOnPasswordFieldOfChangePasswordForm) { | 2052 SuggestionsOnPasswordFieldOfChangePasswordForm) { |
2046 LoadHTML(kPasswordChangeFormHTML); | 2053 LoadHTML(kPasswordChangeFormHTML); |
2047 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2054 UpdateOriginForHTML(kPasswordChangeFormHTML); |
2048 UpdateUsernameAndPasswordElements(); | 2055 UpdateUsernameAndPasswordElements(); |
2049 | 2056 |
2050 ClearUsernameAndPasswordFields(); | 2057 ClearUsernameAndPasswordFields(); |
2051 fill_data_.wait_for_username = true; | 2058 fill_data_.wait_for_username = true; |
2052 fill_data_.is_possible_change_password_form = true; | 2059 fill_data_.is_possible_change_password_form = true; |
2053 SimulateOnFillPasswordForm(fill_data_); | 2060 SimulateOnFillPasswordForm(fill_data_); |
2054 // Simulate a user clicking on the password element. This should produce a | 2061 // Simulate a user clicking on the password element. This should produce a |
2055 // message. | 2062 // message. |
| 2063 render_thread_->sink().ClearMessages(); |
2056 static_cast<PageClickListener*>(autofill_agent_) | 2064 static_cast<PageClickListener*>(autofill_agent_) |
2057 ->FormControlElementClicked(password_element_, true); | 2065 ->FormControlElementClicked(password_element_, true); |
2058 CheckSuggestions("", false); | 2066 CheckSuggestions("", false); |
2059 } | 2067 } |
2060 | 2068 |
2061 // Tests that NOT_PASSWORD field predictions are followed so that no password | 2069 // Tests that NOT_PASSWORD field predictions are followed so that no password |
2062 // form is submitted. | 2070 // form is submitted. |
2063 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { | 2071 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { |
2064 LoadHTML(kCreditCardFormHTML); | 2072 LoadHTML(kCreditCardFormHTML); |
2065 blink::WebInputElement credit_card_owner_element = | 2073 blink::WebInputElement credit_card_owner_element = |
2066 GetInputElementByID(kCreditCardOwnerName); | 2074 GetInputElementByID(kCreditCardOwnerName); |
2067 blink::WebInputElement credit_card_number_element = | 2075 blink::WebInputElement credit_card_number_element = |
2068 GetInputElementByID(kCreditCardNumberName); | 2076 GetInputElementByID(kCreditCardNumberName); |
2069 blink::WebInputElement credit_card_verification_element = | 2077 blink::WebInputElement credit_card_verification_element = |
2070 GetInputElementByID(kCreditCardVerificationName); | 2078 GetInputElementByID(kCreditCardVerificationName); |
2071 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith"); | 2079 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith"); |
2072 SimulateUserInputChangeForElement(&credit_card_number_element, | 2080 SimulateUserInputChangeForElement(&credit_card_number_element, |
2073 "1234123412341234"); | 2081 "1234123412341234"); |
2074 SimulateUserInputChangeForElement(&credit_card_verification_element, "123"); | 2082 SimulateUserInputChangeForElement(&credit_card_verification_element, "123"); |
2075 // Find FormData for visible form. | 2083 // Find FormData for visible form. |
2076 blink::WebFormElement form_element = credit_card_number_element.form(); | 2084 blink::WebFormElement form_element = credit_card_number_element.form(); |
2077 FormData form_data; | 2085 FormData form_data; |
2078 ASSERT_TRUE(WebFormElementToFormData( | 2086 ASSERT_TRUE(WebFormElementToFormData( |
2079 form_element, blink::WebFormControlElement(), nullptr, | 2087 form_element, blink::WebFormControlElement(), nullptr, |
2080 form_util::EXTRACT_NONE, &form_data, nullptr)); | 2088 form_util::EXTRACT_NONE, &form_data, nullptr)); |
2081 // Simulate Autofill predictions: the third field is not a password. | 2089 // Simulate Autofill predictions: the third field is not a password. |
2082 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; | 2090 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
2083 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; | 2091 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; |
2084 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( | 2092 AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions); |
2085 predictions); | 2093 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 2094 ->OnMessageReceived(msg); |
2086 | 2095 |
2087 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2096 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
2088 ->WillSendSubmitEvent(form_element); | 2097 ->WillSendSubmitEvent(form_element); |
2089 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2098 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
2090 ->WillSubmitForm(form_element); | 2099 ->WillSubmitForm(form_element); |
2091 | 2100 |
2092 base::RunLoop().RunUntilIdle(); | 2101 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
2093 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); | 2102 AutofillHostMsg_PasswordFormSubmitted::ID); |
| 2103 ASSERT_FALSE(message); |
2094 } | 2104 } |
2095 | 2105 |
2096 // Tests that only the password field is autocompleted when the browser sends | 2106 // Tests that only the password field is autocompleted when the browser sends |
2097 // back data with only one credentials and empty username. | 2107 // back data with only one credentials and empty username. |
2098 TEST_F(PasswordAutofillAgentTest, NotAutofillNoUsername) { | 2108 TEST_F(PasswordAutofillAgentTest, NotAutofillNoUsername) { |
2099 fill_data_.username_field.value.clear(); | 2109 fill_data_.username_field.value.clear(); |
2100 fill_data_.additional_logins.clear(); | 2110 fill_data_.additional_logins.clear(); |
2101 SimulateOnFillPasswordForm(fill_data_); | 2111 SimulateOnFillPasswordForm(fill_data_); |
2102 | 2112 |
2103 CheckTextFieldsState("", false, kAlicePassword, true); | 2113 CheckTextFieldsState("", false, kAlicePassword, true); |
(...skipping 29 matching lines...) Expand all Loading... |
2133 TEST_F(PasswordAutofillAgentTest, | 2143 TEST_F(PasswordAutofillAgentTest, |
2134 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) { | 2144 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) { |
2135 LoadHTML(kNoFormHTML); | 2145 LoadHTML(kNoFormHTML); |
2136 UpdateUsernameAndPasswordElements(); | 2146 UpdateUsernameAndPasswordElements(); |
2137 | 2147 |
2138 SimulateUsernameChange("Bob"); | 2148 SimulateUsernameChange("Bob"); |
2139 SimulatePasswordChange("mypassword"); | 2149 SimulatePasswordChange("mypassword"); |
2140 | 2150 |
2141 password_autofill_agent_->AJAXSucceeded(); | 2151 password_autofill_agent_->AJAXSucceeded(); |
2142 | 2152 |
2143 base::RunLoop().RunUntilIdle(); | 2153 const IPC::Message* message = |
2144 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); | 2154 render_thread_->sink().GetFirstMessageMatching( |
| 2155 AutofillHostMsg_PasswordFormSubmitted::ID); |
| 2156 ASSERT_FALSE(message); |
2145 } | 2157 } |
2146 | 2158 |
2147 // Tests that credential suggestions are autofilled on a password (and change | 2159 // Tests that credential suggestions are autofilled on a password (and change |
2148 // password) forms having either ambiguous or empty name. | 2160 // password) forms having either ambiguous or empty name. |
2149 TEST_F(PasswordAutofillAgentTest, | 2161 TEST_F(PasswordAutofillAgentTest, |
2150 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { | 2162 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { |
2151 const char kEmpty[] = ""; | 2163 const char kEmpty[] = ""; |
2152 const char kDummyUsernameField[] = "anonymous_username"; | 2164 const char kDummyUsernameField[] = "anonymous_username"; |
2153 const char kDummyPasswordField[] = "anonymous_password"; | 2165 const char kDummyPasswordField[] = "anonymous_password"; |
2154 const char kFormContainsEmptyNamesHTML[] = | 2166 const char kFormContainsEmptyNamesHTML[] = |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2381 TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) { | 2393 TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) { |
2382 // Simulate the browser sending back the login info. | 2394 // Simulate the browser sending back the login info. |
2383 SimulateOnFillPasswordForm(fill_data_); | 2395 SimulateOnFillPasswordForm(fill_data_); |
2384 | 2396 |
2385 // Call SimulateElementClick() to produce a user gesture on the page so | 2397 // Call SimulateElementClick() to produce a user gesture on the page so |
2386 // autofill will actually fill. | 2398 // autofill will actually fill. |
2387 SimulateElementClick(kUsernameName); | 2399 SimulateElementClick(kUsernameName); |
2388 | 2400 |
2389 // Simulate a user clicking on the password element. This should produce a | 2401 // Simulate a user clicking on the password element. This should produce a |
2390 // dropdown with suggestion of all available usernames. | 2402 // dropdown with suggestion of all available usernames. |
| 2403 render_thread_->sink().ClearMessages(); |
2391 static_cast<PageClickListener*>(autofill_agent_) | 2404 static_cast<PageClickListener*>(autofill_agent_) |
2392 ->FormControlElementClicked(password_element_, false); | 2405 ->FormControlElementClicked(password_element_, false); |
2393 CheckSuggestions("", false); | 2406 CheckSuggestions("", false); |
2394 } | 2407 } |
2395 | 2408 |
2396 // Tests that a suggestion dropdown is shown on each password field. But when a | 2409 // Tests that a suggestion dropdown is shown on each password field. But when a |
2397 // user chose one of the fields to autofill, a suggestion dropdown will be shown | 2410 // user chose one of the fields to autofill, a suggestion dropdown will be shown |
2398 // only on this field. | 2411 // only on this field. |
2399 TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) { | 2412 TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) { |
2400 LoadHTML(kPasswordChangeFormHTML); | 2413 LoadHTML(kPasswordChangeFormHTML); |
2401 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2414 UpdateOriginForHTML(kPasswordChangeFormHTML); |
2402 UpdateUsernameAndPasswordElements(); | 2415 UpdateUsernameAndPasswordElements(); |
2403 | 2416 |
2404 // Simulate the browser sending back the login info. | 2417 // Simulate the browser sending back the login info. |
2405 SimulateOnFillPasswordForm(fill_data_); | 2418 SimulateOnFillPasswordForm(fill_data_); |
2406 | 2419 |
2407 // Call SimulateElementClick() to produce a user gesture on the page so | 2420 // Call SimulateElementClick() to produce a user gesture on the page so |
2408 // autofill will actually fill. | 2421 // autofill will actually fill. |
2409 SimulateElementClick(kUsernameName); | 2422 SimulateElementClick(kUsernameName); |
2410 | 2423 |
2411 // Simulate a user clicking on the password elements. This should produce | 2424 // Simulate a user clicking on the password elements. This should produce |
2412 // dropdowns with suggestion of all available usernames. | 2425 // dropdowns with suggestion of all available usernames. |
| 2426 render_thread_->sink().ClearMessages(); |
2413 SimulateElementClick("password"); | 2427 SimulateElementClick("password"); |
2414 CheckSuggestions("", false); | 2428 CheckSuggestions("", false); |
2415 | 2429 |
2416 SimulateElementClick("newpassword"); | 2430 SimulateElementClick("newpassword"); |
2417 CheckSuggestions("", false); | 2431 CheckSuggestions("", false); |
2418 | 2432 |
2419 SimulateElementClick("confirmpassword"); | 2433 SimulateElementClick("confirmpassword"); |
2420 CheckSuggestions("", false); | 2434 CheckSuggestions("", false); |
2421 | 2435 |
2422 // The user chooses to autofill the current password field. | 2436 // The user chooses to autofill the current password field. |
2423 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( | 2437 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( |
2424 password_element_, ASCIIToUTF16(kAliceUsername), | 2438 password_element_, ASCIIToUTF16(kAliceUsername), |
2425 ASCIIToUTF16(kAlicePassword))); | 2439 ASCIIToUTF16(kAlicePassword))); |
2426 | 2440 |
2427 // Simulate a user clicking on not autofilled password fields. This should | 2441 // Simulate a user clicking on not autofilled password fields. This should |
2428 // produce no suggestion dropdowns. | 2442 // produce |
2429 fake_driver_.reset_show_pw_suggestions(); | 2443 // no suggestion dropdowns. |
| 2444 render_thread_->sink().ClearMessages(); |
2430 SimulateElementClick("newpassword"); | 2445 SimulateElementClick("newpassword"); |
2431 SimulateElementClick("confirmpassword"); | 2446 SimulateElementClick("confirmpassword"); |
2432 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); | 2447 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 2448 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
2433 | 2449 |
2434 // But when the user clicks on the autofilled password field again it should | 2450 // But when the user clicks on the autofilled password field again it should |
2435 // still produce a suggestion dropdown. | 2451 // still produce a suggestion dropdown. |
2436 SimulateElementClick("password"); | 2452 SimulateElementClick("password"); |
2437 CheckSuggestions("", false); | 2453 CheckSuggestions("", false); |
2438 } | 2454 } |
2439 | 2455 |
2440 } // namespace autofill | 2456 } // namespace autofill |
OLD | NEW |