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

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

Powered by Google App Engine
This is Rietveld 408576698