| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/autofill/core/browser/autofill_test_utils.h" | |
| 6 #include "components/autofill/core/browser/options_util.h" | 5 #include "components/autofill/core/browser/options_util.h" |
| 7 #include "components/autofill/core/browser/test_personal_data_manager.h" | |
| 8 #include "components/autofill/core/common/autofill_pref_names.h" | |
| 9 #include "components/prefs/pref_registry_simple.h" | |
| 10 #include "components/prefs/testing_pref_service.h" | |
| 11 #include "components/sync_driver/data_type_manager.h" | 6 #include "components/sync_driver/data_type_manager.h" |
| 12 #include "components/sync_driver/fake_sync_service.h" | 7 #include "components/sync_driver/fake_sync_service.h" |
| 13 #include "components/sync_driver/sync_service.h" | 8 #include "components/sync_driver/sync_service.h" |
| 14 #include "google_apis/gaia/google_service_auth_error.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "sync/internal_api/public/engine/sync_status.h" | |
| 16 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | |
| 17 #include "testing/gmock/include/gmock/gmock.h" | |
| 18 | |
| 19 using testing::Return; | |
| 20 | 10 |
| 21 namespace autofill { | 11 namespace autofill { |
| 22 | 12 |
| 23 namespace { | 13 namespace { |
| 24 | 14 |
| 25 class TestSyncService : public sync_driver::FakeSyncService { | 15 class TestSyncService : public sync_driver::FakeSyncService { |
| 26 public: | 16 public: |
| 27 TestSyncService(syncer::ModelTypeSet type_set, | 17 TestSyncService(syncer::ModelTypeSet type_set, |
| 28 bool can_sync_start) | 18 bool can_sync_start) |
| 29 : type_set_(type_set), | 19 : type_set_(type_set), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 47 | 37 |
| 48 scoped_ptr<TestSyncService> CreateSyncService(bool has_autofill_profile, | 38 scoped_ptr<TestSyncService> CreateSyncService(bool has_autofill_profile, |
| 49 bool is_enabled_and_logged_in) { | 39 bool is_enabled_and_logged_in) { |
| 50 syncer::ModelTypeSet type_set; | 40 syncer::ModelTypeSet type_set; |
| 51 if (has_autofill_profile) | 41 if (has_autofill_profile) |
| 52 type_set.Put(syncer::AUTOFILL_PROFILE); | 42 type_set.Put(syncer::AUTOFILL_PROFILE); |
| 53 return make_scoped_ptr( | 43 return make_scoped_ptr( |
| 54 new TestSyncService(type_set, is_enabled_and_logged_in)); | 44 new TestSyncService(type_set, is_enabled_and_logged_in)); |
| 55 } | 45 } |
| 56 | 46 |
| 57 scoped_ptr<TestingPrefServiceSimple> CreatePrefService( | |
| 58 bool autofill_wallet_import_enabled, | |
| 59 bool autofill_wallet_sync_experiment_enabled) { | |
| 60 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); | |
| 61 prefs->registry()->RegisterBooleanPref(prefs::kAutofillEnabled, true); | |
| 62 prefs->registry()->RegisterBooleanPref(prefs::kAutofillWalletImportEnabled, | |
| 63 autofill_wallet_import_enabled); | |
| 64 prefs->registry()->RegisterBooleanPref( | |
| 65 prefs::kAutofillWalletSyncExperimentEnabled, | |
| 66 autofill_wallet_sync_experiment_enabled); | |
| 67 | |
| 68 return prefs; | |
| 69 } | |
| 70 | |
| 71 scoped_ptr<TestPersonalDataManager> CreatePersonalDataManager( | |
| 72 PrefService* prefs) { | |
| 73 scoped_ptr<TestPersonalDataManager> pdm(new TestPersonalDataManager()); | |
| 74 pdm->SetTestingPrefService(prefs); | |
| 75 return pdm; | |
| 76 } | |
| 77 | |
| 78 } // namespace | 47 } // namespace |
| 79 | 48 |
| 80 // Verify that true is returned when all inputs are complete. | 49 // Verify that true is returned when all inputs are complete. |
| 81 TEST(WalletIntegrationAvailableTest, AllInputsComplete) { | 50 TEST(WalletIntegrationAvailableTest, AllInputsComplete) { |
| 82 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true); | 51 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true); |
| 83 scoped_ptr<TestingPrefServiceSimple> prefs = CreatePrefService(true, true); | |
| 84 scoped_ptr<TestPersonalDataManager> pdm = | |
| 85 CreatePersonalDataManager(prefs.get()); | |
| 86 | 52 |
| 87 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *pdm)); | 53 EXPECT_TRUE(WalletIntegrationAvailable(sync.get())); |
| 88 } | |
| 89 | |
| 90 // Verify that true is returned even if wallet import is disabled. (Otherwise | |
| 91 // the user will never be able to enable it). | |
| 92 TEST(WalletIntegrationAvailableTest, WalletImportDisabled) { | |
| 93 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true); | |
| 94 scoped_ptr<TestingPrefServiceSimple> prefs = CreatePrefService(false, true); | |
| 95 scoped_ptr<TestPersonalDataManager> pdm = | |
| 96 CreatePersonalDataManager(prefs.get()); | |
| 97 | |
| 98 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *pdm)); | |
| 99 } | 54 } |
| 100 | 55 |
| 101 // Verify that false is returned when SyncService is missing or incomplete. | 56 // Verify that false is returned when SyncService is missing or incomplete. |
| 102 TEST(WalletIntegrationAvailableTest, MissingOrIncompleteSyncService) { | 57 TEST(WalletIntegrationAvailableTest, MissingOrIncompleteSyncService) { |
| 103 // Setup |prefs| and |pdm| to do their part to make | |
| 104 // WalletIntegrationAvailable() return true. | |
| 105 scoped_ptr<TestingPrefServiceSimple> prefs = CreatePrefService(true, true); | |
| 106 scoped_ptr<TestPersonalDataManager> pdm = | |
| 107 CreatePersonalDataManager(prefs.get()); | |
| 108 | |
| 109 // Incomplete SyncService data should return false. | 58 // Incomplete SyncService data should return false. |
| 110 EXPECT_FALSE(WalletIntegrationAvailable(NULL, *pdm)); | 59 EXPECT_FALSE(WalletIntegrationAvailable(NULL)); |
| 111 | 60 |
| 112 scoped_ptr<TestSyncService> sync = CreateSyncService(false, false); | 61 scoped_ptr<TestSyncService> sync = CreateSyncService(false, false); |
| 113 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); | 62 EXPECT_FALSE(WalletIntegrationAvailable(sync.get())); |
| 114 | 63 |
| 115 sync = CreateSyncService(false, true); | 64 sync = CreateSyncService(false, true); |
| 116 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); | 65 EXPECT_FALSE(WalletIntegrationAvailable(sync.get())); |
| 117 | 66 |
| 118 sync = CreateSyncService(true, false); | 67 sync = CreateSyncService(true, false); |
| 119 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); | 68 EXPECT_FALSE(WalletIntegrationAvailable(sync.get())); |
| 120 | 69 |
| 121 // Complete SyncService data should return true. | 70 // Complete SyncService data should return true. |
| 122 sync = CreateSyncService(true, true); | 71 sync = CreateSyncService(true, true); |
| 123 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *pdm)); | 72 EXPECT_TRUE(WalletIntegrationAvailable(sync.get())); |
| 124 } | |
| 125 | |
| 126 // Verify that false is returned when | |
| 127 // !prefs::kAutofillWalletSyncExperimentEnabled. | |
| 128 TEST(WalletIntegrationAvailableTest, ExperimentalWalletIntegrationDisabled) { | |
| 129 scoped_ptr<TestSyncService> sync = CreateSyncService(true, true); | |
| 130 // Set kAutofillWalletSyncExperimentEnabled to false. | |
| 131 scoped_ptr<TestingPrefServiceSimple> prefs = CreatePrefService(true, false); | |
| 132 scoped_ptr<TestPersonalDataManager> pdm = | |
| 133 CreatePersonalDataManager(prefs.get()); | |
| 134 | |
| 135 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); | |
| 136 } | 73 } |
| 137 | 74 |
| 138 } // namespace autofill | 75 } // namespace autofill |
| OLD | NEW |