| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/autofill/core/browser/autofill_test_utils.h" | |
| 6 #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" | |
| 12 #include "components/sync_driver/fake_sync_service.h" | |
| 13 #include "components/sync_driver/sync_service.h" | |
| 14 #include "google_apis/gaia/google_service_auth_error.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 | |
| 21 namespace autofill { | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 class TestSyncService : public sync_driver::FakeSyncService { | |
| 26 public: | |
| 27 TestSyncService(syncer::ModelTypeSet type_set, | |
| 28 bool can_sync_start) | |
| 29 : type_set_(type_set), | |
| 30 can_sync_start_(can_sync_start) {} | |
| 31 ~TestSyncService() override {} | |
| 32 | |
| 33 // FakeSyncService overrides. | |
| 34 bool IsSyncAllowed() const override { return true; } | |
| 35 syncer::ModelTypeSet GetActiveDataTypes() const override { | |
| 36 return type_set_; | |
| 37 } | |
| 38 syncer::ModelTypeSet GetPreferredDataTypes() const override { | |
| 39 return type_set_; | |
| 40 } | |
| 41 bool CanSyncStart() const override { return can_sync_start_; } | |
| 42 | |
| 43 private: | |
| 44 syncer::ModelTypeSet type_set_; | |
| 45 bool can_sync_start_; | |
| 46 }; | |
| 47 | |
| 48 scoped_ptr<TestSyncService> CreateSyncService(bool has_autofill_profile, | |
| 49 bool is_enabled_and_logged_in) { | |
| 50 syncer::ModelTypeSet type_set; | |
| 51 if (has_autofill_profile) | |
| 52 type_set.Put(syncer::AUTOFILL_PROFILE); | |
| 53 return make_scoped_ptr( | |
| 54 new TestSyncService(type_set, is_enabled_and_logged_in)); | |
| 55 } | |
| 56 | |
| 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 | |
| 79 | |
| 80 // Verify that true is returned when all inputs are complete. | |
| 81 TEST(WalletIntegrationAvailableTest, AllInputsComplete) { | |
| 82 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 | |
| 87 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *pdm)); | |
| 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 } | |
| 100 | |
| 101 // Verify that false is returned when SyncService is missing or incomplete. | |
| 102 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. | |
| 110 EXPECT_FALSE(WalletIntegrationAvailable(NULL, *pdm)); | |
| 111 | |
| 112 scoped_ptr<TestSyncService> sync = CreateSyncService(false, false); | |
| 113 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); | |
| 114 | |
| 115 sync = CreateSyncService(false, true); | |
| 116 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); | |
| 117 | |
| 118 sync = CreateSyncService(true, false); | |
| 119 EXPECT_FALSE(WalletIntegrationAvailable(sync.get(), *pdm)); | |
| 120 | |
| 121 // Complete SyncService data should return true. | |
| 122 sync = CreateSyncService(true, true); | |
| 123 EXPECT_TRUE(WalletIntegrationAvailable(sync.get(), *pdm)); | |
| 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 } | |
| 137 | |
| 138 } // namespace autofill | |
| OLD | NEW |