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

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

Issue 10905033: contacts: Add ContactMap class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apply review feedback Created 8 years, 3 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 store_->Init(); 138 store_->Init();
139 ContactPointers loaded_contacts; 139 ContactPointers loaded_contacts;
140 store_->AppendContacts(&loaded_contacts); 140 store_->AppendContacts(&loaded_contacts);
141 EXPECT_EQ(VarContactsToString(2, contact1.get(), contact2.get()), 141 EXPECT_EQ(VarContactsToString(2, contact1.get(), contact2.get()),
142 ContactsToString(loaded_contacts)); 142 ContactsToString(loaded_contacts));
143 EXPECT_TRUE(test_api_->update_scheduled()); 143 EXPECT_TRUE(test_api_->update_scheduled());
144 EXPECT_EQ(1, observer_.num_updates()); 144 EXPECT_EQ(1, observer_.num_updates());
145 145
146 // The contacts should've been saved to the database, too. 146 // The contacts should've been saved to the database, too.
147 EXPECT_EQ(VarContactsToString(2, contact1.get(), contact2.get()), 147 EXPECT_EQ(VarContactsToString(2, contact1.get(), contact2.get()),
148 ContactsToString(db_->contacts())); 148 ContactMapToString(db_->contacts()));
149 } 149 }
150 150
151 TEST_F(GoogleContactStoreTest, UpdateFromGData) { 151 TEST_F(GoogleContactStoreTest, UpdateFromGData) {
152 scoped_ptr<Contact> contact1(new Contact); 152 scoped_ptr<Contact> contact1(new Contact);
153 InitContact("contact1", "1", false, contact1.get()); 153 InitContact("contact1", "1", false, contact1.get());
154 scoped_ptr<Contact> contact2(new Contact); 154 scoped_ptr<Contact> contact2(new Contact);
155 InitContact("contact2", "2", false, contact2.get()); 155 InitContact("contact2", "2", false, contact2.get());
156 scoped_ptr<Contact> contact3(new Contact); 156 scoped_ptr<Contact> contact3(new Contact);
157 InitContact("contact3", "3", false, contact3.get()); 157 InitContact("contact3", "3", false, contact3.get());
158 158
(...skipping 21 matching lines...) Expand all
180 ContactPointers loaded_contacts; 180 ContactPointers loaded_contacts;
181 store_->AppendContacts(&loaded_contacts); 181 store_->AppendContacts(&loaded_contacts);
182 EXPECT_EQ(VarContactsToString( 182 EXPECT_EQ(VarContactsToString(
183 3, contact1.get(), contact2.get(), contact3.get()), 183 3, contact1.get(), contact2.get(), contact3.get()),
184 ContactsToString(loaded_contacts)); 184 ContactsToString(loaded_contacts));
185 EXPECT_EQ(2, observer_.num_updates()); 185 EXPECT_EQ(2, observer_.num_updates());
186 186
187 // All three contacts should've been saved to the database. 187 // All three contacts should've been saved to the database.
188 EXPECT_EQ(VarContactsToString( 188 EXPECT_EQ(VarContactsToString(
189 3, contact1.get(), contact2.get(), contact3.get()), 189 3, contact1.get(), contact2.get(), contact3.get()),
190 ContactsToString(db_->contacts())); 190 ContactMapToString(db_->contacts()));
191 EXPECT_EQ(3, db_->num_saved_contacts()); 191 EXPECT_EQ(3, db_->num_saved_contacts());
192 EXPECT_TRUE(test_api_->update_scheduled()); 192 EXPECT_TRUE(test_api_->update_scheduled());
193 } 193 }
194 194
195 TEST_F(GoogleContactStoreTest, FetchUpdatedContacts) { 195 TEST_F(GoogleContactStoreTest, FetchUpdatedContacts) {
196 scoped_ptr<Contact> contact1(new Contact); 196 scoped_ptr<Contact> contact1(new Contact);
197 InitContact("contact1", "1", false, contact1.get()); 197 InitContact("contact1", "1", false, contact1.get());
198 scoped_ptr<Contact> contact2(new Contact); 198 scoped_ptr<Contact> contact2(new Contact);
199 InitContact("contact2", "2", false, contact2.get()); 199 InitContact("contact2", "2", false, contact2.get());
200 scoped_ptr<Contact> contact3(new Contact); 200 scoped_ptr<Contact> contact3(new Contact);
201 InitContact("contact3", "3", false, contact3.get()); 201 InitContact("contact3", "3", false, contact3.get());
202 202
203 ContactPointers kAllContacts; 203 ContactPointers kAllContacts;
204 kAllContacts.push_back(contact1.get()); 204 kAllContacts.push_back(contact1.get());
205 kAllContacts.push_back(contact2.get()); 205 kAllContacts.push_back(contact2.get());
206 kAllContacts.push_back(contact3.get()); 206 kAllContacts.push_back(contact3.get());
207 207
208 // Tell the GData service to return all three contacts in response to a full 208 // Tell the GData service to return all three contacts in response to a full
209 // update. 209 // update.
210 ContactPointers gdata_contacts(kAllContacts); 210 ContactPointers gdata_contacts(kAllContacts);
211 gdata_service_->SetContacts(gdata_contacts, base::Time()); 211 gdata_service_->SetContacts(gdata_contacts, base::Time());
212 212
213 // All the contacts should be loaded and saved to the database. 213 // All the contacts should be loaded and saved to the database.
214 store_->Init(); 214 store_->Init();
215 ContactPointers loaded_contacts; 215 ContactPointers loaded_contacts;
216 store_->AppendContacts(&loaded_contacts); 216 store_->AppendContacts(&loaded_contacts);
217 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(loaded_contacts)); 217 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(loaded_contacts));
218 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(db_->contacts())); 218 EXPECT_EQ(ContactsToString(kAllContacts),
219 ContactMapToString(db_->contacts()));
219 EXPECT_EQ(static_cast<int>(kAllContacts.size()), db_->num_saved_contacts()); 220 EXPECT_EQ(static_cast<int>(kAllContacts.size()), db_->num_saved_contacts());
220 EXPECT_TRUE(test_api_->update_scheduled()); 221 EXPECT_TRUE(test_api_->update_scheduled());
221 EXPECT_EQ(1, observer_.num_updates()); 222 EXPECT_EQ(1, observer_.num_updates());
222 observer_.reset_stats(); 223 observer_.reset_stats();
223 224
224 // Update the third contact. 225 // Update the third contact.
225 contact3->set_full_name("new full name"); 226 contact3->set_full_name("new full name");
226 base::Time old_contact3_update_time = 227 base::Time old_contact3_update_time =
227 base::Time::FromInternalValue(contact3->update_time()); 228 base::Time::FromInternalValue(contact3->update_time());
228 contact3->set_update_time( 229 contact3->set_update_time(
229 (old_contact3_update_time + 230 (old_contact3_update_time +
230 base::TimeDelta::FromSeconds(10)).ToInternalValue()); 231 base::TimeDelta::FromSeconds(10)).ToInternalValue());
231 gdata_contacts.clear(); 232 gdata_contacts.clear();
232 gdata_contacts.push_back(contact3.get()); 233 gdata_contacts.push_back(contact3.get());
233 gdata_service_->SetContacts( 234 gdata_service_->SetContacts(
234 gdata_contacts, 235 gdata_contacts,
235 old_contact3_update_time + base::TimeDelta::FromMilliseconds(1)); 236 old_contact3_update_time + base::TimeDelta::FromMilliseconds(1));
236 237
237 // Check that the updated contact is loaded (i.e. the store passed the 238 // Check that the updated contact is loaded (i.e. the store passed the
238 // correct minimum update time to the service) and saved back to the database. 239 // correct minimum update time to the service) and saved back to the database.
239 db_->reset_stats(); 240 db_->reset_stats();
240 test_api_->DoUpdate(); 241 test_api_->DoUpdate();
241 loaded_contacts.clear(); 242 loaded_contacts.clear();
242 store_->AppendContacts(&loaded_contacts); 243 store_->AppendContacts(&loaded_contacts);
243 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(loaded_contacts)); 244 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(loaded_contacts));
244 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(db_->contacts())); 245 EXPECT_EQ(ContactsToString(kAllContacts),
246 ContactMapToString(db_->contacts()));
245 EXPECT_EQ(1, db_->num_saved_contacts()); 247 EXPECT_EQ(1, db_->num_saved_contacts());
246 EXPECT_TRUE(test_api_->update_scheduled()); 248 EXPECT_TRUE(test_api_->update_scheduled());
247 EXPECT_EQ(1, observer_.num_updates()); 249 EXPECT_EQ(1, observer_.num_updates());
248 observer_.reset_stats(); 250 observer_.reset_stats();
249 251
250 // The next update should be based on the third contact's new update time. 252 // The next update should be based on the third contact's new update time.
251 contact3->set_full_name("yet another full name"); 253 contact3->set_full_name("yet another full name");
252 gdata_service_->SetContacts( 254 gdata_service_->SetContacts(
253 gdata_contacts, 255 gdata_contacts,
254 base::Time::FromInternalValue(contact3->update_time()) + 256 base::Time::FromInternalValue(contact3->update_time()) +
255 base::TimeDelta::FromMilliseconds(1)); 257 base::TimeDelta::FromMilliseconds(1));
256 258
257 db_->reset_stats(); 259 db_->reset_stats();
258 test_api_->DoUpdate(); 260 test_api_->DoUpdate();
259 loaded_contacts.clear(); 261 loaded_contacts.clear();
260 store_->AppendContacts(&loaded_contacts); 262 store_->AppendContacts(&loaded_contacts);
261 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(loaded_contacts)); 263 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(loaded_contacts));
262 EXPECT_EQ(ContactsToString(kAllContacts), ContactsToString(db_->contacts())); 264 EXPECT_EQ(ContactsToString(kAllContacts),
265 ContactMapToString(db_->contacts()));
263 EXPECT_EQ(1, db_->num_saved_contacts()); 266 EXPECT_EQ(1, db_->num_saved_contacts());
264 EXPECT_TRUE(test_api_->update_scheduled()); 267 EXPECT_TRUE(test_api_->update_scheduled());
265 EXPECT_EQ(1, observer_.num_updates()); 268 EXPECT_EQ(1, observer_.num_updates());
266 } 269 }
267 270
268 TEST_F(GoogleContactStoreTest, DontReturnDeletedContacts) { 271 TEST_F(GoogleContactStoreTest, DontReturnDeletedContacts) {
269 // Tell GData to return a single deleted contact. 272 // Tell GData to return a single deleted contact.
270 const std::string kContactId = "contact"; 273 const std::string kContactId = "contact";
271 scoped_ptr<Contact> contact(new Contact); 274 scoped_ptr<Contact> contact(new Contact);
272 InitContact(kContactId, "1", true, contact.get()); 275 InitContact(kContactId, "1", true, contact.get());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 EXPECT_EQ(0, gdata_service_->num_download_requests()); 409 EXPECT_EQ(0, gdata_service_->num_download_requests());
407 410
408 // When we're back online, the update should happen. 411 // When we're back online, the update should happen.
409 gdata_service_->reset_stats(); 412 gdata_service_->reset_stats();
410 test_api_->NotifyAboutNetworkStateChange(true); 413 test_api_->NotifyAboutNetworkStateChange(true);
411 EXPECT_EQ(1, gdata_service_->num_download_requests()); 414 EXPECT_EQ(1, gdata_service_->num_download_requests());
412 } 415 }
413 416
414 } // namespace test 417 } // namespace test
415 } // namespace contacts 418 } // namespace contacts
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698