OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 MOCK_METHOD1(AddAutofillProfile, | 112 MOCK_METHOD1(AddAutofillProfile, |
113 bool(const AutofillProfile&)); // NOLINT | 113 bool(const AutofillProfile&)); // NOLINT |
114 MOCK_METHOD1(RemoveAutofillProfile, | 114 MOCK_METHOD1(RemoveAutofillProfile, |
115 bool(const std::string&)); // NOLINT | 115 bool(const std::string&)); // NOLINT |
116 }; | 116 }; |
117 | 117 |
118 MATCHER_P(MatchProfiles, profile, "") { | 118 MATCHER_P(MatchProfiles, profile, "") { |
119 return (profile.Compare(arg) == 0); | 119 return (profile.Compare(arg) == 0); |
120 } | 120 } |
121 | 121 |
122 | |
123 class WebDatabaseFake : public WebDatabase { | 122 class WebDatabaseFake : public WebDatabase { |
124 public: | 123 public: |
125 explicit WebDatabaseFake(AutofillTable* autofill_table) | 124 explicit WebDatabaseFake(AutofillTable* autofill_table) |
126 : autofill_table_(autofill_table) {} | 125 : autofill_table_(autofill_table) {} |
127 | 126 |
128 virtual AutofillTable* GetAutofillTable() OVERRIDE { | 127 virtual AutofillTable* GetAutofillTable() OVERRIDE { |
129 return autofill_table_; | 128 return autofill_table_; |
130 } | 129 } |
131 | 130 |
132 private: | 131 private: |
(...skipping 17 matching lines...) Expand all Loading... |
150 return syncer::AUTOFILL_PROFILE; | 149 return syncer::AUTOFILL_PROFILE; |
151 } | 150 } |
152 | 151 |
153 class WebDataServiceFake : public WebDataService { | 152 class WebDataServiceFake : public WebDataService { |
154 public: | 153 public: |
155 WebDataServiceFake() | 154 WebDataServiceFake() |
156 : web_database_(NULL), | 155 : web_database_(NULL), |
157 syncable_service_created_or_destroyed_(false, false) { | 156 syncable_service_created_or_destroyed_(false, false) { |
158 } | 157 } |
159 | 158 |
160 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) { | |
161 return new WebDataServiceFake; | |
162 } | |
163 | |
164 void SetDatabase(WebDatabase* web_database) { | 159 void SetDatabase(WebDatabase* web_database) { |
165 web_database_ = web_database; | 160 web_database_ = web_database; |
166 } | 161 } |
167 | 162 |
168 void StartSyncableService() { | 163 void StartSyncableService() { |
169 // The |autofill_profile_syncable_service_| must be constructed on the DB | 164 // The |autofill_profile_syncable_service_| must be constructed on the DB |
170 // thread. | 165 // thread. |
171 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 166 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
172 base::Bind(&WebDataServiceFake::CreateSyncableService, | 167 base::Bind(&WebDataServiceFake::CreateSyncableService, |
173 base::Unretained(this))); | 168 base::Unretained(this))); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 237 |
243 WebDatabase* web_database_; | 238 WebDatabase* web_database_; |
244 | 239 |
245 // We own the syncable services, but don't use a |scoped_ptr| because the | 240 // We own the syncable services, but don't use a |scoped_ptr| because the |
246 // lifetime must be managed on the DB thread. | 241 // lifetime must be managed on the DB thread. |
247 AutocompleteSyncableService* autocomplete_syncable_service_; | 242 AutocompleteSyncableService* autocomplete_syncable_service_; |
248 AutofillProfileSyncableService* autofill_profile_syncable_service_; | 243 AutofillProfileSyncableService* autofill_profile_syncable_service_; |
249 WaitableEvent syncable_service_created_or_destroyed_; | 244 WaitableEvent syncable_service_created_or_destroyed_; |
250 }; | 245 }; |
251 | 246 |
| 247 class MockWebDataServiceWrapper : public WebDataServiceWrapper { |
| 248 public: |
| 249 static ProfileKeyedService* Build(Profile* profile) { |
| 250 return new MockWebDataServiceWrapper(); |
| 251 } |
| 252 |
| 253 MockWebDataServiceWrapper() { |
| 254 web_data_service_fake_ = new WebDataServiceFake(); |
| 255 } |
| 256 |
| 257 void Shutdown() OVERRIDE { |
| 258 } |
| 259 |
| 260 scoped_refptr<WebDataService> GetWebData() OVERRIDE { |
| 261 return web_data_service_fake_; |
| 262 } |
| 263 |
| 264 ~MockWebDataServiceWrapper() { |
| 265 web_data_service_fake_ = NULL; |
| 266 } |
| 267 |
| 268 private: |
| 269 scoped_refptr<WebDataServiceFake> web_data_service_fake_; |
| 270 |
| 271 }; |
| 272 |
252 ACTION_P(MakeAutocompleteSyncComponents, wds) { | 273 ACTION_P(MakeAutocompleteSyncComponents, wds) { |
253 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 274 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
254 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) | 275 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) |
255 return base::WeakPtr<syncer::SyncableService>(); | 276 return base::WeakPtr<syncer::SyncableService>(); |
256 return wds->GetAutocompleteSyncableService()->AsWeakPtr(); | 277 return wds->GetAutocompleteSyncableService()->AsWeakPtr(); |
257 } | 278 } |
258 | 279 |
259 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { | 280 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { |
260 return new browser_sync::DataTypeManagerImpl( | 281 return new browser_sync::DataTypeManagerImpl( |
261 debug_listener, | 282 debug_listener, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 NOTREACHED(); | 424 NOTREACHED(); |
404 return NULL; | 425 return NULL; |
405 } | 426 } |
406 } | 427 } |
407 | 428 |
408 virtual void SetUp() OVERRIDE { | 429 virtual void SetUp() OVERRIDE { |
409 AbstractProfileSyncServiceTest::SetUp(); | 430 AbstractProfileSyncServiceTest::SetUp(); |
410 profile_.reset(new ProfileMock()); | 431 profile_.reset(new ProfileMock()); |
411 profile_->CreateRequestContext(); | 432 profile_->CreateRequestContext(); |
412 web_database_.reset(new WebDatabaseFake(&autofill_table_)); | 433 web_database_.reset(new WebDatabaseFake(&autofill_table_)); |
413 web_data_service_ = static_cast<WebDataServiceFake*>( | 434 MockWebDataServiceWrapper* wrapper = |
414 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 435 static_cast<MockWebDataServiceWrapper*>( |
415 profile_.get(), WebDataServiceFake::Build).get()); | 436 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 437 profile_.get(), MockWebDataServiceWrapper::Build)); |
| 438 web_data_service_ = |
| 439 static_cast<WebDataServiceFake*>(wrapper->GetWebData().get()); |
416 web_data_service_->SetDatabase(web_database_.get()); | 440 web_data_service_->SetDatabase(web_database_.get()); |
417 | 441 |
418 MockPersonalDataManagerService* personal_data_manager_service = | 442 MockPersonalDataManagerService* personal_data_manager_service = |
419 static_cast<MockPersonalDataManagerService*>( | 443 static_cast<MockPersonalDataManagerService*>( |
420 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 444 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
421 profile_.get(), MockPersonalDataManagerService::Build)); | 445 profile_.get(), MockPersonalDataManagerService::Build)); |
422 personal_data_manager_ = | 446 personal_data_manager_ = |
423 personal_data_manager_service->GetPersonalDataManager(); | 447 personal_data_manager_service->GetPersonalDataManager(); |
424 | 448 |
425 token_service_ = static_cast<TokenService*>( | 449 token_service_ = static_cast<TokenService*>( |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 std::vector<AutofillEntry> sync_entries; | 1342 std::vector<AutofillEntry> sync_entries; |
1319 std::vector<AutofillProfile> sync_profiles; | 1343 std::vector<AutofillProfile> sync_profiles; |
1320 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1344 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1321 EXPECT_EQ(3U, sync_entries.size()); | 1345 EXPECT_EQ(3U, sync_entries.size()); |
1322 EXPECT_EQ(0U, sync_profiles.size()); | 1346 EXPECT_EQ(0U, sync_profiles.size()); |
1323 for (size_t i = 0; i < sync_entries.size(); i++) { | 1347 for (size_t i = 0; i < sync_entries.size(); i++) { |
1324 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1348 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
1325 << ", " << sync_entries[i].key().value(); | 1349 << ", " << sync_entries[i].key().value(); |
1326 } | 1350 } |
1327 } | 1351 } |
OLD | NEW |