OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <tuple> | |
6 | |
7 #include "base/feature_list.h" | 5 #include "base/feature_list.h" |
8 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/run_loop.h" |
9 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/renderer/autofill/password_generation_test_utils.h" | 10 #include "chrome/renderer/autofill/password_generation_test_utils.h" |
12 #include "chrome/test/base/chrome_render_view_test.h" | 11 #include "chrome/test/base/chrome_render_view_test.h" |
13 #include "components/autofill/content/common/autofill_messages.h" | 12 #include "components/autofill/content/common/autofill_messages.h" |
14 #include "components/autofill/content/renderer/autofill_agent.h" | 13 #include "components/autofill/content/renderer/autofill_agent.h" |
15 #include "components/autofill/content/renderer/form_autofill_util.h" | 14 #include "components/autofill/content/renderer/form_autofill_util.h" |
16 #include "components/autofill/content/renderer/password_autofill_agent.h" | 15 #include "components/autofill/content/renderer/password_autofill_agent.h" |
17 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 16 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
18 #include "components/autofill/content/renderer/test_password_generation_agent.h" | 17 #include "components/autofill/content/renderer/test_password_generation_agent.h" |
19 #include "components/autofill/core/common/autofill_constants.h" | 18 #include "components/autofill/core/common/autofill_constants.h" |
20 #include "components/autofill/core/common/form_data.h" | 19 #include "components/autofill/core/common/form_data.h" |
21 #include "components/autofill/core/common/form_field_data.h" | 20 #include "components/autofill/core/common/form_field_data.h" |
22 #include <components/autofill/core/common/password_form.h> | 21 #include <components/autofill/core/common/password_form.h> |
23 #include "components/autofill/core/common/password_form_field_prediction_map.h" | 22 #include "components/autofill/core/common/password_form_field_prediction_map.h" |
24 #include "components/password_manager/core/common/password_manager_features.h" | 23 #include "components/password_manager/core/common/password_manager_features.h" |
25 #include "content/public/renderer/render_frame.h" | 24 #include "content/public/renderer/render_frame.h" |
| 25 #include "content/public/renderer/render_view.h" |
| 26 #include "mojo/public/cpp/bindings/binding_set.h" |
| 27 #include "services/shell/public/cpp/interface_provider.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "third_party/WebKit/public/platform/WebString.h" | 29 #include "third_party/WebKit/public/platform/WebString.h" |
28 #include "third_party/WebKit/public/platform/WebVector.h" | 30 #include "third_party/WebKit/public/platform/WebVector.h" |
29 #include "third_party/WebKit/public/web/WebDocument.h" | 31 #include "third_party/WebKit/public/web/WebDocument.h" |
30 #include "third_party/WebKit/public/web/WebElement.h" | 32 #include "third_party/WebKit/public/web/WebElement.h" |
31 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 33 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
32 #include "third_party/WebKit/public/web/WebFormElement.h" | 34 #include "third_party/WebKit/public/web/WebFormElement.h" |
33 #include "third_party/WebKit/public/web/WebInputElement.h" | 35 #include "third_party/WebKit/public/web/WebInputElement.h" |
34 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 36 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
35 #include "third_party/WebKit/public/web/WebNode.h" | 37 #include "third_party/WebKit/public/web/WebNode.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 " <INPUT type='password' id='password2' name='password'/>" | 223 " <INPUT type='password' id='password2' name='password'/>" |
222 " <INPUT type='submit' value='Login'/>" | 224 " <INPUT type='submit' value='Login'/>" |
223 "</FORM>"; | 225 "</FORM>"; |
224 | 226 |
225 // Sets the "readonly" attribute of |element| to the value given by |read_only|. | 227 // Sets the "readonly" attribute of |element| to the value given by |read_only|. |
226 void SetElementReadOnly(WebInputElement& element, bool read_only) { | 228 void SetElementReadOnly(WebInputElement& element, bool read_only) { |
227 element.setAttribute(WebString::fromUTF8("readonly"), | 229 element.setAttribute(WebString::fromUTF8("readonly"), |
228 read_only ? WebString::fromUTF8("true") : WebString()); | 230 read_only ? WebString::fromUTF8("true") : WebString()); |
229 } | 231 } |
230 | 232 |
| 233 class FakeContentPasswordManagerDriver |
| 234 : public autofill::mojom::PasswordManagerDriver { |
| 235 public: |
| 236 FakeContentPasswordManagerDriver() {} |
| 237 |
| 238 ~FakeContentPasswordManagerDriver() override {} |
| 239 |
| 240 void BindRequest(autofill::mojom::PasswordManagerDriverRequest request) { |
| 241 bindings_.AddBinding(this, std::move(request)); |
| 242 } |
| 243 |
| 244 bool called_show_pw_suggestions() const { |
| 245 return called_show_pw_suggestions_; |
| 246 } |
| 247 |
| 248 int show_pw_suggestions_key() const { return show_pw_suggestions_key_; } |
| 249 |
| 250 const base::Optional<base::string16>& show_pw_suggestions_username() const { |
| 251 return show_pw_suggestions_username_; |
| 252 } |
| 253 |
| 254 int show_pw_suggestions_options() const { |
| 255 return show_pw_suggestions_options_; |
| 256 } |
| 257 |
| 258 void reset_show_pw_suggestions() { |
| 259 called_show_pw_suggestions_ = false; |
| 260 show_pw_suggestions_key_ = -1; |
| 261 show_pw_suggestions_username_ = base::nullopt; |
| 262 show_pw_suggestions_options_ = -1; |
| 263 } |
| 264 |
| 265 bool called_password_form_submitted() const { |
| 266 return called_password_form_submitted_; |
| 267 } |
| 268 |
| 269 const base::Optional<autofill::PasswordForm>& password_form_submitted() |
| 270 const { |
| 271 return password_form_submitted_; |
| 272 } |
| 273 |
| 274 bool called_inpage_navigation() const { return called_inpage_navigation_; } |
| 275 |
| 276 const base::Optional<autofill::PasswordForm>& |
| 277 password_form_inpage_navigation() const { |
| 278 return password_form_inpage_navigation_; |
| 279 } |
| 280 |
| 281 bool called_password_forms_rendered() const { |
| 282 return called_password_forms_rendered_; |
| 283 } |
| 284 |
| 285 const base::Optional<std::vector<autofill::PasswordForm>>& |
| 286 password_forms_rendered() const { |
| 287 return password_forms_rendered_; |
| 288 } |
| 289 |
| 290 void reset_password_forms_rendered() { |
| 291 called_password_forms_rendered_ = false; |
| 292 password_forms_rendered_ = base::nullopt; |
| 293 } |
| 294 |
| 295 bool called_record_save_progress() const { |
| 296 return called_record_save_progress_; |
| 297 } |
| 298 |
| 299 bool called_agent_constructed() const { return called_agent_constructed_; } |
| 300 |
| 301 private: |
| 302 // mojom::PasswordManagerDriver: |
| 303 void PasswordFormsParsed( |
| 304 const std::vector<autofill::PasswordForm>& forms) override {} |
| 305 |
| 306 void PasswordFormsRendered( |
| 307 const std::vector<autofill::PasswordForm>& visible_forms, |
| 308 bool did_stop_loading) override { |
| 309 called_password_forms_rendered_ = true; |
| 310 password_forms_rendered_ = visible_forms; |
| 311 } |
| 312 |
| 313 void PasswordFormSubmitted( |
| 314 const autofill::PasswordForm& password_form) override { |
| 315 called_password_form_submitted_ = true; |
| 316 password_form_submitted_ = password_form; |
| 317 } |
| 318 |
| 319 void InPageNavigation(const autofill::PasswordForm& password_form) override { |
| 320 called_inpage_navigation_ = true; |
| 321 password_form_inpage_navigation_ = password_form; |
| 322 } |
| 323 |
| 324 void PresaveGeneratedPassword( |
| 325 const autofill::PasswordForm& password_form) override {} |
| 326 |
| 327 void PasswordNoLongerGenerated( |
| 328 const autofill::PasswordForm& password_form) override {} |
| 329 |
| 330 void ShowPasswordSuggestions(int key, |
| 331 base::i18n::TextDirection text_direction, |
| 332 const base::string16& typed_username, |
| 333 int options, |
| 334 const gfx::RectF& bounds) override { |
| 335 called_show_pw_suggestions_ = true; |
| 336 show_pw_suggestions_key_ = key; |
| 337 show_pw_suggestions_username_ = typed_username; |
| 338 show_pw_suggestions_options_ = options; |
| 339 } |
| 340 |
| 341 void PasswordAutofillAgentConstructed() override { |
| 342 called_agent_constructed_ = true; |
| 343 } |
| 344 |
| 345 void RecordSavePasswordProgress(const std::string& log) override { |
| 346 called_record_save_progress_ = true; |
| 347 } |
| 348 |
| 349 void SaveGenerationFieldDetectedByClassifier( |
| 350 const autofill::PasswordForm& password_form, |
| 351 const base::string16& generation_field) override {} |
| 352 |
| 353 // Records whether ShowPasswordSuggestions() gets called. |
| 354 bool called_show_pw_suggestions_ = false; |
| 355 // Records data received via ShowPasswordSuggestions() call. |
| 356 int show_pw_suggestions_key_ = -1; |
| 357 base::Optional<base::string16> show_pw_suggestions_username_; |
| 358 int show_pw_suggestions_options_ = -1; |
| 359 // Records whether PasswordFormSubmitted() gets called. |
| 360 bool called_password_form_submitted_ = false; |
| 361 // Records data received via PasswordFormSubmitted() call. |
| 362 base::Optional<autofill::PasswordForm> password_form_submitted_; |
| 363 // Records whether InPageNavigation() gets called. |
| 364 bool called_inpage_navigation_ = false; |
| 365 // Records data received via InPageNavigation() call. |
| 366 base::Optional<autofill::PasswordForm> password_form_inpage_navigation_; |
| 367 // Records whether PasswordFormsRendered() gets called. |
| 368 bool called_password_forms_rendered_ = false; |
| 369 // Records data received via PasswordFormsRendered() call. |
| 370 base::Optional<std::vector<autofill::PasswordForm>> password_forms_rendered_; |
| 371 // Records whether RecordSavePasswordProgress() gets called. |
| 372 bool called_record_save_progress_ = false; |
| 373 // Records whether PasswordAutofillAgentConstructed() gets called. |
| 374 bool called_agent_constructed_ = false; |
| 375 |
| 376 mojo::BindingSet<autofill::mojom::PasswordManagerDriver> bindings_; |
| 377 }; |
| 378 |
| 379 enum PasswordFormSourceType { |
| 380 PasswordFormSubmitted, |
| 381 PasswordFormInPageNavigation, |
| 382 }; |
| 383 |
231 } // namespace | 384 } // namespace |
232 | 385 |
233 namespace autofill { | 386 namespace autofill { |
234 | 387 |
235 class PasswordAutofillAgentTest : public ChromeRenderViewTest { | 388 class PasswordAutofillAgentTest : public ChromeRenderViewTest { |
236 public: | 389 public: |
237 PasswordAutofillAgentTest() { | 390 PasswordAutofillAgentTest() { |
238 } | 391 } |
239 | 392 |
240 // Simulates the fill password form message being sent to the renderer. | 393 // Simulates the fill password form message being sent to the renderer. |
241 // We use that so we don't have to make RenderView::OnFillPasswordForm() | 394 // We use that so we don't have to make RenderView::OnFillPasswordForm() |
242 // protected. | 395 // protected. |
243 void SimulateOnFillPasswordForm( | 396 void SimulateOnFillPasswordForm( |
244 const PasswordFormFillData& fill_data) { | 397 const PasswordFormFillData& fill_data) { |
245 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); | 398 password_autofill_agent_->FillPasswordForm(kPasswordFillFormDataId, |
246 static_cast<IPC::Listener*>(password_autofill_agent_) | 399 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 } | 400 } |
257 | 401 |
258 // Simulates the show initial password account suggestions message being sent | 402 // Simulates the show initial password account suggestions message being sent |
259 // to the renderer. | 403 // to the renderer. |
260 void SimulateOnShowInitialPasswordAccountSuggestions( | 404 void SimulateOnShowInitialPasswordAccountSuggestions( |
261 const PasswordFormFillData& fill_data) { | 405 const PasswordFormFillData& fill_data) { |
262 autofill_agent_->ShowInitialPasswordAccountSuggestions( | 406 autofill_agent_->ShowInitialPasswordAccountSuggestions( |
263 kPasswordFillFormDataId, fill_data); | 407 kPasswordFillFormDataId, fill_data); |
264 } | 408 } |
265 | 409 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // Now retrieve the input elements so the test can access them. | 462 // Now retrieve the input elements so the test can access them. |
319 UpdateUsernameAndPasswordElements(); | 463 UpdateUsernameAndPasswordElements(); |
320 } | 464 } |
321 | 465 |
322 void TearDown() override { | 466 void TearDown() override { |
323 username_element_.reset(); | 467 username_element_.reset(); |
324 password_element_.reset(); | 468 password_element_.reset(); |
325 ChromeRenderViewTest::TearDown(); | 469 ChromeRenderViewTest::TearDown(); |
326 } | 470 } |
327 | 471 |
| 472 void RegisterMainFrameRemoteInterfaces() override { |
| 473 // We only use the fake driver for main frame |
| 474 // because our test cases only involve the main frame. |
| 475 shell::InterfaceProvider* remote_interfaces = |
| 476 view_->GetMainRenderFrame()->GetRemoteInterfaces(); |
| 477 shell::InterfaceProvider::TestApi test_api(remote_interfaces); |
| 478 test_api.SetBinderForName( |
| 479 mojom::PasswordManagerDriver::Name_, |
| 480 base::Bind(&PasswordAutofillAgentTest::BindPasswordManagerDriver, |
| 481 base::Unretained(this))); |
| 482 } |
| 483 |
328 void SetFillOnAccountSelect() { | 484 void SetFillOnAccountSelect() { |
329 base::FeatureList::ClearInstanceForTesting(); | 485 base::FeatureList::ClearInstanceForTesting(); |
330 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 486 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
331 feature_list->InitializeFromCommandLine( | 487 feature_list->InitializeFromCommandLine( |
332 password_manager::features::kFillOnAccountSelect.name, ""); | 488 password_manager::features::kFillOnAccountSelect.name, ""); |
333 base::FeatureList::SetInstance(std::move(feature_list)); | 489 base::FeatureList::SetInstance(std::move(feature_list)); |
334 } | 490 } |
335 | 491 |
336 void UpdateOriginForHTML(const std::string& html) { | 492 void UpdateOriginForHTML(const std::string& html) { |
337 std::string origin = "data:text/html;charset=utf-8," + html; | 493 std::string origin = "data:text/html;charset=utf-8," + html; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, | 530 SimulateSuggestionChoiceOfUsernameAndPassword(username_input, username, |
375 password); | 531 password); |
376 } | 532 } |
377 | 533 |
378 void SimulateSuggestionChoiceOfUsernameAndPassword( | 534 void SimulateSuggestionChoiceOfUsernameAndPassword( |
379 WebInputElement& input, | 535 WebInputElement& input, |
380 const base::string16& username, | 536 const base::string16& username, |
381 const base::string16& password) { | 537 const base::string16& password) { |
382 // This call is necessary to setup the autofill agent appropriate for the | 538 // This call is necessary to setup the autofill agent appropriate for the |
383 // user selection; simulates the menu actually popping up. | 539 // user selection; simulates the menu actually popping up. |
384 render_thread_->sink().ClearMessages(); | |
385 static_cast<autofill::PageClickListener*>(autofill_agent_) | 540 static_cast<autofill::PageClickListener*>(autofill_agent_) |
386 ->FormControlElementClicked(input, false); | 541 ->FormControlElementClicked(input, false); |
387 | 542 |
388 autofill_agent_->FillPasswordSuggestion(username, password); | 543 autofill_agent_->FillPasswordSuggestion(username, password); |
389 } | 544 } |
390 | 545 |
391 void SimulateUsernameChange(const std::string& username) { | 546 void SimulateUsernameChange(const std::string& username) { |
392 SimulateUserInputChangeForElement(&username_element_, username); | 547 SimulateUserInputChangeForElement(&username_element_, username); |
393 } | 548 } |
394 | 549 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 void CheckUsernameSelection(int start, int end) { | 602 void CheckUsernameSelection(int start, int end) { |
448 EXPECT_EQ(start, username_element_.selectionStart()); | 603 EXPECT_EQ(start, username_element_.selectionStart()); |
449 EXPECT_EQ(end, username_element_.selectionEnd()); | 604 EXPECT_EQ(end, username_element_.selectionEnd()); |
450 } | 605 } |
451 | 606 |
452 // Checks the message sent to PasswordAutofillManager to build the suggestion | 607 // Checks the message sent to PasswordAutofillManager to build the suggestion |
453 // list. |username| is the expected username field value, and |show_all| is | 608 // list. |username| is the expected username field value, and |show_all| is |
454 // the expected flag for the PasswordAutofillManager, whether to show all | 609 // the expected flag for the PasswordAutofillManager, whether to show all |
455 // suggestions, or only those starting with |username|. | 610 // suggestions, or only those starting with |username|. |
456 void CheckSuggestions(const std::string& username, bool show_all) { | 611 void CheckSuggestions(const std::string& username, bool show_all) { |
457 const IPC::Message* message = | 612 base::RunLoop().RunUntilIdle(); |
458 render_thread_->sink().GetFirstMessageMatching( | 613 |
459 AutofillHostMsg_ShowPasswordSuggestions::ID); | 614 ASSERT_TRUE(fake_driver_.called_show_pw_suggestions()); |
460 ASSERT_TRUE(message); | 615 EXPECT_EQ(kPasswordFillFormDataId, fake_driver_.show_pw_suggestions_key()); |
461 std::tuple<int, base::i18n::TextDirection, base::string16, int, gfx::RectF> | 616 ASSERT_TRUE(fake_driver_.show_pw_suggestions_username()); |
462 args; | 617 EXPECT_EQ(ASCIIToUTF16(username), |
463 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); | 618 *(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, | 619 EXPECT_EQ(show_all, |
467 static_cast<bool>(std::get<3>(args) & autofill::SHOW_ALL)); | 620 fake_driver_.show_pw_suggestions_options() & autofill::SHOW_ALL); |
468 | 621 |
469 render_thread_->sink().ClearMessages(); | 622 fake_driver_.reset_show_pw_suggestions(); |
| 623 } |
| 624 |
| 625 bool GetCalledShowPasswordSuggestions() { |
| 626 base::RunLoop().RunUntilIdle(); |
| 627 return fake_driver_.called_show_pw_suggestions(); |
470 } | 628 } |
471 | 629 |
472 void ExpectFormSubmittedWithUsernameAndPasswords( | 630 void ExpectFormSubmittedWithUsernameAndPasswords( |
473 const std::string& username_value, | 631 const std::string& username_value, |
474 const std::string& password_value, | 632 const std::string& password_value, |
475 const std::string& new_password_value) { | 633 const std::string& new_password_value) { |
476 const IPC::Message* message = | 634 base::RunLoop().RunUntilIdle(); |
477 render_thread_->sink().GetFirstMessageMatching( | 635 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); |
478 AutofillHostMsg_PasswordFormSubmitted::ID); | 636 ASSERT_TRUE(fake_driver_.password_form_submitted()); |
479 ASSERT_TRUE(message); | 637 const autofill::PasswordForm& form = |
480 std::tuple<autofill::PasswordForm> args; | 638 *(fake_driver_.password_form_submitted()); |
481 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); | 639 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); |
482 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); | 640 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); |
483 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); | 641 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 } | 642 } |
487 | 643 |
488 void ExpectFieldPropertiesMasks( | 644 void ExpectFieldPropertiesMasks( |
489 uint32_t expected_message_id, | 645 PasswordFormSourceType expected_type, |
490 const std::map<base::string16, FieldPropertiesMask>& | 646 const std::map<base::string16, FieldPropertiesMask>& |
491 expected_properties_masks) { | 647 expected_properties_masks) { |
492 const IPC::Message* message = | 648 base::RunLoop().RunUntilIdle(); |
493 render_thread_->sink().GetFirstMessageMatching(expected_message_id); | 649 autofill::PasswordForm form; |
494 ASSERT_TRUE(message); | 650 if (expected_type == PasswordFormSubmitted) { |
495 std::tuple<autofill::PasswordForm> args; | 651 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); |
496 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); | 652 ASSERT_TRUE(fake_driver_.password_form_submitted()); |
497 const autofill::PasswordForm& form = std::get<0>(args); | 653 form = *(fake_driver_.password_form_submitted()); |
| 654 } else if (expected_type == PasswordFormInPageNavigation) { |
| 655 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); |
| 656 ASSERT_TRUE(fake_driver_.password_form_inpage_navigation()); |
| 657 form = *(fake_driver_.password_form_inpage_navigation()); |
| 658 } else { |
| 659 ASSERT_TRUE(false); |
| 660 } |
498 | 661 |
499 size_t unchecked_masks = expected_properties_masks.size(); | 662 size_t unchecked_masks = expected_properties_masks.size(); |
500 for (const FormFieldData& field : form.form_data.fields) { | 663 for (const FormFieldData& field : form.form_data.fields) { |
501 const auto& it = expected_properties_masks.find(field.name); | 664 const auto& it = expected_properties_masks.find(field.name); |
502 if (it == expected_properties_masks.end()) | 665 if (it == expected_properties_masks.end()) |
503 continue; | 666 continue; |
504 EXPECT_EQ(field.properties_mask, it->second) | 667 EXPECT_EQ(field.properties_mask, it->second) |
505 << "Wrong mask for the field " << field.name; | 668 << "Wrong mask for the field " << field.name; |
506 unchecked_masks--; | 669 unchecked_masks--; |
507 } | 670 } |
508 EXPECT_TRUE(unchecked_masks == 0) | 671 EXPECT_TRUE(unchecked_masks == 0) |
509 << "Some expected masks are missed in FormData"; | 672 << "Some expected masks are missed in FormData"; |
510 } | 673 } |
511 | 674 |
512 void ExpectInPageNavigationWithUsernameAndPasswords( | 675 void ExpectInPageNavigationWithUsernameAndPasswords( |
513 const std::string& username_value, | 676 const std::string& username_value, |
514 const std::string& password_value, | 677 const std::string& password_value, |
515 const std::string& new_password_value) { | 678 const std::string& new_password_value) { |
516 const IPC::Message* message = | 679 base::RunLoop().RunUntilIdle(); |
517 render_thread_->sink().GetFirstMessageMatching( | 680 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); |
518 AutofillHostMsg_InPageNavigation::ID); | 681 ASSERT_TRUE(fake_driver_.password_form_inpage_navigation()); |
519 ASSERT_TRUE(message); | 682 const autofill::PasswordForm& form = |
520 std::tuple<autofill::PasswordForm> args; | 683 *(fake_driver_.password_form_inpage_navigation()); |
521 AutofillHostMsg_InPageNavigation::Read(message, &args); | 684 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); |
522 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); | 685 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); |
523 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); | 686 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); |
524 EXPECT_EQ(ASCIIToUTF16(new_password_value), | |
525 std::get<0>(args).new_password_value); | |
526 } | 687 } |
527 | 688 |
| 689 void BindPasswordManagerDriver(mojo::ScopedMessagePipeHandle handle) { |
| 690 fake_driver_.BindRequest( |
| 691 mojo::MakeRequest<mojom::PasswordManagerDriver>(std::move(handle))); |
| 692 } |
| 693 |
| 694 FakeContentPasswordManagerDriver fake_driver_; |
| 695 |
528 base::string16 username1_; | 696 base::string16 username1_; |
529 base::string16 username2_; | 697 base::string16 username2_; |
530 base::string16 username3_; | 698 base::string16 username3_; |
531 base::string16 password1_; | 699 base::string16 password1_; |
532 base::string16 password2_; | 700 base::string16 password2_; |
533 base::string16 password3_; | 701 base::string16 password3_; |
534 base::string16 alternate_username3_; | 702 base::string16 alternate_username3_; |
535 PasswordFormFillData fill_data_; | 703 PasswordFormFillData fill_data_; |
536 | 704 |
537 WebInputElement username_element_; | 705 WebInputElement username_element_; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 EXPECT_FALSE(form_util::IsWebNodeVisible(forms2[0])); | 978 EXPECT_FALSE(form_util::IsWebNodeVisible(forms2[0])); |
811 | 979 |
812 LoadHTML(kNonVisibleFormHTML); | 980 LoadHTML(kNonVisibleFormHTML); |
813 frame = GetMainFrame(); | 981 frame = GetMainFrame(); |
814 frame->document().forms(forms3); | 982 frame->document().forms(forms3); |
815 ASSERT_EQ(1u, forms3.size()); | 983 ASSERT_EQ(1u, forms3.size()); |
816 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); | 984 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); |
817 } | 985 } |
818 | 986 |
819 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { | 987 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { |
820 render_thread_->sink().ClearMessages(); | 988 fake_driver_.reset_password_forms_rendered(); |
821 LoadHTML(kVisibleFormWithNoUsernameHTML); | 989 LoadHTML(kVisibleFormWithNoUsernameHTML); |
822 const IPC::Message* message = render_thread_->sink() | 990 base::RunLoop().RunUntilIdle(); |
823 .GetFirstMessageMatching(AutofillHostMsg_PasswordFormsRendered::ID); | 991 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
824 EXPECT_TRUE(message); | 992 ASSERT_TRUE(fake_driver_.password_forms_rendered()); |
825 std::tuple<std::vector<autofill::PasswordForm>, bool> param; | 993 EXPECT_TRUE(fake_driver_.password_forms_rendered()->size()); |
826 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | |
827 EXPECT_TRUE(std::get<0>(param).size()); | |
828 | 994 |
829 render_thread_->sink().ClearMessages(); | 995 fake_driver_.reset_password_forms_rendered(); |
830 LoadHTML(kEmptyFormHTML); | 996 LoadHTML(kEmptyFormHTML); |
831 message = render_thread_->sink().GetFirstMessageMatching( | 997 base::RunLoop().RunUntilIdle(); |
832 AutofillHostMsg_PasswordFormsRendered::ID); | 998 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
833 EXPECT_TRUE(message); | 999 ASSERT_TRUE(fake_driver_.password_forms_rendered()); |
834 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 1000 EXPECT_FALSE(fake_driver_.password_forms_rendered()->size()); |
835 EXPECT_FALSE(std::get<0>(param).size()); | |
836 | 1001 |
837 render_thread_->sink().ClearMessages(); | 1002 fake_driver_.reset_password_forms_rendered(); |
838 LoadHTML(kNonVisibleFormHTML); | 1003 LoadHTML(kNonVisibleFormHTML); |
839 message = render_thread_->sink().GetFirstMessageMatching( | 1004 base::RunLoop().RunUntilIdle(); |
840 AutofillHostMsg_PasswordFormsRendered::ID); | 1005 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
841 EXPECT_TRUE(message); | 1006 ASSERT_TRUE(fake_driver_.password_forms_rendered()); |
842 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 1007 EXPECT_FALSE(fake_driver_.password_forms_rendered()->size()); |
843 EXPECT_FALSE(std::get<0>(param).size()); | |
844 } | 1008 } |
845 | 1009 |
846 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { | 1010 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { |
847 render_thread_->sink().ClearMessages(); | 1011 fake_driver_.reset_password_forms_rendered(); |
848 LoadHTML(kEmptyWebpage); | 1012 LoadHTML(kEmptyWebpage); |
849 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1013 base::RunLoop().RunUntilIdle(); |
850 AutofillHostMsg_PasswordFormsRendered::ID)); | 1014 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); |
851 | 1015 |
852 render_thread_->sink().ClearMessages(); | 1016 fake_driver_.reset_password_forms_rendered(); |
853 LoadHTML(kRedirectionWebpage); | 1017 LoadHTML(kRedirectionWebpage); |
854 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1018 base::RunLoop().RunUntilIdle(); |
855 AutofillHostMsg_PasswordFormsRendered::ID)); | 1019 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); |
856 | 1020 |
857 render_thread_->sink().ClearMessages(); | 1021 fake_driver_.reset_password_forms_rendered(); |
858 LoadHTML(kSimpleWebpage); | 1022 LoadHTML(kSimpleWebpage); |
859 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1023 base::RunLoop().RunUntilIdle(); |
860 AutofillHostMsg_PasswordFormsRendered::ID)); | 1024 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
861 | 1025 |
862 render_thread_->sink().ClearMessages(); | 1026 fake_driver_.reset_password_forms_rendered(); |
863 LoadHTML(kWebpageWithDynamicContent); | 1027 LoadHTML(kWebpageWithDynamicContent); |
864 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1028 base::RunLoop().RunUntilIdle(); |
865 AutofillHostMsg_PasswordFormsRendered::ID)); | 1029 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
866 } | 1030 } |
867 | 1031 |
868 // Tests that a password will only be filled as a suggested and will not be | 1032 // 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. | 1033 // accessible by the DOM until a user gesture has occurred. |
870 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { | 1034 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { |
871 // Trigger the initial autocomplete. | 1035 // Trigger the initial autocomplete. |
872 SimulateOnFillPasswordForm(fill_data_); | 1036 SimulateOnFillPasswordForm(fill_data_); |
873 | 1037 |
874 // The username and password should have been autocompleted. | 1038 // The username and password should have been autocompleted. |
875 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 1039 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); | 1374 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); |
1211 EXPECT_FALSE(username_element_.isAutofilled()); | 1375 EXPECT_FALSE(username_element_.isAutofilled()); |
1212 EXPECT_TRUE(password_element_.value().isEmpty()); | 1376 EXPECT_TRUE(password_element_.value().isEmpty()); |
1213 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); | 1377 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); |
1214 EXPECT_FALSE(password_element_.isAutofilled()); | 1378 EXPECT_FALSE(password_element_.isAutofilled()); |
1215 CheckUsernameSelection(0, 0); | 1379 CheckUsernameSelection(0, 0); |
1216 } | 1380 } |
1217 | 1381 |
1218 // Tests that logging is off by default. | 1382 // Tests that logging is off by default. |
1219 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { | 1383 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { |
1220 render_thread_->sink().ClearMessages(); | |
1221 SendVisiblePasswordForms(); | 1384 SendVisiblePasswordForms(); |
1222 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1385 base::RunLoop().RunUntilIdle(); |
1223 AutofillHostMsg_RecordSavePasswordProgress::ID); | 1386 EXPECT_FALSE(fake_driver_.called_record_save_progress()); |
1224 EXPECT_FALSE(message); | |
1225 } | 1387 } |
1226 | 1388 |
1227 // Test that logging can be turned on by a message. | 1389 // Test that logging can be turned on by a message. |
1228 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { | 1390 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { |
1229 // Turn the logging on. | 1391 // Turn the logging on. |
1230 AutofillMsg_SetLoggingState msg_activate(0, true); | 1392 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 | 1393 |
1235 render_thread_->sink().ClearMessages(); | |
1236 SendVisiblePasswordForms(); | 1394 SendVisiblePasswordForms(); |
1237 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1395 base::RunLoop().RunUntilIdle(); |
1238 AutofillHostMsg_RecordSavePasswordProgress::ID); | 1396 EXPECT_TRUE(fake_driver_.called_record_save_progress()); |
1239 EXPECT_TRUE(message); | |
1240 } | 1397 } |
1241 | 1398 |
1242 // Test that logging can be turned off by a message. | 1399 // Test that logging can be turned off by a message. |
1243 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { | 1400 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { |
1244 // Turn the logging on and then off. | 1401 // Turn the logging on and then off. |
1245 AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true); | 1402 password_autofill_agent_->SetLoggingState(true); |
1246 // Up-cast to access OnMessageReceived, which is private in the agent. | 1403 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 | 1404 |
1253 render_thread_->sink().ClearMessages(); | |
1254 SendVisiblePasswordForms(); | 1405 SendVisiblePasswordForms(); |
1255 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1406 base::RunLoop().RunUntilIdle(); |
1256 AutofillHostMsg_RecordSavePasswordProgress::ID); | 1407 EXPECT_FALSE(fake_driver_.called_record_save_progress()); |
1257 EXPECT_FALSE(message); | |
1258 } | 1408 } |
1259 | 1409 |
1260 // Test that the agent sends an IPC call to get the current activity state of | 1410 // Test that the agent sends an IPC call to get the current activity state of |
1261 // password saving logging soon after construction. | 1411 // password saving logging soon after construction. |
1262 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) { | 1412 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) { |
1263 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1413 base::RunLoop().RunUntilIdle(); |
1264 AutofillHostMsg_PasswordAutofillAgentConstructed::ID); | 1414 EXPECT_TRUE(fake_driver_.called_agent_constructed()); |
1265 EXPECT_TRUE(message); | |
1266 } | 1415 } |
1267 | 1416 |
1268 // Tests that one user click on a username field is sufficient to bring up a | 1417 // 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 | 1418 // credential suggestion popup, and the user can autocomplete the password by |
1270 // selecting the credential from the popup. | 1419 // selecting the credential from the popup. |
1271 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { | 1420 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { |
1272 // SimulateElementClick() is called so that a user gesture is actually made | 1421 // SimulateElementClick() is called so that a user gesture is actually made |
1273 // and the password can be filled. However, SimulateElementClick() does not | 1422 // and the password can be filled. However, SimulateElementClick() does not |
1274 // actually lead to the AutofillAgent's InputElementClicked() method being | 1423 // actually lead to the AutofillAgent's InputElementClicked() method being |
1275 // called, so SimulateSuggestionChoice has to manually call | 1424 // called, so SimulateSuggestionChoice has to manually call |
(...skipping 18 matching lines...) Expand all Loading... |
1294 | 1443 |
1295 // Clear the text fields to start fresh. | 1444 // Clear the text fields to start fresh. |
1296 ClearUsernameAndPasswordFields(); | 1445 ClearUsernameAndPasswordFields(); |
1297 | 1446 |
1298 // Call SimulateElementClick() to produce a user gesture on the page so | 1447 // Call SimulateElementClick() to produce a user gesture on the page so |
1299 // autofill will actually fill. | 1448 // autofill will actually fill. |
1300 SimulateElementClick(kUsernameName); | 1449 SimulateElementClick(kUsernameName); |
1301 | 1450 |
1302 // Simulate a user clicking on the username element. This should produce a | 1451 // Simulate a user clicking on the username element. This should produce a |
1303 // message with all the usernames. | 1452 // message with all the usernames. |
1304 render_thread_->sink().ClearMessages(); | |
1305 static_cast<PageClickListener*>(autofill_agent_) | 1453 static_cast<PageClickListener*>(autofill_agent_) |
1306 ->FormControlElementClicked(username_element_, false); | 1454 ->FormControlElementClicked(username_element_, false); |
1307 CheckSuggestions(std::string(), false); | 1455 CheckSuggestions(std::string(), false); |
1308 | 1456 |
1309 // Now simulate a user typing in an unrecognized username and then | 1457 // Now simulate a user typing in an unrecognized username and then |
1310 // clicking on the username element. This should also produce a message with | 1458 // clicking on the username element. This should also produce a message with |
1311 // all the usernames. | 1459 // all the usernames. |
1312 SimulateUsernameChange("baz"); | 1460 SimulateUsernameChange("baz"); |
1313 render_thread_->sink().ClearMessages(); | |
1314 static_cast<PageClickListener*>(autofill_agent_) | 1461 static_cast<PageClickListener*>(autofill_agent_) |
1315 ->FormControlElementClicked(username_element_, true); | 1462 ->FormControlElementClicked(username_element_, true); |
1316 CheckSuggestions("baz", true); | 1463 CheckSuggestions("baz", true); |
1317 ClearUsernameAndPasswordFields(); | 1464 ClearUsernameAndPasswordFields(); |
1318 } | 1465 } |
1319 | 1466 |
1320 // Tests that there is an autosuggestion from the password manager when the | 1467 // Tests that there is an autosuggestion from the password manager when the |
1321 // user clicks on the password field when FillOnAccountSelect is enabled. | 1468 // user clicks on the password field when FillOnAccountSelect is enabled. |
1322 TEST_F(PasswordAutofillAgentTest, | 1469 TEST_F(PasswordAutofillAgentTest, |
1323 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { | 1470 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { |
1324 SetFillOnAccountSelect(); | 1471 SetFillOnAccountSelect(); |
1325 | 1472 |
1326 // Simulate the browser sending back the login info. | 1473 // Simulate the browser sending back the login info. |
1327 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); | 1474 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
1328 | 1475 |
1329 // Clear the text fields to start fresh. | 1476 // Clear the text fields to start fresh. |
1330 ClearUsernameAndPasswordFields(); | 1477 ClearUsernameAndPasswordFields(); |
1331 | 1478 |
1332 // Call SimulateElementClick() to produce a user gesture on the page so | 1479 // Call SimulateElementClick() to produce a user gesture on the page so |
1333 // autofill will actually fill. | 1480 // autofill will actually fill. |
1334 SimulateElementClick(kUsernameName); | 1481 SimulateElementClick(kUsernameName); |
1335 | 1482 |
1336 // Simulate a user clicking on the password element. This should produce no | 1483 // Simulate a user clicking on the password element. This should produce no |
1337 // message. | 1484 // message. |
1338 render_thread_->sink().ClearMessages(); | 1485 fake_driver_.reset_show_pw_suggestions(); |
1339 static_cast<PageClickListener*>(autofill_agent_) | 1486 static_cast<PageClickListener*>(autofill_agent_) |
1340 ->FormControlElementClicked(password_element_, false); | 1487 ->FormControlElementClicked(password_element_, false); |
1341 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1488 EXPECT_TRUE(GetCalledShowPasswordSuggestions()); |
1342 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
1343 } | 1489 } |
1344 | 1490 |
1345 // Tests the autosuggestions that are given when a password element is clicked, | 1491 // Tests the autosuggestions that are given when a password element is clicked, |
1346 // the username element is not editable, and FillOnAccountSelect is enabled. | 1492 // the username element is not editable, and FillOnAccountSelect is enabled. |
1347 // Specifically, tests when the user clicks on the password element after page | 1493 // Specifically, tests when the user clicks on the password element after page |
1348 // load, and the corresponding username element is readonly (and thus | 1494 // load, and the corresponding username element is readonly (and thus |
1349 // uneditable), that the credentials for the already-filled username are | 1495 // uneditable), that the credentials for the already-filled username are |
1350 // suggested. | 1496 // suggested. |
1351 TEST_F(PasswordAutofillAgentTest, | 1497 TEST_F(PasswordAutofillAgentTest, |
1352 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { | 1498 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { |
(...skipping 10 matching lines...) Expand all Loading... |
1363 username_element_.setValue("alicia"); | 1509 username_element_.setValue("alicia"); |
1364 SetElementReadOnly(username_element_, true); | 1510 SetElementReadOnly(username_element_, true); |
1365 | 1511 |
1366 // Call SimulateElementClick() to produce a user gesture on the page so | 1512 // Call SimulateElementClick() to produce a user gesture on the page so |
1367 // autofill will actually fill. | 1513 // autofill will actually fill. |
1368 SimulateElementClick(kUsernameName); | 1514 SimulateElementClick(kUsernameName); |
1369 | 1515 |
1370 // Simulate a user clicking on the password element. This should produce a | 1516 // Simulate a user clicking on the password element. This should produce a |
1371 // dropdown with suggestion of all available usernames and so username | 1517 // dropdown with suggestion of all available usernames and so username |
1372 // filter will be the empty string. | 1518 // filter will be the empty string. |
1373 render_thread_->sink().ClearMessages(); | |
1374 static_cast<PageClickListener*>(autofill_agent_) | 1519 static_cast<PageClickListener*>(autofill_agent_) |
1375 ->FormControlElementClicked(password_element_, false); | 1520 ->FormControlElementClicked(password_element_, false); |
1376 CheckSuggestions("", false); | 1521 CheckSuggestions("", false); |
1377 } | 1522 } |
1378 | 1523 |
1379 // Tests that there is an autosuggestion from the password manager when the | 1524 // Tests that there is an autosuggestion from the password manager when the |
1380 // user clicks on the password field. | 1525 // user clicks on the password field. |
1381 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { | 1526 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { |
1382 // Simulate the browser sending back the login info. | 1527 // Simulate the browser sending back the login info. |
1383 SimulateOnFillPasswordForm(fill_data_); | 1528 SimulateOnFillPasswordForm(fill_data_); |
1384 | 1529 |
1385 // Clear the text fields to start fresh. | 1530 // Clear the text fields to start fresh. |
1386 ClearUsernameAndPasswordFields(); | 1531 ClearUsernameAndPasswordFields(); |
1387 | 1532 |
1388 // Call SimulateElementClick() to produce a user gesture on the page so | 1533 // Call SimulateElementClick() to produce a user gesture on the page so |
1389 // autofill will actually fill. | 1534 // autofill will actually fill. |
1390 SimulateElementClick(kUsernameName); | 1535 SimulateElementClick(kUsernameName); |
1391 | 1536 |
1392 // Simulate a user clicking on the password element. This should produce no | 1537 // Simulate a user clicking on the password element. This should produce no |
1393 // message. | 1538 // message. |
1394 render_thread_->sink().ClearMessages(); | 1539 fake_driver_.reset_show_pw_suggestions(); |
1395 static_cast<PageClickListener*>(autofill_agent_) | 1540 static_cast<PageClickListener*>(autofill_agent_) |
1396 ->FormControlElementClicked(password_element_, false); | 1541 ->FormControlElementClicked(password_element_, false); |
1397 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1542 EXPECT_TRUE(GetCalledShowPasswordSuggestions()); |
1398 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
1399 } | 1543 } |
1400 | 1544 |
1401 // The user types in a username and a password, but then just before sending | 1545 // 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 | 1546 // the form off, a script clears them. This test checks that |
1403 // PasswordAutofillAgent can still remember the username and the password | 1547 // PasswordAutofillAgent can still remember the username and the password |
1404 // typed by the user. | 1548 // typed by the user. |
1405 TEST_F(PasswordAutofillAgentTest, | 1549 TEST_F(PasswordAutofillAgentTest, |
1406 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { | 1550 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { |
1407 SimulateUsernameChange("temp"); | 1551 SimulateUsernameChange("temp"); |
1408 SimulatePasswordChange("random"); | 1552 SimulatePasswordChange("random"); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 ->WillSubmitForm(username_element_.form()); | 1678 ->WillSubmitForm(username_element_.form()); |
1535 | 1679 |
1536 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; | 1680 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; |
1537 expected_properties_masks[ASCIIToUTF16("random_field")] = | 1681 expected_properties_masks[ASCIIToUTF16("random_field")] = |
1538 FieldPropertiesFlags::NO_FLAGS; | 1682 FieldPropertiesFlags::NO_FLAGS; |
1539 expected_properties_masks[ASCIIToUTF16("username")] = | 1683 expected_properties_masks[ASCIIToUTF16("username")] = |
1540 FieldPropertiesFlags::USER_TYPED; | 1684 FieldPropertiesFlags::USER_TYPED; |
1541 expected_properties_masks[ASCIIToUTF16("password")] = | 1685 expected_properties_masks[ASCIIToUTF16("password")] = |
1542 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; | 1686 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; |
1543 | 1687 |
1544 ExpectFieldPropertiesMasks(AutofillHostMsg_PasswordFormSubmitted::ID, | 1688 ExpectFieldPropertiesMasks(PasswordFormSubmitted, expected_properties_masks); |
1545 expected_properties_masks); | |
1546 } | 1689 } |
1547 | 1690 |
1548 TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) { | 1691 TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) { |
1549 LoadHTML(kNoFormHTML); | 1692 LoadHTML(kNoFormHTML); |
1550 UpdateUsernameAndPasswordElements(); | 1693 UpdateUsernameAndPasswordElements(); |
1551 | 1694 |
1552 SimulateUsernameChange("Bob"); | 1695 SimulateUsernameChange("Bob"); |
1553 SimulatePasswordChange("mypassword"); | 1696 SimulatePasswordChange("mypassword"); |
1554 | 1697 |
1555 username_element_.setAttribute("style", "display:none;"); | 1698 username_element_.setAttribute("style", "display:none;"); |
1556 password_element_.setAttribute("style", "display:none;"); | 1699 password_element_.setAttribute("style", "display:none;"); |
1557 | 1700 |
1558 password_autofill_agent_->AJAXSucceeded(); | 1701 password_autofill_agent_->AJAXSucceeded(); |
1559 | 1702 |
1560 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; | 1703 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; |
1561 expected_properties_masks[ASCIIToUTF16("username")] = | 1704 expected_properties_masks[ASCIIToUTF16("username")] = |
1562 FieldPropertiesFlags::USER_TYPED; | 1705 FieldPropertiesFlags::USER_TYPED; |
1563 expected_properties_masks[ASCIIToUTF16("password")] = | 1706 expected_properties_masks[ASCIIToUTF16("password")] = |
1564 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; | 1707 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; |
1565 | 1708 |
1566 ExpectFieldPropertiesMasks(AutofillHostMsg_InPageNavigation::ID, | 1709 ExpectFieldPropertiesMasks(PasswordFormInPageNavigation, |
1567 expected_properties_masks); | 1710 expected_properties_masks); |
1568 } | 1711 } |
1569 | 1712 |
1570 // The username/password is autofilled by password manager then just before | 1713 // The username/password is autofilled by password manager then just before |
1571 // sending the form off, a script changes them. This test checks that | 1714 // sending the form off, a script changes them. This test checks that |
1572 // PasswordAutofillAgent can still get the username and the password autofilled. | 1715 // PasswordAutofillAgent can still get the username and the password autofilled. |
1573 TEST_F(PasswordAutofillAgentTest, | 1716 TEST_F(PasswordAutofillAgentTest, |
1574 RememberLastAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { | 1717 RememberLastAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { |
1575 SimulateOnFillPasswordForm(fill_data_); | 1718 SimulateOnFillPasswordForm(fill_data_); |
1576 | 1719 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1795 // Simulate the browser sending back the login info for an initial page load. | 1938 // Simulate the browser sending back the login info for an initial page load. |
1796 SimulateOnFillPasswordForm(fill_data_); | 1939 SimulateOnFillPasswordForm(fill_data_); |
1797 | 1940 |
1798 // Do not show popup suggesstion when the password field is not-empty and not | 1941 // Do not show popup suggesstion when the password field is not-empty and not |
1799 // autofilled. | 1942 // autofilled. |
1800 password_element_.setValue("123"); | 1943 password_element_.setValue("123"); |
1801 password_element_.setAutofilled(false); | 1944 password_element_.setAutofilled(false); |
1802 | 1945 |
1803 SimulateSuggestionChoiceOfUsernameAndPassword( | 1946 SimulateSuggestionChoiceOfUsernameAndPassword( |
1804 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); | 1947 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); |
1805 ASSERT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1948 ASSERT_FALSE(GetCalledShowPasswordSuggestions()); |
1806 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
1807 } | 1949 } |
1808 | 1950 |
1809 // Tests with fill-on-account-select enabled that if the username element is | 1951 // 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 | 1952 // 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). | 1953 // highlighted as autofillable (regression test for https://crbug.com/442564). |
1812 TEST_F(PasswordAutofillAgentTest, | 1954 TEST_F(PasswordAutofillAgentTest, |
1813 FillOnAccountSelectOnlyReadonlyUnknownUsername) { | 1955 FillOnAccountSelectOnlyReadonlyUnknownUsername) { |
1814 SetFillOnAccountSelect(); | 1956 SetFillOnAccountSelect(); |
1815 | 1957 |
1816 ClearUsernameAndPasswordFields(); | 1958 ClearUsernameAndPasswordFields(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1853 blink::WebFormElement form_element = username_element_.form(); | 1995 blink::WebFormElement form_element = username_element_.form(); |
1854 FormData form_data; | 1996 FormData form_data; |
1855 ASSERT_TRUE(WebFormElementToFormData( | 1997 ASSERT_TRUE(WebFormElementToFormData( |
1856 form_element, blink::WebFormControlElement(), nullptr, | 1998 form_element, blink::WebFormControlElement(), nullptr, |
1857 form_util::EXTRACT_NONE, &form_data, nullptr)); | 1999 form_util::EXTRACT_NONE, &form_data, nullptr)); |
1858 // Simulate Autofill predictions: the first field is username, the third | 2000 // Simulate Autofill predictions: the first field is username, the third |
1859 // one is password. | 2001 // one is password. |
1860 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; | 2002 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
1861 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME; | 2003 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME; |
1862 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD; | 2004 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD; |
1863 AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions); | 2005 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( |
1864 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2006 predictions); |
1865 ->OnMessageReceived(msg); | |
1866 | 2007 |
1867 // The predictions should still match even if the form changes, as long | 2008 // The predictions should still match even if the form changes, as long |
1868 // as the particular elements don't change. | 2009 // as the particular elements don't change. |
1869 std::string add_field_to_form = | 2010 std::string add_field_to_form = |
1870 "var form = document.getElementById('LoginTestForm');" | 2011 "var form = document.getElementById('LoginTestForm');" |
1871 "var new_input = document.createElement('input');" | 2012 "var new_input = document.createElement('input');" |
1872 "new_input.setAttribute('type', 'text');" | 2013 "new_input.setAttribute('type', 'text');" |
1873 "new_input.setAttribute('id', 'other_field');" | 2014 "new_input.setAttribute('id', 'other_field');" |
1874 "form.appendChild(new_input);"; | 2015 "form.appendChild(new_input);"; |
1875 ExecuteJavaScriptForTests(add_field_to_form.c_str()); | 2016 ExecuteJavaScriptForTests(add_field_to_form.c_str()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 // generation both trigger. Regression test for https://crbug.com/493455. | 2068 // generation both trigger. Regression test for https://crbug.com/493455. |
1928 TEST_F(PasswordAutofillAgentTest, | 2069 TEST_F(PasswordAutofillAgentTest, |
1929 PasswordGenerationTriggered_GeneratedPassword) { | 2070 PasswordGenerationTriggered_GeneratedPassword) { |
1930 SimulateOnFillPasswordForm(fill_data_); | 2071 SimulateOnFillPasswordForm(fill_data_); |
1931 | 2072 |
1932 SetNotBlacklistedMessage(password_generation_, kFormHTML); | 2073 SetNotBlacklistedMessage(password_generation_, kFormHTML); |
1933 SetAccountCreationFormsDetectedMessage(password_generation_, | 2074 SetAccountCreationFormsDetectedMessage(password_generation_, |
1934 GetMainFrame()->document(), 0, 2); | 2075 GetMainFrame()->document(), 0, 2); |
1935 | 2076 |
1936 base::string16 password = base::ASCIIToUTF16("NewPass22"); | 2077 base::string16 password = base::ASCIIToUTF16("NewPass22"); |
1937 AutofillMsg_GeneratedPasswordAccepted msg(0, password); | 2078 password_generation_->GeneratedPasswordAccepted(password); |
1938 static_cast<IPC::Listener*>(password_generation_)->OnMessageReceived(msg); | |
1939 | 2079 |
1940 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2080 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1941 ->WillSendSubmitEvent(username_element_.form()); | 2081 ->WillSendSubmitEvent(username_element_.form()); |
1942 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2082 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
1943 ->WillSubmitForm(username_element_.form()); | 2083 ->WillSubmitForm(username_element_.form()); |
1944 | 2084 |
1945 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); | 2085 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); |
1946 } | 2086 } |
1947 | 2087 |
1948 // If password generation is enabled for a field, password autofill should not | 2088 // If password generation is enabled for a field, password autofill should not |
(...skipping 20 matching lines...) Expand all Loading... |
1969 // Simulate generation triggering. | 2109 // Simulate generation triggering. |
1970 SetNotBlacklistedMessage(password_generation_, | 2110 SetNotBlacklistedMessage(password_generation_, |
1971 kSignupFormHTML); | 2111 kSignupFormHTML); |
1972 SetAccountCreationFormsDetectedMessage(password_generation_, | 2112 SetAccountCreationFormsDetectedMessage(password_generation_, |
1973 GetMainFrame()->document(), 0, 1); | 2113 GetMainFrame()->document(), 0, 1); |
1974 | 2114 |
1975 // Simulate the field being clicked to start typing. This should trigger | 2115 // Simulate the field being clicked to start typing. This should trigger |
1976 // generation but not password autofill. | 2116 // generation but not password autofill. |
1977 SetFocused(password_element_); | 2117 SetFocused(password_element_); |
1978 SimulateElementClick("new_password"); | 2118 SimulateElementClick("new_password"); |
1979 EXPECT_EQ(nullptr, | 2119 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); |
1980 render_thread_->sink().GetFirstMessageMatching( | |
1981 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
1982 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 2120 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
1983 AutofillHostMsg_ShowPasswordGenerationPopup::ID)); | 2121 AutofillHostMsg_ShowPasswordGenerationPopup::ID)); |
1984 } | 2122 } |
1985 | 2123 |
1986 // Tests that a password change form is properly filled with the username and | 2124 // Tests that a password change form is properly filled with the username and |
1987 // password. | 2125 // password. |
1988 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { | 2126 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { |
1989 LoadHTML(kPasswordChangeFormHTML); | 2127 LoadHTML(kPasswordChangeFormHTML); |
1990 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2128 UpdateOriginForHTML(kPasswordChangeFormHTML); |
1991 UpdateUsernameAndPasswordElements(); | 2129 UpdateUsernameAndPasswordElements(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 LoadHTML(kPasswordChangeFormHTML); | 2171 LoadHTML(kPasswordChangeFormHTML); |
2034 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2172 UpdateOriginForHTML(kPasswordChangeFormHTML); |
2035 UpdateUsernameAndPasswordElements(); | 2173 UpdateUsernameAndPasswordElements(); |
2036 | 2174 |
2037 ClearUsernameAndPasswordFields(); | 2175 ClearUsernameAndPasswordFields(); |
2038 fill_data_.wait_for_username = true; | 2176 fill_data_.wait_for_username = true; |
2039 fill_data_.is_possible_change_password_form = true; | 2177 fill_data_.is_possible_change_password_form = true; |
2040 SimulateOnFillPasswordForm(fill_data_); | 2178 SimulateOnFillPasswordForm(fill_data_); |
2041 // Simulate a user clicking on the username element. This should produce a | 2179 // Simulate a user clicking on the username element. This should produce a |
2042 // message. | 2180 // message. |
2043 render_thread_->sink().ClearMessages(); | |
2044 static_cast<PageClickListener*>(autofill_agent_) | 2181 static_cast<PageClickListener*>(autofill_agent_) |
2045 ->FormControlElementClicked(username_element_, true); | 2182 ->FormControlElementClicked(username_element_, true); |
2046 CheckSuggestions("", true); | 2183 CheckSuggestions("", true); |
2047 } | 2184 } |
2048 | 2185 |
2049 // Tests that one user click on a password field is sufficient to bring up a | 2186 // Tests that one user click on a password field is sufficient to bring up a |
2050 // credential suggestion popup on a change password form. | 2187 // credential suggestion popup on a change password form. |
2051 TEST_F(PasswordAutofillAgentTest, | 2188 TEST_F(PasswordAutofillAgentTest, |
2052 SuggestionsOnPasswordFieldOfChangePasswordForm) { | 2189 SuggestionsOnPasswordFieldOfChangePasswordForm) { |
2053 LoadHTML(kPasswordChangeFormHTML); | 2190 LoadHTML(kPasswordChangeFormHTML); |
2054 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2191 UpdateOriginForHTML(kPasswordChangeFormHTML); |
2055 UpdateUsernameAndPasswordElements(); | 2192 UpdateUsernameAndPasswordElements(); |
2056 | 2193 |
2057 ClearUsernameAndPasswordFields(); | 2194 ClearUsernameAndPasswordFields(); |
2058 fill_data_.wait_for_username = true; | 2195 fill_data_.wait_for_username = true; |
2059 fill_data_.is_possible_change_password_form = true; | 2196 fill_data_.is_possible_change_password_form = true; |
2060 SimulateOnFillPasswordForm(fill_data_); | 2197 SimulateOnFillPasswordForm(fill_data_); |
2061 // Simulate a user clicking on the password element. This should produce a | 2198 // Simulate a user clicking on the password element. This should produce a |
2062 // message. | 2199 // message. |
2063 render_thread_->sink().ClearMessages(); | |
2064 static_cast<PageClickListener*>(autofill_agent_) | 2200 static_cast<PageClickListener*>(autofill_agent_) |
2065 ->FormControlElementClicked(password_element_, true); | 2201 ->FormControlElementClicked(password_element_, true); |
2066 CheckSuggestions("", false); | 2202 CheckSuggestions("", false); |
2067 } | 2203 } |
2068 | 2204 |
2069 // Tests that NOT_PASSWORD field predictions are followed so that no password | 2205 // Tests that NOT_PASSWORD field predictions are followed so that no password |
2070 // form is submitted. | 2206 // form is submitted. |
2071 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { | 2207 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { |
2072 LoadHTML(kCreditCardFormHTML); | 2208 LoadHTML(kCreditCardFormHTML); |
2073 blink::WebInputElement credit_card_owner_element = | 2209 blink::WebInputElement credit_card_owner_element = |
2074 GetInputElementByID(kCreditCardOwnerName); | 2210 GetInputElementByID(kCreditCardOwnerName); |
2075 blink::WebInputElement credit_card_number_element = | 2211 blink::WebInputElement credit_card_number_element = |
2076 GetInputElementByID(kCreditCardNumberName); | 2212 GetInputElementByID(kCreditCardNumberName); |
2077 blink::WebInputElement credit_card_verification_element = | 2213 blink::WebInputElement credit_card_verification_element = |
2078 GetInputElementByID(kCreditCardVerificationName); | 2214 GetInputElementByID(kCreditCardVerificationName); |
2079 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith"); | 2215 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith"); |
2080 SimulateUserInputChangeForElement(&credit_card_number_element, | 2216 SimulateUserInputChangeForElement(&credit_card_number_element, |
2081 "1234123412341234"); | 2217 "1234123412341234"); |
2082 SimulateUserInputChangeForElement(&credit_card_verification_element, "123"); | 2218 SimulateUserInputChangeForElement(&credit_card_verification_element, "123"); |
2083 // Find FormData for visible form. | 2219 // Find FormData for visible form. |
2084 blink::WebFormElement form_element = credit_card_number_element.form(); | 2220 blink::WebFormElement form_element = credit_card_number_element.form(); |
2085 FormData form_data; | 2221 FormData form_data; |
2086 ASSERT_TRUE(WebFormElementToFormData( | 2222 ASSERT_TRUE(WebFormElementToFormData( |
2087 form_element, blink::WebFormControlElement(), nullptr, | 2223 form_element, blink::WebFormControlElement(), nullptr, |
2088 form_util::EXTRACT_NONE, &form_data, nullptr)); | 2224 form_util::EXTRACT_NONE, &form_data, nullptr)); |
2089 // Simulate Autofill predictions: the third field is not a password. | 2225 // Simulate Autofill predictions: the third field is not a password. |
2090 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; | 2226 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
2091 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; | 2227 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; |
2092 AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions); | 2228 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( |
2093 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2229 predictions); |
2094 ->OnMessageReceived(msg); | |
2095 | 2230 |
2096 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2231 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
2097 ->WillSendSubmitEvent(form_element); | 2232 ->WillSendSubmitEvent(form_element); |
2098 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2233 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
2099 ->WillSubmitForm(form_element); | 2234 ->WillSubmitForm(form_element); |
2100 | 2235 |
2101 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 2236 base::RunLoop().RunUntilIdle(); |
2102 AutofillHostMsg_PasswordFormSubmitted::ID); | 2237 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); |
2103 ASSERT_FALSE(message); | |
2104 } | 2238 } |
2105 | 2239 |
2106 // Tests that only the password field is autocompleted when the browser sends | 2240 // Tests that only the password field is autocompleted when the browser sends |
2107 // back data with only one credentials and empty username. | 2241 // back data with only one credentials and empty username. |
2108 TEST_F(PasswordAutofillAgentTest, NotAutofillNoUsername) { | 2242 TEST_F(PasswordAutofillAgentTest, NotAutofillNoUsername) { |
2109 fill_data_.username_field.value.clear(); | 2243 fill_data_.username_field.value.clear(); |
2110 fill_data_.additional_logins.clear(); | 2244 fill_data_.additional_logins.clear(); |
2111 SimulateOnFillPasswordForm(fill_data_); | 2245 SimulateOnFillPasswordForm(fill_data_); |
2112 | 2246 |
2113 CheckTextFieldsState("", false, kAlicePassword, true); | 2247 CheckTextFieldsState("", false, kAlicePassword, true); |
(...skipping 29 matching lines...) Expand all Loading... |
2143 TEST_F(PasswordAutofillAgentTest, | 2277 TEST_F(PasswordAutofillAgentTest, |
2144 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) { | 2278 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) { |
2145 LoadHTML(kNoFormHTML); | 2279 LoadHTML(kNoFormHTML); |
2146 UpdateUsernameAndPasswordElements(); | 2280 UpdateUsernameAndPasswordElements(); |
2147 | 2281 |
2148 SimulateUsernameChange("Bob"); | 2282 SimulateUsernameChange("Bob"); |
2149 SimulatePasswordChange("mypassword"); | 2283 SimulatePasswordChange("mypassword"); |
2150 | 2284 |
2151 password_autofill_agent_->AJAXSucceeded(); | 2285 password_autofill_agent_->AJAXSucceeded(); |
2152 | 2286 |
2153 const IPC::Message* message = | 2287 base::RunLoop().RunUntilIdle(); |
2154 render_thread_->sink().GetFirstMessageMatching( | 2288 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); |
2155 AutofillHostMsg_PasswordFormSubmitted::ID); | |
2156 ASSERT_FALSE(message); | |
2157 } | 2289 } |
2158 | 2290 |
2159 // Tests that credential suggestions are autofilled on a password (and change | 2291 // Tests that credential suggestions are autofilled on a password (and change |
2160 // password) forms having either ambiguous or empty name. | 2292 // password) forms having either ambiguous or empty name. |
2161 TEST_F(PasswordAutofillAgentTest, | 2293 TEST_F(PasswordAutofillAgentTest, |
2162 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { | 2294 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { |
2163 const char kEmpty[] = ""; | 2295 const char kEmpty[] = ""; |
2164 const char kDummyUsernameField[] = "anonymous_username"; | 2296 const char kDummyUsernameField[] = "anonymous_username"; |
2165 const char kDummyPasswordField[] = "anonymous_password"; | 2297 const char kDummyPasswordField[] = "anonymous_password"; |
2166 const char kFormContainsEmptyNamesHTML[] = | 2298 const char kFormContainsEmptyNamesHTML[] = |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2393 TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) { | 2525 TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) { |
2394 // Simulate the browser sending back the login info. | 2526 // Simulate the browser sending back the login info. |
2395 SimulateOnFillPasswordForm(fill_data_); | 2527 SimulateOnFillPasswordForm(fill_data_); |
2396 | 2528 |
2397 // Call SimulateElementClick() to produce a user gesture on the page so | 2529 // Call SimulateElementClick() to produce a user gesture on the page so |
2398 // autofill will actually fill. | 2530 // autofill will actually fill. |
2399 SimulateElementClick(kUsernameName); | 2531 SimulateElementClick(kUsernameName); |
2400 | 2532 |
2401 // Simulate a user clicking on the password element. This should produce a | 2533 // Simulate a user clicking on the password element. This should produce a |
2402 // dropdown with suggestion of all available usernames. | 2534 // dropdown with suggestion of all available usernames. |
2403 render_thread_->sink().ClearMessages(); | |
2404 static_cast<PageClickListener*>(autofill_agent_) | 2535 static_cast<PageClickListener*>(autofill_agent_) |
2405 ->FormControlElementClicked(password_element_, false); | 2536 ->FormControlElementClicked(password_element_, false); |
2406 CheckSuggestions("", false); | 2537 CheckSuggestions("", false); |
2407 } | 2538 } |
2408 | 2539 |
2409 // Tests that a suggestion dropdown is shown on each password field. But when a | 2540 // 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 | 2541 // user chose one of the fields to autofill, a suggestion dropdown will be shown |
2411 // only on this field. | 2542 // only on this field. |
2412 TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) { | 2543 TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) { |
2413 LoadHTML(kPasswordChangeFormHTML); | 2544 LoadHTML(kPasswordChangeFormHTML); |
2414 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2545 UpdateOriginForHTML(kPasswordChangeFormHTML); |
2415 UpdateUsernameAndPasswordElements(); | 2546 UpdateUsernameAndPasswordElements(); |
2416 | 2547 |
2417 // Simulate the browser sending back the login info. | 2548 // Simulate the browser sending back the login info. |
2418 SimulateOnFillPasswordForm(fill_data_); | 2549 SimulateOnFillPasswordForm(fill_data_); |
2419 | 2550 |
2420 // Call SimulateElementClick() to produce a user gesture on the page so | 2551 // Call SimulateElementClick() to produce a user gesture on the page so |
2421 // autofill will actually fill. | 2552 // autofill will actually fill. |
2422 SimulateElementClick(kUsernameName); | 2553 SimulateElementClick(kUsernameName); |
2423 | 2554 |
2424 // Simulate a user clicking on the password elements. This should produce | 2555 // Simulate a user clicking on the password elements. This should produce |
2425 // dropdowns with suggestion of all available usernames. | 2556 // dropdowns with suggestion of all available usernames. |
2426 render_thread_->sink().ClearMessages(); | |
2427 SimulateElementClick("password"); | 2557 SimulateElementClick("password"); |
2428 CheckSuggestions("", false); | 2558 CheckSuggestions("", false); |
2429 | 2559 |
2430 SimulateElementClick("newpassword"); | 2560 SimulateElementClick("newpassword"); |
2431 CheckSuggestions("", false); | 2561 CheckSuggestions("", false); |
2432 | 2562 |
2433 SimulateElementClick("confirmpassword"); | 2563 SimulateElementClick("confirmpassword"); |
2434 CheckSuggestions("", false); | 2564 CheckSuggestions("", false); |
2435 | 2565 |
2436 // The user chooses to autofill the current password field. | 2566 // The user chooses to autofill the current password field. |
2437 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( | 2567 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( |
2438 password_element_, ASCIIToUTF16(kAliceUsername), | 2568 password_element_, ASCIIToUTF16(kAliceUsername), |
2439 ASCIIToUTF16(kAlicePassword))); | 2569 ASCIIToUTF16(kAlicePassword))); |
2440 | 2570 |
2441 // Simulate a user clicking on not autofilled password fields. This should | 2571 // Simulate a user clicking on not autofilled password fields. This should |
2442 // produce | 2572 // produce no suggestion dropdowns. |
2443 // no suggestion dropdowns. | 2573 fake_driver_.reset_show_pw_suggestions(); |
2444 render_thread_->sink().ClearMessages(); | |
2445 SimulateElementClick("newpassword"); | 2574 SimulateElementClick("newpassword"); |
2446 SimulateElementClick("confirmpassword"); | 2575 SimulateElementClick("confirmpassword"); |
2447 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 2576 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); |
2448 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
2449 | 2577 |
2450 // But when the user clicks on the autofilled password field again it should | 2578 // But when the user clicks on the autofilled password field again it should |
2451 // still produce a suggestion dropdown. | 2579 // still produce a suggestion dropdown. |
2452 SimulateElementClick("password"); | 2580 SimulateElementClick("password"); |
2453 CheckSuggestions("", false); | 2581 CheckSuggestions("", false); |
2454 } | 2582 } |
2455 | 2583 |
2456 } // namespace autofill | 2584 } // namespace autofill |
OLD | NEW |