| 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 | |
| 7 #include "base/feature_list.h" | 5 #include "base/feature_list.h" |
| 8 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/run_loop.h" |
| 9 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 9 #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" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "third_party/WebKit/public/platform/WebString.h" | 29 #include "third_party/WebKit/public/platform/WebString.h" |
| 28 #include "third_party/WebKit/public/platform/WebVector.h" | 30 #include "third_party/WebKit/public/platform/WebVector.h" |
| 29 #include "third_party/WebKit/public/web/WebDocument.h" | 31 #include "third_party/WebKit/public/web/WebDocument.h" |
| 30 #include "third_party/WebKit/public/web/WebElement.h" | 32 #include "third_party/WebKit/public/web/WebElement.h" |
| 31 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 33 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 32 #include "third_party/WebKit/public/web/WebFormElement.h" | 34 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 33 #include "third_party/WebKit/public/web/WebInputElement.h" | 35 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 34 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 36 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 35 #include "third_party/WebKit/public/web/WebNode.h" | 37 #include "third_party/WebKit/public/web/WebNode.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 " <INPUT type='password' id='password2' name='password'/>" | 223 " <INPUT type='password' id='password2' name='password'/>" |
| 222 " <INPUT type='submit' value='Login'/>" | 224 " <INPUT type='submit' value='Login'/>" |
| 223 "</FORM>"; | 225 "</FORM>"; |
| 224 | 226 |
| 225 // Sets the "readonly" attribute of |element| to the value given by |read_only|. | 227 // Sets the "readonly" attribute of |element| to the value given by |read_only|. |
| 226 void SetElementReadOnly(WebInputElement& element, bool read_only) { | 228 void SetElementReadOnly(WebInputElement& element, bool read_only) { |
| 227 element.setAttribute(WebString::fromUTF8("readonly"), | 229 element.setAttribute(WebString::fromUTF8("readonly"), |
| 228 read_only ? WebString::fromUTF8("true") : WebString()); | 230 read_only ? WebString::fromUTF8("true") : WebString()); |
| 229 } | 231 } |
| 230 | 232 |
| 233 enum PasswordFormSourceType { |
| 234 PasswordFormSubmitted, |
| 235 PasswordFormInPageNavigation, |
| 236 }; |
| 237 |
| 231 } // namespace | 238 } // namespace |
| 232 | 239 |
| 233 namespace autofill { | 240 namespace autofill { |
| 234 | 241 |
| 235 class PasswordAutofillAgentTest : public ChromeRenderViewTest { | 242 class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
| 236 public: | 243 public: |
| 237 PasswordAutofillAgentTest() { | 244 PasswordAutofillAgentTest() { |
| 238 } | 245 } |
| 239 | 246 |
| 240 // Simulates the fill password form message being sent to the renderer. | 247 // Simulates the fill password form message being sent to the renderer. |
| 241 // We use that so we don't have to make RenderView::OnFillPasswordForm() | 248 // We use that so we don't have to make RenderView::OnFillPasswordForm() |
| 242 // protected. | 249 // protected. |
| 243 void SimulateOnFillPasswordForm( | 250 void SimulateOnFillPasswordForm( |
| 244 const PasswordFormFillData& fill_data) { | 251 const PasswordFormFillData& fill_data) { |
| 245 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); | 252 password_autofill_agent_->FillPasswordForm(kPasswordFillFormDataId, |
| 246 static_cast<IPC::Listener*>(password_autofill_agent_) | 253 fill_data); |
| 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); | |
| 256 } | 254 } |
| 257 | 255 |
| 258 // Simulates the show initial password account suggestions message being sent | 256 // Simulates the show initial password account suggestions message being sent |
| 259 // to the renderer. | 257 // to the renderer. |
| 260 void SimulateOnShowInitialPasswordAccountSuggestions( | 258 void SimulateOnShowInitialPasswordAccountSuggestions( |
| 261 const PasswordFormFillData& fill_data) { | 259 const PasswordFormFillData& fill_data) { |
| 262 autofill_agent_->ShowInitialPasswordAccountSuggestions( | 260 autofill_agent_->ShowInitialPasswordAccountSuggestions( |
| 263 kPasswordFillFormDataId, fill_data); | 261 kPasswordFillFormDataId, fill_data); |
| 264 } | 262 } |
| 265 | 263 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // Now retrieve the input elements so the test can access them. | 316 // Now retrieve the input elements so the test can access them. |
| 319 UpdateUsernameAndPasswordElements(); | 317 UpdateUsernameAndPasswordElements(); |
| 320 } | 318 } |
| 321 | 319 |
| 322 void TearDown() override { | 320 void TearDown() override { |
| 323 username_element_.reset(); | 321 username_element_.reset(); |
| 324 password_element_.reset(); | 322 password_element_.reset(); |
| 325 ChromeRenderViewTest::TearDown(); | 323 ChromeRenderViewTest::TearDown(); |
| 326 } | 324 } |
| 327 | 325 |
| 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 |
| 328 void SetFillOnAccountSelect() { | 338 void SetFillOnAccountSelect() { |
| 329 base::FeatureList::ClearInstanceForTesting(); | 339 base::FeatureList::ClearInstanceForTesting(); |
| 330 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 340 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 331 feature_list->InitializeFromCommandLine( | 341 feature_list->InitializeFromCommandLine( |
| 332 password_manager::features::kFillOnAccountSelect.name, ""); | 342 password_manager::features::kFillOnAccountSelect.name, ""); |
| 333 base::FeatureList::SetInstance(std::move(feature_list)); | 343 base::FeatureList::SetInstance(std::move(feature_list)); |
| 334 } | 344 } |
| 335 | 345 |
| 336 void UpdateOriginForHTML(const std::string& html) { | 346 void UpdateOriginForHTML(const std::string& html) { |
| 337 std::string origin = "data:text/html;charset=utf-8," + html; | 347 std::string origin = "data:text/html;charset=utf-8," + html; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, | 379 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, |
| 370 password); | 380 password); |
| 371 } | 381 } |
| 372 | 382 |
| 373 void SimulateSuggestionChoiceOfUsernameAndPassword( | 383 void SimulateSuggestionChoiceOfUsernameAndPassword( |
| 374 WebInputElement& input, | 384 WebInputElement& input, |
| 375 const base::string16& username, | 385 const base::string16& username, |
| 376 const base::string16& password) { | 386 const base::string16& password) { |
| 377 // This call is necessary to setup the autofill agent appropriate for the | 387 // This call is necessary to setup the autofill agent appropriate for the |
| 378 // user selection; simulates the menu actually popping up. | 388 // user selection; simulates the menu actually popping up. |
| 379 render_thread_->sink().ClearMessages(); | |
| 380 static_cast<autofill::PageClickListener*>(autofill_agent_) | 389 static_cast<autofill::PageClickListener*>(autofill_agent_) |
| 381 ->FormControlElementClicked(input, false); | 390 ->FormControlElementClicked(input, false); |
| 382 | 391 |
| 383 autofill_agent_->FillPasswordSuggestion(username, password); | 392 autofill_agent_->FillPasswordSuggestion(username, password); |
| 384 } | 393 } |
| 385 | 394 |
| 386 void SimulateUsernameChange(const std::string& username) { | 395 void SimulateUsernameChange(const std::string& username) { |
| 387 SimulateUserInputChangeForElement(&username_element_, username); | 396 SimulateUserInputChangeForElement(&username_element_, username); |
| 388 } | 397 } |
| 389 | 398 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 void CheckUsernameSelection(int start, int end) { | 451 void CheckUsernameSelection(int start, int end) { |
| 443 EXPECT_EQ(start, username_element_.selectionStart()); | 452 EXPECT_EQ(start, username_element_.selectionStart()); |
| 444 EXPECT_EQ(end, username_element_.selectionEnd()); | 453 EXPECT_EQ(end, username_element_.selectionEnd()); |
| 445 } | 454 } |
| 446 | 455 |
| 447 // Checks the message sent to PasswordAutofillManager to build the suggestion | 456 // Checks the message sent to PasswordAutofillManager to build the suggestion |
| 448 // list. |username| is the expected username field value, and |show_all| is | 457 // list. |username| is the expected username field value, and |show_all| is |
| 449 // the expected flag for the PasswordAutofillManager, whether to show all | 458 // the expected flag for the PasswordAutofillManager, whether to show all |
| 450 // suggestions, or only those starting with |username|. | 459 // suggestions, or only those starting with |username|. |
| 451 void CheckSuggestions(const std::string& username, bool show_all) { | 460 void CheckSuggestions(const std::string& username, bool show_all) { |
| 452 const IPC::Message* message = | 461 base::RunLoop().RunUntilIdle(); |
| 453 render_thread_->sink().GetFirstMessageMatching( | 462 |
| 454 AutofillHostMsg_ShowPasswordSuggestions::ID); | 463 ASSERT_TRUE(fake_driver_.called_show_pw_suggestions()); |
| 455 ASSERT_TRUE(message); | 464 EXPECT_EQ(kPasswordFillFormDataId, fake_driver_.show_pw_suggestions_key()); |
| 456 std::tuple<int, base::i18n::TextDirection, base::string16, int, gfx::RectF> | 465 ASSERT_TRUE(static_cast<bool>(fake_driver_.show_pw_suggestions_username())); |
| 457 args; | 466 EXPECT_EQ(ASCIIToUTF16(username), |
| 458 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); | 467 *(fake_driver_.show_pw_suggestions_username())); |
| 459 EXPECT_EQ(kPasswordFillFormDataId, std::get<0>(args)); | |
| 460 EXPECT_EQ(ASCIIToUTF16(username), std::get<2>(args)); | |
| 461 EXPECT_EQ(show_all, | 468 EXPECT_EQ(show_all, |
| 462 static_cast<bool>(std::get<3>(args) & autofill::SHOW_ALL)); | 469 static_cast<bool>(fake_driver_.show_pw_suggestions_options() & |
| 470 autofill::SHOW_ALL)); |
| 463 | 471 |
| 464 render_thread_->sink().ClearMessages(); | 472 fake_driver_.reset_show_pw_suggestions(); |
| 473 } |
| 474 |
| 475 bool GetCalledShowPasswordSuggestions() { |
| 476 base::RunLoop().RunUntilIdle(); |
| 477 return fake_driver_.called_show_pw_suggestions(); |
| 465 } | 478 } |
| 466 | 479 |
| 467 void ExpectFormSubmittedWithUsernameAndPasswords( | 480 void ExpectFormSubmittedWithUsernameAndPasswords( |
| 468 const std::string& username_value, | 481 const std::string& username_value, |
| 469 const std::string& password_value, | 482 const std::string& password_value, |
| 470 const std::string& new_password_value) { | 483 const std::string& new_password_value) { |
| 471 const IPC::Message* message = | 484 base::RunLoop().RunUntilIdle(); |
| 472 render_thread_->sink().GetFirstMessageMatching( | 485 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); |
| 473 AutofillHostMsg_PasswordFormSubmitted::ID); | 486 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted())); |
| 474 ASSERT_TRUE(message); | 487 const autofill::PasswordForm& form = |
| 475 std::tuple<autofill::PasswordForm> args; | 488 *(fake_driver_.password_form_submitted()); |
| 476 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); | 489 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); |
| 477 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); | 490 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); |
| 478 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); | 491 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); |
| 479 EXPECT_EQ(ASCIIToUTF16(new_password_value), | |
| 480 std::get<0>(args).new_password_value); | |
| 481 } | 492 } |
| 482 | 493 |
| 483 void ExpectFieldPropertiesMasks( | 494 void ExpectFieldPropertiesMasks( |
| 484 uint32_t expected_message_id, | 495 PasswordFormSourceType expected_type, |
| 485 const std::map<base::string16, FieldPropertiesMask>& | 496 const std::map<base::string16, FieldPropertiesMask>& |
| 486 expected_properties_masks) { | 497 expected_properties_masks) { |
| 487 const IPC::Message* message = | 498 base::RunLoop().RunUntilIdle(); |
| 488 render_thread_->sink().GetFirstMessageMatching(expected_message_id); | 499 autofill::PasswordForm form; |
| 489 ASSERT_TRUE(message); | 500 if (expected_type == PasswordFormSubmitted) { |
| 490 std::tuple<autofill::PasswordForm> args; | 501 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); |
| 491 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); | 502 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted())); |
| 492 const autofill::PasswordForm& form = std::get<0>(args); | 503 form = *(fake_driver_.password_form_submitted()); |
| 504 } else { |
| 505 ASSERT_EQ(PasswordFormInPageNavigation, expected_type); |
| 506 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); |
| 507 ASSERT_TRUE( |
| 508 static_cast<bool>(fake_driver_.password_form_inpage_navigation())); |
| 509 form = *(fake_driver_.password_form_inpage_navigation()); |
| 510 } |
| 493 | 511 |
| 494 size_t unchecked_masks = expected_properties_masks.size(); | 512 size_t unchecked_masks = expected_properties_masks.size(); |
| 495 for (const FormFieldData& field : form.form_data.fields) { | 513 for (const FormFieldData& field : form.form_data.fields) { |
| 496 const auto& it = expected_properties_masks.find(field.name); | 514 const auto& it = expected_properties_masks.find(field.name); |
| 497 if (it == expected_properties_masks.end()) | 515 if (it == expected_properties_masks.end()) |
| 498 continue; | 516 continue; |
| 499 EXPECT_EQ(field.properties_mask, it->second) | 517 EXPECT_EQ(field.properties_mask, it->second) |
| 500 << "Wrong mask for the field " << field.name; | 518 << "Wrong mask for the field " << field.name; |
| 501 unchecked_masks--; | 519 unchecked_masks--; |
| 502 } | 520 } |
| 503 EXPECT_TRUE(unchecked_masks == 0) | 521 EXPECT_TRUE(unchecked_masks == 0) |
| 504 << "Some expected masks are missed in FormData"; | 522 << "Some expected masks are missed in FormData"; |
| 505 } | 523 } |
| 506 | 524 |
| 507 void ExpectInPageNavigationWithUsernameAndPasswords( | 525 void ExpectInPageNavigationWithUsernameAndPasswords( |
| 508 const std::string& username_value, | 526 const std::string& username_value, |
| 509 const std::string& password_value, | 527 const std::string& password_value, |
| 510 const std::string& new_password_value) { | 528 const std::string& new_password_value) { |
| 511 const IPC::Message* message = | 529 base::RunLoop().RunUntilIdle(); |
| 512 render_thread_->sink().GetFirstMessageMatching( | 530 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); |
| 513 AutofillHostMsg_InPageNavigation::ID); | 531 ASSERT_TRUE( |
| 514 ASSERT_TRUE(message); | 532 static_cast<bool>(fake_driver_.password_form_inpage_navigation())); |
| 515 std::tuple<autofill::PasswordForm> args; | 533 const autofill::PasswordForm& form = |
| 516 AutofillHostMsg_InPageNavigation::Read(message, &args); | 534 *(fake_driver_.password_form_inpage_navigation()); |
| 517 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); | 535 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); |
| 518 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); | 536 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); |
| 519 EXPECT_EQ(ASCIIToUTF16(new_password_value), | 537 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); |
| 520 std::get<0>(args).new_password_value); | |
| 521 } | 538 } |
| 522 | 539 |
| 540 void BindPasswordManagerDriver(mojo::ScopedMessagePipeHandle handle) { |
| 541 fake_driver_.BindRequest( |
| 542 mojo::MakeRequest<mojom::PasswordManagerDriver>(std::move(handle))); |
| 543 } |
| 544 |
| 545 FakeContentPasswordManagerDriver fake_driver_; |
| 546 |
| 523 base::string16 username1_; | 547 base::string16 username1_; |
| 524 base::string16 username2_; | 548 base::string16 username2_; |
| 525 base::string16 username3_; | 549 base::string16 username3_; |
| 526 base::string16 password1_; | 550 base::string16 password1_; |
| 527 base::string16 password2_; | 551 base::string16 password2_; |
| 528 base::string16 password3_; | 552 base::string16 password3_; |
| 529 base::string16 alternate_username3_; | 553 base::string16 alternate_username3_; |
| 530 PasswordFormFillData fill_data_; | 554 PasswordFormFillData fill_data_; |
| 531 | 555 |
| 532 WebInputElement username_element_; | 556 WebInputElement username_element_; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 EXPECT_FALSE(form_util::IsWebNodeVisible(forms2[0])); | 809 EXPECT_FALSE(form_util::IsWebNodeVisible(forms2[0])); |
| 786 | 810 |
| 787 LoadHTML(kNonVisibleFormHTML); | 811 LoadHTML(kNonVisibleFormHTML); |
| 788 frame = GetMainFrame(); | 812 frame = GetMainFrame(); |
| 789 frame->document().forms(forms3); | 813 frame->document().forms(forms3); |
| 790 ASSERT_EQ(1u, forms3.size()); | 814 ASSERT_EQ(1u, forms3.size()); |
| 791 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); | 815 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); |
| 792 } | 816 } |
| 793 | 817 |
| 794 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { | 818 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { |
| 795 render_thread_->sink().ClearMessages(); | 819 fake_driver_.reset_password_forms_rendered(); |
| 796 LoadHTML(kVisibleFormWithNoUsernameHTML); | 820 LoadHTML(kVisibleFormWithNoUsernameHTML); |
| 797 const IPC::Message* message = render_thread_->sink() | 821 base::RunLoop().RunUntilIdle(); |
| 798 .GetFirstMessageMatching(AutofillHostMsg_PasswordFormsRendered::ID); | 822 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 799 EXPECT_TRUE(message); | 823 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered())); |
| 800 std::tuple<std::vector<autofill::PasswordForm>, bool> param; | 824 EXPECT_FALSE(fake_driver_.password_forms_rendered()->empty()); |
| 801 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | |
| 802 EXPECT_TRUE(std::get<0>(param).size()); | |
| 803 | 825 |
| 804 render_thread_->sink().ClearMessages(); | 826 fake_driver_.reset_password_forms_rendered(); |
| 805 LoadHTML(kEmptyFormHTML); | 827 LoadHTML(kEmptyFormHTML); |
| 806 message = render_thread_->sink().GetFirstMessageMatching( | 828 base::RunLoop().RunUntilIdle(); |
| 807 AutofillHostMsg_PasswordFormsRendered::ID); | 829 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 808 EXPECT_TRUE(message); | 830 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered())); |
| 809 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 831 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); |
| 810 EXPECT_FALSE(std::get<0>(param).size()); | |
| 811 | 832 |
| 812 render_thread_->sink().ClearMessages(); | 833 fake_driver_.reset_password_forms_rendered(); |
| 813 LoadHTML(kNonVisibleFormHTML); | 834 LoadHTML(kNonVisibleFormHTML); |
| 814 message = render_thread_->sink().GetFirstMessageMatching( | 835 base::RunLoop().RunUntilIdle(); |
| 815 AutofillHostMsg_PasswordFormsRendered::ID); | 836 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 816 EXPECT_TRUE(message); | 837 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered())); |
| 817 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 838 EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty()); |
| 818 EXPECT_FALSE(std::get<0>(param).size()); | |
| 819 } | 839 } |
| 820 | 840 |
| 821 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { | 841 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { |
| 822 render_thread_->sink().ClearMessages(); | 842 fake_driver_.reset_password_forms_rendered(); |
| 823 LoadHTML(kEmptyWebpage); | 843 LoadHTML(kEmptyWebpage); |
| 824 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 844 base::RunLoop().RunUntilIdle(); |
| 825 AutofillHostMsg_PasswordFormsRendered::ID)); | 845 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); |
| 826 | 846 |
| 827 render_thread_->sink().ClearMessages(); | 847 fake_driver_.reset_password_forms_rendered(); |
| 828 LoadHTML(kRedirectionWebpage); | 848 LoadHTML(kRedirectionWebpage); |
| 829 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 849 base::RunLoop().RunUntilIdle(); |
| 830 AutofillHostMsg_PasswordFormsRendered::ID)); | 850 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); |
| 831 | 851 |
| 832 render_thread_->sink().ClearMessages(); | 852 fake_driver_.reset_password_forms_rendered(); |
| 833 LoadHTML(kSimpleWebpage); | 853 LoadHTML(kSimpleWebpage); |
| 834 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 854 base::RunLoop().RunUntilIdle(); |
| 835 AutofillHostMsg_PasswordFormsRendered::ID)); | 855 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 836 | 856 |
| 837 render_thread_->sink().ClearMessages(); | 857 fake_driver_.reset_password_forms_rendered(); |
| 838 LoadHTML(kWebpageWithDynamicContent); | 858 LoadHTML(kWebpageWithDynamicContent); |
| 839 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 859 base::RunLoop().RunUntilIdle(); |
| 840 AutofillHostMsg_PasswordFormsRendered::ID)); | 860 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 841 } | 861 } |
| 842 | 862 |
| 843 // Tests that a password will only be filled as a suggested and will not be | 863 // Tests that a password will only be filled as a suggested and will not be |
| 844 // accessible by the DOM until a user gesture has occurred. | 864 // accessible by the DOM until a user gesture has occurred. |
| 845 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { | 865 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { |
| 846 // Trigger the initial autocomplete. | 866 // Trigger the initial autocomplete. |
| 847 SimulateOnFillPasswordForm(fill_data_); | 867 SimulateOnFillPasswordForm(fill_data_); |
| 848 | 868 |
| 849 // The username and password should have been autocompleted. | 869 // The username and password should have been autocompleted. |
| 850 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 870 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); | 1205 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); |
| 1186 EXPECT_FALSE(username_element_.isAutofilled()); | 1206 EXPECT_FALSE(username_element_.isAutofilled()); |
| 1187 EXPECT_TRUE(password_element_.value().isEmpty()); | 1207 EXPECT_TRUE(password_element_.value().isEmpty()); |
| 1188 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); | 1208 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); |
| 1189 EXPECT_FALSE(password_element_.isAutofilled()); | 1209 EXPECT_FALSE(password_element_.isAutofilled()); |
| 1190 CheckUsernameSelection(0, 0); | 1210 CheckUsernameSelection(0, 0); |
| 1191 } | 1211 } |
| 1192 | 1212 |
| 1193 // Tests that logging is off by default. | 1213 // Tests that logging is off by default. |
| 1194 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { | 1214 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { |
| 1195 render_thread_->sink().ClearMessages(); | |
| 1196 SendVisiblePasswordForms(); | 1215 SendVisiblePasswordForms(); |
| 1197 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1216 base::RunLoop().RunUntilIdle(); |
| 1198 AutofillHostMsg_RecordSavePasswordProgress::ID); | 1217 EXPECT_FALSE(fake_driver_.called_record_save_progress()); |
| 1199 EXPECT_FALSE(message); | |
| 1200 } | 1218 } |
| 1201 | 1219 |
| 1202 // Test that logging can be turned on by a message. | 1220 // Test that logging can be turned on by a message. |
| 1203 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { | 1221 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { |
| 1204 // Turn the logging on. | 1222 // Turn the logging on. |
| 1205 AutofillMsg_SetLoggingState msg_activate(0, true); | 1223 password_autofill_agent_->SetLoggingState(true); |
| 1206 // Up-cast to access OnMessageReceived, which is private in the agent. | |
| 1207 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_) | |
| 1208 ->OnMessageReceived(msg_activate)); | |
| 1209 | 1224 |
| 1210 render_thread_->sink().ClearMessages(); | |
| 1211 SendVisiblePasswordForms(); | 1225 SendVisiblePasswordForms(); |
| 1212 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1226 base::RunLoop().RunUntilIdle(); |
| 1213 AutofillHostMsg_RecordSavePasswordProgress::ID); | 1227 EXPECT_TRUE(fake_driver_.called_record_save_progress()); |
| 1214 EXPECT_TRUE(message); | |
| 1215 } | 1228 } |
| 1216 | 1229 |
| 1217 // Test that logging can be turned off by a message. | 1230 // Test that logging can be turned off by a message. |
| 1218 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { | 1231 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { |
| 1219 // Turn the logging on and then off. | 1232 // Turn the logging on and then off. |
| 1220 AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true); | 1233 password_autofill_agent_->SetLoggingState(true); |
| 1221 // Up-cast to access OnMessageReceived, which is private in the agent. | 1234 password_autofill_agent_->SetLoggingState(false); |
| 1222 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_) | |
| 1223 ->OnMessageReceived(msg_activate)); | |
| 1224 AutofillMsg_SetLoggingState msg_deactivate(0, /*active=*/false); | |
| 1225 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_agent_) | |
| 1226 ->OnMessageReceived(msg_deactivate)); | |
| 1227 | 1235 |
| 1228 render_thread_->sink().ClearMessages(); | |
| 1229 SendVisiblePasswordForms(); | 1236 SendVisiblePasswordForms(); |
| 1230 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1237 base::RunLoop().RunUntilIdle(); |
| 1231 AutofillHostMsg_RecordSavePasswordProgress::ID); | 1238 EXPECT_FALSE(fake_driver_.called_record_save_progress()); |
| 1232 EXPECT_FALSE(message); | |
| 1233 } | 1239 } |
| 1234 | 1240 |
| 1235 // Test that the agent sends an IPC call to get the current activity state of | 1241 // Test that the agent sends an IPC call to get the current activity state of |
| 1236 // password saving logging soon after construction. | 1242 // password saving logging soon after construction. |
| 1237 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) { | 1243 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) { |
| 1238 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1244 base::RunLoop().RunUntilIdle(); |
| 1239 AutofillHostMsg_PasswordAutofillAgentConstructed::ID); | 1245 EXPECT_TRUE(fake_driver_.called_agent_constructed()); |
| 1240 EXPECT_TRUE(message); | |
| 1241 } | 1246 } |
| 1242 | 1247 |
| 1243 // Tests that one user click on a username field is sufficient to bring up a | 1248 // Tests that one user click on a username field is sufficient to bring up a |
| 1244 // credential suggestion popup, and the user can autocomplete the password by | 1249 // credential suggestion popup, and the user can autocomplete the password by |
| 1245 // selecting the credential from the popup. | 1250 // selecting the credential from the popup. |
| 1246 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { | 1251 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { |
| 1247 // SimulateElementClick() is called so that a user gesture is actually made | 1252 // SimulateElementClick() is called so that a user gesture is actually made |
| 1248 // and the password can be filled. However, SimulateElementClick() does not | 1253 // and the password can be filled. However, SimulateElementClick() does not |
| 1249 // actually lead to the AutofillAgent's InputElementClicked() method being | 1254 // actually lead to the AutofillAgent's InputElementClicked() method being |
| 1250 // called, so SimulateSuggestionChoice has to manually call | 1255 // called, so SimulateSuggestionChoice has to manually call |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1269 | 1274 |
| 1270 // Clear the text fields to start fresh. | 1275 // Clear the text fields to start fresh. |
| 1271 ClearUsernameAndPasswordFields(); | 1276 ClearUsernameAndPasswordFields(); |
| 1272 | 1277 |
| 1273 // Call SimulateElementClick() to produce a user gesture on the page so | 1278 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1274 // autofill will actually fill. | 1279 // autofill will actually fill. |
| 1275 SimulateElementClick(kUsernameName); | 1280 SimulateElementClick(kUsernameName); |
| 1276 | 1281 |
| 1277 // Simulate a user clicking on the username element. This should produce a | 1282 // Simulate a user clicking on the username element. This should produce a |
| 1278 // message with all the usernames. | 1283 // message with all the usernames. |
| 1279 render_thread_->sink().ClearMessages(); | |
| 1280 static_cast<PageClickListener*>(autofill_agent_) | 1284 static_cast<PageClickListener*>(autofill_agent_) |
| 1281 ->FormControlElementClicked(username_element_, false); | 1285 ->FormControlElementClicked(username_element_, false); |
| 1282 CheckSuggestions(std::string(), false); | 1286 CheckSuggestions(std::string(), false); |
| 1283 | 1287 |
| 1284 // Now simulate a user typing in an unrecognized username and then | 1288 // Now simulate a user typing in an unrecognized username and then |
| 1285 // clicking on the username element. This should also produce a message with | 1289 // clicking on the username element. This should also produce a message with |
| 1286 // all the usernames. | 1290 // all the usernames. |
| 1287 SimulateUsernameChange("baz"); | 1291 SimulateUsernameChange("baz"); |
| 1288 render_thread_->sink().ClearMessages(); | |
| 1289 static_cast<PageClickListener*>(autofill_agent_) | 1292 static_cast<PageClickListener*>(autofill_agent_) |
| 1290 ->FormControlElementClicked(username_element_, true); | 1293 ->FormControlElementClicked(username_element_, true); |
| 1291 CheckSuggestions("baz", true); | 1294 CheckSuggestions("baz", true); |
| 1292 ClearUsernameAndPasswordFields(); | 1295 ClearUsernameAndPasswordFields(); |
| 1293 } | 1296 } |
| 1294 | 1297 |
| 1295 // Tests that there is an autosuggestion from the password manager when the | 1298 // Tests that there is an autosuggestion from the password manager when the |
| 1296 // user clicks on the password field when FillOnAccountSelect is enabled. | 1299 // user clicks on the password field when FillOnAccountSelect is enabled. |
| 1297 TEST_F(PasswordAutofillAgentTest, | 1300 TEST_F(PasswordAutofillAgentTest, |
| 1298 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { | 1301 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { |
| 1299 SetFillOnAccountSelect(); | 1302 SetFillOnAccountSelect(); |
| 1300 | 1303 |
| 1301 // Simulate the browser sending back the login info. | 1304 // Simulate the browser sending back the login info. |
| 1302 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); | 1305 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
| 1303 | 1306 |
| 1304 // Clear the text fields to start fresh. | 1307 // Clear the text fields to start fresh. |
| 1305 ClearUsernameAndPasswordFields(); | 1308 ClearUsernameAndPasswordFields(); |
| 1306 | 1309 |
| 1307 // Call SimulateElementClick() to produce a user gesture on the page so | 1310 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1308 // autofill will actually fill. | 1311 // autofill will actually fill. |
| 1309 SimulateElementClick(kUsernameName); | 1312 SimulateElementClick(kUsernameName); |
| 1310 | 1313 |
| 1311 // Simulate a user clicking on the password element. This should produce no | 1314 // Simulate a user clicking on the password element. This should produce no |
| 1312 // message. | 1315 // message. |
| 1313 render_thread_->sink().ClearMessages(); | 1316 fake_driver_.reset_show_pw_suggestions(); |
| 1314 static_cast<PageClickListener*>(autofill_agent_) | 1317 static_cast<PageClickListener*>(autofill_agent_) |
| 1315 ->FormControlElementClicked(password_element_, false); | 1318 ->FormControlElementClicked(password_element_, false); |
| 1316 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1319 EXPECT_TRUE(GetCalledShowPasswordSuggestions()); |
| 1317 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 1318 } | 1320 } |
| 1319 | 1321 |
| 1320 // Tests the autosuggestions that are given when a password element is clicked, | 1322 // Tests the autosuggestions that are given when a password element is clicked, |
| 1321 // the username element is not editable, and FillOnAccountSelect is enabled. | 1323 // the username element is not editable, and FillOnAccountSelect is enabled. |
| 1322 // Specifically, tests when the user clicks on the password element after page | 1324 // Specifically, tests when the user clicks on the password element after page |
| 1323 // load, and the corresponding username element is readonly (and thus | 1325 // load, and the corresponding username element is readonly (and thus |
| 1324 // uneditable), that the credentials for the already-filled username are | 1326 // uneditable), that the credentials for the already-filled username are |
| 1325 // suggested. | 1327 // suggested. |
| 1326 TEST_F(PasswordAutofillAgentTest, | 1328 TEST_F(PasswordAutofillAgentTest, |
| 1327 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { | 1329 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1338 username_element_.setValue("alicia"); | 1340 username_element_.setValue("alicia"); |
| 1339 SetElementReadOnly(username_element_, true); | 1341 SetElementReadOnly(username_element_, true); |
| 1340 | 1342 |
| 1341 // Call SimulateElementClick() to produce a user gesture on the page so | 1343 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1342 // autofill will actually fill. | 1344 // autofill will actually fill. |
| 1343 SimulateElementClick(kUsernameName); | 1345 SimulateElementClick(kUsernameName); |
| 1344 | 1346 |
| 1345 // Simulate a user clicking on the password element. This should produce a | 1347 // Simulate a user clicking on the password element. This should produce a |
| 1346 // dropdown with suggestion of all available usernames and so username | 1348 // dropdown with suggestion of all available usernames and so username |
| 1347 // filter will be the empty string. | 1349 // filter will be the empty string. |
| 1348 render_thread_->sink().ClearMessages(); | |
| 1349 static_cast<PageClickListener*>(autofill_agent_) | 1350 static_cast<PageClickListener*>(autofill_agent_) |
| 1350 ->FormControlElementClicked(password_element_, false); | 1351 ->FormControlElementClicked(password_element_, false); |
| 1351 CheckSuggestions("", false); | 1352 CheckSuggestions("", false); |
| 1352 } | 1353 } |
| 1353 | 1354 |
| 1354 // Tests that there is an autosuggestion from the password manager when the | 1355 // Tests that there is an autosuggestion from the password manager when the |
| 1355 // user clicks on the password field. | 1356 // user clicks on the password field. |
| 1356 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { | 1357 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { |
| 1357 // Simulate the browser sending back the login info. | 1358 // Simulate the browser sending back the login info. |
| 1358 SimulateOnFillPasswordForm(fill_data_); | 1359 SimulateOnFillPasswordForm(fill_data_); |
| 1359 | 1360 |
| 1360 // Clear the text fields to start fresh. | 1361 // Clear the text fields to start fresh. |
| 1361 ClearUsernameAndPasswordFields(); | 1362 ClearUsernameAndPasswordFields(); |
| 1362 | 1363 |
| 1363 // Call SimulateElementClick() to produce a user gesture on the page so | 1364 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1364 // autofill will actually fill. | 1365 // autofill will actually fill. |
| 1365 SimulateElementClick(kUsernameName); | 1366 SimulateElementClick(kUsernameName); |
| 1366 | 1367 |
| 1367 // Simulate a user clicking on the password element. This should produce no | 1368 // Simulate a user clicking on the password element. This should produce no |
| 1368 // message. | 1369 // message. |
| 1369 render_thread_->sink().ClearMessages(); | 1370 fake_driver_.reset_show_pw_suggestions(); |
| 1370 static_cast<PageClickListener*>(autofill_agent_) | 1371 static_cast<PageClickListener*>(autofill_agent_) |
| 1371 ->FormControlElementClicked(password_element_, false); | 1372 ->FormControlElementClicked(password_element_, false); |
| 1372 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1373 EXPECT_TRUE(GetCalledShowPasswordSuggestions()); |
| 1373 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 1374 } | 1374 } |
| 1375 | 1375 |
| 1376 // The user types in a username and a password, but then just before sending | 1376 // The user types in a username and a password, but then just before sending |
| 1377 // the form off, a script clears them. This test checks that | 1377 // the form off, a script clears them. This test checks that |
| 1378 // PasswordAutofillAgent can still remember the username and the password | 1378 // PasswordAutofillAgent can still remember the username and the password |
| 1379 // typed by the user. | 1379 // typed by the user. |
| 1380 TEST_F(PasswordAutofillAgentTest, | 1380 TEST_F(PasswordAutofillAgentTest, |
| 1381 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { | 1381 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { |
| 1382 SimulateUsernameChange("temp"); | 1382 SimulateUsernameChange("temp"); |
| 1383 SimulatePasswordChange("random"); | 1383 SimulatePasswordChange("random"); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 ->WillSubmitForm(username_element_.form()); | 1504 ->WillSubmitForm(username_element_.form()); |
| 1505 | 1505 |
| 1506 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; | 1506 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; |
| 1507 expected_properties_masks[ASCIIToUTF16("random_field")] = | 1507 expected_properties_masks[ASCIIToUTF16("random_field")] = |
| 1508 FieldPropertiesFlags::NO_FLAGS; | 1508 FieldPropertiesFlags::NO_FLAGS; |
| 1509 expected_properties_masks[ASCIIToUTF16("username")] = | 1509 expected_properties_masks[ASCIIToUTF16("username")] = |
| 1510 FieldPropertiesFlags::USER_TYPED; | 1510 FieldPropertiesFlags::USER_TYPED; |
| 1511 expected_properties_masks[ASCIIToUTF16("password")] = | 1511 expected_properties_masks[ASCIIToUTF16("password")] = |
| 1512 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; | 1512 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; |
| 1513 | 1513 |
| 1514 ExpectFieldPropertiesMasks(AutofillHostMsg_PasswordFormSubmitted::ID, | 1514 ExpectFieldPropertiesMasks(PasswordFormSubmitted, expected_properties_masks); |
| 1515 expected_properties_masks); | |
| 1516 } | 1515 } |
| 1517 | 1516 |
| 1518 TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) { | 1517 TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) { |
| 1519 LoadHTML(kNoFormHTML); | 1518 LoadHTML(kNoFormHTML); |
| 1520 UpdateUsernameAndPasswordElements(); | 1519 UpdateUsernameAndPasswordElements(); |
| 1521 | 1520 |
| 1522 SimulateUsernameChange("Bob"); | 1521 SimulateUsernameChange("Bob"); |
| 1523 SimulatePasswordChange("mypassword"); | 1522 SimulatePasswordChange("mypassword"); |
| 1524 | 1523 |
| 1525 username_element_.setAttribute("style", "display:none;"); | 1524 username_element_.setAttribute("style", "display:none;"); |
| 1526 password_element_.setAttribute("style", "display:none;"); | 1525 password_element_.setAttribute("style", "display:none;"); |
| 1527 | 1526 |
| 1528 password_autofill_agent_->AJAXSucceeded(); | 1527 password_autofill_agent_->AJAXSucceeded(); |
| 1529 | 1528 |
| 1530 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; | 1529 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; |
| 1531 expected_properties_masks[ASCIIToUTF16("username")] = | 1530 expected_properties_masks[ASCIIToUTF16("username")] = |
| 1532 FieldPropertiesFlags::USER_TYPED; | 1531 FieldPropertiesFlags::USER_TYPED; |
| 1533 expected_properties_masks[ASCIIToUTF16("password")] = | 1532 expected_properties_masks[ASCIIToUTF16("password")] = |
| 1534 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; | 1533 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; |
| 1535 | 1534 |
| 1536 ExpectFieldPropertiesMasks(AutofillHostMsg_InPageNavigation::ID, | 1535 ExpectFieldPropertiesMasks(PasswordFormInPageNavigation, |
| 1537 expected_properties_masks); | 1536 expected_properties_masks); |
| 1538 } | 1537 } |
| 1539 | 1538 |
| 1540 // The username/password is autofilled by password manager then just before | 1539 // The username/password is autofilled by password manager then just before |
| 1541 // sending the form off, a script changes them. This test checks that | 1540 // sending the form off, a script changes them. This test checks that |
| 1542 // PasswordAutofillAgent can still get the username and the password autofilled. | 1541 // PasswordAutofillAgent can still get the username and the password autofilled. |
| 1543 TEST_F(PasswordAutofillAgentTest, | 1542 TEST_F(PasswordAutofillAgentTest, |
| 1544 RememberLastAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { | 1543 RememberLastAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { |
| 1545 SimulateOnFillPasswordForm(fill_data_); | 1544 SimulateOnFillPasswordForm(fill_data_); |
| 1546 | 1545 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1765 // Simulate the browser sending back the login info for an initial page load. | 1764 // Simulate the browser sending back the login info for an initial page load. |
| 1766 SimulateOnFillPasswordForm(fill_data_); | 1765 SimulateOnFillPasswordForm(fill_data_); |
| 1767 | 1766 |
| 1768 // Do not show popup suggesstion when the password field is not-empty and not | 1767 // Do not show popup suggesstion when the password field is not-empty and not |
| 1769 // autofilled. | 1768 // autofilled. |
| 1770 password_element_.setValue("123"); | 1769 password_element_.setValue("123"); |
| 1771 password_element_.setAutofilled(false); | 1770 password_element_.setAutofilled(false); |
| 1772 | 1771 |
| 1773 SimulateSuggestionChoiceOfUsernameAndPassword( | 1772 SimulateSuggestionChoiceOfUsernameAndPassword( |
| 1774 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); | 1773 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); |
| 1775 ASSERT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1774 ASSERT_FALSE(GetCalledShowPasswordSuggestions()); |
| 1776 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 1777 } | 1775 } |
| 1778 | 1776 |
| 1779 // Tests with fill-on-account-select enabled that if the username element is | 1777 // Tests with fill-on-account-select enabled that if the username element is |
| 1780 // read-only and filled with an unknown username, then the password field is not | 1778 // read-only and filled with an unknown username, then the password field is not |
| 1781 // highlighted as autofillable (regression test for https://crbug.com/442564). | 1779 // highlighted as autofillable (regression test for https://crbug.com/442564). |
| 1782 TEST_F(PasswordAutofillAgentTest, | 1780 TEST_F(PasswordAutofillAgentTest, |
| 1783 FillOnAccountSelectOnlyReadonlyUnknownUsername) { | 1781 FillOnAccountSelectOnlyReadonlyUnknownUsername) { |
| 1784 SetFillOnAccountSelect(); | 1782 SetFillOnAccountSelect(); |
| 1785 | 1783 |
| 1786 ClearUsernameAndPasswordFields(); | 1784 ClearUsernameAndPasswordFields(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 blink::WebFormElement form_element = username_element_.form(); | 1821 blink::WebFormElement form_element = username_element_.form(); |
| 1824 FormData form_data; | 1822 FormData form_data; |
| 1825 ASSERT_TRUE(WebFormElementToFormData( | 1823 ASSERT_TRUE(WebFormElementToFormData( |
| 1826 form_element, blink::WebFormControlElement(), nullptr, | 1824 form_element, blink::WebFormControlElement(), nullptr, |
| 1827 form_util::EXTRACT_NONE, &form_data, nullptr)); | 1825 form_util::EXTRACT_NONE, &form_data, nullptr)); |
| 1828 // Simulate Autofill predictions: the first field is username, the third | 1826 // Simulate Autofill predictions: the first field is username, the third |
| 1829 // one is password. | 1827 // one is password. |
| 1830 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; | 1828 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
| 1831 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME; | 1829 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME; |
| 1832 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD; | 1830 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD; |
| 1833 AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions); | 1831 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( |
| 1834 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1832 predictions); |
| 1835 ->OnMessageReceived(msg); | |
| 1836 | 1833 |
| 1837 // The predictions should still match even if the form changes, as long | 1834 // The predictions should still match even if the form changes, as long |
| 1838 // as the particular elements don't change. | 1835 // as the particular elements don't change. |
| 1839 std::string add_field_to_form = | 1836 std::string add_field_to_form = |
| 1840 "var form = document.getElementById('LoginTestForm');" | 1837 "var form = document.getElementById('LoginTestForm');" |
| 1841 "var new_input = document.createElement('input');" | 1838 "var new_input = document.createElement('input');" |
| 1842 "new_input.setAttribute('type', 'text');" | 1839 "new_input.setAttribute('type', 'text');" |
| 1843 "new_input.setAttribute('id', 'other_field');" | 1840 "new_input.setAttribute('id', 'other_field');" |
| 1844 "form.appendChild(new_input);"; | 1841 "form.appendChild(new_input);"; |
| 1845 ExecuteJavaScriptForTests(add_field_to_form.c_str()); | 1842 ExecuteJavaScriptForTests(add_field_to_form.c_str()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 // generation both trigger. Regression test for https://crbug.com/493455. | 1894 // generation both trigger. Regression test for https://crbug.com/493455. |
| 1898 TEST_F(PasswordAutofillAgentTest, | 1895 TEST_F(PasswordAutofillAgentTest, |
| 1899 PasswordGenerationTriggered_GeneratedPassword) { | 1896 PasswordGenerationTriggered_GeneratedPassword) { |
| 1900 SimulateOnFillPasswordForm(fill_data_); | 1897 SimulateOnFillPasswordForm(fill_data_); |
| 1901 | 1898 |
| 1902 SetNotBlacklistedMessage(password_generation_, kFormHTML); | 1899 SetNotBlacklistedMessage(password_generation_, kFormHTML); |
| 1903 SetAccountCreationFormsDetectedMessage(password_generation_, | 1900 SetAccountCreationFormsDetectedMessage(password_generation_, |
| 1904 GetMainFrame()->document(), 0, 2); | 1901 GetMainFrame()->document(), 0, 2); |
| 1905 | 1902 |
| 1906 base::string16 password = base::ASCIIToUTF16("NewPass22"); | 1903 base::string16 password = base::ASCIIToUTF16("NewPass22"); |
| 1907 AutofillMsg_GeneratedPasswordAccepted msg(0, password); | 1904 password_generation_->GeneratedPasswordAccepted(password); |
| 1908 static_cast<IPC::Listener*>(password_generation_)->OnMessageReceived(msg); | |
| 1909 | 1905 |
| 1910 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1906 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 1911 ->WillSendSubmitEvent(username_element_.form()); | 1907 ->WillSendSubmitEvent(username_element_.form()); |
| 1912 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 1908 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 1913 ->WillSubmitForm(username_element_.form()); | 1909 ->WillSubmitForm(username_element_.form()); |
| 1914 | 1910 |
| 1915 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); | 1911 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); |
| 1916 } | 1912 } |
| 1917 | 1913 |
| 1918 // If password generation is enabled for a field, password autofill should not | 1914 // If password generation is enabled for a field, password autofill should not |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1939 // Simulate generation triggering. | 1935 // Simulate generation triggering. |
| 1940 SetNotBlacklistedMessage(password_generation_, | 1936 SetNotBlacklistedMessage(password_generation_, |
| 1941 kSignupFormHTML); | 1937 kSignupFormHTML); |
| 1942 SetAccountCreationFormsDetectedMessage(password_generation_, | 1938 SetAccountCreationFormsDetectedMessage(password_generation_, |
| 1943 GetMainFrame()->document(), 0, 1); | 1939 GetMainFrame()->document(), 0, 1); |
| 1944 | 1940 |
| 1945 // Simulate the field being clicked to start typing. This should trigger | 1941 // Simulate the field being clicked to start typing. This should trigger |
| 1946 // generation but not password autofill. | 1942 // generation but not password autofill. |
| 1947 SetFocused(password_element_); | 1943 SetFocused(password_element_); |
| 1948 SimulateElementClick("new_password"); | 1944 SimulateElementClick("new_password"); |
| 1949 EXPECT_EQ(nullptr, | 1945 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); |
| 1950 render_thread_->sink().GetFirstMessageMatching( | |
| 1951 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 1952 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1946 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 1953 AutofillHostMsg_ShowPasswordGenerationPopup::ID)); | 1947 AutofillHostMsg_ShowPasswordGenerationPopup::ID)); |
| 1954 } | 1948 } |
| 1955 | 1949 |
| 1956 // Tests that a password change form is properly filled with the username and | 1950 // Tests that a password change form is properly filled with the username and |
| 1957 // password. | 1951 // password. |
| 1958 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { | 1952 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { |
| 1959 LoadHTML(kPasswordChangeFormHTML); | 1953 LoadHTML(kPasswordChangeFormHTML); |
| 1960 UpdateOriginForHTML(kPasswordChangeFormHTML); | 1954 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 1961 UpdateUsernameAndPasswordElements(); | 1955 UpdateUsernameAndPasswordElements(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2003 LoadHTML(kPasswordChangeFormHTML); | 1997 LoadHTML(kPasswordChangeFormHTML); |
| 2004 UpdateOriginForHTML(kPasswordChangeFormHTML); | 1998 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 2005 UpdateUsernameAndPasswordElements(); | 1999 UpdateUsernameAndPasswordElements(); |
| 2006 | 2000 |
| 2007 ClearUsernameAndPasswordFields(); | 2001 ClearUsernameAndPasswordFields(); |
| 2008 fill_data_.wait_for_username = true; | 2002 fill_data_.wait_for_username = true; |
| 2009 fill_data_.is_possible_change_password_form = true; | 2003 fill_data_.is_possible_change_password_form = true; |
| 2010 SimulateOnFillPasswordForm(fill_data_); | 2004 SimulateOnFillPasswordForm(fill_data_); |
| 2011 // Simulate a user clicking on the username element. This should produce a | 2005 // Simulate a user clicking on the username element. This should produce a |
| 2012 // message. | 2006 // message. |
| 2013 render_thread_->sink().ClearMessages(); | |
| 2014 static_cast<PageClickListener*>(autofill_agent_) | 2007 static_cast<PageClickListener*>(autofill_agent_) |
| 2015 ->FormControlElementClicked(username_element_, true); | 2008 ->FormControlElementClicked(username_element_, true); |
| 2016 CheckSuggestions("", true); | 2009 CheckSuggestions("", true); |
| 2017 } | 2010 } |
| 2018 | 2011 |
| 2019 // Tests that one user click on a password field is sufficient to bring up a | 2012 // Tests that one user click on a password field is sufficient to bring up a |
| 2020 // credential suggestion popup on a change password form. | 2013 // credential suggestion popup on a change password form. |
| 2021 TEST_F(PasswordAutofillAgentTest, | 2014 TEST_F(PasswordAutofillAgentTest, |
| 2022 SuggestionsOnPasswordFieldOfChangePasswordForm) { | 2015 SuggestionsOnPasswordFieldOfChangePasswordForm) { |
| 2023 LoadHTML(kPasswordChangeFormHTML); | 2016 LoadHTML(kPasswordChangeFormHTML); |
| 2024 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2017 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 2025 UpdateUsernameAndPasswordElements(); | 2018 UpdateUsernameAndPasswordElements(); |
| 2026 | 2019 |
| 2027 ClearUsernameAndPasswordFields(); | 2020 ClearUsernameAndPasswordFields(); |
| 2028 fill_data_.wait_for_username = true; | 2021 fill_data_.wait_for_username = true; |
| 2029 fill_data_.is_possible_change_password_form = true; | 2022 fill_data_.is_possible_change_password_form = true; |
| 2030 SimulateOnFillPasswordForm(fill_data_); | 2023 SimulateOnFillPasswordForm(fill_data_); |
| 2031 // Simulate a user clicking on the password element. This should produce a | 2024 // Simulate a user clicking on the password element. This should produce a |
| 2032 // message. | 2025 // message. |
| 2033 render_thread_->sink().ClearMessages(); | |
| 2034 static_cast<PageClickListener*>(autofill_agent_) | 2026 static_cast<PageClickListener*>(autofill_agent_) |
| 2035 ->FormControlElementClicked(password_element_, true); | 2027 ->FormControlElementClicked(password_element_, true); |
| 2036 CheckSuggestions("", false); | 2028 CheckSuggestions("", false); |
| 2037 } | 2029 } |
| 2038 | 2030 |
| 2039 // Tests that NOT_PASSWORD field predictions are followed so that no password | 2031 // Tests that NOT_PASSWORD field predictions are followed so that no password |
| 2040 // form is submitted. | 2032 // form is submitted. |
| 2041 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { | 2033 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { |
| 2042 LoadHTML(kCreditCardFormHTML); | 2034 LoadHTML(kCreditCardFormHTML); |
| 2043 blink::WebInputElement credit_card_owner_element = | 2035 blink::WebInputElement credit_card_owner_element = |
| 2044 GetInputElementByID(kCreditCardOwnerName); | 2036 GetInputElementByID(kCreditCardOwnerName); |
| 2045 blink::WebInputElement credit_card_number_element = | 2037 blink::WebInputElement credit_card_number_element = |
| 2046 GetInputElementByID(kCreditCardNumberName); | 2038 GetInputElementByID(kCreditCardNumberName); |
| 2047 blink::WebInputElement credit_card_verification_element = | 2039 blink::WebInputElement credit_card_verification_element = |
| 2048 GetInputElementByID(kCreditCardVerificationName); | 2040 GetInputElementByID(kCreditCardVerificationName); |
| 2049 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith"); | 2041 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith"); |
| 2050 SimulateUserInputChangeForElement(&credit_card_number_element, | 2042 SimulateUserInputChangeForElement(&credit_card_number_element, |
| 2051 "1234123412341234"); | 2043 "1234123412341234"); |
| 2052 SimulateUserInputChangeForElement(&credit_card_verification_element, "123"); | 2044 SimulateUserInputChangeForElement(&credit_card_verification_element, "123"); |
| 2053 // Find FormData for visible form. | 2045 // Find FormData for visible form. |
| 2054 blink::WebFormElement form_element = credit_card_number_element.form(); | 2046 blink::WebFormElement form_element = credit_card_number_element.form(); |
| 2055 FormData form_data; | 2047 FormData form_data; |
| 2056 ASSERT_TRUE(WebFormElementToFormData( | 2048 ASSERT_TRUE(WebFormElementToFormData( |
| 2057 form_element, blink::WebFormControlElement(), nullptr, | 2049 form_element, blink::WebFormControlElement(), nullptr, |
| 2058 form_util::EXTRACT_NONE, &form_data, nullptr)); | 2050 form_util::EXTRACT_NONE, &form_data, nullptr)); |
| 2059 // Simulate Autofill predictions: the third field is not a password. | 2051 // Simulate Autofill predictions: the third field is not a password. |
| 2060 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; | 2052 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
| 2061 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; | 2053 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; |
| 2062 AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions); | 2054 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( |
| 2063 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2055 predictions); |
| 2064 ->OnMessageReceived(msg); | |
| 2065 | 2056 |
| 2066 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2057 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 2067 ->WillSendSubmitEvent(form_element); | 2058 ->WillSendSubmitEvent(form_element); |
| 2068 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2059 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 2069 ->WillSubmitForm(form_element); | 2060 ->WillSubmitForm(form_element); |
| 2070 | 2061 |
| 2071 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 2062 base::RunLoop().RunUntilIdle(); |
| 2072 AutofillHostMsg_PasswordFormSubmitted::ID); | 2063 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); |
| 2073 ASSERT_FALSE(message); | |
| 2074 } | 2064 } |
| 2075 | 2065 |
| 2076 // Tests that only the password field is autocompleted when the browser sends | 2066 // Tests that only the password field is autocompleted when the browser sends |
| 2077 // back data with only one credentials and empty username. | 2067 // back data with only one credentials and empty username. |
| 2078 TEST_F(PasswordAutofillAgentTest, NotAutofillNoUsername) { | 2068 TEST_F(PasswordAutofillAgentTest, NotAutofillNoUsername) { |
| 2079 fill_data_.username_field.value.clear(); | 2069 fill_data_.username_field.value.clear(); |
| 2080 fill_data_.additional_logins.clear(); | 2070 fill_data_.additional_logins.clear(); |
| 2081 SimulateOnFillPasswordForm(fill_data_); | 2071 SimulateOnFillPasswordForm(fill_data_); |
| 2082 | 2072 |
| 2083 CheckTextFieldsState("", false, kAlicePassword, true); | 2073 CheckTextFieldsState("", false, kAlicePassword, true); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2113 TEST_F(PasswordAutofillAgentTest, | 2103 TEST_F(PasswordAutofillAgentTest, |
| 2114 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) { | 2104 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) { |
| 2115 LoadHTML(kNoFormHTML); | 2105 LoadHTML(kNoFormHTML); |
| 2116 UpdateUsernameAndPasswordElements(); | 2106 UpdateUsernameAndPasswordElements(); |
| 2117 | 2107 |
| 2118 SimulateUsernameChange("Bob"); | 2108 SimulateUsernameChange("Bob"); |
| 2119 SimulatePasswordChange("mypassword"); | 2109 SimulatePasswordChange("mypassword"); |
| 2120 | 2110 |
| 2121 password_autofill_agent_->AJAXSucceeded(); | 2111 password_autofill_agent_->AJAXSucceeded(); |
| 2122 | 2112 |
| 2123 const IPC::Message* message = | 2113 base::RunLoop().RunUntilIdle(); |
| 2124 render_thread_->sink().GetFirstMessageMatching( | 2114 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); |
| 2125 AutofillHostMsg_PasswordFormSubmitted::ID); | |
| 2126 ASSERT_FALSE(message); | |
| 2127 } | 2115 } |
| 2128 | 2116 |
| 2129 // Tests that credential suggestions are autofilled on a password (and change | 2117 // Tests that credential suggestions are autofilled on a password (and change |
| 2130 // password) forms having either ambiguous or empty name. | 2118 // password) forms having either ambiguous or empty name. |
| 2131 TEST_F(PasswordAutofillAgentTest, | 2119 TEST_F(PasswordAutofillAgentTest, |
| 2132 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { | 2120 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { |
| 2133 const char kEmpty[] = ""; | 2121 const char kEmpty[] = ""; |
| 2134 const char kDummyUsernameField[] = "anonymous_username"; | 2122 const char kDummyUsernameField[] = "anonymous_username"; |
| 2135 const char kDummyPasswordField[] = "anonymous_password"; | 2123 const char kDummyPasswordField[] = "anonymous_password"; |
| 2136 const char kFormContainsEmptyNamesHTML[] = | 2124 const char kFormContainsEmptyNamesHTML[] = |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2363 TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) { | 2351 TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) { |
| 2364 // Simulate the browser sending back the login info. | 2352 // Simulate the browser sending back the login info. |
| 2365 SimulateOnFillPasswordForm(fill_data_); | 2353 SimulateOnFillPasswordForm(fill_data_); |
| 2366 | 2354 |
| 2367 // Call SimulateElementClick() to produce a user gesture on the page so | 2355 // Call SimulateElementClick() to produce a user gesture on the page so |
| 2368 // autofill will actually fill. | 2356 // autofill will actually fill. |
| 2369 SimulateElementClick(kUsernameName); | 2357 SimulateElementClick(kUsernameName); |
| 2370 | 2358 |
| 2371 // Simulate a user clicking on the password element. This should produce a | 2359 // Simulate a user clicking on the password element. This should produce a |
| 2372 // dropdown with suggestion of all available usernames. | 2360 // dropdown with suggestion of all available usernames. |
| 2373 render_thread_->sink().ClearMessages(); | |
| 2374 static_cast<PageClickListener*>(autofill_agent_) | 2361 static_cast<PageClickListener*>(autofill_agent_) |
| 2375 ->FormControlElementClicked(password_element_, false); | 2362 ->FormControlElementClicked(password_element_, false); |
| 2376 CheckSuggestions("", false); | 2363 CheckSuggestions("", false); |
| 2377 } | 2364 } |
| 2378 | 2365 |
| 2379 // Tests that a suggestion dropdown is shown on each password field. But when a | 2366 // Tests that a suggestion dropdown is shown on each password field. But when a |
| 2380 // user chose one of the fields to autofill, a suggestion dropdown will be shown | 2367 // user chose one of the fields to autofill, a suggestion dropdown will be shown |
| 2381 // only on this field. | 2368 // only on this field. |
| 2382 TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) { | 2369 TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) { |
| 2383 LoadHTML(kPasswordChangeFormHTML); | 2370 LoadHTML(kPasswordChangeFormHTML); |
| 2384 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2371 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 2385 UpdateUsernameAndPasswordElements(); | 2372 UpdateUsernameAndPasswordElements(); |
| 2386 | 2373 |
| 2387 // Simulate the browser sending back the login info. | 2374 // Simulate the browser sending back the login info. |
| 2388 SimulateOnFillPasswordForm(fill_data_); | 2375 SimulateOnFillPasswordForm(fill_data_); |
| 2389 | 2376 |
| 2390 // Call SimulateElementClick() to produce a user gesture on the page so | 2377 // Call SimulateElementClick() to produce a user gesture on the page so |
| 2391 // autofill will actually fill. | 2378 // autofill will actually fill. |
| 2392 SimulateElementClick(kUsernameName); | 2379 SimulateElementClick(kUsernameName); |
| 2393 | 2380 |
| 2394 // Simulate a user clicking on the password elements. This should produce | 2381 // Simulate a user clicking on the password elements. This should produce |
| 2395 // dropdowns with suggestion of all available usernames. | 2382 // dropdowns with suggestion of all available usernames. |
| 2396 render_thread_->sink().ClearMessages(); | |
| 2397 SimulateElementClick("password"); | 2383 SimulateElementClick("password"); |
| 2398 CheckSuggestions("", false); | 2384 CheckSuggestions("", false); |
| 2399 | 2385 |
| 2400 SimulateElementClick("newpassword"); | 2386 SimulateElementClick("newpassword"); |
| 2401 CheckSuggestions("", false); | 2387 CheckSuggestions("", false); |
| 2402 | 2388 |
| 2403 SimulateElementClick("confirmpassword"); | 2389 SimulateElementClick("confirmpassword"); |
| 2404 CheckSuggestions("", false); | 2390 CheckSuggestions("", false); |
| 2405 | 2391 |
| 2406 // The user chooses to autofill the current password field. | 2392 // The user chooses to autofill the current password field. |
| 2407 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( | 2393 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( |
| 2408 password_element_, ASCIIToUTF16(kAliceUsername), | 2394 password_element_, ASCIIToUTF16(kAliceUsername), |
| 2409 ASCIIToUTF16(kAlicePassword))); | 2395 ASCIIToUTF16(kAlicePassword))); |
| 2410 | 2396 |
| 2411 // Simulate a user clicking on not autofilled password fields. This should | 2397 // Simulate a user clicking on not autofilled password fields. This should |
| 2412 // produce | 2398 // produce no suggestion dropdowns. |
| 2413 // no suggestion dropdowns. | 2399 fake_driver_.reset_show_pw_suggestions(); |
| 2414 render_thread_->sink().ClearMessages(); | |
| 2415 SimulateElementClick("newpassword"); | 2400 SimulateElementClick("newpassword"); |
| 2416 SimulateElementClick("confirmpassword"); | 2401 SimulateElementClick("confirmpassword"); |
| 2417 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 2402 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); |
| 2418 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 2419 | 2403 |
| 2420 // But when the user clicks on the autofilled password field again it should | 2404 // But when the user clicks on the autofilled password field again it should |
| 2421 // still produce a suggestion dropdown. | 2405 // still produce a suggestion dropdown. |
| 2422 SimulateElementClick("password"); | 2406 SimulateElementClick("password"); |
| 2423 CheckSuggestions("", false); | 2407 CheckSuggestions("", false); |
| 2424 } | 2408 } |
| 2425 | 2409 |
| 2426 } // namespace autofill | 2410 } // namespace autofill |
| OLD | NEW |