| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperSyncable); | 133 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperSyncable); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 class SyncAutofillDataTypeControllerTest : public testing::Test { | 136 class SyncAutofillDataTypeControllerTest : public testing::Test { |
| 137 public: | 137 public: |
| 138 SyncAutofillDataTypeControllerTest() | 138 SyncAutofillDataTypeControllerTest() |
| 139 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD), | 139 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD), |
| 140 service_(&profile_), | 140 service_(&profile_), |
| 141 last_start_result_(DataTypeController::OK), | 141 last_start_result_(sync_driver::DataTypeController::OK), |
| 142 weak_ptr_factory_(this) {} | 142 weak_ptr_factory_(this) {} |
| 143 | 143 |
| 144 virtual ~SyncAutofillDataTypeControllerTest() {} | 144 virtual ~SyncAutofillDataTypeControllerTest() {} |
| 145 | 145 |
| 146 virtual void SetUp() { | 146 virtual void SetUp() { |
| 147 EXPECT_CALL(profile_sync_factory_, | 147 EXPECT_CALL(profile_sync_factory_, |
| 148 GetSyncableServiceForType(_)). | 148 GetSyncableServiceForType(_)). |
| 149 WillRepeatedly(Return(base::WeakPtr<syncer::SyncableService>())); | 149 WillRepeatedly(Return(base::WeakPtr<syncer::SyncableService>())); |
| 150 | 150 |
| 151 WebDataServiceFactory::GetInstance()->SetTestingFactory( | 151 WebDataServiceFactory::GetInstance()->SetTestingFactory( |
| 152 &profile_, MockWebDataServiceWrapperSyncable::Build); | 152 &profile_, MockWebDataServiceWrapperSyncable::Build); |
| 153 | 153 |
| 154 autofill_dtc_ = | 154 autofill_dtc_ = |
| 155 new AutofillDataTypeController( | 155 new AutofillDataTypeController( |
| 156 &profile_sync_factory_, &profile_, | 156 &profile_sync_factory_, &profile_, |
| 157 DataTypeController::DisableTypeCallback()); | 157 sync_driver::DataTypeController::DisableTypeCallback()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Passed to AutofillDTC::Start(). | 160 // Passed to AutofillDTC::Start(). |
| 161 void OnStartFinished(DataTypeController::StartResult result, | 161 void OnStartFinished(sync_driver::DataTypeController::StartResult result, |
| 162 const syncer::SyncMergeResult& local_merge_result, | 162 const syncer::SyncMergeResult& local_merge_result, |
| 163 const syncer::SyncMergeResult& syncer_merge_result) { | 163 const syncer::SyncMergeResult& syncer_merge_result) { |
| 164 last_start_result_ = result; | 164 last_start_result_ = result; |
| 165 last_start_error_ = local_merge_result.error(); | 165 last_start_error_ = local_merge_result.error(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void OnLoadFinished(syncer::ModelType type, syncer::SyncError error) { | 168 void OnLoadFinished(syncer::ModelType type, syncer::SyncError error) { |
| 169 EXPECT_FALSE(error.IsSet()); | 169 EXPECT_FALSE(error.IsSet()); |
| 170 EXPECT_EQ(type, syncer::AUTOFILL); | 170 EXPECT_EQ(type, syncer::AUTOFILL); |
| 171 } | 171 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 182 } | 182 } |
| 183 | 183 |
| 184 protected: | 184 protected: |
| 185 content::TestBrowserThreadBundle thread_bundle_; | 185 content::TestBrowserThreadBundle thread_bundle_; |
| 186 ProfileSyncComponentsFactoryMock profile_sync_factory_; | 186 ProfileSyncComponentsFactoryMock profile_sync_factory_; |
| 187 TestingProfile profile_; | 187 TestingProfile profile_; |
| 188 ProfileSyncServiceMock service_; | 188 ProfileSyncServiceMock service_; |
| 189 scoped_refptr<AutofillDataTypeController> autofill_dtc_; | 189 scoped_refptr<AutofillDataTypeController> autofill_dtc_; |
| 190 | 190 |
| 191 // Stores arguments of most recent call of OnStartFinished(). | 191 // Stores arguments of most recent call of OnStartFinished(). |
| 192 DataTypeController::StartResult last_start_result_; | 192 sync_driver::DataTypeController::StartResult last_start_result_; |
| 193 syncer::SyncError last_start_error_; | 193 syncer::SyncError last_start_error_; |
| 194 base::WeakPtrFactory<SyncAutofillDataTypeControllerTest> weak_ptr_factory_; | 194 base::WeakPtrFactory<SyncAutofillDataTypeControllerTest> weak_ptr_factory_; |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 // Load the WDS's database, then start the Autofill DTC. It should | 197 // Load the WDS's database, then start the Autofill DTC. It should |
| 198 // immediately try to start association and fail (due to missing DB | 198 // immediately try to start association and fail (due to missing DB |
| 199 // thread). | 199 // thread). |
| 200 TEST_F(SyncAutofillDataTypeControllerTest, StartWDSReady) { | 200 TEST_F(SyncAutofillDataTypeControllerTest, StartWDSReady) { |
| 201 FakeWebDataService* web_db = | 201 FakeWebDataService* web_db = |
| 202 static_cast<FakeWebDataService*>( | 202 static_cast<FakeWebDataService*>( |
| 203 WebDataServiceFactory::GetAutofillWebDataForProfile( | 203 WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 204 &profile_, Profile::EXPLICIT_ACCESS).get()); | 204 &profile_, Profile::EXPLICIT_ACCESS).get()); |
| 205 web_db->LoadDatabase(); | 205 web_db->LoadDatabase(); |
| 206 autofill_dtc_->LoadModels( | 206 autofill_dtc_->LoadModels( |
| 207 base::Bind(&SyncAutofillDataTypeControllerTest::OnLoadFinished, | 207 base::Bind(&SyncAutofillDataTypeControllerTest::OnLoadFinished, |
| 208 weak_ptr_factory_.GetWeakPtr())); | 208 weak_ptr_factory_.GetWeakPtr())); |
| 209 | 209 |
| 210 autofill_dtc_->StartAssociating( | 210 autofill_dtc_->StartAssociating( |
| 211 base::Bind(&SyncAutofillDataTypeControllerTest::OnStartFinished, | 211 base::Bind(&SyncAutofillDataTypeControllerTest::OnStartFinished, |
| 212 weak_ptr_factory_.GetWeakPtr())); | 212 weak_ptr_factory_.GetWeakPtr())); |
| 213 BlockForDBThread(); | 213 BlockForDBThread(); |
| 214 | 214 |
| 215 EXPECT_EQ(DataTypeController::ASSOCIATION_FAILED, last_start_result_); | 215 EXPECT_EQ(sync_driver::DataTypeController::ASSOCIATION_FAILED, |
| 216 last_start_result_); |
| 216 EXPECT_TRUE(last_start_error_.IsSet()); | 217 EXPECT_TRUE(last_start_error_.IsSet()); |
| 217 EXPECT_EQ(DataTypeController::DISABLED, autofill_dtc_->state()); | 218 EXPECT_EQ(sync_driver::DataTypeController::DISABLED, autofill_dtc_->state()); |
| 218 } | 219 } |
| 219 | 220 |
| 220 // Start the autofill DTC without the WDS's database loaded, then | 221 // Start the autofill DTC without the WDS's database loaded, then |
| 221 // start the DB. The Autofill DTC should be in the MODEL_STARTING | 222 // start the DB. The Autofill DTC should be in the MODEL_STARTING |
| 222 // state until the database in loaded, when it should try to start | 223 // state until the database in loaded, when it should try to start |
| 223 // association and fail (due to missing DB thread). | 224 // association and fail (due to missing DB thread). |
| 224 TEST_F(SyncAutofillDataTypeControllerTest, StartWDSNotReady) { | 225 TEST_F(SyncAutofillDataTypeControllerTest, StartWDSNotReady) { |
| 225 autofill_dtc_->LoadModels( | 226 autofill_dtc_->LoadModels( |
| 226 base::Bind(&SyncAutofillDataTypeControllerTest::OnLoadFinished, | 227 base::Bind(&SyncAutofillDataTypeControllerTest::OnLoadFinished, |
| 227 weak_ptr_factory_.GetWeakPtr())); | 228 weak_ptr_factory_.GetWeakPtr())); |
| 228 | 229 |
| 229 EXPECT_EQ(DataTypeController::OK, last_start_result_); | 230 EXPECT_EQ(sync_driver::DataTypeController::OK, last_start_result_); |
| 230 EXPECT_FALSE(last_start_error_.IsSet()); | 231 EXPECT_FALSE(last_start_error_.IsSet()); |
| 231 EXPECT_EQ(DataTypeController::MODEL_STARTING, autofill_dtc_->state()); | 232 EXPECT_EQ(sync_driver::DataTypeController::MODEL_STARTING, |
| 233 autofill_dtc_->state()); |
| 232 | 234 |
| 233 FakeWebDataService* web_db = | 235 FakeWebDataService* web_db = static_cast<FakeWebDataService*>( |
| 234 static_cast<FakeWebDataService*>( | 236 WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 235 WebDataServiceFactory::GetAutofillWebDataForProfile( | 237 &profile_, Profile::EXPLICIT_ACCESS).get()); |
| 236 &profile_, Profile::EXPLICIT_ACCESS).get()); | |
| 237 web_db->LoadDatabase(); | 238 web_db->LoadDatabase(); |
| 238 | 239 |
| 239 autofill_dtc_->StartAssociating( | 240 autofill_dtc_->StartAssociating( |
| 240 base::Bind(&SyncAutofillDataTypeControllerTest::OnStartFinished, | 241 base::Bind(&SyncAutofillDataTypeControllerTest::OnStartFinished, |
| 241 weak_ptr_factory_.GetWeakPtr())); | 242 weak_ptr_factory_.GetWeakPtr())); |
| 242 BlockForDBThread(); | 243 BlockForDBThread(); |
| 243 | 244 |
| 244 EXPECT_EQ(DataTypeController::ASSOCIATION_FAILED, last_start_result_); | 245 EXPECT_EQ(sync_driver::DataTypeController::ASSOCIATION_FAILED, |
| 246 last_start_result_); |
| 245 EXPECT_TRUE(last_start_error_.IsSet()); | 247 EXPECT_TRUE(last_start_error_.IsSet()); |
| 246 | 248 |
| 247 EXPECT_EQ(DataTypeController::DISABLED, autofill_dtc_->state()); | 249 EXPECT_EQ(sync_driver::DataTypeController::DISABLED, autofill_dtc_->state()); |
| 248 } | 250 } |
| 249 | 251 |
| 250 } // namespace | 252 } // namespace |
| 251 | 253 |
| 252 } // namespace browser_sync | 254 } // namespace browser_sync |
| OLD | NEW |