| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <vector> |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" |
| 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 12 #include "chrome/browser/sync/chrome_sync_client.h" |
| 13 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 14 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 15 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 16 #include "chrome/common/channel_info.h" |
| 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "components/browser_sync/browser/profile_sync_service.h" |
| 20 #include "components/browser_sync/common/browser_sync_switches.h" |
| 21 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 22 #include "components/sync_driver/data_type_controller.h" |
| 23 #include "components/sync_driver/signin_manager_wrapper.h" |
| 24 #include "components/sync_driver/sync_util.h" |
| 25 #include "content/public/test/test_browser_thread_bundle.h" |
| 26 #include "google_apis/gaia/gaia_constants.h" |
| 27 #include "google_apis/gaia/oauth2_token_service.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "ui/app_list/app_list_switches.h" |
| 30 |
| 31 using sync_driver::DataTypeController; |
| 32 |
| 33 class ProfileSyncComponentsFactoryImplTest : public testing::Test { |
| 34 protected: |
| 35 ProfileSyncComponentsFactoryImplTest() |
| 36 : thread_bundle_(content::TestBrowserThreadBundle::DEFAULT) {} |
| 37 |
| 38 void SetUp() override { |
| 39 profile_.reset(new TestingProfile()); |
| 40 base::FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); |
| 41 command_line_.reset(new base::CommandLine(program_path)); |
| 42 scope_set_.insert(GaiaConstants::kChromeSyncOAuth2Scope); |
| 43 } |
| 44 |
| 45 // Returns the collection of default datatypes. |
| 46 static std::vector<syncer::ModelType> DefaultDatatypes() { |
| 47 std::vector<syncer::ModelType> datatypes; |
| 48 datatypes.push_back(syncer::APPS); |
| 49 #if defined(ENABLE_APP_LIST) |
| 50 if (app_list::switches::IsAppListSyncEnabled()) |
| 51 datatypes.push_back(syncer::APP_LIST); |
| 52 #endif |
| 53 datatypes.push_back(syncer::APP_SETTINGS); |
| 54 datatypes.push_back(syncer::AUTOFILL); |
| 55 datatypes.push_back(syncer::AUTOFILL_PROFILE); |
| 56 datatypes.push_back(syncer::AUTOFILL_WALLET_DATA); |
| 57 datatypes.push_back(syncer::BOOKMARKS); |
| 58 datatypes.push_back(syncer::DEVICE_INFO); |
| 59 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) |
| 60 datatypes.push_back(syncer::DICTIONARY); |
| 61 #endif |
| 62 datatypes.push_back(syncer::EXTENSIONS); |
| 63 datatypes.push_back(syncer::EXTENSION_SETTINGS); |
| 64 datatypes.push_back(syncer::HISTORY_DELETE_DIRECTIVES); |
| 65 datatypes.push_back(syncer::PASSWORDS); |
| 66 datatypes.push_back(syncer::PREFERENCES); |
| 67 datatypes.push_back(syncer::PRIORITY_PREFERENCES); |
| 68 datatypes.push_back(syncer::SEARCH_ENGINES); |
| 69 datatypes.push_back(syncer::SESSIONS); |
| 70 datatypes.push_back(syncer::PROXY_TABS); |
| 71 datatypes.push_back(syncer::THEMES); |
| 72 datatypes.push_back(syncer::TYPED_URLS); |
| 73 datatypes.push_back(syncer::FAVICON_TRACKING); |
| 74 datatypes.push_back(syncer::FAVICON_IMAGES); |
| 75 datatypes.push_back(syncer::SUPERVISED_USERS); |
| 76 datatypes.push_back(syncer::SUPERVISED_USER_SETTINGS); |
| 77 datatypes.push_back(syncer::SUPERVISED_USER_SHARED_SETTINGS); |
| 78 datatypes.push_back(syncer::SUPERVISED_USER_WHITELISTS); |
| 79 |
| 80 return datatypes; |
| 81 } |
| 82 |
| 83 // Returns the number of default datatypes. |
| 84 static size_t DefaultDatatypesCount() { |
| 85 return DefaultDatatypes().size(); |
| 86 } |
| 87 |
| 88 // Asserts that all the default datatypes are in |map|, except |
| 89 // for |exception_type|, which unless it is UNDEFINED, is asserted to |
| 90 // not be in |map|. |
| 91 static void CheckDefaultDatatypesInMapExcept( |
| 92 DataTypeController::StateMap* map, |
| 93 syncer::ModelTypeSet exception_types) { |
| 94 std::vector<syncer::ModelType> defaults = DefaultDatatypes(); |
| 95 std::vector<syncer::ModelType>::iterator iter; |
| 96 for (iter = defaults.begin(); iter != defaults.end(); ++iter) { |
| 97 if (exception_types.Has(*iter)) |
| 98 EXPECT_EQ(0U, map->count(*iter)) |
| 99 << *iter << " found in dataypes map, shouldn't be there."; |
| 100 else |
| 101 EXPECT_EQ(1U, map->count(*iter)) |
| 102 << *iter << " not found in datatypes map"; |
| 103 } |
| 104 } |
| 105 |
| 106 // Asserts that if you disable types via the command line, all other types |
| 107 // are enabled. |
| 108 void TestSwitchDisablesType(syncer::ModelTypeSet types) { |
| 109 command_line_->AppendSwitchASCII(switches::kDisableSyncTypes, |
| 110 syncer::ModelTypeSetToString(types)); |
| 111 GURL sync_service_url = |
| 112 GetSyncServiceURL(*command_line_, chrome::GetChannel()); |
| 113 ProfileOAuth2TokenService* token_service = |
| 114 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
| 115 scoped_ptr<sync_driver::SyncApiComponentFactory> factory( |
| 116 new ProfileSyncComponentsFactoryImpl( |
| 117 profile_.get(), command_line_.get(), |
| 118 GetSyncServiceURL(*command_line_, chrome::GetChannel()), |
| 119 token_service, profile_->GetRequestContext())); |
| 120 scoped_ptr<sync_driver::SyncClient> sync_client( |
| 121 new browser_sync::ChromeSyncClient(profile_.get(), factory.Pass())); |
| 122 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( |
| 123 sync_client.Pass(), |
| 124 make_scoped_ptr<SigninManagerWrapper>(NULL), token_service, |
| 125 browser_sync::MANUAL_START, base::Bind(&EmptyNetworkTimeUpdate), |
| 126 profile_->GetPath(), profile_->GetRequestContext(), |
| 127 profile_->GetDebugName(), chrome::GetChannel(), |
| 128 content::BrowserThread::GetMessageLoopProxyForThread( |
| 129 content::BrowserThread::DB), |
| 130 content::BrowserThread::GetMessageLoopProxyForThread( |
| 131 content::BrowserThread::FILE), |
| 132 content::BrowserThread::GetBlockingPool())); |
| 133 pss->GetSyncClient()->Initialize(pss.get()); |
| 134 DataTypeController::StateMap controller_states; |
| 135 pss->GetDataTypeControllerStates(&controller_states); |
| 136 EXPECT_EQ(DefaultDatatypesCount() - types.Size(), controller_states.size()); |
| 137 CheckDefaultDatatypesInMapExcept(&controller_states, types); |
| 138 } |
| 139 |
| 140 content::TestBrowserThreadBundle thread_bundle_; |
| 141 scoped_ptr<Profile> profile_; |
| 142 scoped_ptr<base::CommandLine> command_line_; |
| 143 OAuth2TokenService::ScopeSet scope_set_; |
| 144 }; |
| 145 |
| 146 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { |
| 147 ProfileOAuth2TokenService* token_service = |
| 148 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
| 149 scoped_ptr<sync_driver::SyncApiComponentFactory> factory( |
| 150 new ProfileSyncComponentsFactoryImpl( |
| 151 profile_.get(), command_line_.get(), |
| 152 GetSyncServiceURL(*command_line_, chrome::GetChannel()), |
| 153 token_service, profile_->GetRequestContext())); |
| 154 scoped_ptr<sync_driver::SyncClient> sync_client( |
| 155 new browser_sync::ChromeSyncClient(profile_.get(), factory.Pass())); |
| 156 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( |
| 157 sync_client.Pass(), |
| 158 make_scoped_ptr<SigninManagerWrapper>(NULL), token_service, |
| 159 browser_sync::MANUAL_START, base::Bind(&EmptyNetworkTimeUpdate), |
| 160 profile_->GetPath(), profile_->GetRequestContext(), |
| 161 profile_->GetDebugName(), chrome::GetChannel(), |
| 162 content::BrowserThread::GetMessageLoopProxyForThread( |
| 163 content::BrowserThread::DB), |
| 164 content::BrowserThread::GetMessageLoopProxyForThread( |
| 165 content::BrowserThread::FILE), |
| 166 content::BrowserThread::GetBlockingPool())); |
| 167 pss->GetSyncClient()->Initialize(pss.get()); |
| 168 DataTypeController::StateMap controller_states; |
| 169 pss->GetDataTypeControllerStates(&controller_states); |
| 170 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); |
| 171 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet()); |
| 172 } |
| 173 |
| 174 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableOne) { |
| 175 TestSwitchDisablesType(syncer::ModelTypeSet(syncer::AUTOFILL)); |
| 176 } |
| 177 |
| 178 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableMultiple) { |
| 179 TestSwitchDisablesType( |
| 180 syncer::ModelTypeSet(syncer::AUTOFILL_PROFILE, syncer::BOOKMARKS)); |
| 181 } |
| OLD | NEW |