| 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::AUTOFILL_WALLET_METADATA); |  | 
| 58     datatypes.push_back(syncer::BOOKMARKS); |  | 
| 59     datatypes.push_back(syncer::DEVICE_INFO); |  | 
| 60 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS) |  | 
| 61     datatypes.push_back(syncer::DICTIONARY); |  | 
| 62 #endif |  | 
| 63     datatypes.push_back(syncer::EXTENSIONS); |  | 
| 64     datatypes.push_back(syncer::EXTENSION_SETTINGS); |  | 
| 65     datatypes.push_back(syncer::HISTORY_DELETE_DIRECTIVES); |  | 
| 66     datatypes.push_back(syncer::PASSWORDS); |  | 
| 67     datatypes.push_back(syncer::PREFERENCES); |  | 
| 68     datatypes.push_back(syncer::PRIORITY_PREFERENCES); |  | 
| 69     datatypes.push_back(syncer::SEARCH_ENGINES); |  | 
| 70     datatypes.push_back(syncer::SESSIONS); |  | 
| 71     datatypes.push_back(syncer::PROXY_TABS); |  | 
| 72     datatypes.push_back(syncer::THEMES); |  | 
| 73     datatypes.push_back(syncer::TYPED_URLS); |  | 
| 74     datatypes.push_back(syncer::FAVICON_TRACKING); |  | 
| 75     datatypes.push_back(syncer::FAVICON_IMAGES); |  | 
| 76     datatypes.push_back(syncer::SUPERVISED_USERS); |  | 
| 77     datatypes.push_back(syncer::SUPERVISED_USER_SETTINGS); |  | 
| 78     datatypes.push_back(syncer::SUPERVISED_USER_SHARED_SETTINGS); |  | 
| 79     datatypes.push_back(syncer::SUPERVISED_USER_WHITELISTS); |  | 
| 80 |  | 
| 81     return datatypes; |  | 
| 82   } |  | 
| 83 |  | 
| 84   // Returns the number of default datatypes. |  | 
| 85   static size_t DefaultDatatypesCount() { |  | 
| 86     return DefaultDatatypes().size(); |  | 
| 87   } |  | 
| 88 |  | 
| 89   // Asserts that all the default datatypes are in |map|, except |  | 
| 90   // for |exception_type|, which unless it is UNDEFINED, is asserted to |  | 
| 91   // not be in |map|. |  | 
| 92   static void CheckDefaultDatatypesInMapExcept( |  | 
| 93       DataTypeController::StateMap* map, |  | 
| 94       syncer::ModelTypeSet exception_types) { |  | 
| 95     std::vector<syncer::ModelType> defaults = DefaultDatatypes(); |  | 
| 96     std::vector<syncer::ModelType>::iterator iter; |  | 
| 97     for (iter = defaults.begin(); iter != defaults.end(); ++iter) { |  | 
| 98       if (exception_types.Has(*iter)) |  | 
| 99         EXPECT_EQ(0U, map->count(*iter)) |  | 
| 100             << *iter << " found in dataypes map, shouldn't be there."; |  | 
| 101       else |  | 
| 102         EXPECT_EQ(1U, map->count(*iter)) |  | 
| 103             << *iter << " not found in datatypes map"; |  | 
| 104     } |  | 
| 105   } |  | 
| 106 |  | 
| 107   // Asserts that if you disable types via the command line, all other types |  | 
| 108   // are enabled. |  | 
| 109   void TestSwitchDisablesType(syncer::ModelTypeSet types) { |  | 
| 110     command_line_->AppendSwitchASCII(switches::kDisableSyncTypes, |  | 
| 111                                      syncer::ModelTypeSetToString(types)); |  | 
| 112     GURL sync_service_url = |  | 
| 113         GetSyncServiceURL(*command_line_, chrome::GetChannel()); |  | 
| 114     ProfileOAuth2TokenService* token_service = |  | 
| 115         ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |  | 
| 116     scoped_ptr<sync_driver::SyncApiComponentFactory> factory( |  | 
| 117         new ProfileSyncComponentsFactoryImpl( |  | 
| 118             profile_.get(), command_line_.get(), |  | 
| 119             GetSyncServiceURL(*command_line_, chrome::GetChannel()), |  | 
| 120             token_service, profile_->GetRequestContext())); |  | 
| 121     scoped_ptr<sync_driver::SyncClient> sync_client( |  | 
| 122         new browser_sync::ChromeSyncClient(profile_.get(), factory.Pass())); |  | 
| 123     scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( |  | 
| 124         sync_client.Pass(), |  | 
| 125         make_scoped_ptr<SigninManagerWrapper>(NULL), token_service, |  | 
| 126         browser_sync::MANUAL_START, base::Bind(&EmptyNetworkTimeUpdate), |  | 
| 127         profile_->GetPath(), profile_->GetRequestContext(), |  | 
| 128         profile_->GetDebugName(), chrome::GetChannel(), |  | 
| 129         content::BrowserThread::GetMessageLoopProxyForThread( |  | 
| 130             content::BrowserThread::DB), |  | 
| 131         content::BrowserThread::GetMessageLoopProxyForThread( |  | 
| 132             content::BrowserThread::FILE), |  | 
| 133         content::BrowserThread::GetBlockingPool())); |  | 
| 134     pss->GetSyncClient()->Initialize(pss.get()); |  | 
| 135     DataTypeController::StateMap controller_states; |  | 
| 136     pss->GetDataTypeControllerStates(&controller_states); |  | 
| 137     EXPECT_EQ(DefaultDatatypesCount() - types.Size(), controller_states.size()); |  | 
| 138     CheckDefaultDatatypesInMapExcept(&controller_states, types); |  | 
| 139   } |  | 
| 140 |  | 
| 141   content::TestBrowserThreadBundle thread_bundle_; |  | 
| 142   scoped_ptr<Profile> profile_; |  | 
| 143   scoped_ptr<base::CommandLine> command_line_; |  | 
| 144   OAuth2TokenService::ScopeSet scope_set_; |  | 
| 145 }; |  | 
| 146 |  | 
| 147 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { |  | 
| 148   ProfileOAuth2TokenService* token_service = |  | 
| 149       ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |  | 
| 150   scoped_ptr<sync_driver::SyncApiComponentFactory> factory( |  | 
| 151       new ProfileSyncComponentsFactoryImpl( |  | 
| 152           profile_.get(), command_line_.get(), |  | 
| 153           GetSyncServiceURL(*command_line_, chrome::GetChannel()), |  | 
| 154           token_service, profile_->GetRequestContext())); |  | 
| 155   scoped_ptr<sync_driver::SyncClient> sync_client( |  | 
| 156       new browser_sync::ChromeSyncClient(profile_.get(), factory.Pass())); |  | 
| 157   scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( |  | 
| 158       sync_client.Pass(), |  | 
| 159       make_scoped_ptr<SigninManagerWrapper>(NULL), token_service, |  | 
| 160       browser_sync::MANUAL_START, base::Bind(&EmptyNetworkTimeUpdate), |  | 
| 161       profile_->GetPath(), profile_->GetRequestContext(), |  | 
| 162       profile_->GetDebugName(), chrome::GetChannel(), |  | 
| 163       content::BrowserThread::GetMessageLoopProxyForThread( |  | 
| 164           content::BrowserThread::DB), |  | 
| 165       content::BrowserThread::GetMessageLoopProxyForThread( |  | 
| 166           content::BrowserThread::FILE), |  | 
| 167       content::BrowserThread::GetBlockingPool())); |  | 
| 168   pss->GetSyncClient()->Initialize(pss.get()); |  | 
| 169   DataTypeController::StateMap controller_states; |  | 
| 170   pss->GetDataTypeControllerStates(&controller_states); |  | 
| 171   EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); |  | 
| 172   CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet()); |  | 
| 173 } |  | 
| 174 |  | 
| 175 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableOne) { |  | 
| 176   TestSwitchDisablesType(syncer::ModelTypeSet(syncer::AUTOFILL)); |  | 
| 177 } |  | 
| 178 |  | 
| 179 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableMultiple) { |  | 
| 180   TestSwitchDisablesType( |  | 
| 181       syncer::ModelTypeSet(syncer::AUTOFILL_PROFILE, syncer::BOOKMARKS)); |  | 
| 182 } |  | 
| OLD | NEW | 
|---|