| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 void MockCallback(const FormStructure*, const std::string&) {} | 45 void MockCallback(const FormStructure*, const std::string&) {} |
| 46 | 46 |
| 47 class MockAutofillMetrics : public AutofillMetrics { | 47 class MockAutofillMetrics : public AutofillMetrics { |
| 48 public: | 48 public: |
| 49 MockAutofillMetrics() | 49 MockAutofillMetrics() |
| 50 : dialog_type_(static_cast<DialogType>(-1)), | 50 : dialog_type_(static_cast<DialogType>(-1)), |
| 51 dialog_dismissal_action_( | 51 dialog_dismissal_action_( |
| 52 static_cast<AutofillMetrics::DialogDismissalAction>(-1)), | 52 static_cast<AutofillMetrics::DialogDismissalAction>(-1)) {} |
| 53 autocheckout_status_( | |
| 54 static_cast<AutofillMetrics::AutocheckoutCompletionStatus>(-1)) {} | |
| 55 virtual ~MockAutofillMetrics() {} | 53 virtual ~MockAutofillMetrics() {} |
| 56 | 54 |
| 57 // AutofillMetrics: | |
| 58 virtual void LogAutocheckoutDuration( | |
| 59 const base::TimeDelta& duration, | |
| 60 AutocheckoutCompletionStatus status) const OVERRIDE { | |
| 61 // Ignore constness for testing. | |
| 62 MockAutofillMetrics* mutable_this = const_cast<MockAutofillMetrics*>(this); | |
| 63 mutable_this->autocheckout_status_ = status; | |
| 64 } | |
| 65 | |
| 66 virtual void LogDialogUiDuration( | 55 virtual void LogDialogUiDuration( |
| 67 const base::TimeDelta& duration, | 56 const base::TimeDelta& duration, |
| 68 DialogType dialog_type, | 57 DialogType dialog_type, |
| 69 DialogDismissalAction dismissal_action) const OVERRIDE { | 58 DialogDismissalAction dismissal_action) const OVERRIDE { |
| 70 // Ignore constness for testing. | 59 // Ignore constness for testing. |
| 71 MockAutofillMetrics* mutable_this = const_cast<MockAutofillMetrics*>(this); | 60 MockAutofillMetrics* mutable_this = const_cast<MockAutofillMetrics*>(this); |
| 72 mutable_this->dialog_type_ = dialog_type; | 61 mutable_this->dialog_type_ = dialog_type; |
| 73 mutable_this->dialog_dismissal_action_ = dismissal_action; | 62 mutable_this->dialog_dismissal_action_ = dismissal_action; |
| 74 } | 63 } |
| 75 | 64 |
| 76 DialogType dialog_type() const { return dialog_type_; } | 65 DialogType dialog_type() const { return dialog_type_; } |
| 77 AutofillMetrics::DialogDismissalAction dialog_dismissal_action() const { | 66 AutofillMetrics::DialogDismissalAction dialog_dismissal_action() const { |
| 78 return dialog_dismissal_action_; | 67 return dialog_dismissal_action_; |
| 79 } | 68 } |
| 80 | 69 |
| 81 AutofillMetrics::AutocheckoutCompletionStatus autocheckout_status() const { | |
| 82 return autocheckout_status_; | |
| 83 } | |
| 84 | |
| 85 MOCK_CONST_METHOD2(LogDialogDismissalState, | 70 MOCK_CONST_METHOD2(LogDialogDismissalState, |
| 86 void(DialogType dialog_type, DialogDismissalState state)); | 71 void(DialogType dialog_type, DialogDismissalState state)); |
| 87 | 72 |
| 88 private: | 73 private: |
| 89 DialogType dialog_type_; | 74 DialogType dialog_type_; |
| 90 AutofillMetrics::DialogDismissalAction dialog_dismissal_action_; | 75 AutofillMetrics::DialogDismissalAction dialog_dismissal_action_; |
| 91 AutofillMetrics::AutocheckoutCompletionStatus autocheckout_status_; | |
| 92 | 76 |
| 93 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); | 77 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); |
| 94 }; | 78 }; |
| 95 | 79 |
| 96 class TestAutofillDialogController : public AutofillDialogControllerImpl { | 80 class TestAutofillDialogController : public AutofillDialogControllerImpl { |
| 97 public: | 81 public: |
| 98 TestAutofillDialogController(content::WebContents* contents, | 82 TestAutofillDialogController(content::WebContents* contents, |
| 99 const FormData& form_data, | 83 const FormData& form_data, |
| 100 const AutofillMetrics& metric_logger, | 84 const AutofillMetrics& metric_logger, |
| 101 scoped_refptr<content::MessageLoopRunner> runner, | 85 scoped_refptr<content::MessageLoopRunner> runner, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 AutofillMetrics::DIALOG_CANCELED_DURING_SIGNIN)); | 390 AutofillMetrics::DIALOG_CANCELED_DURING_SIGNIN)); |
| 407 controller()->GetTestableView()->CancelForTesting(); | 391 controller()->GetTestableView()->CancelForTesting(); |
| 408 | 392 |
| 409 RunMessageLoop(); | 393 RunMessageLoop(); |
| 410 | 394 |
| 411 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, | 395 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, |
| 412 metric_logger().dialog_dismissal_action()); | 396 metric_logger().dialog_dismissal_action()); |
| 413 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); | 397 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); |
| 414 } | 398 } |
| 415 | 399 |
| 416 // Test Autocheckout success metrics. | |
| 417 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutSuccess) { | |
| 418 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); | |
| 419 controller()->GetTestableView()->SubmitForTesting(); | |
| 420 | |
| 421 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | |
| 422 metric_logger().dialog_dismissal_action()); | |
| 423 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | |
| 424 | |
| 425 controller()->OnAutocheckoutSuccess(); | |
| 426 controller()->GetTestableView()->CancelForTesting(); | |
| 427 RunMessageLoop(); | |
| 428 | |
| 429 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED, | |
| 430 metric_logger().autocheckout_status()); | |
| 431 | |
| 432 // Ensure closing the dialog doesn't fire any new metrics. | |
| 433 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | |
| 434 metric_logger().dialog_dismissal_action()); | |
| 435 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | |
| 436 } | |
| 437 | |
| 438 // Test Autocheckout failure metric. | |
| 439 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutError) { | |
| 440 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); | |
| 441 controller()->GetTestableView()->SubmitForTesting(); | |
| 442 | |
| 443 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | |
| 444 metric_logger().dialog_dismissal_action()); | |
| 445 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | |
| 446 | |
| 447 controller()->OnAutocheckoutError(); | |
| 448 controller()->GetTestableView()->CancelForTesting(); | |
| 449 RunMessageLoop(); | |
| 450 | |
| 451 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED, | |
| 452 metric_logger().autocheckout_status()); | |
| 453 | |
| 454 // Ensure closing the dialog doesn't fire any new metrics. | |
| 455 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | |
| 456 metric_logger().dialog_dismissal_action()); | |
| 457 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | |
| 458 } | |
| 459 | |
| 460 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutCancelled) { | |
| 461 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); | |
| 462 controller()->GetTestableView()->SubmitForTesting(); | |
| 463 | |
| 464 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | |
| 465 metric_logger().dialog_dismissal_action()); | |
| 466 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | |
| 467 | |
| 468 controller()->GetTestableView()->CancelForTesting(); | |
| 469 RunMessageLoop(); | |
| 470 | |
| 471 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_CANCELLED, | |
| 472 metric_logger().autocheckout_status()); | |
| 473 | |
| 474 // Ensure closing the dialog doesn't fire any new metrics. | |
| 475 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | |
| 476 metric_logger().dialog_dismissal_action()); | |
| 477 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | |
| 478 } | |
| 479 | |
| 480 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { | 400 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { |
| 481 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | 401 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
| 482 | 402 |
| 483 AutofillProfile full_profile(test::GetFullProfile()); | 403 AutofillProfile full_profile(test::GetFullProfile()); |
| 484 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 404 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 485 | 405 |
| 486 const DetailInputs& inputs = | 406 const DetailInputs& inputs = |
| 487 controller()->RequestedFieldsForSection(SECTION_SHIPPING); | 407 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
| 488 const DetailInput& triggering_input = inputs[0]; | 408 const DetailInput& triggering_input = inputs[0]; |
| 489 string16 value = full_profile.GetRawInfo(triggering_input.type); | 409 string16 value = full_profile.GetRawInfo(triggering_input.type); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 519 value.substr(0, value.size() / 2)); | 439 value.substr(0, value.size() / 2)); |
| 520 view->ActivateInput(triggering_input); | 440 view->ActivateInput(triggering_input); |
| 521 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); | 441 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
| 522 controller()->DidAcceptSuggestion(string16(), 0); | 442 controller()->DidAcceptSuggestion(string16(), 0); |
| 523 | 443 |
| 524 for (size_t i = 0; i < inputs.size(); ++i) { | 444 for (size_t i = 0; i < inputs.size(); ++i) { |
| 525 EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i])); | 445 EXPECT_EQ(expectations[i], view->GetTextContentsOfInput(inputs[i])); |
| 526 } | 446 } |
| 527 } | 447 } |
| 528 | 448 |
| 529 // Test that Autocheckout steps are shown after submitting the | |
| 530 // dialog for controller with type DIALOG_TYPE_AUTOCHECKOUT. | |
| 531 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutShowsSteps) { | |
| 532 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); | |
| 533 controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD); | |
| 534 | |
| 535 EXPECT_TRUE(controller()->ShouldShowDetailArea()); | |
| 536 EXPECT_TRUE(controller()->CurrentAutocheckoutSteps().empty()); | |
| 537 EXPECT_FALSE(controller()->ShouldShowProgressBar()); | |
| 538 | |
| 539 controller()->GetTestableView()->SubmitForTesting(); | |
| 540 EXPECT_FALSE(controller()->ShouldShowDetailArea()); | |
| 541 EXPECT_FALSE(controller()->CurrentAutocheckoutSteps().empty()); | |
| 542 EXPECT_TRUE(controller()->ShouldShowProgressBar()); | |
| 543 controller()->GetTestableView()->CancelForTesting(); | |
| 544 RunMessageLoop(); | |
| 545 } | |
| 546 | |
| 547 // Test that Autocheckout steps are not showing after submitting the | |
| 548 // dialog for controller with type DIALOG_TYPE_REQUEST_AUTOCOMPLETE. | |
| 549 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | |
| 550 RequestAutocompleteDoesntShowSteps) { | |
| 551 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | |
| 552 controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_PROXY_CARD); | |
| 553 | |
| 554 EXPECT_TRUE(controller()->ShouldShowDetailArea()); | |
| 555 EXPECT_TRUE(controller()->CurrentAutocheckoutSteps().empty()); | |
| 556 EXPECT_FALSE(controller()->ShouldShowProgressBar()); | |
| 557 | |
| 558 controller()->GetTestableView()->SubmitForTesting(); | |
| 559 EXPECT_TRUE(controller()->ShouldShowDetailArea()); | |
| 560 EXPECT_TRUE(controller()->CurrentAutocheckoutSteps().empty()); | |
| 561 EXPECT_FALSE(controller()->ShouldShowProgressBar()); | |
| 562 } | |
| 563 | |
| 564 // Tests that changing the value of a CC expiration date combobox works as | 449 // Tests that changing the value of a CC expiration date combobox works as |
| 565 // expected when Autofill is used to fill text inputs. | 450 // expected when Autofill is used to fill text inputs. |
| 566 // | 451 // |
| 567 // Flaky on Win7, WinXP, and Win Aura. http://crbug.com/270314. | 452 // Flaky on Win7, WinXP, and Win Aura. http://crbug.com/270314. |
| 568 // TODO(groby): Enable this test on mac once AutofillDialogCocoa handles | 453 // TODO(groby): Enable this test on mac once AutofillDialogCocoa handles |
| 569 // comboboxes for GetTextContentsForInput. http://crbug.com/270205 | 454 // comboboxes for GetTextContentsForInput. http://crbug.com/270205 |
| 570 #if defined(OS_MACOSX) || defined(OS_WIN) | 455 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 571 #define MAYBE_FillComboboxFromAutofill DISABLED_FillComboboxFromAutofill | 456 #define MAYBE_FillComboboxFromAutofill DISABLED_FillComboboxFromAutofill |
| 572 #else | 457 #else |
| 573 #define MAYBE_FillComboboxFromAutofill FillComboboxFromAutofill | 458 #define MAYBE_FillComboboxFromAutofill FillComboboxFromAutofill |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 EXPECT_EQ(cc_number.type, new_cc_number.type); | 769 EXPECT_EQ(cc_number.type, new_cc_number.type); |
| 885 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), | 770 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), |
| 886 view->GetTextContentsOfInput(new_cc_number)); | 771 view->GetTextContentsOfInput(new_cc_number)); |
| 887 | 772 |
| 888 EXPECT_NE(ASCIIToUTF16("shipping name"), | 773 EXPECT_NE(ASCIIToUTF16("shipping name"), |
| 889 view->GetTextContentsOfInput(shipping_zip)); | 774 view->GetTextContentsOfInput(shipping_zip)); |
| 890 } | 775 } |
| 891 #endif // defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) | 776 #endif // defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) |
| 892 | 777 |
| 893 } // namespace autofill | 778 } // namespace autofill |
| OLD | NEW |