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

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

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

Powered by Google App Engine
This is Rietveld 408576698