Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: chrome/browser/sync/profile_sync_service_autofill_unittest.cc

Issue 12476031: Refactor notifications of chrome/browser/webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 26 matching lines...) Expand all
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/autofill_web_data_service.h" 43 #include "chrome/browser/webdata/autofill_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_data_service_test_util.h"
46 #include "chrome/browser/webdata/web_database.h" 46 #include "chrome/browser/webdata/web_database.h"
47 #include "chrome/common/chrome_notification_types.h"
48 #include "components/autofill/browser/autofill_common_test.h" 47 #include "components/autofill/browser/autofill_common_test.h"
49 #include "components/autofill/browser/personal_data_manager.h" 48 #include "components/autofill/browser/personal_data_manager.h"
50 #include "content/public/browser/notification_source.h"
51 #include "content/public/test/test_browser_thread.h" 49 #include "content/public/test/test_browser_thread.h"
52 #include "google_apis/gaia/gaia_constants.h" 50 #include "google_apis/gaia/gaia_constants.h"
53 #include "sync/internal_api/public/base/model_type.h" 51 #include "sync/internal_api/public/base/model_type.h"
54 #include "sync/internal_api/public/read_node.h" 52 #include "sync/internal_api/public/read_node.h"
55 #include "sync/internal_api/public/read_transaction.h" 53 #include "sync/internal_api/public/read_transaction.h"
56 #include "sync/internal_api/public/write_node.h" 54 #include "sync/internal_api/public/write_node.h"
57 #include "sync/internal_api/public/write_transaction.h" 55 #include "sync/internal_api/public/write_transaction.h"
58 #include "sync/protocol/autofill_specifics.pb.h" 56 #include "sync/protocol/autofill_specifics.pb.h"
59 #include "sync/syncable/mutable_entry.h" 57 #include "sync/syncable/mutable_entry.h"
60 #include "sync/syncable/syncable_write_transaction.h" 58 #include "sync/syncable/syncable_write_transaction.h"
(...skipping 25 matching lines...) Expand all
86 using testing::ElementsAre; 84 using testing::ElementsAre;
87 using testing::SetArgumentPointee; 85 using testing::SetArgumentPointee;
88 using testing::Return; 86 using testing::Return;
89 87
90 namespace syncable { 88 namespace syncable {
91 class Id; 89 class Id;
92 } 90 }
93 91
94 class HistoryService; 92 class HistoryService;
95 93
94 namespace {
95
96 void RunAndSignal(const base::Closure& cb, WaitableEvent* event) {
97 cb.Run();
98 event->Signal();
99 }
100
101 } // namespace
102
96 class AutofillTableMock : public AutofillTable { 103 class AutofillTableMock : public AutofillTable {
97 public: 104 public:
98 AutofillTableMock() : AutofillTable() {} 105 AutofillTableMock() : AutofillTable() {}
99 MOCK_METHOD2(RemoveFormElement, 106 MOCK_METHOD2(RemoveFormElement,
100 bool(const string16& name, const string16& value)); // NOLINT 107 bool(const string16& name, const string16& value)); // NOLINT
101 MOCK_METHOD1(GetAllAutofillEntries, 108 MOCK_METHOD1(GetAllAutofillEntries,
102 bool(std::vector<AutofillEntry>* entries)); // NOLINT 109 bool(std::vector<AutofillEntry>* entries)); // NOLINT
103 MOCK_METHOD3(GetAutofillTimestamps, 110 MOCK_METHOD3(GetAutofillTimestamps,
104 bool(const string16& name, // NOLINT 111 bool(const string16& name, // NOLINT
105 const string16& value, 112 const string16& value,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 175
169 private: 176 private:
170 virtual ~TokenWebDataServiceFake() {} 177 virtual ~TokenWebDataServiceFake() {}
171 178
172 DISALLOW_COPY_AND_ASSIGN(TokenWebDataServiceFake); 179 DISALLOW_COPY_AND_ASSIGN(TokenWebDataServiceFake);
173 }; 180 };
174 181
175 class WebDataServiceFake : public AutofillWebDataService { 182 class WebDataServiceFake : public AutofillWebDataService {
176 public: 183 public:
177 WebDataServiceFake() 184 WebDataServiceFake()
178 : AutofillWebDataService( 185 : AutofillWebDataService(NULL,
179 NULL, WebDataServiceBase::ProfileErrorCallback()), 186 WebDataServiceBase::ProfileErrorCallback()),
180 web_database_(NULL), 187 web_database_(NULL),
188 autocomplete_syncable_service_(NULL),
189 autofill_profile_syncable_service_(NULL),
181 syncable_service_created_or_destroyed_(false, false) { 190 syncable_service_created_or_destroyed_(false, false) {
182 } 191 }
183 192
184 void SetDatabase(WebDatabase* web_database) { 193 void SetDatabase(WebDatabase* web_database) {
185 web_database_ = web_database; 194 web_database_ = web_database;
186 } 195 }
187 196
188 void StartSyncableService() { 197 void StartSyncableService() {
189 // The |autofill_profile_syncable_service_| must be constructed on the DB 198 // The |autofill_profile_syncable_service_| must be constructed on the DB
190 // thread. 199 // thread.
(...skipping 15 matching lines...) Expand all
206 virtual bool IsDatabaseLoaded() OVERRIDE { 215 virtual bool IsDatabaseLoaded() OVERRIDE {
207 return true; 216 return true;
208 } 217 }
209 218
210 virtual WebDatabase* GetDatabase() OVERRIDE { 219 virtual WebDatabase* GetDatabase() OVERRIDE {
211 return web_database_; 220 return web_database_;
212 } 221 }
213 222
214 virtual void ShutdownOnUIThread() OVERRIDE {} 223 virtual void ShutdownOnUIThread() OVERRIDE {}
215 224
225 void OnAutofillEntriesChanged(const AutofillChangeList& changes) {
226 WaitableEvent event(true, false);
227
228 base::Closure notify_cb =
229 base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged,
230 base::Unretained(autocomplete_syncable_service_),
231 changes);
232 BrowserThread::PostTask(
233 BrowserThread::DB,
234 FROM_HERE,
235 base::Bind(&RunAndSignal, notify_cb, &event));
236 event.Wait();
237 }
238
239 void OnAutofillProfileChanged(const AutofillProfileChange& changes) {
240 WaitableEvent event(true, false);
241
242 base::Closure notify_cb =
243 base::Bind(&AutocompleteSyncableService::AutofillProfileChanged,
244 base::Unretained(autofill_profile_syncable_service_),
245 changes);
246 BrowserThread::PostTask(
247 BrowserThread::DB,
248 FROM_HERE,
249 base::Bind(&RunAndSignal, notify_cb, &event));
250 event.Wait();
251 }
252
216 private: 253 private:
217 virtual ~WebDataServiceFake() {} 254 virtual ~WebDataServiceFake() {}
218 255
219 void CreateSyncableService() { 256 void CreateSyncableService() {
220 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 257 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
221 // These services are deleted in DestroySyncableService(). 258 // These services are deleted in DestroySyncableService().
222 AutocompleteSyncableService::CreateForWebDataService(this); 259 AutocompleteSyncableService::CreateForWebDataService(this);
223 AutofillProfileSyncableService::CreateForWebDataService(this); 260 AutofillProfileSyncableService::CreateForWebDataService(this);
261
262 autocomplete_syncable_service_ =
263 AutocompleteSyncableService::FromWebDataService(this);
264 autofill_profile_syncable_service_ =
265 AutofillProfileSyncableService::FromWebDataService(this);
266
224 syncable_service_created_or_destroyed_.Signal(); 267 syncable_service_created_or_destroyed_.Signal();
225 } 268 }
226 269
227 void DestroySyncableService() { 270 void DestroySyncableService() {
228 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); 271 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
229 WebDataServiceBase::ShutdownOnDBThread(); 272 WebDataServiceBase::ShutdownOnDBThread();
273 autocomplete_syncable_service_ = NULL;
274 autofill_profile_syncable_service_ = NULL;
230 syncable_service_created_or_destroyed_.Signal(); 275 syncable_service_created_or_destroyed_.Signal();
231 } 276 }
232 277
233 WebDatabase* web_database_; 278 WebDatabase* web_database_;
279 AutocompleteSyncableService* autocomplete_syncable_service_;
280 AutofillProfileSyncableService* autofill_profile_syncable_service_;
234 281
235 WaitableEvent syncable_service_created_or_destroyed_; 282 WaitableEvent syncable_service_created_or_destroyed_;
236 283
237 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFake); 284 DISALLOW_COPY_AND_ASSIGN(WebDataServiceFake);
238 }; 285 };
239 286
240 ProfileKeyedService* BuildMockWebDataServiceWrapper(Profile* profile) { 287 ProfileKeyedService* BuildMockWebDataServiceWrapper(Profile* profile) {
241 return new MockWebDataServiceWrapper( 288 return new MockWebDataServiceWrapper(
242 new TokenWebDataServiceFake(), 289 new TokenWebDataServiceFake(),
243 new WebDataServiceFake()); 290 new WebDataServiceFake());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 MOCK_METHOD0(LoadCreditCards, void()); 391 MOCK_METHOD0(LoadCreditCards, void());
345 MOCK_METHOD0(Refresh, void()); 392 MOCK_METHOD0(Refresh, void());
346 }; 393 };
347 394
348 class MockPersonalDataManagerService : public PersonalDataManagerService { 395 class MockPersonalDataManagerService : public PersonalDataManagerService {
349 public: 396 public:
350 static ProfileKeyedService* Build(Profile* profile) { 397 static ProfileKeyedService* Build(Profile* profile) {
351 return new MockPersonalDataManagerService(); 398 return new MockPersonalDataManagerService();
352 } 399 }
353 400
354 MockPersonalDataManagerService() {} 401 MockPersonalDataManagerService() {
402 personal_data_manager_.reset(new MockPersonalDataManager());
403 }
355 virtual ~MockPersonalDataManagerService() {} 404 virtual ~MockPersonalDataManagerService() {}
356 405
406 virtual void Shutdown() OVERRIDE {
407 personal_data_manager_.reset();
408 }
409
357 virtual MockPersonalDataManager* GetPersonalDataManager() OVERRIDE { 410 virtual MockPersonalDataManager* GetPersonalDataManager() OVERRIDE {
358 return &personal_data_manager_; 411 return personal_data_manager_.get();
359 } 412 }
360 413
361 private: 414 private:
362 MockPersonalDataManager personal_data_manager_; 415 scoped_ptr<MockPersonalDataManager> personal_data_manager_;
363 DISALLOW_COPY_AND_ASSIGN(MockPersonalDataManagerService); 416 DISALLOW_COPY_AND_ASSIGN(MockPersonalDataManagerService);
364 }; 417 };
365 418
366 template <class T> class AddAutofillHelper; 419 template <class T> class AddAutofillHelper;
367 420
368 class ProfileSyncServiceAutofillTest 421 class ProfileSyncServiceAutofillTest
369 : public AbstractProfileSyncServiceTest, 422 : public AbstractProfileSyncServiceTest,
370 public syncer::DataTypeDebugInfoListener { 423 public syncer::DataTypeDebugInfoListener {
371 public: 424 public:
372 // DataTypeDebugInfoListener implementation. 425 // DataTypeDebugInfoListener implementation.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 personal_data_manager_service->GetPersonalDataManager(); 473 personal_data_manager_service->GetPersonalDataManager();
421 474
422 token_service_ = static_cast<TokenService*>( 475 token_service_ = static_cast<TokenService*>(
423 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( 476 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
424 profile_.get(), BuildTokenService)); 477 profile_.get(), BuildTokenService));
425 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1); 478 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1);
426 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1); 479 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1);
427 480
428 personal_data_manager_->Init(profile_.get()); 481 personal_data_manager_->Init(profile_.get());
429 482
430 // Note: This must be called *after* the notification service is created.
431 web_data_service_->StartSyncableService(); 483 web_data_service_->StartSyncableService();
432 } 484 }
433 485
434 virtual void TearDown() OVERRIDE { 486 virtual void TearDown() OVERRIDE {
435 // Note: The tear down order is important. 487 // Note: The tear down order is important.
436 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory( 488 ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(
437 profile_.get(), NULL); 489 profile_.get(), NULL);
438 web_data_service_->ShutdownSyncableService(); 490 web_data_service_->ShutdownSyncableService();
439 profile_->ResetRequestContext(); 491 profile_->ResetRequestContext();
440 // To prevent a leak, fully release TestURLRequestContext to ensure its 492 // To prevent a leak, fully release TestURLRequestContext to ensure its
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 ASSERT_TRUE(create_root.success()); 1174 ASSERT_TRUE(create_root.success());
1123 1175
1124 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1)); 1176 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1));
1125 std::vector<base::Time> timestamps(added_entry.timestamps()); 1177 std::vector<base::Time> timestamps(added_entry.timestamps());
1126 1178
1127 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)). 1179 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).
1128 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true))); 1180 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true)));
1129 1181
1130 AutofillChangeList changes; 1182 AutofillChangeList changes;
1131 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); 1183 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key()));
1132 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( 1184
1133 db_thread_.DeprecatedGetThreadObject())); 1185 web_data_service_->OnAutofillEntriesChanged(changes);
1134 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1135 content::Source<AutofillWebDataService>(
1136 web_data_service_.get()),
1137 content::Details<AutofillChangeList>(&changes));
1138 1186
1139 std::vector<AutofillEntry> new_sync_entries; 1187 std::vector<AutofillEntry> new_sync_entries;
1140 std::vector<AutofillProfile> new_sync_profiles; 1188 std::vector<AutofillProfile> new_sync_profiles;
1141 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, 1189 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries,
1142 &new_sync_profiles)); 1190 &new_sync_profiles));
1143 ASSERT_EQ(1U, new_sync_entries.size()); 1191 ASSERT_EQ(1U, new_sync_entries.size());
1144 EXPECT_TRUE(added_entry == new_sync_entries[0]); 1192 EXPECT_TRUE(added_entry == new_sync_entries[0]);
1145 } 1193 }
1146 1194
1147 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { 1195 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) {
1148 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true)); 1196 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true));
1149 EXPECT_CALL(*personal_data_manager_, Refresh()); 1197 EXPECT_CALL(*personal_data_manager_, Refresh());
1150 SetIdleChangeProcessorExpectations(); 1198 SetIdleChangeProcessorExpectations();
1151 CreateRootHelper create_root(this, syncer::AUTOFILL_PROFILE); 1199 CreateRootHelper create_root(this, syncer::AUTOFILL_PROFILE);
1152 StartSyncService(create_root.callback(), false, syncer::AUTOFILL_PROFILE); 1200 StartSyncService(create_root.callback(), false, syncer::AUTOFILL_PROFILE);
1153 ASSERT_TRUE(create_root.success()); 1201 ASSERT_TRUE(create_root.success());
1154 1202
1155 AutofillProfile added_profile; 1203 AutofillProfile added_profile;
1156 autofill_test::SetProfileInfoWithGuid(&added_profile, 1204 autofill_test::SetProfileInfoWithGuid(&added_profile,
1157 "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", "Alicia", "Saenz", 1205 "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", "Alicia", "Saenz",
1158 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", 1206 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
1159 "32801", "US", "19482937549"); 1207 "32801", "US", "19482937549");
1160 1208
1161 AutofillProfileChange change(AutofillProfileChange::ADD, 1209 AutofillProfileChange change(
1162 added_profile.guid(), &added_profile); 1210 AutofillProfileChange::ADD, added_profile.guid(), &added_profile);
1163 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( 1211 web_data_service_->OnAutofillProfileChanged(change);
1164 db_thread_.DeprecatedGetThreadObject()));
1165 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
1166 content::Source<AutofillWebDataService>(
1167 web_data_service_.get()),
1168 content::Details<AutofillProfileChange>(&change));
1169 1212
1170 std::vector<AutofillProfile> new_sync_profiles; 1213 std::vector<AutofillProfile> new_sync_profiles;
1171 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 1214 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
1172 &new_sync_profiles)); 1215 &new_sync_profiles));
1173 ASSERT_EQ(1U, new_sync_profiles.size()); 1216 ASSERT_EQ(1U, new_sync_profiles.size());
1174 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0])); 1217 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0]));
1175 } 1218 }
1176 1219
1177 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) { 1220 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) {
1178 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); 1221 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1));
1179 std::vector<AutofillEntry> original_entries; 1222 std::vector<AutofillEntry> original_entries;
1180 original_entries.push_back(original_entry); 1223 original_entries.push_back(original_entry);
1181 1224
1182 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 1225 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
1183 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); 1226 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true)));
1184 EXPECT_CALL(*personal_data_manager_, Refresh()); 1227 EXPECT_CALL(*personal_data_manager_, Refresh());
1185 CreateRootHelper create_root(this, syncer::AUTOFILL); 1228 CreateRootHelper create_root(this, syncer::AUTOFILL);
1186 StartSyncService(create_root.callback(), false, syncer::AUTOFILL); 1229 StartSyncService(create_root.callback(), false, syncer::AUTOFILL);
1187 ASSERT_TRUE(create_root.success()); 1230 ASSERT_TRUE(create_root.success());
1188 1231
1189 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2)); 1232 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2));
1190 std::vector<base::Time> timestamps(updated_entry.timestamps()); 1233 std::vector<base::Time> timestamps(updated_entry.timestamps());
1191 1234
1192 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)). 1235 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _)).
1193 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true))); 1236 WillOnce(DoAll(SetArgumentPointee<2>(timestamps), Return(true)));
1194 1237
1195 AutofillChangeList changes; 1238 AutofillChangeList changes;
1196 changes.push_back(AutofillChange(AutofillChange::UPDATE, 1239 changes.push_back(AutofillChange(AutofillChange::UPDATE,
1197 updated_entry.key())); 1240 updated_entry.key()));
1198 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( 1241 web_data_service_->OnAutofillEntriesChanged(changes);
1199 db_thread_.DeprecatedGetThreadObject()));
1200 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1201 content::Source<AutofillWebDataService>(
1202 web_data_service_.get()),
1203 content::Details<AutofillChangeList>(&changes));
1204 1242
1205 std::vector<AutofillEntry> new_sync_entries; 1243 std::vector<AutofillEntry> new_sync_entries;
1206 std::vector<AutofillProfile> new_sync_profiles; 1244 std::vector<AutofillProfile> new_sync_profiles;
1207 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, 1245 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries,
1208 &new_sync_profiles)); 1246 &new_sync_profiles));
1209 ASSERT_EQ(1U, new_sync_entries.size()); 1247 ASSERT_EQ(1U, new_sync_entries.size());
1210 EXPECT_TRUE(updated_entry == new_sync_entries[0]); 1248 EXPECT_TRUE(updated_entry == new_sync_entries[0]);
1211 } 1249 }
1212 1250
1213 1251
1214 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { 1252 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) {
1215 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); 1253 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1));
1216 std::vector<AutofillEntry> original_entries; 1254 std::vector<AutofillEntry> original_entries;
1217 original_entries.push_back(original_entry); 1255 original_entries.push_back(original_entry);
1218 1256
1219 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). 1257 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).
1220 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); 1258 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true)));
1221 EXPECT_CALL(*personal_data_manager_, Refresh()); 1259 EXPECT_CALL(*personal_data_manager_, Refresh());
1222 CreateRootHelper create_root(this, syncer::AUTOFILL); 1260 CreateRootHelper create_root(this, syncer::AUTOFILL);
1223 StartSyncService(create_root.callback(), false, syncer::AUTOFILL); 1261 StartSyncService(create_root.callback(), false, syncer::AUTOFILL);
1224 ASSERT_TRUE(create_root.success()); 1262 ASSERT_TRUE(create_root.success());
1225 1263
1226 AutofillChangeList changes; 1264 AutofillChangeList changes;
1227 changes.push_back(AutofillChange(AutofillChange::REMOVE, 1265 changes.push_back(AutofillChange(AutofillChange::REMOVE,
1228 original_entry.key())); 1266 original_entry.key()));
1229 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( 1267 web_data_service_->OnAutofillEntriesChanged(changes);
1230 db_thread_.DeprecatedGetThreadObject()));
1231 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1232 content::Source<AutofillWebDataService>(
1233 web_data_service_.get()),
1234 content::Details<AutofillChangeList>(&changes));
1235 1268
1236 std::vector<AutofillEntry> new_sync_entries; 1269 std::vector<AutofillEntry> new_sync_entries;
1237 std::vector<AutofillProfile> new_sync_profiles; 1270 std::vector<AutofillProfile> new_sync_profiles;
1238 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, 1271 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries,
1239 &new_sync_profiles)); 1272 &new_sync_profiles));
1240 ASSERT_EQ(0U, new_sync_entries.size()); 1273 ASSERT_EQ(0U, new_sync_entries.size());
1241 } 1274 }
1242 1275
1243 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) { 1276 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) {
1244 AutofillProfile sync_profile; 1277 AutofillProfile sync_profile;
(...skipping 12 matching lines...) Expand all
1257 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)). 1290 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).
1258 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); 1291 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true)));
1259 1292
1260 std::vector<AutofillProfile> sync_profiles; 1293 std::vector<AutofillProfile> sync_profiles;
1261 sync_profiles.push_back(sync_profile); 1294 sync_profiles.push_back(sync_profile);
1262 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); 1295 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles);
1263 EXPECT_CALL(*personal_data_manager_, Refresh()); 1296 EXPECT_CALL(*personal_data_manager_, Refresh());
1264 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL_PROFILE); 1297 StartSyncService(add_autofill.callback(), false, syncer::AUTOFILL_PROFILE);
1265 ASSERT_TRUE(add_autofill.success()); 1298 ASSERT_TRUE(add_autofill.success());
1266 1299
1267 AutofillProfileChange change(AutofillProfileChange::REMOVE, 1300 AutofillProfileChange change(
1268 sync_profile.guid(), NULL); 1301 AutofillProfileChange::REMOVE, sync_profile.guid(), NULL);
1269 scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( 1302 web_data_service_->OnAutofillProfileChanged(change);
1270 db_thread_.DeprecatedGetThreadObject()));
1271 notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
1272 content::Source<AutofillWebDataService>(
1273 web_data_service_.get()),
1274 content::Details<AutofillProfileChange>(&change));
1275 1303
1276 std::vector<AutofillProfile> new_sync_profiles; 1304 std::vector<AutofillProfile> new_sync_profiles;
1277 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( 1305 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(
1278 &new_sync_profiles)); 1306 &new_sync_profiles));
1279 ASSERT_EQ(0U, new_sync_profiles.size()); 1307 ASSERT_EQ(0U, new_sync_profiles.size());
1280 } 1308 }
1281 1309
1282 // http://crbug.com/57884 1310 // http://crbug.com/57884
1283 TEST_F(ProfileSyncServiceAutofillTest, DISABLED_ServerChangeRace) { 1311 TEST_F(ProfileSyncServiceAutofillTest, DISABLED_ServerChangeRace) {
1284 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via 1312 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 std::vector<AutofillEntry> sync_entries; 1348 std::vector<AutofillEntry> sync_entries;
1321 std::vector<AutofillProfile> sync_profiles; 1349 std::vector<AutofillProfile> sync_profiles;
1322 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1350 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1323 EXPECT_EQ(3U, sync_entries.size()); 1351 EXPECT_EQ(3U, sync_entries.size());
1324 EXPECT_EQ(0U, sync_profiles.size()); 1352 EXPECT_EQ(0U, sync_profiles.size());
1325 for (size_t i = 0; i < sync_entries.size(); i++) { 1353 for (size_t i = 0; i < sync_entries.size(); i++) {
1326 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1354 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1327 << ", " << sync_entries[i].key().value(); 1355 << ", " << sync_entries[i].key().value();
1328 } 1356 }
1329 } 1357 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698