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/guid.h" | 5 #include "base/guid.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 virtual void UpdateButtonStrip() OVERRIDE {} | 49 virtual void UpdateButtonStrip() OVERRIDE {} |
50 virtual void UpdateSection(DialogSection section, UserInputAction action) | 50 virtual void UpdateSection(DialogSection section, UserInputAction action) |
51 OVERRIDE {} | 51 OVERRIDE {} |
52 virtual void GetUserInput(DialogSection section, DetailOutputMap* output) | 52 virtual void GetUserInput(DialogSection section, DetailOutputMap* output) |
53 OVERRIDE { | 53 OVERRIDE { |
54 *output = outputs_[section]; | 54 *output = outputs_[section]; |
55 } | 55 } |
56 | 56 |
57 virtual string16 GetCvc() OVERRIDE { return string16(); } | 57 virtual string16 GetCvc() OVERRIDE { return string16(); } |
58 virtual bool UseBillingForShipping() OVERRIDE { return false; } | 58 virtual bool UseBillingForShipping() OVERRIDE { return false; } |
59 virtual bool SaveDetailsInWallet() OVERRIDE { return false; } | |
60 virtual bool SaveDetailsLocally() OVERRIDE { return true; } | 59 virtual bool SaveDetailsLocally() OVERRIDE { return true; } |
61 virtual const content::NavigationController* ShowSignIn() OVERRIDE { | 60 virtual const content::NavigationController* ShowSignIn() OVERRIDE { |
62 return NULL; | 61 return NULL; |
63 } | 62 } |
64 virtual void HideSignIn() OVERRIDE {} | 63 virtual void HideSignIn() OVERRIDE {} |
65 virtual void UpdateProgressBar(double value) OVERRIDE {} | 64 virtual void UpdateProgressBar(double value) OVERRIDE {} |
66 virtual void SubmitForTesting() OVERRIDE {} | 65 virtual void SubmitForTesting() OVERRIDE {} |
67 virtual void CancelForTesting() OVERRIDE {} | 66 virtual void CancelForTesting() OVERRIDE {} |
68 | 67 |
69 MOCK_METHOD0(ModelChanged, void()); | 68 MOCK_METHOD0(ModelChanged, void()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 const base::Callback<void(const FormStructure*, | 153 const base::Callback<void(const FormStructure*, |
155 const std::string&)>& callback) | 154 const std::string&)>& callback) |
156 : AutofillDialogControllerImpl(contents, | 155 : AutofillDialogControllerImpl(contents, |
157 form_structure, | 156 form_structure, |
158 source_url, | 157 source_url, |
159 dialog_type, | 158 dialog_type, |
160 callback), | 159 callback), |
161 metric_logger_(metric_logger), | 160 metric_logger_(metric_logger), |
162 ALLOW_THIS_IN_INITIALIZER_LIST(test_wallet_client_( | 161 ALLOW_THIS_IN_INITIALIZER_LIST(test_wallet_client_( |
163 Profile::FromBrowserContext(contents->GetBrowserContext())-> | 162 Profile::FromBrowserContext(contents->GetBrowserContext())-> |
164 GetRequestContext(), this)) {} | 163 GetRequestContext(), this)), |
| 164 is_first_run_(true) {} |
165 virtual ~TestAutofillDialogController() {} | 165 virtual ~TestAutofillDialogController() {} |
166 | 166 |
167 virtual AutofillDialogView* CreateView() OVERRIDE { | 167 virtual AutofillDialogView* CreateView() OVERRIDE { |
168 return new testing::NiceMock<TestAutofillDialogView>(); | 168 return new testing::NiceMock<TestAutofillDialogView>(); |
169 } | 169 } |
170 | 170 |
171 void Init(content::BrowserContext* browser_context) { | 171 void Init(content::BrowserContext* browser_context) { |
172 test_manager_.Init(browser_context); | 172 test_manager_.Init(browser_context); |
173 } | 173 } |
174 | 174 |
175 TestAutofillDialogView* GetView() { | 175 TestAutofillDialogView* GetView() { |
176 return static_cast<TestAutofillDialogView*>(view()); | 176 return static_cast<TestAutofillDialogView*>(view()); |
177 } | 177 } |
178 | 178 |
179 TestPersonalDataManager* GetTestingManager() { | 179 TestPersonalDataManager* GetTestingManager() { |
180 return &test_manager_; | 180 return &test_manager_; |
181 } | 181 } |
182 | 182 |
183 TestWalletClient* GetTestingWalletClient() { | 183 TestWalletClient* GetTestingWalletClient() { |
184 return &test_wallet_client_; | 184 return &test_wallet_client_; |
185 } | 185 } |
186 | 186 |
| 187 void set_is_first_run(bool is_first_run) { is_first_run_ = is_first_run; } |
| 188 |
187 protected: | 189 protected: |
188 virtual PersonalDataManager* GetManager() OVERRIDE { | 190 virtual PersonalDataManager* GetManager() OVERRIDE { |
189 return &test_manager_; | 191 return &test_manager_; |
190 } | 192 } |
191 | 193 |
192 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 194 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
193 return &test_wallet_client_; | 195 return &test_wallet_client_; |
194 } | 196 } |
195 | 197 |
| 198 virtual bool IsFirstRun() const OVERRIDE { |
| 199 return is_first_run_; |
| 200 } |
| 201 |
196 private: | 202 private: |
197 // To specify our own metric logger. | 203 // To specify our own metric logger. |
198 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { | 204 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { |
199 return metric_logger_; | 205 return metric_logger_; |
200 } | 206 } |
201 | 207 |
202 const AutofillMetrics& metric_logger_; | 208 const AutofillMetrics& metric_logger_; |
203 TestPersonalDataManager test_manager_; | 209 TestPersonalDataManager test_manager_; |
204 testing::NiceMock<TestWalletClient> test_wallet_client_; | 210 testing::NiceMock<TestWalletClient> test_wallet_client_; |
| 211 bool is_first_run_; |
205 | 212 |
206 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | 213 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
207 }; | 214 }; |
208 | 215 |
209 class AutofillDialogControllerTest : public testing::Test { | 216 class AutofillDialogControllerTest : public testing::Test { |
210 public: | 217 public: |
211 AutofillDialogControllerTest() | 218 AutofillDialogControllerTest() |
212 : ui_thread_(BrowserThread::UI, &loop_), | 219 : ui_thread_(BrowserThread::UI, &loop_), |
213 file_thread_(BrowserThread::FILE), | 220 file_thread_(BrowserThread::FILE), |
214 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING), | 221 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 273 |
267 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { | 274 static scoped_ptr<wallet::FullWallet> CreateFullWalletWithVerifyCvv() { |
268 base::DictionaryValue dict; | 275 base::DictionaryValue dict; |
269 scoped_ptr<base::ListValue> list(new base::ListValue()); | 276 scoped_ptr<base::ListValue> list(new base::ListValue()); |
270 list->AppendString("verify_cvv"); | 277 list->AppendString("verify_cvv"); |
271 dict.Set("required_action", list.release()); | 278 dict.Set("required_action", list.release()); |
272 return wallet::FullWallet::CreateFullWallet(dict); | 279 return wallet::FullWallet::CreateFullWallet(dict); |
273 } | 280 } |
274 | 281 |
275 void SetUpWallet() { | 282 void SetUpWallet() { |
276 controller()->MenuModelForAccountChooser()->ActivatedAt(0); | 283 controller()->MenuModelForAccountChooser()->ActivatedAt( |
| 284 AccountChooserModel::kWalletItemId); |
277 controller()->OnUserNameFetchSuccess("user@example.com"); | 285 controller()->OnUserNameFetchSuccess("user@example.com"); |
278 } | 286 } |
279 | 287 |
280 TestAutofillDialogController* controller() { return controller_; } | 288 TestAutofillDialogController* controller() { return controller_; } |
281 | 289 |
282 TestingProfile* profile() { return &profile_; } | 290 TestingProfile* profile() { return &profile_; } |
283 | 291 |
284 private: | 292 private: |
285 void FinishedCallback(const FormStructure* form_structure, | 293 void FinishedCallback(const FormStructure* form_structure, |
286 const std::string& google_transaction_id) {} | 294 const std::string& google_transaction_id) {} |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 566 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
559 | 567 |
560 SuggestionState suggestion_state = | 568 SuggestionState suggestion_state = |
561 controller()->SuggestionStateForSection(SECTION_CC_BILLING); | 569 controller()->SuggestionStateForSection(SECTION_CC_BILLING); |
562 EXPECT_TRUE(suggestion_state.extra_text.empty()); | 570 EXPECT_TRUE(suggestion_state.extra_text.empty()); |
563 | 571 |
564 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); | 572 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); |
565 | 573 |
566 EXPECT_FALSE( | 574 EXPECT_FALSE( |
567 NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); | 575 NotificationsOfType(DialogNotification::REQUIRED_ACTION).empty()); |
568 const std::vector<DialogNotification>& notifications = | |
569 NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); | |
570 EXPECT_FALSE(notifications.front().interactive()); | |
571 | |
572 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL)); | 576 EXPECT_FALSE(controller()->SectionIsActive(SECTION_EMAIL)); |
573 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); | 577 EXPECT_FALSE(controller()->SectionIsActive(SECTION_SHIPPING)); |
574 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); | 578 EXPECT_TRUE(controller()->SectionIsActive(SECTION_CC_BILLING)); |
575 | 579 |
576 suggestion_state = | 580 suggestion_state = |
577 controller()->SuggestionStateForSection(SECTION_CC_BILLING); | 581 controller()->SuggestionStateForSection(SECTION_CC_BILLING); |
578 EXPECT_FALSE(suggestion_state.extra_text.empty()); | 582 EXPECT_FALSE(suggestion_state.extra_text.empty()); |
579 EXPECT_EQ( | 583 EXPECT_EQ( |
580 0, controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); | 584 0, controller()->MenuModelForSection(SECTION_CC_BILLING)->GetItemCount()); |
581 | 585 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 622 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
619 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 623 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
620 controller()->OnAccept(); | 624 controller()->OnAccept(); |
621 | 625 |
622 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 626 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
623 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 627 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
624 | 628 |
625 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); | 629 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); |
626 ASSERT_TRUE(account_menu); | 630 ASSERT_TRUE(account_menu); |
627 ASSERT_GE(2, account_menu->GetItemCount()); | 631 ASSERT_GE(2, account_menu->GetItemCount()); |
628 account_menu->ActivatedAt(0); | 632 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); |
629 account_menu->ActivatedAt(1); | 633 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); |
630 | 634 |
631 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 635 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
632 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 636 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
633 } | 637 } |
634 | 638 |
635 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { | 639 TEST_F(AutofillDialogControllerTest, ErrorDuringVerifyCvv) { |
636 SetUpWallet(); | 640 SetUpWallet(); |
637 | 641 |
638 EXPECT_CALL(*controller()->GetTestingWalletClient(), | 642 EXPECT_CALL(*controller()->GetTestingWalletClient(), |
639 GetFullWallet(_)).Times(1); | 643 GetFullWallet(_)).Times(1); |
(...skipping 27 matching lines...) Expand all Loading... |
667 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 671 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
668 controller()->OnAccept(); | 672 controller()->OnAccept(); |
669 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); | 673 controller()->OnDidGetFullWallet(CreateFullWalletWithVerifyCvv()); |
670 | 674 |
671 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 675 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
672 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 676 ASSERT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
673 | 677 |
674 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); | 678 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); |
675 ASSERT_TRUE(account_menu); | 679 ASSERT_TRUE(account_menu); |
676 ASSERT_GE(2, account_menu->GetItemCount()); | 680 ASSERT_GE(2, account_menu->GetItemCount()); |
677 account_menu->ActivatedAt(0); | 681 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); |
678 account_menu->ActivatedAt(1); | 682 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); |
679 | 683 |
680 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | 684 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
681 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); | 685 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_CANCEL)); |
682 } | 686 } |
683 | 687 |
| 688 // Test that when a wallet error happens only an error is shown (and no other |
| 689 // Wallet-related notifications). |
| 690 TEST_F(AutofillDialogControllerTest, WalletErrorNotification) { |
| 691 SetUpWallet(); |
| 692 |
| 693 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); |
| 694 |
| 695 EXPECT_EQ(1U, NotificationsOfType( |
| 696 DialogNotification::WALLET_ERROR).size()); |
| 697 |
| 698 // No other wallet notifications should show on Wallet error. |
| 699 EXPECT_TRUE(NotificationsOfType( |
| 700 DialogNotification::WALLET_SIGNIN_PROMO).empty()); |
| 701 EXPECT_TRUE(NotificationsOfType( |
| 702 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); |
| 703 EXPECT_TRUE(NotificationsOfType( |
| 704 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
| 705 } |
| 706 |
| 707 // Test that only on first run an explanation of where Chrome got the user's |
| 708 // data is shown (i.e. "Got these details from Wallet"). |
| 709 TEST_F(AutofillDialogControllerTest, WalletDetailsExplanation) { |
| 710 SetUpWallet(); |
| 711 |
| 712 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 713 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 714 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
| 715 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 716 |
| 717 EXPECT_EQ(1U, NotificationsOfType( |
| 718 DialogNotification::EXPLANATORY_MESSAGE).size()); |
| 719 |
| 720 // Wallet notifications are mutually exclusive. |
| 721 EXPECT_TRUE(NotificationsOfType( |
| 722 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); |
| 723 EXPECT_TRUE(NotificationsOfType( |
| 724 DialogNotification::WALLET_SIGNIN_PROMO).empty()); |
| 725 |
| 726 // Switch to using Autofill, no explanatory message should show. |
| 727 ui::MenuModel* account_menu = controller()->MenuModelForAccountChooser(); |
| 728 account_menu->ActivatedAt(AccountChooserModel::kAutofillItemId); |
| 729 EXPECT_TRUE(NotificationsOfType( |
| 730 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
| 731 |
| 732 // Switch to Wallet, pretend this isn't first run. No message should show. |
| 733 account_menu->ActivatedAt(AccountChooserModel::kWalletItemId); |
| 734 controller()->set_is_first_run(false); |
| 735 EXPECT_TRUE(NotificationsOfType( |
| 736 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
| 737 } |
| 738 |
| 739 // Verifies that the "[X] Save details in wallet" notification shows on first |
| 740 // run with an incomplete profile, stays showing when switching to Autofill in |
| 741 // the account chooser, and continues to show on second+ run when a user's |
| 742 // wallet is incomplete. This also tests that submitting disables interactivity. |
| 743 TEST_F(AutofillDialogControllerTest, SaveDetailsInWallet) { |
| 744 SetUpWallet(); |
| 745 |
| 746 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 747 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 748 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 749 |
| 750 std::vector<DialogNotification> notifications = |
| 751 NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); |
| 752 EXPECT_EQ(1U, notifications.size()); |
| 753 EXPECT_TRUE(notifications.front().checked()); |
| 754 EXPECT_TRUE(notifications.front().interactive()); |
| 755 |
| 756 // Wallet notifications are mutually exclusive. |
| 757 EXPECT_TRUE(NotificationsOfType( |
| 758 DialogNotification::WALLET_SIGNIN_PROMO).empty()); |
| 759 EXPECT_TRUE(NotificationsOfType( |
| 760 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
| 761 |
| 762 // Using Autofill on second run, show an interactive, unchecked checkbox. |
| 763 ui::MenuModel* account_model = controller()->MenuModelForAccountChooser(); |
| 764 account_model->ActivatedAt(AccountChooserModel::kAutofillItemId); |
| 765 controller()->set_is_first_run(false); |
| 766 |
| 767 notifications = |
| 768 NotificationsOfType(DialogNotification::WALLET_USAGE_CONFIRMATION); |
| 769 EXPECT_EQ(1U, notifications.size()); |
| 770 EXPECT_FALSE(notifications.front().checked()); |
| 771 EXPECT_TRUE(notifications.front().interactive()); |
| 772 |
| 773 // Notifications shouldn't be interactive while submitting. |
| 774 account_model->ActivatedAt(AccountChooserModel::kWalletItemId); |
| 775 controller()->OnAccept(); |
| 776 EXPECT_FALSE(NotificationsOfType( |
| 777 DialogNotification::WALLET_USAGE_CONFIRMATION).front().interactive()); |
| 778 } |
| 779 |
| 780 // Verifies that no Wallet notifications are shown after first run (i.e. no |
| 781 // "[X] Save details to wallet" or "These details are from your Wallet") when |
| 782 // the user has a complete wallet. |
| 783 TEST_F(AutofillDialogControllerTest, NoWalletNotifications) { |
| 784 SetUpWallet(); |
| 785 controller()->set_is_first_run(false); |
| 786 |
| 787 // Simulate a complete wallet. |
| 788 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 789 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 790 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
| 791 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 792 |
| 793 EXPECT_TRUE(NotificationsOfType( |
| 794 DialogNotification::EXPLANATORY_MESSAGE).empty()); |
| 795 EXPECT_TRUE(NotificationsOfType( |
| 796 DialogNotification::WALLET_USAGE_CONFIRMATION).empty()); |
| 797 } |
| 798 |
684 } // namespace autofill | 799 } // namespace autofill |
OLD | NEW |