| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
| 6 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 6 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
| 7 #include "chrome/common/pref_names.h" | 7 #include "chrome/common/pref_names.h" |
| 8 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 TestingProfile profile_; | 34 TestingProfile profile_; |
| 35 MockAccountChooserModelDelegate delegate_; | 35 MockAccountChooserModelDelegate delegate_; |
| 36 AccountChooserModel model_; | 36 AccountChooserModel model_; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 TEST_F(AccountChooserModelTest, ObeysPref) { | 41 TEST_F(AccountChooserModelTest, ObeysPref) { |
| 42 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2); | 42 // When "Pay without wallet" is false, use Wallet by default. |
| 43 { |
| 44 profile()->GetPrefs()->SetBoolean( |
| 45 prefs::kAutofillDialogPayWithoutWallet, false); |
| 46 AccountChooserModel model(delegate(), profile()->GetPrefs()); |
| 47 EXPECT_TRUE(model.WalletIsSelected()); |
| 48 } |
| 49 // When the user chose to "Pay without wallet", use Autofill. |
| 50 { |
| 51 profile()->GetPrefs()->SetBoolean( |
| 52 prefs::kAutofillDialogPayWithoutWallet, true); |
| 53 AccountChooserModel model(delegate(), profile()->GetPrefs()); |
| 54 EXPECT_FALSE(model.WalletIsSelected()); |
| 55 } |
| 56 } |
| 43 | 57 |
| 44 profile()->GetPrefs()->SetBoolean( | 58 TEST_F(AccountChooserModelTest, IgnoresPrefChanges) { |
| 45 prefs::kAutofillDialogPayWithoutWallet, false); | 59 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
| 60 prefs::kAutofillDialogPayWithoutWallet)); |
| 46 EXPECT_TRUE(model()->WalletIsSelected()); | 61 EXPECT_TRUE(model()->WalletIsSelected()); |
| 47 | 62 |
| 63 // Check that nothing changes while this dialog is running if a pref changes |
| 64 // (this could cause subtle bugs or annoyances if a user closes another |
| 65 // running dialog). |
| 48 profile()->GetPrefs()->SetBoolean( | 66 profile()->GetPrefs()->SetBoolean( |
| 49 prefs::kAutofillDialogPayWithoutWallet, true); | 67 prefs::kAutofillDialogPayWithoutWallet, true); |
| 50 EXPECT_FALSE(model()->WalletIsSelected()); | 68 EXPECT_TRUE(model()->WalletIsSelected()); |
| 51 } | 69 } |
| 52 | 70 |
| 53 TEST_F(AccountChooserModelTest, HandlesError) { | 71 TEST_F(AccountChooserModelTest, HandlesError) { |
| 54 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2); | 72 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1); |
| 55 | 73 |
| 56 profile()->GetPrefs()->SetBoolean( | 74 ASSERT_TRUE(model()->WalletIsSelected()); |
| 57 prefs::kAutofillDialogPayWithoutWallet, false); | 75 ASSERT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); |
| 58 EXPECT_TRUE(model()->WalletIsSelected()); | |
| 59 | 76 |
| 60 model()->SetHadWalletError(); | 77 model()->SetHadWalletError(); |
| 61 EXPECT_FALSE(model()->WalletIsSelected()); | 78 EXPECT_FALSE(model()->WalletIsSelected()); |
| 62 EXPECT_FALSE(model()->IsCommandIdEnabled(0)); | 79 EXPECT_FALSE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); |
| 63 } | 80 } |
| 64 | 81 |
| 65 TEST_F(AccountChooserModelTest, HandlesSigninError) { | 82 TEST_F(AccountChooserModelTest, HandlesSigninError) { |
| 66 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2); | 83 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(1); |
| 67 | 84 |
| 68 profile()->GetPrefs()->SetBoolean( | 85 ASSERT_TRUE(model()->WalletIsSelected()); |
| 69 prefs::kAutofillDialogPayWithoutWallet, false); | 86 ASSERT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); |
| 70 EXPECT_TRUE(model()->WalletIsSelected()); | |
| 71 | 87 |
| 72 model()->SetHadWalletSigninError(); | 88 model()->SetHadWalletSigninError(); |
| 73 EXPECT_FALSE(model()->WalletIsSelected()); | 89 EXPECT_FALSE(model()->WalletIsSelected()); |
| 74 EXPECT_TRUE(model()->IsCommandIdEnabled(0)); | 90 EXPECT_TRUE(model()->IsCommandIdEnabled(AccountChooserModel::kWalletItemId)); |
| 75 } | 91 } |
| 76 | 92 |
| 77 TEST_F(AccountChooserModelTest, RespectsUserChoice) { | 93 TEST_F(AccountChooserModelTest, RespectsUserChoice) { |
| 78 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(3); | 94 EXPECT_CALL(*delegate(), AccountChoiceChanged()).Times(2); |
| 79 | 95 |
| 80 profile()->GetPrefs()->SetBoolean( | 96 model()->ExecuteCommand(AccountChooserModel::kAutofillItemId, 0); |
| 81 prefs::kAutofillDialogPayWithoutWallet, false); | |
| 82 EXPECT_TRUE(model()->WalletIsSelected()); | |
| 83 | |
| 84 model()->ExecuteCommand(1, 0); | |
| 85 EXPECT_FALSE(model()->WalletIsSelected()); | 97 EXPECT_FALSE(model()->WalletIsSelected()); |
| 86 | 98 |
| 87 model()->ExecuteCommand(0, 0); | 99 model()->ExecuteCommand(AccountChooserModel::kWalletItemId, 0); |
| 88 EXPECT_TRUE(model()->WalletIsSelected()); | 100 EXPECT_TRUE(model()->WalletIsSelected()); |
| 89 } | 101 } |
| 90 | 102 |
| 91 } // namespace autofill | 103 } // namespace autofill |
| OLD | NEW |