OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/gdata/fake_gdata_contacts_service.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/time.h" |
| 10 #include "chrome/browser/chromeos/contacts/contact.h" |
| 11 #include "chrome/browser/chromeos/contacts/contact_test_util.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 14 |
| 15 using content::BrowserThread; |
| 16 |
| 17 namespace gdata { |
| 18 |
| 19 FakeGDataContactsService::FakeGDataContactsService() |
| 20 : download_should_succeed_(true) { |
| 21 } |
| 22 |
| 23 FakeGDataContactsService::~FakeGDataContactsService() { |
| 24 } |
| 25 |
| 26 void FakeGDataContactsService::SetContacts( |
| 27 const contacts::ContactPointers& contacts, |
| 28 const base::Time& expected_min_update_time) { |
| 29 contacts::test::CopyContacts(contacts, &contacts_); |
| 30 expected_min_update_time_ = expected_min_update_time; |
| 31 } |
| 32 |
| 33 void FakeGDataContactsService::Initialize() { |
| 34 } |
| 35 |
| 36 void FakeGDataContactsService::DownloadContacts( |
| 37 SuccessCallback success_callback, |
| 38 FailureCallback failure_callback, |
| 39 const base::Time& min_update_time) { |
| 40 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 41 |
| 42 if (!download_should_succeed_) { |
| 43 failure_callback.Run(); |
| 44 return; |
| 45 } |
| 46 |
| 47 if (min_update_time != expected_min_update_time_) { |
| 48 LOG(ERROR) << "Actual minimum update time (" |
| 49 << util::FormatTimeAsString(min_update_time) << ") " |
| 50 << "differed from expected (" |
| 51 << util::FormatTimeAsString(expected_min_update_time_) |
| 52 << "); not returning any contacts"; |
| 53 failure_callback.Run(); |
| 54 return; |
| 55 } |
| 56 |
| 57 scoped_ptr<ScopedVector<contacts::Contact> > contacts( |
| 58 new ScopedVector<contacts::Contact>()); |
| 59 contacts::test::CopyContacts(contacts_, contacts.get()); |
| 60 success_callback.Run(contacts.Pass()); |
| 61 } |
| 62 |
| 63 } // namespace contacts |
OLD | NEW |