Chromium Code Reviews| 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(static_cast<bool>(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 static_cast<bool>(fake_driver_.show_pw_suggestions_options() & |
| 621 autofill::SHOW_ALL)); | |
| 468 | 622 |
| 469 render_thread_->sink().ClearMessages(); | 623 fake_driver_.reset_show_pw_suggestions(); |
| 624 } | |
| 625 | |
| 626 bool GetCalledShowPasswordSuggestions() { | |
| 627 base::RunLoop().RunUntilIdle(); | |
| 628 return fake_driver_.called_show_pw_suggestions(); | |
| 470 } | 629 } |
| 471 | 630 |
| 472 void ExpectFormSubmittedWithUsernameAndPasswords( | 631 void ExpectFormSubmittedWithUsernameAndPasswords( |
| 473 const std::string& username_value, | 632 const std::string& username_value, |
| 474 const std::string& password_value, | 633 const std::string& password_value, |
| 475 const std::string& new_password_value) { | 634 const std::string& new_password_value) { |
| 476 const IPC::Message* message = | 635 base::RunLoop().RunUntilIdle(); |
| 477 render_thread_->sink().GetFirstMessageMatching( | 636 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); |
| 478 AutofillHostMsg_PasswordFormSubmitted::ID); | 637 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted())); |
| 479 ASSERT_TRUE(message); | 638 const autofill::PasswordForm& form = |
| 480 std::tuple<autofill::PasswordForm> args; | 639 *(fake_driver_.password_form_submitted()); |
| 481 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); | 640 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); |
| 482 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); | 641 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); |
| 483 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); | 642 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 } | 643 } |
| 487 | 644 |
| 488 void ExpectFieldPropertiesMasks( | 645 void ExpectFieldPropertiesMasks( |
| 489 uint32_t expected_message_id, | 646 PasswordFormSourceType expected_type, |
| 490 const std::map<base::string16, FieldPropertiesMask>& | 647 const std::map<base::string16, FieldPropertiesMask>& |
| 491 expected_properties_masks) { | 648 expected_properties_masks) { |
| 492 const IPC::Message* message = | 649 base::RunLoop().RunUntilIdle(); |
| 493 render_thread_->sink().GetFirstMessageMatching(expected_message_id); | 650 autofill::PasswordForm form; |
| 494 ASSERT_TRUE(message); | 651 if (expected_type == PasswordFormSubmitted) { |
| 495 std::tuple<autofill::PasswordForm> args; | 652 ASSERT_TRUE(fake_driver_.called_password_form_submitted()); |
| 496 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); | 653 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_form_submitted())); |
| 497 const autofill::PasswordForm& form = std::get<0>(args); | 654 form = *(fake_driver_.password_form_submitted()); |
| 655 } else if (expected_type == PasswordFormInPageNavigation) { | |
| 656 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); | |
| 657 ASSERT_TRUE( | |
| 658 static_cast<bool>(fake_driver_.password_form_inpage_navigation())); | |
| 659 form = *(fake_driver_.password_form_inpage_navigation()); | |
| 660 } else { | |
| 661 ASSERT_TRUE(false); | |
|
vabr (Chromium)
2016/08/09 17:36:17
Let's rephrase this a bit to improve readability.
leonhsl(Using Gerrit)
2016/08/10 13:22:02
Done.
| |
| 662 } | |
| 498 | 663 |
| 499 size_t unchecked_masks = expected_properties_masks.size(); | 664 size_t unchecked_masks = expected_properties_masks.size(); |
| 500 for (const FormFieldData& field : form.form_data.fields) { | 665 for (const FormFieldData& field : form.form_data.fields) { |
| 501 const auto& it = expected_properties_masks.find(field.name); | 666 const auto& it = expected_properties_masks.find(field.name); |
| 502 if (it == expected_properties_masks.end()) | 667 if (it == expected_properties_masks.end()) |
| 503 continue; | 668 continue; |
| 504 EXPECT_EQ(field.properties_mask, it->second) | 669 EXPECT_EQ(field.properties_mask, it->second) |
| 505 << "Wrong mask for the field " << field.name; | 670 << "Wrong mask for the field " << field.name; |
| 506 unchecked_masks--; | 671 unchecked_masks--; |
| 507 } | 672 } |
| 508 EXPECT_TRUE(unchecked_masks == 0) | 673 EXPECT_TRUE(unchecked_masks == 0) |
| 509 << "Some expected masks are missed in FormData"; | 674 << "Some expected masks are missed in FormData"; |
| 510 } | 675 } |
| 511 | 676 |
| 512 void ExpectInPageNavigationWithUsernameAndPasswords( | 677 void ExpectInPageNavigationWithUsernameAndPasswords( |
| 513 const std::string& username_value, | 678 const std::string& username_value, |
| 514 const std::string& password_value, | 679 const std::string& password_value, |
| 515 const std::string& new_password_value) { | 680 const std::string& new_password_value) { |
| 516 const IPC::Message* message = | 681 base::RunLoop().RunUntilIdle(); |
| 517 render_thread_->sink().GetFirstMessageMatching( | 682 ASSERT_TRUE(fake_driver_.called_inpage_navigation()); |
| 518 AutofillHostMsg_InPageNavigation::ID); | 683 ASSERT_TRUE( |
| 519 ASSERT_TRUE(message); | 684 static_cast<bool>(fake_driver_.password_form_inpage_navigation())); |
| 520 std::tuple<autofill::PasswordForm> args; | 685 const autofill::PasswordForm& form = |
| 521 AutofillHostMsg_InPageNavigation::Read(message, &args); | 686 *(fake_driver_.password_form_inpage_navigation()); |
| 522 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); | 687 EXPECT_EQ(ASCIIToUTF16(username_value), form.username_value); |
| 523 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); | 688 EXPECT_EQ(ASCIIToUTF16(password_value), form.password_value); |
| 524 EXPECT_EQ(ASCIIToUTF16(new_password_value), | 689 EXPECT_EQ(ASCIIToUTF16(new_password_value), form.new_password_value); |
| 525 std::get<0>(args).new_password_value); | |
| 526 } | 690 } |
| 527 | 691 |
| 692 void BindPasswordManagerDriver(mojo::ScopedMessagePipeHandle handle) { | |
| 693 fake_driver_.BindRequest( | |
| 694 mojo::MakeRequest<mojom::PasswordManagerDriver>(std::move(handle))); | |
| 695 } | |
| 696 | |
| 697 FakeContentPasswordManagerDriver fake_driver_; | |
| 698 | |
| 528 base::string16 username1_; | 699 base::string16 username1_; |
| 529 base::string16 username2_; | 700 base::string16 username2_; |
| 530 base::string16 username3_; | 701 base::string16 username3_; |
| 531 base::string16 password1_; | 702 base::string16 password1_; |
| 532 base::string16 password2_; | 703 base::string16 password2_; |
| 533 base::string16 password3_; | 704 base::string16 password3_; |
| 534 base::string16 alternate_username3_; | 705 base::string16 alternate_username3_; |
| 535 PasswordFormFillData fill_data_; | 706 PasswordFormFillData fill_data_; |
| 536 | 707 |
| 537 WebInputElement username_element_; | 708 WebInputElement username_element_; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 EXPECT_FALSE(form_util::IsWebNodeVisible(forms2[0])); | 981 EXPECT_FALSE(form_util::IsWebNodeVisible(forms2[0])); |
| 811 | 982 |
| 812 LoadHTML(kNonVisibleFormHTML); | 983 LoadHTML(kNonVisibleFormHTML); |
| 813 frame = GetMainFrame(); | 984 frame = GetMainFrame(); |
| 814 frame->document().forms(forms3); | 985 frame->document().forms(forms3); |
| 815 ASSERT_EQ(1u, forms3.size()); | 986 ASSERT_EQ(1u, forms3.size()); |
| 816 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); | 987 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); |
| 817 } | 988 } |
| 818 | 989 |
| 819 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { | 990 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { |
| 820 render_thread_->sink().ClearMessages(); | 991 fake_driver_.reset_password_forms_rendered(); |
| 821 LoadHTML(kVisibleFormWithNoUsernameHTML); | 992 LoadHTML(kVisibleFormWithNoUsernameHTML); |
| 822 const IPC::Message* message = render_thread_->sink() | 993 base::RunLoop().RunUntilIdle(); |
| 823 .GetFirstMessageMatching(AutofillHostMsg_PasswordFormsRendered::ID); | 994 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 824 EXPECT_TRUE(message); | 995 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered())); |
| 825 std::tuple<std::vector<autofill::PasswordForm>, bool> param; | 996 EXPECT_TRUE(fake_driver_.password_forms_rendered()->size()); |
|
vabr (Chromium)
2016/08/09 17:36:17
nit: For a container "x", instead of
EXPECT_TRUE(x
leonhsl(Using Gerrit)
2016/08/10 13:22:02
Done.
| |
| 826 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | |
| 827 EXPECT_TRUE(std::get<0>(param).size()); | |
| 828 | 997 |
| 829 render_thread_->sink().ClearMessages(); | 998 fake_driver_.reset_password_forms_rendered(); |
| 830 LoadHTML(kEmptyFormHTML); | 999 LoadHTML(kEmptyFormHTML); |
| 831 message = render_thread_->sink().GetFirstMessageMatching( | 1000 base::RunLoop().RunUntilIdle(); |
| 832 AutofillHostMsg_PasswordFormsRendered::ID); | 1001 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 833 EXPECT_TRUE(message); | 1002 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered())); |
| 834 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 1003 EXPECT_FALSE(fake_driver_.password_forms_rendered()->size()); |
| 835 EXPECT_FALSE(std::get<0>(param).size()); | |
| 836 | 1004 |
| 837 render_thread_->sink().ClearMessages(); | 1005 fake_driver_.reset_password_forms_rendered(); |
| 838 LoadHTML(kNonVisibleFormHTML); | 1006 LoadHTML(kNonVisibleFormHTML); |
| 839 message = render_thread_->sink().GetFirstMessageMatching( | 1007 base::RunLoop().RunUntilIdle(); |
| 840 AutofillHostMsg_PasswordFormsRendered::ID); | 1008 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 841 EXPECT_TRUE(message); | 1009 ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered())); |
| 842 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 1010 EXPECT_FALSE(fake_driver_.password_forms_rendered()->size()); |
| 843 EXPECT_FALSE(std::get<0>(param).size()); | |
| 844 } | 1011 } |
| 845 | 1012 |
| 846 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { | 1013 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { |
| 847 render_thread_->sink().ClearMessages(); | 1014 fake_driver_.reset_password_forms_rendered(); |
| 848 LoadHTML(kEmptyWebpage); | 1015 LoadHTML(kEmptyWebpage); |
| 849 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1016 base::RunLoop().RunUntilIdle(); |
| 850 AutofillHostMsg_PasswordFormsRendered::ID)); | 1017 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); |
| 851 | 1018 |
| 852 render_thread_->sink().ClearMessages(); | 1019 fake_driver_.reset_password_forms_rendered(); |
| 853 LoadHTML(kRedirectionWebpage); | 1020 LoadHTML(kRedirectionWebpage); |
| 854 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1021 base::RunLoop().RunUntilIdle(); |
| 855 AutofillHostMsg_PasswordFormsRendered::ID)); | 1022 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); |
| 856 | 1023 |
| 857 render_thread_->sink().ClearMessages(); | 1024 fake_driver_.reset_password_forms_rendered(); |
| 858 LoadHTML(kSimpleWebpage); | 1025 LoadHTML(kSimpleWebpage); |
| 859 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1026 base::RunLoop().RunUntilIdle(); |
| 860 AutofillHostMsg_PasswordFormsRendered::ID)); | 1027 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 861 | 1028 |
| 862 render_thread_->sink().ClearMessages(); | 1029 fake_driver_.reset_password_forms_rendered(); |
| 863 LoadHTML(kWebpageWithDynamicContent); | 1030 LoadHTML(kWebpageWithDynamicContent); |
| 864 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1031 base::RunLoop().RunUntilIdle(); |
| 865 AutofillHostMsg_PasswordFormsRendered::ID)); | 1032 EXPECT_TRUE(fake_driver_.called_password_forms_rendered()); |
| 866 } | 1033 } |
| 867 | 1034 |
| 868 // Tests that a password will only be filled as a suggested and will not be | 1035 // 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. | 1036 // accessible by the DOM until a user gesture has occurred. |
| 870 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { | 1037 TEST_F(PasswordAutofillAgentTest, GestureRequiredTest) { |
| 871 // Trigger the initial autocomplete. | 1038 // Trigger the initial autocomplete. |
| 872 SimulateOnFillPasswordForm(fill_data_); | 1039 SimulateOnFillPasswordForm(fill_data_); |
| 873 | 1040 |
| 874 // The username and password should have been autocompleted. | 1041 // The username and password should have been autocompleted. |
| 875 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 1042 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()); | 1377 EXPECT_TRUE(username_element_.suggestedValue().isEmpty()); |
| 1211 EXPECT_FALSE(username_element_.isAutofilled()); | 1378 EXPECT_FALSE(username_element_.isAutofilled()); |
| 1212 EXPECT_TRUE(password_element_.value().isEmpty()); | 1379 EXPECT_TRUE(password_element_.value().isEmpty()); |
| 1213 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); | 1380 EXPECT_TRUE(password_element_.suggestedValue().isEmpty()); |
| 1214 EXPECT_FALSE(password_element_.isAutofilled()); | 1381 EXPECT_FALSE(password_element_.isAutofilled()); |
| 1215 CheckUsernameSelection(0, 0); | 1382 CheckUsernameSelection(0, 0); |
| 1216 } | 1383 } |
| 1217 | 1384 |
| 1218 // Tests that logging is off by default. | 1385 // Tests that logging is off by default. |
| 1219 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { | 1386 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { |
| 1220 render_thread_->sink().ClearMessages(); | |
| 1221 SendVisiblePasswordForms(); | 1387 SendVisiblePasswordForms(); |
| 1222 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1388 base::RunLoop().RunUntilIdle(); |
| 1223 AutofillHostMsg_RecordSavePasswordProgress::ID); | 1389 EXPECT_FALSE(fake_driver_.called_record_save_progress()); |
| 1224 EXPECT_FALSE(message); | |
| 1225 } | 1390 } |
| 1226 | 1391 |
| 1227 // Test that logging can be turned on by a message. | 1392 // Test that logging can be turned on by a message. |
| 1228 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { | 1393 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { |
| 1229 // Turn the logging on. | 1394 // Turn the logging on. |
| 1230 AutofillMsg_SetLoggingState msg_activate(0, true); | 1395 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 | 1396 |
| 1235 render_thread_->sink().ClearMessages(); | |
| 1236 SendVisiblePasswordForms(); | 1397 SendVisiblePasswordForms(); |
| 1237 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1398 base::RunLoop().RunUntilIdle(); |
| 1238 AutofillHostMsg_RecordSavePasswordProgress::ID); | 1399 EXPECT_TRUE(fake_driver_.called_record_save_progress()); |
| 1239 EXPECT_TRUE(message); | |
| 1240 } | 1400 } |
| 1241 | 1401 |
| 1242 // Test that logging can be turned off by a message. | 1402 // Test that logging can be turned off by a message. |
| 1243 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { | 1403 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { |
| 1244 // Turn the logging on and then off. | 1404 // Turn the logging on and then off. |
| 1245 AutofillMsg_SetLoggingState msg_activate(0, /*active=*/true); | 1405 password_autofill_agent_->SetLoggingState(true); |
| 1246 // Up-cast to access OnMessageReceived, which is private in the agent. | 1406 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 | 1407 |
| 1253 render_thread_->sink().ClearMessages(); | |
| 1254 SendVisiblePasswordForms(); | 1408 SendVisiblePasswordForms(); |
| 1255 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1409 base::RunLoop().RunUntilIdle(); |
| 1256 AutofillHostMsg_RecordSavePasswordProgress::ID); | 1410 EXPECT_FALSE(fake_driver_.called_record_save_progress()); |
| 1257 EXPECT_FALSE(message); | |
| 1258 } | 1411 } |
| 1259 | 1412 |
| 1260 // Test that the agent sends an IPC call to get the current activity state of | 1413 // Test that the agent sends an IPC call to get the current activity state of |
| 1261 // password saving logging soon after construction. | 1414 // password saving logging soon after construction. |
| 1262 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) { | 1415 TEST_F(PasswordAutofillAgentTest, SendsLoggingStateUpdatePingOnConstruction) { |
| 1263 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 1416 base::RunLoop().RunUntilIdle(); |
| 1264 AutofillHostMsg_PasswordAutofillAgentConstructed::ID); | 1417 EXPECT_TRUE(fake_driver_.called_agent_constructed()); |
| 1265 EXPECT_TRUE(message); | |
| 1266 } | 1418 } |
| 1267 | 1419 |
| 1268 // Tests that one user click on a username field is sufficient to bring up a | 1420 // 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 | 1421 // credential suggestion popup, and the user can autocomplete the password by |
| 1270 // selecting the credential from the popup. | 1422 // selecting the credential from the popup. |
| 1271 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { | 1423 TEST_F(PasswordAutofillAgentTest, ClickAndSelect) { |
| 1272 // SimulateElementClick() is called so that a user gesture is actually made | 1424 // SimulateElementClick() is called so that a user gesture is actually made |
| 1273 // and the password can be filled. However, SimulateElementClick() does not | 1425 // and the password can be filled. However, SimulateElementClick() does not |
| 1274 // actually lead to the AutofillAgent's InputElementClicked() method being | 1426 // actually lead to the AutofillAgent's InputElementClicked() method being |
| 1275 // called, so SimulateSuggestionChoice has to manually call | 1427 // called, so SimulateSuggestionChoice has to manually call |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1294 | 1446 |
| 1295 // Clear the text fields to start fresh. | 1447 // Clear the text fields to start fresh. |
| 1296 ClearUsernameAndPasswordFields(); | 1448 ClearUsernameAndPasswordFields(); |
| 1297 | 1449 |
| 1298 // Call SimulateElementClick() to produce a user gesture on the page so | 1450 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1299 // autofill will actually fill. | 1451 // autofill will actually fill. |
| 1300 SimulateElementClick(kUsernameName); | 1452 SimulateElementClick(kUsernameName); |
| 1301 | 1453 |
| 1302 // Simulate a user clicking on the username element. This should produce a | 1454 // Simulate a user clicking on the username element. This should produce a |
| 1303 // message with all the usernames. | 1455 // message with all the usernames. |
| 1304 render_thread_->sink().ClearMessages(); | |
| 1305 static_cast<PageClickListener*>(autofill_agent_) | 1456 static_cast<PageClickListener*>(autofill_agent_) |
| 1306 ->FormControlElementClicked(username_element_, false); | 1457 ->FormControlElementClicked(username_element_, false); |
| 1307 CheckSuggestions(std::string(), false); | 1458 CheckSuggestions(std::string(), false); |
| 1308 | 1459 |
| 1309 // Now simulate a user typing in an unrecognized username and then | 1460 // Now simulate a user typing in an unrecognized username and then |
| 1310 // clicking on the username element. This should also produce a message with | 1461 // clicking on the username element. This should also produce a message with |
| 1311 // all the usernames. | 1462 // all the usernames. |
| 1312 SimulateUsernameChange("baz"); | 1463 SimulateUsernameChange("baz"); |
| 1313 render_thread_->sink().ClearMessages(); | |
| 1314 static_cast<PageClickListener*>(autofill_agent_) | 1464 static_cast<PageClickListener*>(autofill_agent_) |
| 1315 ->FormControlElementClicked(username_element_, true); | 1465 ->FormControlElementClicked(username_element_, true); |
| 1316 CheckSuggestions("baz", true); | 1466 CheckSuggestions("baz", true); |
| 1317 ClearUsernameAndPasswordFields(); | 1467 ClearUsernameAndPasswordFields(); |
| 1318 } | 1468 } |
| 1319 | 1469 |
| 1320 // Tests that there is an autosuggestion from the password manager when the | 1470 // Tests that there is an autosuggestion from the password manager when the |
| 1321 // user clicks on the password field when FillOnAccountSelect is enabled. | 1471 // user clicks on the password field when FillOnAccountSelect is enabled. |
| 1322 TEST_F(PasswordAutofillAgentTest, | 1472 TEST_F(PasswordAutofillAgentTest, |
| 1323 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { | 1473 FillOnAccountSelectOnlyNoCredentialsOnPasswordClick) { |
| 1324 SetFillOnAccountSelect(); | 1474 SetFillOnAccountSelect(); |
| 1325 | 1475 |
| 1326 // Simulate the browser sending back the login info. | 1476 // Simulate the browser sending back the login info. |
| 1327 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); | 1477 SimulateOnShowInitialPasswordAccountSuggestions(fill_data_); |
| 1328 | 1478 |
| 1329 // Clear the text fields to start fresh. | 1479 // Clear the text fields to start fresh. |
| 1330 ClearUsernameAndPasswordFields(); | 1480 ClearUsernameAndPasswordFields(); |
| 1331 | 1481 |
| 1332 // Call SimulateElementClick() to produce a user gesture on the page so | 1482 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1333 // autofill will actually fill. | 1483 // autofill will actually fill. |
| 1334 SimulateElementClick(kUsernameName); | 1484 SimulateElementClick(kUsernameName); |
| 1335 | 1485 |
| 1336 // Simulate a user clicking on the password element. This should produce no | 1486 // Simulate a user clicking on the password element. This should produce no |
| 1337 // message. | 1487 // message. |
| 1338 render_thread_->sink().ClearMessages(); | 1488 fake_driver_.reset_show_pw_suggestions(); |
| 1339 static_cast<PageClickListener*>(autofill_agent_) | 1489 static_cast<PageClickListener*>(autofill_agent_) |
| 1340 ->FormControlElementClicked(password_element_, false); | 1490 ->FormControlElementClicked(password_element_, false); |
| 1341 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1491 EXPECT_TRUE(GetCalledShowPasswordSuggestions()); |
| 1342 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 1343 } | 1492 } |
| 1344 | 1493 |
| 1345 // Tests the autosuggestions that are given when a password element is clicked, | 1494 // Tests the autosuggestions that are given when a password element is clicked, |
| 1346 // the username element is not editable, and FillOnAccountSelect is enabled. | 1495 // the username element is not editable, and FillOnAccountSelect is enabled. |
| 1347 // Specifically, tests when the user clicks on the password element after page | 1496 // Specifically, tests when the user clicks on the password element after page |
| 1348 // load, and the corresponding username element is readonly (and thus | 1497 // load, and the corresponding username element is readonly (and thus |
| 1349 // uneditable), that the credentials for the already-filled username are | 1498 // uneditable), that the credentials for the already-filled username are |
| 1350 // suggested. | 1499 // suggested. |
| 1351 TEST_F(PasswordAutofillAgentTest, | 1500 TEST_F(PasswordAutofillAgentTest, |
| 1352 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { | 1501 FillOnAccountSelectOnlyCredentialsOnPasswordClick) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1363 username_element_.setValue("alicia"); | 1512 username_element_.setValue("alicia"); |
| 1364 SetElementReadOnly(username_element_, true); | 1513 SetElementReadOnly(username_element_, true); |
| 1365 | 1514 |
| 1366 // Call SimulateElementClick() to produce a user gesture on the page so | 1515 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1367 // autofill will actually fill. | 1516 // autofill will actually fill. |
| 1368 SimulateElementClick(kUsernameName); | 1517 SimulateElementClick(kUsernameName); |
| 1369 | 1518 |
| 1370 // Simulate a user clicking on the password element. This should produce a | 1519 // Simulate a user clicking on the password element. This should produce a |
| 1371 // dropdown with suggestion of all available usernames and so username | 1520 // dropdown with suggestion of all available usernames and so username |
| 1372 // filter will be the empty string. | 1521 // filter will be the empty string. |
| 1373 render_thread_->sink().ClearMessages(); | |
| 1374 static_cast<PageClickListener*>(autofill_agent_) | 1522 static_cast<PageClickListener*>(autofill_agent_) |
| 1375 ->FormControlElementClicked(password_element_, false); | 1523 ->FormControlElementClicked(password_element_, false); |
| 1376 CheckSuggestions("", false); | 1524 CheckSuggestions("", false); |
| 1377 } | 1525 } |
| 1378 | 1526 |
| 1379 // Tests that there is an autosuggestion from the password manager when the | 1527 // Tests that there is an autosuggestion from the password manager when the |
| 1380 // user clicks on the password field. | 1528 // user clicks on the password field. |
| 1381 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { | 1529 TEST_F(PasswordAutofillAgentTest, NoCredentialsOnPasswordClick) { |
| 1382 // Simulate the browser sending back the login info. | 1530 // Simulate the browser sending back the login info. |
| 1383 SimulateOnFillPasswordForm(fill_data_); | 1531 SimulateOnFillPasswordForm(fill_data_); |
| 1384 | 1532 |
| 1385 // Clear the text fields to start fresh. | 1533 // Clear the text fields to start fresh. |
| 1386 ClearUsernameAndPasswordFields(); | 1534 ClearUsernameAndPasswordFields(); |
| 1387 | 1535 |
| 1388 // Call SimulateElementClick() to produce a user gesture on the page so | 1536 // Call SimulateElementClick() to produce a user gesture on the page so |
| 1389 // autofill will actually fill. | 1537 // autofill will actually fill. |
| 1390 SimulateElementClick(kUsernameName); | 1538 SimulateElementClick(kUsernameName); |
| 1391 | 1539 |
| 1392 // Simulate a user clicking on the password element. This should produce no | 1540 // Simulate a user clicking on the password element. This should produce no |
| 1393 // message. | 1541 // message. |
| 1394 render_thread_->sink().ClearMessages(); | 1542 fake_driver_.reset_show_pw_suggestions(); |
| 1395 static_cast<PageClickListener*>(autofill_agent_) | 1543 static_cast<PageClickListener*>(autofill_agent_) |
| 1396 ->FormControlElementClicked(password_element_, false); | 1544 ->FormControlElementClicked(password_element_, false); |
| 1397 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 1545 EXPECT_TRUE(GetCalledShowPasswordSuggestions()); |
| 1398 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 1399 } | 1546 } |
| 1400 | 1547 |
| 1401 // The user types in a username and a password, but then just before sending | 1548 // 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 | 1549 // the form off, a script clears them. This test checks that |
| 1403 // PasswordAutofillAgent can still remember the username and the password | 1550 // PasswordAutofillAgent can still remember the username and the password |
| 1404 // typed by the user. | 1551 // typed by the user. |
| 1405 TEST_F(PasswordAutofillAgentTest, | 1552 TEST_F(PasswordAutofillAgentTest, |
| 1406 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { | 1553 RememberLastNonEmptyUsernameAndPasswordOnSubmit_ScriptCleared) { |
| 1407 SimulateUsernameChange("temp"); | 1554 SimulateUsernameChange("temp"); |
| 1408 SimulatePasswordChange("random"); | 1555 SimulatePasswordChange("random"); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1534 ->WillSubmitForm(username_element_.form()); | 1681 ->WillSubmitForm(username_element_.form()); |
| 1535 | 1682 |
| 1536 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; | 1683 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; |
| 1537 expected_properties_masks[ASCIIToUTF16("random_field")] = | 1684 expected_properties_masks[ASCIIToUTF16("random_field")] = |
| 1538 FieldPropertiesFlags::NO_FLAGS; | 1685 FieldPropertiesFlags::NO_FLAGS; |
| 1539 expected_properties_masks[ASCIIToUTF16("username")] = | 1686 expected_properties_masks[ASCIIToUTF16("username")] = |
| 1540 FieldPropertiesFlags::USER_TYPED; | 1687 FieldPropertiesFlags::USER_TYPED; |
| 1541 expected_properties_masks[ASCIIToUTF16("password")] = | 1688 expected_properties_masks[ASCIIToUTF16("password")] = |
| 1542 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; | 1689 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; |
| 1543 | 1690 |
| 1544 ExpectFieldPropertiesMasks(AutofillHostMsg_PasswordFormSubmitted::ID, | 1691 ExpectFieldPropertiesMasks(PasswordFormSubmitted, expected_properties_masks); |
| 1545 expected_properties_masks); | |
| 1546 } | 1692 } |
| 1547 | 1693 |
| 1548 TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) { | 1694 TEST_F(PasswordAutofillAgentTest, RememberFieldPropertiesOnInPageNavigation) { |
| 1549 LoadHTML(kNoFormHTML); | 1695 LoadHTML(kNoFormHTML); |
| 1550 UpdateUsernameAndPasswordElements(); | 1696 UpdateUsernameAndPasswordElements(); |
| 1551 | 1697 |
| 1552 SimulateUsernameChange("Bob"); | 1698 SimulateUsernameChange("Bob"); |
| 1553 SimulatePasswordChange("mypassword"); | 1699 SimulatePasswordChange("mypassword"); |
| 1554 | 1700 |
| 1555 username_element_.setAttribute("style", "display:none;"); | 1701 username_element_.setAttribute("style", "display:none;"); |
| 1556 password_element_.setAttribute("style", "display:none;"); | 1702 password_element_.setAttribute("style", "display:none;"); |
| 1557 | 1703 |
| 1558 password_autofill_agent_->AJAXSucceeded(); | 1704 password_autofill_agent_->AJAXSucceeded(); |
| 1559 | 1705 |
| 1560 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; | 1706 std::map<base::string16, FieldPropertiesMask> expected_properties_masks; |
| 1561 expected_properties_masks[ASCIIToUTF16("username")] = | 1707 expected_properties_masks[ASCIIToUTF16("username")] = |
| 1562 FieldPropertiesFlags::USER_TYPED; | 1708 FieldPropertiesFlags::USER_TYPED; |
| 1563 expected_properties_masks[ASCIIToUTF16("password")] = | 1709 expected_properties_masks[ASCIIToUTF16("password")] = |
| 1564 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; | 1710 FieldPropertiesFlags::USER_TYPED | FieldPropertiesFlags::HAD_FOCUS; |
| 1565 | 1711 |
| 1566 ExpectFieldPropertiesMasks(AutofillHostMsg_InPageNavigation::ID, | 1712 ExpectFieldPropertiesMasks(PasswordFormInPageNavigation, |
| 1567 expected_properties_masks); | 1713 expected_properties_masks); |
| 1568 } | 1714 } |
| 1569 | 1715 |
| 1570 // The username/password is autofilled by password manager then just before | 1716 // The username/password is autofilled by password manager then just before |
| 1571 // sending the form off, a script changes them. This test checks that | 1717 // sending the form off, a script changes them. This test checks that |
| 1572 // PasswordAutofillAgent can still get the username and the password autofilled. | 1718 // PasswordAutofillAgent can still get the username and the password autofilled. |
| 1573 TEST_F(PasswordAutofillAgentTest, | 1719 TEST_F(PasswordAutofillAgentTest, |
| 1574 RememberLastAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { | 1720 RememberLastAutofilledUsernameAndPasswordOnSubmit_ScriptChanged) { |
| 1575 SimulateOnFillPasswordForm(fill_data_); | 1721 SimulateOnFillPasswordForm(fill_data_); |
| 1576 | 1722 |
| (...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. | 1941 // Simulate the browser sending back the login info for an initial page load. |
| 1796 SimulateOnFillPasswordForm(fill_data_); | 1942 SimulateOnFillPasswordForm(fill_data_); |
| 1797 | 1943 |
| 1798 // Do not show popup suggesstion when the password field is not-empty and not | 1944 // Do not show popup suggesstion when the password field is not-empty and not |
| 1799 // autofilled. | 1945 // autofilled. |
| 1800 password_element_.setValue("123"); | 1946 password_element_.setValue("123"); |
| 1801 password_element_.setAutofilled(false); | 1947 password_element_.setAutofilled(false); |
| 1802 | 1948 |
| 1803 SimulateSuggestionChoiceOfUsernameAndPassword( | 1949 SimulateSuggestionChoiceOfUsernameAndPassword( |
| 1804 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); | 1950 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); |
| 1805 ASSERT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 1951 ASSERT_FALSE(GetCalledShowPasswordSuggestions()); |
| 1806 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 1807 } | 1952 } |
| 1808 | 1953 |
| 1809 // Tests with fill-on-account-select enabled that if the username element is | 1954 // 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 | 1955 // 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). | 1956 // highlighted as autofillable (regression test for https://crbug.com/442564). |
| 1812 TEST_F(PasswordAutofillAgentTest, | 1957 TEST_F(PasswordAutofillAgentTest, |
| 1813 FillOnAccountSelectOnlyReadonlyUnknownUsername) { | 1958 FillOnAccountSelectOnlyReadonlyUnknownUsername) { |
| 1814 SetFillOnAccountSelect(); | 1959 SetFillOnAccountSelect(); |
| 1815 | 1960 |
| 1816 ClearUsernameAndPasswordFields(); | 1961 ClearUsernameAndPasswordFields(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1853 blink::WebFormElement form_element = username_element_.form(); | 1998 blink::WebFormElement form_element = username_element_.form(); |
| 1854 FormData form_data; | 1999 FormData form_data; |
| 1855 ASSERT_TRUE(WebFormElementToFormData( | 2000 ASSERT_TRUE(WebFormElementToFormData( |
| 1856 form_element, blink::WebFormControlElement(), nullptr, | 2001 form_element, blink::WebFormControlElement(), nullptr, |
| 1857 form_util::EXTRACT_NONE, &form_data, nullptr)); | 2002 form_util::EXTRACT_NONE, &form_data, nullptr)); |
| 1858 // Simulate Autofill predictions: the first field is username, the third | 2003 // Simulate Autofill predictions: the first field is username, the third |
| 1859 // one is password. | 2004 // one is password. |
| 1860 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; | 2005 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
| 1861 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME; | 2006 predictions[form_data][form_data.fields[0]] = PREDICTION_USERNAME; |
| 1862 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD; | 2007 predictions[form_data][form_data.fields[2]] = PREDICTION_NEW_PASSWORD; |
| 1863 AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions); | 2008 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( |
| 1864 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2009 predictions); |
| 1865 ->OnMessageReceived(msg); | |
| 1866 | 2010 |
| 1867 // The predictions should still match even if the form changes, as long | 2011 // The predictions should still match even if the form changes, as long |
| 1868 // as the particular elements don't change. | 2012 // as the particular elements don't change. |
| 1869 std::string add_field_to_form = | 2013 std::string add_field_to_form = |
| 1870 "var form = document.getElementById('LoginTestForm');" | 2014 "var form = document.getElementById('LoginTestForm');" |
| 1871 "var new_input = document.createElement('input');" | 2015 "var new_input = document.createElement('input');" |
| 1872 "new_input.setAttribute('type', 'text');" | 2016 "new_input.setAttribute('type', 'text');" |
| 1873 "new_input.setAttribute('id', 'other_field');" | 2017 "new_input.setAttribute('id', 'other_field');" |
| 1874 "form.appendChild(new_input);"; | 2018 "form.appendChild(new_input);"; |
| 1875 ExecuteJavaScriptForTests(add_field_to_form.c_str()); | 2019 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. | 2071 // generation both trigger. Regression test for https://crbug.com/493455. |
| 1928 TEST_F(PasswordAutofillAgentTest, | 2072 TEST_F(PasswordAutofillAgentTest, |
| 1929 PasswordGenerationTriggered_GeneratedPassword) { | 2073 PasswordGenerationTriggered_GeneratedPassword) { |
| 1930 SimulateOnFillPasswordForm(fill_data_); | 2074 SimulateOnFillPasswordForm(fill_data_); |
| 1931 | 2075 |
| 1932 SetNotBlacklistedMessage(password_generation_, kFormHTML); | 2076 SetNotBlacklistedMessage(password_generation_, kFormHTML); |
| 1933 SetAccountCreationFormsDetectedMessage(password_generation_, | 2077 SetAccountCreationFormsDetectedMessage(password_generation_, |
| 1934 GetMainFrame()->document(), 0, 2); | 2078 GetMainFrame()->document(), 0, 2); |
| 1935 | 2079 |
| 1936 base::string16 password = base::ASCIIToUTF16("NewPass22"); | 2080 base::string16 password = base::ASCIIToUTF16("NewPass22"); |
| 1937 AutofillMsg_GeneratedPasswordAccepted msg(0, password); | 2081 password_generation_->GeneratedPasswordAccepted(password); |
| 1938 static_cast<IPC::Listener*>(password_generation_)->OnMessageReceived(msg); | |
| 1939 | 2082 |
| 1940 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2083 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 1941 ->WillSendSubmitEvent(username_element_.form()); | 2084 ->WillSendSubmitEvent(username_element_.form()); |
| 1942 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2085 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 1943 ->WillSubmitForm(username_element_.form()); | 2086 ->WillSubmitForm(username_element_.form()); |
| 1944 | 2087 |
| 1945 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); | 2088 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); |
| 1946 } | 2089 } |
| 1947 | 2090 |
| 1948 // If password generation is enabled for a field, password autofill should not | 2091 // If password generation is enabled for a field, password autofill should not |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1969 // Simulate generation triggering. | 2112 // Simulate generation triggering. |
| 1970 SetNotBlacklistedMessage(password_generation_, | 2113 SetNotBlacklistedMessage(password_generation_, |
| 1971 kSignupFormHTML); | 2114 kSignupFormHTML); |
| 1972 SetAccountCreationFormsDetectedMessage(password_generation_, | 2115 SetAccountCreationFormsDetectedMessage(password_generation_, |
| 1973 GetMainFrame()->document(), 0, 1); | 2116 GetMainFrame()->document(), 0, 1); |
| 1974 | 2117 |
| 1975 // Simulate the field being clicked to start typing. This should trigger | 2118 // Simulate the field being clicked to start typing. This should trigger |
| 1976 // generation but not password autofill. | 2119 // generation but not password autofill. |
| 1977 SetFocused(password_element_); | 2120 SetFocused(password_element_); |
| 1978 SimulateElementClick("new_password"); | 2121 SimulateElementClick("new_password"); |
| 1979 EXPECT_EQ(nullptr, | 2122 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); |
| 1980 render_thread_->sink().GetFirstMessageMatching( | |
| 1981 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 1982 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 2123 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 1983 AutofillHostMsg_ShowPasswordGenerationPopup::ID)); | 2124 AutofillHostMsg_ShowPasswordGenerationPopup::ID)); |
| 1984 } | 2125 } |
| 1985 | 2126 |
| 1986 // Tests that a password change form is properly filled with the username and | 2127 // Tests that a password change form is properly filled with the username and |
| 1987 // password. | 2128 // password. |
| 1988 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { | 2129 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) { |
| 1989 LoadHTML(kPasswordChangeFormHTML); | 2130 LoadHTML(kPasswordChangeFormHTML); |
| 1990 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2131 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 1991 UpdateUsernameAndPasswordElements(); | 2132 UpdateUsernameAndPasswordElements(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2033 LoadHTML(kPasswordChangeFormHTML); | 2174 LoadHTML(kPasswordChangeFormHTML); |
| 2034 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2175 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 2035 UpdateUsernameAndPasswordElements(); | 2176 UpdateUsernameAndPasswordElements(); |
| 2036 | 2177 |
| 2037 ClearUsernameAndPasswordFields(); | 2178 ClearUsernameAndPasswordFields(); |
| 2038 fill_data_.wait_for_username = true; | 2179 fill_data_.wait_for_username = true; |
| 2039 fill_data_.is_possible_change_password_form = true; | 2180 fill_data_.is_possible_change_password_form = true; |
| 2040 SimulateOnFillPasswordForm(fill_data_); | 2181 SimulateOnFillPasswordForm(fill_data_); |
| 2041 // Simulate a user clicking on the username element. This should produce a | 2182 // Simulate a user clicking on the username element. This should produce a |
| 2042 // message. | 2183 // message. |
| 2043 render_thread_->sink().ClearMessages(); | |
| 2044 static_cast<PageClickListener*>(autofill_agent_) | 2184 static_cast<PageClickListener*>(autofill_agent_) |
| 2045 ->FormControlElementClicked(username_element_, true); | 2185 ->FormControlElementClicked(username_element_, true); |
| 2046 CheckSuggestions("", true); | 2186 CheckSuggestions("", true); |
| 2047 } | 2187 } |
| 2048 | 2188 |
| 2049 // Tests that one user click on a password field is sufficient to bring up a | 2189 // Tests that one user click on a password field is sufficient to bring up a |
| 2050 // credential suggestion popup on a change password form. | 2190 // credential suggestion popup on a change password form. |
| 2051 TEST_F(PasswordAutofillAgentTest, | 2191 TEST_F(PasswordAutofillAgentTest, |
| 2052 SuggestionsOnPasswordFieldOfChangePasswordForm) { | 2192 SuggestionsOnPasswordFieldOfChangePasswordForm) { |
| 2053 LoadHTML(kPasswordChangeFormHTML); | 2193 LoadHTML(kPasswordChangeFormHTML); |
| 2054 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2194 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 2055 UpdateUsernameAndPasswordElements(); | 2195 UpdateUsernameAndPasswordElements(); |
| 2056 | 2196 |
| 2057 ClearUsernameAndPasswordFields(); | 2197 ClearUsernameAndPasswordFields(); |
| 2058 fill_data_.wait_for_username = true; | 2198 fill_data_.wait_for_username = true; |
| 2059 fill_data_.is_possible_change_password_form = true; | 2199 fill_data_.is_possible_change_password_form = true; |
| 2060 SimulateOnFillPasswordForm(fill_data_); | 2200 SimulateOnFillPasswordForm(fill_data_); |
| 2061 // Simulate a user clicking on the password element. This should produce a | 2201 // Simulate a user clicking on the password element. This should produce a |
| 2062 // message. | 2202 // message. |
| 2063 render_thread_->sink().ClearMessages(); | |
| 2064 static_cast<PageClickListener*>(autofill_agent_) | 2203 static_cast<PageClickListener*>(autofill_agent_) |
| 2065 ->FormControlElementClicked(password_element_, true); | 2204 ->FormControlElementClicked(password_element_, true); |
| 2066 CheckSuggestions("", false); | 2205 CheckSuggestions("", false); |
| 2067 } | 2206 } |
| 2068 | 2207 |
| 2069 // Tests that NOT_PASSWORD field predictions are followed so that no password | 2208 // Tests that NOT_PASSWORD field predictions are followed so that no password |
| 2070 // form is submitted. | 2209 // form is submitted. |
| 2071 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { | 2210 TEST_F(PasswordAutofillAgentTest, IgnoreNotPasswordFields) { |
| 2072 LoadHTML(kCreditCardFormHTML); | 2211 LoadHTML(kCreditCardFormHTML); |
| 2073 blink::WebInputElement credit_card_owner_element = | 2212 blink::WebInputElement credit_card_owner_element = |
| 2074 GetInputElementByID(kCreditCardOwnerName); | 2213 GetInputElementByID(kCreditCardOwnerName); |
| 2075 blink::WebInputElement credit_card_number_element = | 2214 blink::WebInputElement credit_card_number_element = |
| 2076 GetInputElementByID(kCreditCardNumberName); | 2215 GetInputElementByID(kCreditCardNumberName); |
| 2077 blink::WebInputElement credit_card_verification_element = | 2216 blink::WebInputElement credit_card_verification_element = |
| 2078 GetInputElementByID(kCreditCardVerificationName); | 2217 GetInputElementByID(kCreditCardVerificationName); |
| 2079 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith"); | 2218 SimulateUserInputChangeForElement(&credit_card_owner_element, "JohnSmith"); |
| 2080 SimulateUserInputChangeForElement(&credit_card_number_element, | 2219 SimulateUserInputChangeForElement(&credit_card_number_element, |
| 2081 "1234123412341234"); | 2220 "1234123412341234"); |
| 2082 SimulateUserInputChangeForElement(&credit_card_verification_element, "123"); | 2221 SimulateUserInputChangeForElement(&credit_card_verification_element, "123"); |
| 2083 // Find FormData for visible form. | 2222 // Find FormData for visible form. |
| 2084 blink::WebFormElement form_element = credit_card_number_element.form(); | 2223 blink::WebFormElement form_element = credit_card_number_element.form(); |
| 2085 FormData form_data; | 2224 FormData form_data; |
| 2086 ASSERT_TRUE(WebFormElementToFormData( | 2225 ASSERT_TRUE(WebFormElementToFormData( |
| 2087 form_element, blink::WebFormControlElement(), nullptr, | 2226 form_element, blink::WebFormControlElement(), nullptr, |
| 2088 form_util::EXTRACT_NONE, &form_data, nullptr)); | 2227 form_util::EXTRACT_NONE, &form_data, nullptr)); |
| 2089 // Simulate Autofill predictions: the third field is not a password. | 2228 // Simulate Autofill predictions: the third field is not a password. |
| 2090 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; | 2229 std::map<autofill::FormData, PasswordFormFieldPredictionMap> predictions; |
| 2091 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; | 2230 predictions[form_data][form_data.fields[2]] = PREDICTION_NOT_PASSWORD; |
| 2092 AutofillMsg_AutofillUsernameAndPasswordDataReceived msg(0, predictions); | 2231 password_autofill_agent_->AutofillUsernameAndPasswordDataReceived( |
| 2093 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2232 predictions); |
| 2094 ->OnMessageReceived(msg); | |
| 2095 | 2233 |
| 2096 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2234 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 2097 ->WillSendSubmitEvent(form_element); | 2235 ->WillSendSubmitEvent(form_element); |
| 2098 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2236 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 2099 ->WillSubmitForm(form_element); | 2237 ->WillSubmitForm(form_element); |
| 2100 | 2238 |
| 2101 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 2239 base::RunLoop().RunUntilIdle(); |
| 2102 AutofillHostMsg_PasswordFormSubmitted::ID); | 2240 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); |
| 2103 ASSERT_FALSE(message); | |
| 2104 } | 2241 } |
| 2105 | 2242 |
| 2106 // Tests that only the password field is autocompleted when the browser sends | 2243 // Tests that only the password field is autocompleted when the browser sends |
| 2107 // back data with only one credentials and empty username. | 2244 // back data with only one credentials and empty username. |
| 2108 TEST_F(PasswordAutofillAgentTest, NotAutofillNoUsername) { | 2245 TEST_F(PasswordAutofillAgentTest, NotAutofillNoUsername) { |
| 2109 fill_data_.username_field.value.clear(); | 2246 fill_data_.username_field.value.clear(); |
| 2110 fill_data_.additional_logins.clear(); | 2247 fill_data_.additional_logins.clear(); |
| 2111 SimulateOnFillPasswordForm(fill_data_); | 2248 SimulateOnFillPasswordForm(fill_data_); |
| 2112 | 2249 |
| 2113 CheckTextFieldsState("", false, kAlicePassword, true); | 2250 CheckTextFieldsState("", false, kAlicePassword, true); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 2143 TEST_F(PasswordAutofillAgentTest, | 2280 TEST_F(PasswordAutofillAgentTest, |
| 2144 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) { | 2281 NoForm_NoPromptForAJAXSubmitWithoutNavigationAndElementsVisible) { |
| 2145 LoadHTML(kNoFormHTML); | 2282 LoadHTML(kNoFormHTML); |
| 2146 UpdateUsernameAndPasswordElements(); | 2283 UpdateUsernameAndPasswordElements(); |
| 2147 | 2284 |
| 2148 SimulateUsernameChange("Bob"); | 2285 SimulateUsernameChange("Bob"); |
| 2149 SimulatePasswordChange("mypassword"); | 2286 SimulatePasswordChange("mypassword"); |
| 2150 | 2287 |
| 2151 password_autofill_agent_->AJAXSucceeded(); | 2288 password_autofill_agent_->AJAXSucceeded(); |
| 2152 | 2289 |
| 2153 const IPC::Message* message = | 2290 base::RunLoop().RunUntilIdle(); |
| 2154 render_thread_->sink().GetFirstMessageMatching( | 2291 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); |
| 2155 AutofillHostMsg_PasswordFormSubmitted::ID); | |
| 2156 ASSERT_FALSE(message); | |
| 2157 } | 2292 } |
| 2158 | 2293 |
| 2159 // Tests that credential suggestions are autofilled on a password (and change | 2294 // Tests that credential suggestions are autofilled on a password (and change |
| 2160 // password) forms having either ambiguous or empty name. | 2295 // password) forms having either ambiguous or empty name. |
| 2161 TEST_F(PasswordAutofillAgentTest, | 2296 TEST_F(PasswordAutofillAgentTest, |
| 2162 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { | 2297 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { |
| 2163 const char kEmpty[] = ""; | 2298 const char kEmpty[] = ""; |
| 2164 const char kDummyUsernameField[] = "anonymous_username"; | 2299 const char kDummyUsernameField[] = "anonymous_username"; |
| 2165 const char kDummyPasswordField[] = "anonymous_password"; | 2300 const char kDummyPasswordField[] = "anonymous_password"; |
| 2166 const char kFormContainsEmptyNamesHTML[] = | 2301 const char kFormContainsEmptyNamesHTML[] = |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2393 TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) { | 2528 TEST_F(PasswordAutofillAgentTest, SuggestPasswordFieldSignInForm) { |
| 2394 // Simulate the browser sending back the login info. | 2529 // Simulate the browser sending back the login info. |
| 2395 SimulateOnFillPasswordForm(fill_data_); | 2530 SimulateOnFillPasswordForm(fill_data_); |
| 2396 | 2531 |
| 2397 // Call SimulateElementClick() to produce a user gesture on the page so | 2532 // Call SimulateElementClick() to produce a user gesture on the page so |
| 2398 // autofill will actually fill. | 2533 // autofill will actually fill. |
| 2399 SimulateElementClick(kUsernameName); | 2534 SimulateElementClick(kUsernameName); |
| 2400 | 2535 |
| 2401 // Simulate a user clicking on the password element. This should produce a | 2536 // Simulate a user clicking on the password element. This should produce a |
| 2402 // dropdown with suggestion of all available usernames. | 2537 // dropdown with suggestion of all available usernames. |
| 2403 render_thread_->sink().ClearMessages(); | |
| 2404 static_cast<PageClickListener*>(autofill_agent_) | 2538 static_cast<PageClickListener*>(autofill_agent_) |
| 2405 ->FormControlElementClicked(password_element_, false); | 2539 ->FormControlElementClicked(password_element_, false); |
| 2406 CheckSuggestions("", false); | 2540 CheckSuggestions("", false); |
| 2407 } | 2541 } |
| 2408 | 2542 |
| 2409 // Tests that a suggestion dropdown is shown on each password field. But when a | 2543 // 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 | 2544 // user chose one of the fields to autofill, a suggestion dropdown will be shown |
| 2411 // only on this field. | 2545 // only on this field. |
| 2412 TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) { | 2546 TEST_F(PasswordAutofillAgentTest, SuggestMultiplePasswordFields) { |
| 2413 LoadHTML(kPasswordChangeFormHTML); | 2547 LoadHTML(kPasswordChangeFormHTML); |
| 2414 UpdateOriginForHTML(kPasswordChangeFormHTML); | 2548 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 2415 UpdateUsernameAndPasswordElements(); | 2549 UpdateUsernameAndPasswordElements(); |
| 2416 | 2550 |
| 2417 // Simulate the browser sending back the login info. | 2551 // Simulate the browser sending back the login info. |
| 2418 SimulateOnFillPasswordForm(fill_data_); | 2552 SimulateOnFillPasswordForm(fill_data_); |
| 2419 | 2553 |
| 2420 // Call SimulateElementClick() to produce a user gesture on the page so | 2554 // Call SimulateElementClick() to produce a user gesture on the page so |
| 2421 // autofill will actually fill. | 2555 // autofill will actually fill. |
| 2422 SimulateElementClick(kUsernameName); | 2556 SimulateElementClick(kUsernameName); |
| 2423 | 2557 |
| 2424 // Simulate a user clicking on the password elements. This should produce | 2558 // Simulate a user clicking on the password elements. This should produce |
| 2425 // dropdowns with suggestion of all available usernames. | 2559 // dropdowns with suggestion of all available usernames. |
| 2426 render_thread_->sink().ClearMessages(); | |
| 2427 SimulateElementClick("password"); | 2560 SimulateElementClick("password"); |
| 2428 CheckSuggestions("", false); | 2561 CheckSuggestions("", false); |
| 2429 | 2562 |
| 2430 SimulateElementClick("newpassword"); | 2563 SimulateElementClick("newpassword"); |
| 2431 CheckSuggestions("", false); | 2564 CheckSuggestions("", false); |
| 2432 | 2565 |
| 2433 SimulateElementClick("confirmpassword"); | 2566 SimulateElementClick("confirmpassword"); |
| 2434 CheckSuggestions("", false); | 2567 CheckSuggestions("", false); |
| 2435 | 2568 |
| 2436 // The user chooses to autofill the current password field. | 2569 // The user chooses to autofill the current password field. |
| 2437 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( | 2570 EXPECT_TRUE(password_autofill_agent_->FillSuggestion( |
| 2438 password_element_, ASCIIToUTF16(kAliceUsername), | 2571 password_element_, ASCIIToUTF16(kAliceUsername), |
| 2439 ASCIIToUTF16(kAlicePassword))); | 2572 ASCIIToUTF16(kAlicePassword))); |
| 2440 | 2573 |
| 2441 // Simulate a user clicking on not autofilled password fields. This should | 2574 // Simulate a user clicking on not autofilled password fields. This should |
| 2442 // produce | 2575 // produce no suggestion dropdowns. |
| 2443 // no suggestion dropdowns. | 2576 fake_driver_.reset_show_pw_suggestions(); |
| 2444 render_thread_->sink().ClearMessages(); | |
| 2445 SimulateElementClick("newpassword"); | 2577 SimulateElementClick("newpassword"); |
| 2446 SimulateElementClick("confirmpassword"); | 2578 SimulateElementClick("confirmpassword"); |
| 2447 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 2579 EXPECT_FALSE(GetCalledShowPasswordSuggestions()); |
| 2448 AutofillHostMsg_ShowPasswordSuggestions::ID)); | |
| 2449 | 2580 |
| 2450 // But when the user clicks on the autofilled password field again it should | 2581 // But when the user clicks on the autofilled password field again it should |
| 2451 // still produce a suggestion dropdown. | 2582 // still produce a suggestion dropdown. |
| 2452 SimulateElementClick("password"); | 2583 SimulateElementClick("password"); |
| 2453 CheckSuggestions("", false); | 2584 CheckSuggestions("", false); |
| 2454 } | 2585 } |
| 2455 | 2586 |
| 2456 } // namespace autofill | 2587 } // namespace autofill |
| OLD | NEW |