| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_STUB_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_STUB_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_STUB_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_STUB_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/chromeos/gdata/gdata_contacts_service.h" | 8 #include "chrome/browser/chromeos/gdata/gdata_contacts_service.h" |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 | 13 |
| 14 namespace contacts { | 14 namespace contacts { |
| 15 typedef std::vector<const contacts::Contact*> ContactPointers; | 15 typedef std::vector<const contacts::Contact*> ContactPointers; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace gdata { | 18 namespace gdata { |
| 19 | 19 |
| 20 // "Stub" implementation of GDataContactsServiceInterface used for testing. | 20 // "Stub" implementation of GDataContactsServiceInterface used for testing. |
| 21 // Returns a pre-set list of contacts in response to DownloadContacts() calls. | 21 // Returns a pre-set list of contacts in response to DownloadContacts() calls. |
| 22 class GDataContactsServiceStub : public GDataContactsServiceInterface { | 22 class GDataContactsServiceStub : public GDataContactsServiceInterface { |
| 23 public: | 23 public: |
| 24 GDataContactsServiceStub(); | 24 GDataContactsServiceStub(); |
| 25 virtual ~GDataContactsServiceStub(); | 25 virtual ~GDataContactsServiceStub(); |
| 26 | 26 |
| 27 int num_download_requests() const { return num_download_requests_; } | 27 int num_download_requests() const { return num_download_requests_; } |
| 28 void reset_stats() { num_download_requests_ = 0; } | 28 int num_download_requests_with_wrong_timestamps() const { |
| 29 return num_download_requests_with_wrong_timestamps_; |
| 30 } |
| 31 void reset_stats() { |
| 32 num_download_requests_ = 0; |
| 33 num_download_requests_with_wrong_timestamps_ = 0; |
| 34 } |
| 29 void set_download_should_succeed(bool succeed) { | 35 void set_download_should_succeed(bool succeed) { |
| 30 download_should_succeed_ = succeed; | 36 download_should_succeed_ = succeed; |
| 31 } | 37 } |
| 32 | 38 |
| 33 // Sets the contacts that will be returned by DownloadContacts(), assuming | 39 // Sets the contacts that will be returned by DownloadContacts(), assuming |
| 34 // that the request's |min_update_time| matches |expected_min_update_time|. | 40 // that the request's |min_update_time| matches |expected_min_update_time|. |
| 35 void SetContacts(const contacts::ContactPointers& contacts, | 41 void SetContacts(const contacts::ContactPointers& contacts, |
| 36 const base::Time& expected_min_update_time); | 42 const base::Time& expected_min_update_time); |
| 37 | 43 |
| 38 // Overridden from GDataContactsServiceInterface: | 44 // Overridden from GDataContactsServiceInterface: |
| 39 virtual void Initialize() OVERRIDE; | 45 virtual void Initialize() OVERRIDE; |
| 40 virtual void DownloadContacts(SuccessCallback success_callback, | 46 virtual void DownloadContacts(SuccessCallback success_callback, |
| 41 FailureCallback failure_callback, | 47 FailureCallback failure_callback, |
| 42 const base::Time& min_update_time) OVERRIDE; | 48 const base::Time& min_update_time) OVERRIDE; |
| 43 | 49 |
| 44 private: | 50 private: |
| 45 // How many times has DownloadContacts() been called? | 51 // How many times has DownloadContacts() been called? |
| 46 int num_download_requests_; | 52 int num_download_requests_; |
| 47 | 53 |
| 54 // How many times has DownloadContacts() been called with a |min_update_time| |
| 55 // parameter that doesn't match |expected_min_update_time_|? |
| 56 int num_download_requests_with_wrong_timestamps_; |
| 57 |
| 48 // Should calls to DownloadContacts() succeed? | 58 // Should calls to DownloadContacts() succeed? |
| 49 bool download_should_succeed_; | 59 bool download_should_succeed_; |
| 50 | 60 |
| 51 // Contacts to be returned by calls to DownloadContacts(). | 61 // Contacts to be returned by calls to DownloadContacts(). |
| 52 ScopedVector<contacts::Contact> contacts_; | 62 ScopedVector<contacts::Contact> contacts_; |
| 53 | 63 |
| 54 // |min_update_time| value that we expect to be passed to DownloadContacts(). | 64 // |min_update_time| value that we expect to be passed to DownloadContacts(). |
| 55 // If a different value is passed, we'll log an error and report failure. | 65 // If a different value is passed, we'll log an error and report failure. |
| 56 base::Time expected_min_update_time_; | 66 base::Time expected_min_update_time_; |
| 57 | 67 |
| 58 DISALLOW_COPY_AND_ASSIGN(GDataContactsServiceStub); | 68 DISALLOW_COPY_AND_ASSIGN(GDataContactsServiceStub); |
| 59 }; | 69 }; |
| 60 | 70 |
| 61 } // namespace gdata | 71 } // namespace gdata |
| 62 | 72 |
| 63 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_STUB_H_ | 73 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_CONTACTS_SERVICE_STUB_H_ |
| OLD | NEW |