OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
13 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
14 #include "chrome/browser/sync/profile_sync_service_factory.h" | 14 #include "chrome/browser/sync/profile_sync_service_factory.h" |
15 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" | 15 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" |
| 16 #include "chrome/common/channel_info.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/sync_util.h" | |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
19 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 19 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
20 #include "components/sync_driver/data_type_controller.h" | 20 #include "components/sync_driver/data_type_controller.h" |
| 21 #include "components/sync_driver/sync_util.h" |
21 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
22 #include "google_apis/gaia/gaia_constants.h" | 23 #include "google_apis/gaia/gaia_constants.h" |
23 #include "google_apis/gaia/oauth2_token_service.h" | 24 #include "google_apis/gaia/oauth2_token_service.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "ui/app_list/app_list_switches.h" | 26 #include "ui/app_list/app_list_switches.h" |
26 | 27 |
27 using sync_driver::DataTypeController; | 28 using sync_driver::DataTypeController; |
28 | 29 |
29 class ProfileSyncComponentsFactoryImplTest : public testing::Test { | 30 class ProfileSyncComponentsFactoryImplTest : public testing::Test { |
30 protected: | 31 protected: |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 EXPECT_EQ(1U, map->count(*iter)) | 98 EXPECT_EQ(1U, map->count(*iter)) |
98 << *iter << " not found in datatypes map"; | 99 << *iter << " not found in datatypes map"; |
99 } | 100 } |
100 } | 101 } |
101 | 102 |
102 // Asserts that if you disable types via the command line, all other types | 103 // Asserts that if you disable types via the command line, all other types |
103 // are enabled. | 104 // are enabled. |
104 void TestSwitchDisablesType(syncer::ModelTypeSet types) { | 105 void TestSwitchDisablesType(syncer::ModelTypeSet types) { |
105 command_line_->AppendSwitchASCII(switches::kDisableSyncTypes, | 106 command_line_->AppendSwitchASCII(switches::kDisableSyncTypes, |
106 syncer::ModelTypeSetToString(types)); | 107 syncer::ModelTypeSetToString(types)); |
107 GURL sync_service_url = GetSyncServiceURL(*command_line_); | 108 GURL sync_service_url = |
| 109 GetSyncServiceURL(*command_line_, chrome::GetChannel()); |
108 ProfileOAuth2TokenService* token_service = | 110 ProfileOAuth2TokenService* token_service = |
109 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 111 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
110 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( | 112 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( |
111 scoped_ptr<ProfileSyncComponentsFactory>( | 113 scoped_ptr<ProfileSyncComponentsFactory>( |
112 new ProfileSyncComponentsFactoryImpl( | 114 new ProfileSyncComponentsFactoryImpl( |
113 profile_.get(), | 115 profile_.get(), command_line_.get(), |
114 command_line_.get(), | 116 GetSyncServiceURL(*command_line_, chrome::GetChannel()), |
115 GetSyncServiceURL(*command_line_), | 117 token_service, profile_->GetRequestContext())), |
116 token_service, | |
117 profile_->GetRequestContext())), | |
118 profile_.get(), | 118 profile_.get(), |
119 make_scoped_ptr<SupervisedUserSigninManagerWrapper>(NULL), | 119 make_scoped_ptr<SupervisedUserSigninManagerWrapper>(NULL), |
120 token_service, | 120 token_service, browser_sync::MANUAL_START)); |
121 browser_sync::MANUAL_START)); | |
122 pss->factory()->RegisterDataTypes(pss.get()); | 121 pss->factory()->RegisterDataTypes(pss.get()); |
123 DataTypeController::StateMap controller_states; | 122 DataTypeController::StateMap controller_states; |
124 pss->GetDataTypeControllerStates(&controller_states); | 123 pss->GetDataTypeControllerStates(&controller_states); |
125 EXPECT_EQ(DefaultDatatypesCount() - types.Size(), controller_states.size()); | 124 EXPECT_EQ(DefaultDatatypesCount() - types.Size(), controller_states.size()); |
126 CheckDefaultDatatypesInMapExcept(&controller_states, types); | 125 CheckDefaultDatatypesInMapExcept(&controller_states, types); |
127 } | 126 } |
128 | 127 |
129 content::TestBrowserThreadBundle thread_bundle_; | 128 content::TestBrowserThreadBundle thread_bundle_; |
130 scoped_ptr<Profile> profile_; | 129 scoped_ptr<Profile> profile_; |
131 scoped_ptr<base::CommandLine> command_line_; | 130 scoped_ptr<base::CommandLine> command_line_; |
132 OAuth2TokenService::ScopeSet scope_set_; | 131 OAuth2TokenService::ScopeSet scope_set_; |
133 }; | 132 }; |
134 | 133 |
135 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { | 134 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { |
136 ProfileOAuth2TokenService* token_service = | 135 ProfileOAuth2TokenService* token_service = |
137 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 136 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
138 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( | 137 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService( |
139 scoped_ptr<ProfileSyncComponentsFactory>( | 138 scoped_ptr<ProfileSyncComponentsFactory>( |
140 new ProfileSyncComponentsFactoryImpl( | 139 new ProfileSyncComponentsFactoryImpl( |
141 profile_.get(), | 140 profile_.get(), command_line_.get(), |
142 command_line_.get(), | 141 GetSyncServiceURL(*command_line_, chrome::GetChannel()), |
143 GetSyncServiceURL(*command_line_), | 142 token_service, profile_->GetRequestContext())), |
144 token_service, | 143 profile_.get(), make_scoped_ptr<SupervisedUserSigninManagerWrapper>(NULL), |
145 profile_->GetRequestContext())), | 144 token_service, browser_sync::MANUAL_START)); |
146 profile_.get(), | |
147 make_scoped_ptr<SupervisedUserSigninManagerWrapper>(NULL), | |
148 token_service, | |
149 browser_sync::MANUAL_START)); | |
150 pss->factory()->RegisterDataTypes(pss.get()); | 145 pss->factory()->RegisterDataTypes(pss.get()); |
151 DataTypeController::StateMap controller_states; | 146 DataTypeController::StateMap controller_states; |
152 pss->GetDataTypeControllerStates(&controller_states); | 147 pss->GetDataTypeControllerStates(&controller_states); |
153 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); | 148 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); |
154 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet()); | 149 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet()); |
155 } | 150 } |
156 | 151 |
157 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableOne) { | 152 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableOne) { |
158 TestSwitchDisablesType(syncer::ModelTypeSet(syncer::AUTOFILL)); | 153 TestSwitchDisablesType(syncer::ModelTypeSet(syncer::AUTOFILL)); |
159 } | 154 } |
160 | 155 |
161 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableMultiple) { | 156 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableMultiple) { |
162 TestSwitchDisablesType( | 157 TestSwitchDisablesType( |
163 syncer::ModelTypeSet(syncer::AUTOFILL_PROFILE, syncer::BOOKMARKS)); | 158 syncer::ModelTypeSet(syncer::AUTOFILL_PROFILE, syncer::BOOKMARKS)); |
164 } | 159 } |
OLD | NEW |