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

Side by Side Diff: chrome/browser/chromeos/contacts/google_contact_store_unittest.cc

Issue 10850033: contacts: Add ContactStoreFactory and FakeContactStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix GoogleContactStore db-saving bug and FakeContactDatabase partial-update bug and apply review fe… Created 8 years, 4 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 (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 "chrome/browser/chromeos/contacts/google_contact_store.h" 5 #include "chrome/browser/chromeos/contacts/google_contact_store.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 store_->AppendContacts(&loaded_contacts); 177 store_->AppendContacts(&loaded_contacts);
178 EXPECT_EQ(VarContactsToString( 178 EXPECT_EQ(VarContactsToString(
179 3, contact1.get(), contact2.get(), contact3.get()), 179 3, contact1.get(), contact2.get(), contact3.get()),
180 ContactsToString(loaded_contacts)); 180 ContactsToString(loaded_contacts));
181 EXPECT_EQ(2, observer_.num_updates()); 181 EXPECT_EQ(2, observer_.num_updates());
182 182
183 // All three contacts should've been saved to the database. 183 // All three contacts should've been saved to the database.
184 EXPECT_EQ(VarContactsToString( 184 EXPECT_EQ(VarContactsToString(
185 3, contact1.get(), contact2.get(), contact3.get()), 185 3, contact1.get(), contact2.get(), contact3.get()),
186 ContactsToString(db_->contacts())); 186 ContactsToString(db_->contacts()));
187 EXPECT_EQ(3, db_->num_saved_contacts());
187 EXPECT_TRUE(test_api_->update_scheduled()); 188 EXPECT_TRUE(test_api_->update_scheduled());
188 } 189 }
189 190
190 TEST_F(GoogleContactStoreTest, FetchUpdatedContacts) { 191 TEST_F(GoogleContactStoreTest, FetchUpdatedContacts) {
191 scoped_ptr<Contact> contact1(new Contact); 192 scoped_ptr<Contact> contact1(new Contact);
192 InitContact("provider1", "1", false, contact1.get()); 193 InitContact("provider1", "1", false, contact1.get());
193 scoped_ptr<Contact> contact2(new Contact); 194 scoped_ptr<Contact> contact2(new Contact);
194 InitContact("provider2", "2", false, contact2.get()); 195 InitContact("provider2", "2", false, contact2.get());
195 scoped_ptr<Contact> contact3(new Contact); 196 scoped_ptr<Contact> contact3(new Contact);
196 InitContact("provider3", "3", false, contact3.get()); 197 InitContact("provider3", "3", false, contact3.get());
197 198
199 ContactPointers kAllContacts;
200 kAllContacts.push_back(contact1.get());
201 kAllContacts.push_back(contact2.get());
202 kAllContacts.push_back(contact3.get());
203
198 // Tell the GData service to return all three contacts in response to a full 204 // Tell the GData service to return all three contacts in response to a full
199 // update. 205 // update.
200 ContactPointers gdata_contacts; 206 ContactPointers gdata_contacts(kAllContacts);
201 gdata_contacts.push_back(contact1.get());
202 gdata_contacts.push_back(contact2.get());
203 gdata_contacts.push_back(contact3.get());
204 gdata_service_->SetContacts(gdata_contacts, base::Time()); 207 gdata_service_->SetContacts(gdata_contacts, base::Time());
205 208
209 // All the contacts should be loaded and saved to the database.
206 store_->Init(); 210 store_->Init();
207 ContactPointers loaded_contacts; 211 ContactPointers loaded_contacts;
208 store_->AppendContacts(&loaded_contacts); 212 store_->AppendContacts(&loaded_contacts);
209 EXPECT_EQ(ContactsToString(gdata_contacts), 213 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(loaded_contacts));
210 ContactsToString(loaded_contacts)); 214 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(db_->contacts()));
211 EXPECT_EQ(ContactsToString(gdata_contacts), 215 EXPECT_EQ(static_cast<int>(kAllContacts.size()), db_->num_saved_contacts());
212 ContactsToString(db_->contacts()));
213 EXPECT_TRUE(test_api_->update_scheduled()); 216 EXPECT_TRUE(test_api_->update_scheduled());
214 EXPECT_EQ(1, observer_.num_updates()); 217 EXPECT_EQ(1, observer_.num_updates());
215 observer_.reset_stats(); 218 observer_.reset_stats();
216 219
217 // Update the third contact. 220 // Update the third contact.
218 contact3->set_full_name("new full name"); 221 contact3->set_full_name("new full name");
219 base::Time old_contact3_update_time = 222 base::Time old_contact3_update_time =
220 base::Time::FromInternalValue(contact3->update_time()); 223 base::Time::FromInternalValue(contact3->update_time());
221 contact3->set_update_time( 224 contact3->set_update_time(
222 (old_contact3_update_time + 225 (old_contact3_update_time +
223 base::TimeDelta::FromSeconds(10)).ToInternalValue()); 226 base::TimeDelta::FromSeconds(10)).ToInternalValue());
227 gdata_contacts.clear();
228 gdata_contacts.push_back(contact3.get());
224 gdata_service_->SetContacts( 229 gdata_service_->SetContacts(
225 gdata_contacts, 230 gdata_contacts,
226 old_contact3_update_time + base::TimeDelta::FromMilliseconds(1)); 231 old_contact3_update_time + base::TimeDelta::FromMilliseconds(1));
227 232
228 // Check that the updated contact is loaded (i.e. the store passed the 233 // Check that the updated contact is loaded (i.e. the store passed the
229 // correct minimum update time to the service). 234 // correct minimum update time to the service) and saved back to the database.
235 db_->reset_stats();
230 test_api_->DoUpdate(); 236 test_api_->DoUpdate();
231 loaded_contacts.clear(); 237 loaded_contacts.clear();
232 store_->AppendContacts(&loaded_contacts); 238 store_->AppendContacts(&loaded_contacts);
233 EXPECT_EQ(ContactsToString(gdata_contacts), 239 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(loaded_contacts));
234 ContactsToString(loaded_contacts)); 240 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(db_->contacts()));
235 EXPECT_EQ(ContactsToString(gdata_contacts), 241 EXPECT_EQ(1, db_->num_saved_contacts());
236 ContactsToString(db_->contacts()));
237 EXPECT_TRUE(test_api_->update_scheduled()); 242 EXPECT_TRUE(test_api_->update_scheduled());
238 EXPECT_EQ(1, observer_.num_updates()); 243 EXPECT_EQ(1, observer_.num_updates());
239 observer_.reset_stats(); 244 observer_.reset_stats();
240 245
241 // The next update should be based on the third contact's new update time. 246 // The next update should be based on the third contact's new update time.
242 contact3->set_full_name("yet another full name"); 247 contact3->set_full_name("yet another full name");
243 gdata_service_->SetContacts( 248 gdata_service_->SetContacts(
244 gdata_contacts, 249 gdata_contacts,
245 base::Time::FromInternalValue(contact3->update_time()) + 250 base::Time::FromInternalValue(contact3->update_time()) +
246 base::TimeDelta::FromMilliseconds(1)); 251 base::TimeDelta::FromMilliseconds(1));
252
253 db_->reset_stats();
247 test_api_->DoUpdate(); 254 test_api_->DoUpdate();
248 loaded_contacts.clear(); 255 loaded_contacts.clear();
249 store_->AppendContacts(&loaded_contacts); 256 store_->AppendContacts(&loaded_contacts);
250 EXPECT_EQ(ContactsToString(gdata_contacts), 257 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(loaded_contacts));
251 ContactsToString(loaded_contacts)); 258 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(db_->contacts()));
252 EXPECT_EQ(ContactsToString(gdata_contacts), 259 EXPECT_EQ(1, db_->num_saved_contacts());
253 ContactsToString(db_->contacts()));
254 EXPECT_TRUE(test_api_->update_scheduled()); 260 EXPECT_TRUE(test_api_->update_scheduled());
255 EXPECT_EQ(1, observer_.num_updates()); 261 EXPECT_EQ(1, observer_.num_updates());
256 } 262 }
257 263
258 TEST_F(GoogleContactStoreTest, DontReturnDeletedContacts) { 264 TEST_F(GoogleContactStoreTest, DontReturnDeletedContacts) {
259 // Tell GData to return a single deleted contact. 265 // Tell GData to return a single deleted contact.
260 const std::string kProviderId = "provider"; 266 const std::string kProviderId = "provider";
261 scoped_ptr<Contact> contact(new Contact); 267 scoped_ptr<Contact> contact(new Contact);
262 InitContact(kProviderId, "1", true, contact.get()); 268 InitContact(kProviderId, "1", true, contact.get());
263 ContactPointers gdata_contacts; 269 ContactPointers gdata_contacts;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 store_->Init(); 372 store_->Init();
367 ContactPointers loaded_contacts; 373 ContactPointers loaded_contacts;
368 store_->AppendContacts(&loaded_contacts); 374 store_->AppendContacts(&loaded_contacts);
369 EXPECT_EQ(ContactsToString(gdata_contacts), 375 EXPECT_EQ(ContactsToString(gdata_contacts),
370 ContactsToString(loaded_contacts)); 376 ContactsToString(loaded_contacts));
371 EXPECT_TRUE(test_api_->update_scheduled()); 377 EXPECT_TRUE(test_api_->update_scheduled());
372 } 378 }
373 379
374 } // namespace test 380 } // namespace test
375 } // namespace contacts 381 } // namespace contacts
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698