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

Side by Side Diff: chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc

Issue 8274020: Revert 105404 - [Sync] Refactor non-frontend DTC to handle new API properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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
« no previous file with comments | « chrome/browser/webdata/autofill_profile_syncable_service.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/location.h" 5 #include "base/location.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/autofill/autofill_profile.h" 7 #include "chrome/browser/autofill/autofill_profile.h"
8 #include "chrome/browser/sync/internal_api/read_node_mock.h" 8 #include "chrome/browser/sync/internal_api/read_node_mock.h"
9 #include "chrome/browser/sync/internal_api/syncapi_mock.h" 9 #include "chrome/browser/sync/internal_api/syncapi_mock.h"
10 #include "chrome/browser/sync/syncable/syncable.h" 10 #include "chrome/browser/sync/syncable/syncable.h"
(...skipping 14 matching lines...) Expand all
25 class MockAutofillProfileSyncableService 25 class MockAutofillProfileSyncableService
26 : public AutofillProfileSyncableService { 26 : public AutofillProfileSyncableService {
27 public: 27 public:
28 MockAutofillProfileSyncableService() { 28 MockAutofillProfileSyncableService() {
29 } 29 }
30 virtual ~MockAutofillProfileSyncableService() {} 30 virtual ~MockAutofillProfileSyncableService() {}
31 31
32 MOCK_METHOD1(LoadAutofillData, bool(std::vector<AutofillProfile*>*)); 32 MOCK_METHOD1(LoadAutofillData, bool(std::vector<AutofillProfile*>*));
33 MOCK_METHOD1(SaveChangesToWebData, 33 MOCK_METHOD1(SaveChangesToWebData,
34 bool(const AutofillProfileSyncableService::DataBundle&)); 34 bool(const AutofillProfileSyncableService::DataBundle&));
35
36 // Helper for tests that do not need to setup service completely through the
37 // MergeDataAndStartSyncing().
38 class AutoSetSyncProcessor {
39 public:
40 AutoSetSyncProcessor(MockAutofillProfileSyncableService* service,
41 SyncChangeProcessor* sync_processor)
42 : service_(service) {
43 service->set_sync_processor(sync_processor);
44 }
45 ~AutoSetSyncProcessor() {
46 service_->set_sync_processor(NULL);
47 }
48 MockAutofillProfileSyncableService* service_;
49 };
35 }; 50 };
36 51
37 ACTION_P(CopyData, data) { 52 ACTION_P(CopyData, data) {
38 arg0->resize(data->size()); 53 arg0->resize(data->size());
39 std::copy(data->begin(), data->end(), arg0->begin()); 54 std::copy(data->begin(), data->end(), arg0->begin());
40 } 55 }
41 56
42 MATCHER_P(CheckSyncChanges, n_sync_changes_list, "") { 57 MATCHER_P(CheckSyncChanges, n_sync_changes_list, "") {
43 if (arg.size() != n_sync_changes_list.size()) 58 if (arg.size() != n_sync_changes_list.size())
44 return false; 59 return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 MOCK_METHOD2(ProcessSyncChanges, 105 MOCK_METHOD2(ProcessSyncChanges,
91 SyncError(const tracked_objects::Location&, 106 SyncError(const tracked_objects::Location&,
92 const SyncChangeList&)); 107 const SyncChangeList&));
93 }; 108 };
94 109
95 class AutofillProfileSyncableServiceTest : public testing::Test { 110 class AutofillProfileSyncableServiceTest : public testing::Test {
96 public: 111 public:
97 AutofillProfileSyncableServiceTest() 112 AutofillProfileSyncableServiceTest()
98 : db_thread_(BrowserThread::DB, &message_loop_) {} 113 : db_thread_(BrowserThread::DB, &message_loop_) {}
99 114
100 virtual void SetUp() OVERRIDE {
101 sync_processor_.reset(new MockSyncChangeProcessor);
102 }
103
104 virtual void TearDown() OVERRIDE {
105 // Each test passes ownership of the sync processor to the SyncableService.
106 // We don't release it immediately so we can verify the mock calls, so
107 // release it at teardown. Any test that doesn't call
108 // MergeDataAndStartSyncing or set_sync_processor must ensure the
109 // sync_processor_ gets properly reset.
110 ignore_result(sync_processor_.release());
111 }
112 protected: 115 protected:
113 MessageLoop message_loop_; 116 MessageLoop message_loop_;
114 BrowserThread db_thread_; 117 BrowserThread db_thread_;
115 MockAutofillProfileSyncableService autofill_syncable_service_; 118 MockAutofillProfileSyncableService autofill_syncable_service_;
116 scoped_ptr<MockSyncChangeProcessor> sync_processor_; 119 MockSyncChangeProcessor sync_processor_;
117 }; 120 };
118 121
119 TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) { 122 TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) {
120 std::vector<AutofillProfile *> profiles_from_web_db; 123 std::vector<AutofillProfile *> profiles_from_web_db;
121 std::string guid_present1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; 124 std::string guid_present1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44B";
122 std::string guid_present2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44C"; 125 std::string guid_present2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44C";
123 std::string guid_synced1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44D"; 126 std::string guid_synced1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44D";
124 std::string guid_synced2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44E"; 127 std::string guid_synced2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44E";
125 128
126 profiles_from_web_db.push_back(new AutofillProfile(guid_present1)); 129 profiles_from_web_db.push_back(new AutofillProfile(guid_present1));
(...skipping 24 matching lines...) Expand all
151 expected_bundle.profiles_to_add.push_back(&profile2); 154 expected_bundle.profiles_to_add.push_back(&profile2);
152 expected_bundle.profiles_to_update.push_back(&profile3); 155 expected_bundle.profiles_to_update.push_back(&profile3);
153 156
154 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) 157 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_))
155 .Times(1) 158 .Times(1)
156 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); 159 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true)));
157 EXPECT_CALL(autofill_syncable_service_, 160 EXPECT_CALL(autofill_syncable_service_,
158 SaveChangesToWebData(DataBundleCheck(expected_bundle))) 161 SaveChangesToWebData(DataBundleCheck(expected_bundle)))
159 .Times(1) 162 .Times(1)
160 .WillOnce(Return(true)); 163 .WillOnce(Return(true));
161 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 164 ON_CALL(sync_processor_, ProcessSyncChanges(_, _))
162 .WillByDefault(Return(SyncError())); 165 .WillByDefault(Return(SyncError()));
163 EXPECT_CALL(*sync_processor_, 166 EXPECT_CALL(sync_processor_,
164 ProcessSyncChanges(_, CheckSyncChanges(expected_change_list))) 167 ProcessSyncChanges(_, CheckSyncChanges(expected_change_list)))
165 .Times(1) 168 .Times(1)
166 .WillOnce(Return(SyncError())); 169 .WillOnce(Return(SyncError()));
167 170
168 // Takes ownership of sync_processor_.
169 autofill_syncable_service_.MergeDataAndStartSyncing( 171 autofill_syncable_service_.MergeDataAndStartSyncing(
170 syncable::AUTOFILL_PROFILE, data_list, sync_processor_.get()); 172 syncable::AUTOFILL_PROFILE, data_list, &sync_processor_);
171 autofill_syncable_service_.StopSyncing(syncable::AUTOFILL_PROFILE); 173 autofill_syncable_service_.StopSyncing(syncable::AUTOFILL_PROFILE);
172 } 174 }
173 175
174 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { 176 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) {
175 std::vector<AutofillProfile *> profiles_from_web_db; 177 std::vector<AutofillProfile *> profiles_from_web_db;
176 std::string guid_present1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; 178 std::string guid_present1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44B";
177 std::string guid_present2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44C"; 179 std::string guid_present2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44C";
178 180
179 profiles_from_web_db.push_back(new AutofillProfile(guid_present1)); 181 profiles_from_web_db.push_back(new AutofillProfile(guid_present1));
180 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John")); 182 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John"));
181 profiles_from_web_db.push_back(new AutofillProfile(guid_present2)); 183 profiles_from_web_db.push_back(new AutofillProfile(guid_present2));
182 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); 184 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
183 185
184 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) 186 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_))
185 .Times(1) 187 .Times(1)
186 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); 188 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true)));
187 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(_)) 189 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(_))
188 .Times(1) 190 .Times(1)
189 .WillOnce(Return(true)); 191 .WillOnce(Return(true));
190 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 192 ON_CALL(sync_processor_, ProcessSyncChanges(_, _))
191 .WillByDefault(Return(SyncError())); 193 .WillByDefault(Return(SyncError()));
192 EXPECT_CALL(*sync_processor_, 194 EXPECT_CALL(sync_processor_,
193 ProcessSyncChanges(_, Property(&SyncChangeList::size, Eq(2U)))) 195 ProcessSyncChanges(_, Property(&SyncChangeList::size, Eq(2U))))
194 .Times(1) 196 .Times(1)
195 .WillOnce(Return(SyncError())); 197 .WillOnce(Return(SyncError()));
196 198
197 SyncDataList data_list; 199 SyncDataList data_list;
198 // Takes ownership of sync_processor_.
199 autofill_syncable_service_.MergeDataAndStartSyncing( 200 autofill_syncable_service_.MergeDataAndStartSyncing(
200 syncable::AUTOFILL_PROFILE, data_list, sync_processor_.get()); 201 syncable::AUTOFILL_PROFILE, data_list, &sync_processor_);
201 202
202 SyncDataList data = 203 SyncDataList data =
203 autofill_syncable_service_.GetAllSyncData(syncable::AUTOFILL_PROFILE); 204 autofill_syncable_service_.GetAllSyncData(syncable::AUTOFILL_PROFILE);
204 205
205 EXPECT_EQ(2U, data.size()); 206 EXPECT_EQ(2U, data.size());
206 EXPECT_EQ(guid_present1, data.front().GetSpecifics() 207 EXPECT_EQ(guid_present1, data.front().GetSpecifics()
207 .GetExtension(sync_pb::autofill_profile).guid()); 208 .GetExtension(sync_pb::autofill_profile).guid());
208 EXPECT_EQ(guid_present2, data.back().GetSpecifics() 209 EXPECT_EQ(guid_present2, data.back().GetSpecifics()
209 .GetExtension(sync_pb::autofill_profile).guid()); 210 .GetExtension(sync_pb::autofill_profile).guid());
210 } 211 }
(...skipping 16 matching lines...) Expand all
227 228
228 AutofillProfileSyncableService::DataBundle expected_bundle; 229 AutofillProfileSyncableService::DataBundle expected_bundle;
229 expected_bundle.profiles_to_delete.push_back(guid_present); 230 expected_bundle.profiles_to_delete.push_back(guid_present);
230 expected_bundle.profiles_to_add.push_back(&profile); 231 expected_bundle.profiles_to_add.push_back(&profile);
231 232
232 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData( 233 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(
233 DataBundleCheck(expected_bundle))) 234 DataBundleCheck(expected_bundle)))
234 .Times(1) 235 .Times(1)
235 .WillOnce(Return(true)); 236 .WillOnce(Return(true));
236 237
237 autofill_syncable_service_.set_sync_processor(sync_processor_.get()); 238 MockAutofillProfileSyncableService::AutoSetSyncProcessor temp(
239 &autofill_syncable_service_, &sync_processor_);
238 SyncError error = autofill_syncable_service_.ProcessSyncChanges( 240 SyncError error = autofill_syncable_service_.ProcessSyncChanges(
239 FROM_HERE, change_list); 241 FROM_HERE, change_list);
240 242
241 EXPECT_FALSE(error.IsSet()); 243 EXPECT_FALSE(error.IsSet());
242 } 244 }
243 245
244 TEST_F(AutofillProfileSyncableServiceTest, ActOnChange) { 246 TEST_F(AutofillProfileSyncableServiceTest, ActOnChange) {
245 std::string guid1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; 247 std::string guid1 = "EDC609ED-7EEE-4F27-B00C-423242A9C44B";
246 std::string guid2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44C"; 248 std::string guid2 = "EDC609ED-7EEE-4F27-B00C-423242A9C44C";
247 249
248 AutofillProfile profile(guid1); 250 AutofillProfile profile(guid1);
249 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); 251 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
250 AutofillProfileChange change1(AutofillProfileChange::ADD, guid1, &profile); 252 AutofillProfileChange change1(AutofillProfileChange::ADD, guid1, &profile);
251 AutofillProfileChange change2(AutofillProfileChange::REMOVE, guid2, NULL); 253 AutofillProfileChange change2(AutofillProfileChange::REMOVE, guid2, NULL);
252 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 254 ON_CALL(sync_processor_, ProcessSyncChanges(_, _))
253 .WillByDefault(Return(SyncError(FROM_HERE, std::string("an error"), 255 .WillByDefault(Return(SyncError(FROM_HERE, std::string("an error"),
254 syncable::AUTOFILL_PROFILE))); 256 syncable::AUTOFILL_PROFILE)));
255 257
256 autofill_syncable_service_.set_sync_processor(sync_processor_.get()); 258 MockAutofillProfileSyncableService::AutoSetSyncProcessor temp(
259 &autofill_syncable_service_, &sync_processor_);
257 autofill_syncable_service_.ActOnChange(change1); 260 autofill_syncable_service_.ActOnChange(change1);
258 autofill_syncable_service_.ActOnChange(change2); 261 autofill_syncable_service_.ActOnChange(change2);
259 } 262 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/autofill_profile_syncable_service.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698