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