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 24 matching lines...) Expand all Loading... |
35 #include "chrome/browser/sync/profile_sync_service_factory.h" | 35 #include "chrome/browser/sync/profile_sync_service_factory.h" |
36 #include "chrome/browser/sync/profile_sync_test_util.h" | 36 #include "chrome/browser/sync/profile_sync_test_util.h" |
37 #include "chrome/browser/sync/test_profile_sync_service.h" | 37 #include "chrome/browser/sync/test_profile_sync_service.h" |
38 #include "chrome/browser/webdata/autocomplete_syncable_service.h" | 38 #include "chrome/browser/webdata/autocomplete_syncable_service.h" |
39 #include "chrome/browser/webdata/autofill_change.h" | 39 #include "chrome/browser/webdata/autofill_change.h" |
40 #include "chrome/browser/webdata/autofill_entry.h" | 40 #include "chrome/browser/webdata/autofill_entry.h" |
41 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" | 41 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" |
42 #include "chrome/browser/webdata/autofill_table.h" | 42 #include "chrome/browser/webdata/autofill_table.h" |
43 #include "chrome/browser/webdata/web_data_service.h" | 43 #include "chrome/browser/webdata/web_data_service.h" |
44 #include "chrome/browser/webdata/web_data_service_factory.h" | 44 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 45 #include "chrome/browser/webdata/web_data_service_test_util.h" |
45 #include "chrome/browser/webdata/web_database.h" | 46 #include "chrome/browser/webdata/web_database.h" |
46 #include "chrome/common/chrome_notification_types.h" | 47 #include "chrome/common/chrome_notification_types.h" |
47 #include "components/autofill/browser/autofill_common_test.h" | 48 #include "components/autofill/browser/autofill_common_test.h" |
48 #include "components/autofill/browser/personal_data_manager.h" | 49 #include "components/autofill/browser/personal_data_manager.h" |
49 #include "content/public/browser/notification_source.h" | 50 #include "content/public/browser/notification_source.h" |
50 #include "content/public/test/test_browser_thread.h" | 51 #include "content/public/test/test_browser_thread.h" |
51 #include "google_apis/gaia/gaia_constants.h" | 52 #include "google_apis/gaia/gaia_constants.h" |
52 #include "sync/internal_api/public/base/model_type.h" | 53 #include "sync/internal_api/public/base/model_type.h" |
53 #include "sync/internal_api/public/read_node.h" | 54 #include "sync/internal_api/public/read_node.h" |
54 #include "sync/internal_api/public/read_transaction.h" | 55 #include "sync/internal_api/public/read_transaction.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 using testing::Return; | 88 using testing::Return; |
88 | 89 |
89 namespace syncable { | 90 namespace syncable { |
90 class Id; | 91 class Id; |
91 } | 92 } |
92 | 93 |
93 class HistoryService; | 94 class HistoryService; |
94 | 95 |
95 class AutofillTableMock : public AutofillTable { | 96 class AutofillTableMock : public AutofillTable { |
96 public: | 97 public: |
97 AutofillTableMock() : AutofillTable(NULL, NULL) {} | 98 AutofillTableMock() : AutofillTable() {} |
98 MOCK_METHOD2(RemoveFormElement, | 99 MOCK_METHOD2(RemoveFormElement, |
99 bool(const string16& name, const string16& value)); // NOLINT | 100 bool(const string16& name, const string16& value)); // NOLINT |
100 MOCK_METHOD1(GetAllAutofillEntries, | 101 MOCK_METHOD1(GetAllAutofillEntries, |
101 bool(std::vector<AutofillEntry>* entries)); // NOLINT | 102 bool(std::vector<AutofillEntry>* entries)); // NOLINT |
102 MOCK_METHOD3(GetAutofillTimestamps, | 103 MOCK_METHOD3(GetAutofillTimestamps, |
103 bool(const string16& name, // NOLINT | 104 bool(const string16& name, // NOLINT |
104 const string16& value, | 105 const string16& value, |
105 std::vector<base::Time>* timestamps)); | 106 std::vector<base::Time>* timestamps)); |
106 MOCK_METHOD1(UpdateAutofillEntries, | 107 MOCK_METHOD1(UpdateAutofillEntries, |
107 bool(const std::vector<AutofillEntry>&)); // NOLINT | 108 bool(const std::vector<AutofillEntry>&)); // NOLINT |
108 MOCK_METHOD1(GetAutofillProfiles, | 109 MOCK_METHOD1(GetAutofillProfiles, |
109 bool(std::vector<AutofillProfile*>*)); // NOLINT | 110 bool(std::vector<AutofillProfile*>*)); // NOLINT |
110 MOCK_METHOD1(UpdateAutofillProfileMulti, | 111 MOCK_METHOD1(UpdateAutofillProfileMulti, |
111 bool(const AutofillProfile&)); // NOLINT | 112 bool(const AutofillProfile&)); // NOLINT |
112 MOCK_METHOD1(AddAutofillProfile, | 113 MOCK_METHOD1(AddAutofillProfile, |
113 bool(const AutofillProfile&)); // NOLINT | 114 bool(const AutofillProfile&)); // NOLINT |
114 MOCK_METHOD1(RemoveAutofillProfile, | 115 MOCK_METHOD1(RemoveAutofillProfile, |
115 bool(const std::string&)); // NOLINT | 116 bool(const std::string&)); // NOLINT |
116 }; | 117 }; |
117 | 118 |
118 MATCHER_P(MatchProfiles, profile, "") { | 119 MATCHER_P(MatchProfiles, profile, "") { |
119 return (profile.Compare(arg) == 0); | 120 return (profile.Compare(arg) == 0); |
120 } | 121 } |
121 | 122 |
122 | |
123 class WebDatabaseFake : public WebDatabase { | 123 class WebDatabaseFake : public WebDatabase { |
124 public: | 124 public: |
125 explicit WebDatabaseFake(AutofillTable* autofill_table) | 125 explicit WebDatabaseFake(AutofillTable* autofill_table) { |
126 : autofill_table_(autofill_table) {} | 126 AddTable(autofill_table); |
127 | |
128 virtual AutofillTable* GetAutofillTable() OVERRIDE { | |
129 return autofill_table_; | |
130 } | 127 } |
131 | |
132 private: | |
133 AutofillTable* autofill_table_; | |
134 }; | 128 }; |
135 | 129 |
136 class ProfileSyncServiceAutofillTest; | 130 class ProfileSyncServiceAutofillTest; |
137 | 131 |
138 template<class AutofillProfile> | 132 template<class AutofillProfile> |
139 syncer::ModelType GetModelType() { | 133 syncer::ModelType GetModelType() { |
140 return syncer::UNSPECIFIED; | 134 return syncer::UNSPECIFIED; |
141 } | 135 } |
142 | 136 |
143 template<> | 137 template<> |
144 syncer::ModelType GetModelType<AutofillEntry>() { | 138 syncer::ModelType GetModelType<AutofillEntry>() { |
145 return syncer::AUTOFILL; | 139 return syncer::AUTOFILL; |
146 } | 140 } |
147 | 141 |
148 template<> | 142 template<> |
149 syncer::ModelType GetModelType<AutofillProfile>() { | 143 syncer::ModelType GetModelType<AutofillProfile>() { |
150 return syncer::AUTOFILL_PROFILE; | 144 return syncer::AUTOFILL_PROFILE; |
151 } | 145 } |
152 | 146 |
153 class WebDataServiceFake : public WebDataService { | 147 class WebDataServiceFake : public WebDataService { |
154 public: | 148 public: |
155 WebDataServiceFake() | 149 WebDataServiceFake() |
156 : web_database_(NULL), | 150 : web_database_(NULL), |
157 syncable_service_created_or_destroyed_(false, false) { | 151 syncable_service_created_or_destroyed_(false, false) { |
158 } | 152 } |
159 | 153 |
160 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) { | |
161 return new WebDataServiceFake; | |
162 } | |
163 | |
164 void SetDatabase(WebDatabase* web_database) { | 154 void SetDatabase(WebDatabase* web_database) { |
165 web_database_ = web_database; | 155 web_database_ = web_database; |
166 } | 156 } |
167 | 157 |
168 void StartSyncableService() { | 158 void StartSyncableService() { |
169 // The |autofill_profile_syncable_service_| must be constructed on the DB | 159 // The |autofill_profile_syncable_service_| must be constructed on the DB |
170 // thread. | 160 // thread. |
171 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 161 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
172 base::Bind(&WebDataServiceFake::CreateSyncableService, | 162 base::Bind(&WebDataServiceFake::CreateSyncableService, |
173 base::Unretained(this))); | 163 base::Unretained(this))); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 202 } |
213 | 203 |
214 virtual AutofillProfileSyncableService* | 204 virtual AutofillProfileSyncableService* |
215 GetAutofillProfileSyncableService() const OVERRIDE { | 205 GetAutofillProfileSyncableService() const OVERRIDE { |
216 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 206 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
217 EXPECT_TRUE(autofill_profile_syncable_service_); | 207 EXPECT_TRUE(autofill_profile_syncable_service_); |
218 | 208 |
219 return autofill_profile_syncable_service_; | 209 return autofill_profile_syncable_service_; |
220 } | 210 } |
221 | 211 |
222 virtual void ShutdownOnUIThread() OVERRIDE {} | |
223 | |
224 private: | 212 private: |
225 virtual ~WebDataServiceFake() {} | 213 virtual ~WebDataServiceFake() {} |
226 | 214 |
227 void CreateSyncableService() { | 215 void CreateSyncableService() { |
228 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 216 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
229 // These services are deleted in DestroySyncableService(). | 217 // These services are deleted in DestroySyncableService(). |
230 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); | 218 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); |
231 autofill_profile_syncable_service_ = | 219 autofill_profile_syncable_service_ = |
232 new AutofillProfileSyncableService(this); | 220 new AutofillProfileSyncableService(this); |
233 syncable_service_created_or_destroyed_.Signal(); | 221 syncable_service_created_or_destroyed_.Signal(); |
234 } | 222 } |
235 | 223 |
236 void DestroySyncableService() { | 224 void DestroySyncableService() { |
237 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 225 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
238 delete autofill_profile_syncable_service_; | 226 delete autofill_profile_syncable_service_; |
239 delete autocomplete_syncable_service_; | 227 delete autocomplete_syncable_service_; |
240 syncable_service_created_or_destroyed_.Signal(); | 228 syncable_service_created_or_destroyed_.Signal(); |
241 } | 229 } |
242 | 230 |
243 WebDatabase* web_database_; | 231 WebDatabase* web_database_; |
244 | 232 |
245 // We own the syncable services, but don't use a |scoped_ptr| because the | 233 // We own the syncable services, but don't use a |scoped_ptr| because the |
246 // lifetime must be managed on the DB thread. | 234 // lifetime must be managed on the DB thread. |
247 AutocompleteSyncableService* autocomplete_syncable_service_; | 235 AutocompleteSyncableService* autocomplete_syncable_service_; |
248 AutofillProfileSyncableService* autofill_profile_syncable_service_; | 236 AutofillProfileSyncableService* autofill_profile_syncable_service_; |
249 WaitableEvent syncable_service_created_or_destroyed_; | 237 WaitableEvent syncable_service_created_or_destroyed_; |
250 }; | 238 }; |
251 | 239 |
| 240 ProfileKeyedService* BuildMockWebDataServiceWrapper(Profile* profile) { |
| 241 return new MockWebDataServiceWrapper(new WebDataServiceFake()); |
| 242 } |
| 243 |
252 ACTION_P(MakeAutocompleteSyncComponents, wds) { | 244 ACTION_P(MakeAutocompleteSyncComponents, wds) { |
253 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 245 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
254 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) | 246 if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) |
255 return base::WeakPtr<syncer::SyncableService>(); | 247 return base::WeakPtr<syncer::SyncableService>(); |
256 return wds->GetAutocompleteSyncableService()->AsWeakPtr(); | 248 return wds->GetAutocompleteSyncableService()->AsWeakPtr(); |
257 } | 249 } |
258 | 250 |
259 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { | 251 ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) { |
260 return new browser_sync::DataTypeManagerImpl( | 252 return new browser_sync::DataTypeManagerImpl( |
261 debug_listener, | 253 debug_listener, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 NOTREACHED(); | 395 NOTREACHED(); |
404 return NULL; | 396 return NULL; |
405 } | 397 } |
406 } | 398 } |
407 | 399 |
408 virtual void SetUp() OVERRIDE { | 400 virtual void SetUp() OVERRIDE { |
409 AbstractProfileSyncServiceTest::SetUp(); | 401 AbstractProfileSyncServiceTest::SetUp(); |
410 profile_.reset(new ProfileMock()); | 402 profile_.reset(new ProfileMock()); |
411 profile_->CreateRequestContext(); | 403 profile_->CreateRequestContext(); |
412 web_database_.reset(new WebDatabaseFake(&autofill_table_)); | 404 web_database_.reset(new WebDatabaseFake(&autofill_table_)); |
413 web_data_service_ = static_cast<WebDataServiceFake*>( | 405 MockWebDataServiceWrapper* wrapper = |
414 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 406 static_cast<MockWebDataServiceWrapper*>( |
415 profile_.get(), WebDataServiceFake::Build).get()); | 407 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 408 profile_.get(), BuildMockWebDataServiceWrapper)); |
| 409 web_data_service_ = |
| 410 static_cast<WebDataServiceFake*>(wrapper->GetWebData().get()); |
416 web_data_service_->SetDatabase(web_database_.get()); | 411 web_data_service_->SetDatabase(web_database_.get()); |
417 | 412 |
418 MockPersonalDataManagerService* personal_data_manager_service = | 413 MockPersonalDataManagerService* personal_data_manager_service = |
419 static_cast<MockPersonalDataManagerService*>( | 414 static_cast<MockPersonalDataManagerService*>( |
420 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 415 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
421 profile_.get(), MockPersonalDataManagerService::Build)); | 416 profile_.get(), MockPersonalDataManagerService::Build)); |
422 personal_data_manager_ = | 417 personal_data_manager_ = |
423 personal_data_manager_service->GetPersonalDataManager(); | 418 personal_data_manager_service->GetPersonalDataManager(); |
424 | 419 |
425 token_service_ = static_cast<TokenService*>( | 420 token_service_ = static_cast<TokenService*>( |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 std::vector<AutofillEntry> sync_entries; | 1313 std::vector<AutofillEntry> sync_entries; |
1319 std::vector<AutofillProfile> sync_profiles; | 1314 std::vector<AutofillProfile> sync_profiles; |
1320 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1315 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
1321 EXPECT_EQ(3U, sync_entries.size()); | 1316 EXPECT_EQ(3U, sync_entries.size()); |
1322 EXPECT_EQ(0U, sync_profiles.size()); | 1317 EXPECT_EQ(0U, sync_profiles.size()); |
1323 for (size_t i = 0; i < sync_entries.size(); i++) { | 1318 for (size_t i = 0; i < sync_entries.size(); i++) { |
1324 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1319 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
1325 << ", " << sync_entries[i].key().value(); | 1320 << ", " << sync_entries[i].key().value(); |
1326 } | 1321 } |
1327 } | 1322 } |
OLD | NEW |