1 // Copyright 2013 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_SERVICES_GCM_GCM_CLIENT_MOCK_H_
6 #define CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_
10 #include "base/compiler_specific.h"
11 #include "google_apis/gcm/gcm_client.h"
15 class GCMClientMock
: public GCMClient
{
18 virtual ~GCMClientMock();
20 // Overridden from GCMClient:
21 // Called on IO thread.
22 virtual void SetUserDelegate(const std::string
& username
,
23 Delegate
* delegate
) OVERRIDE
;
24 virtual void CheckIn(const std::string
& username
) OVERRIDE
;
25 virtual void Register(const std::string
& username
,
26 const std::string
& app_id
,
27 const std::string
& cert
,
28 const std::vector
<std::string
>& sender_ids
) OVERRIDE
;
29 virtual void Unregister(const std::string
& username
,
30 const std::string
& app_id
) OVERRIDE
;
31 virtual void Send(const std::string
& username
,
32 const std::string
& app_id
,
33 const std::string
& receiver_id
,
34 const OutgoingMessage
& message
) OVERRIDE
;
35 virtual bool IsLoading() const OVERRIDE
;
37 // Simulate receiving something from the server.
38 // Called on UI thread.
39 void ReceiveMessage(const std::string
& username
,
40 const std::string
& app_id
,
41 const IncomingMessage
& message
);
42 void DeleteMessages(const std::string
& username
, const std::string
& app_id
);
44 void set_simulate_server_error(bool simulate_server_error
) {
45 simulate_server_error_
= simulate_server_error
;
48 void SetIsLoading(bool is_loading
);
50 static CheckinInfo
GetCheckinInfoFromUsername(const std::string
& username
);
51 static std::string
GetRegistrationIdFromSenderIds(
52 const std::vector
<std::string
>& sender_ids
);
55 Delegate
* GetDelegate(const std::string
& username
) const;
57 // Called on IO thread.
58 // TODO(fgorski): Update parameters to const ref.
59 void CheckInFinished(std::string username
, CheckinInfo checkin_info
);
60 void RegisterFinished(std::string username
,
62 std::string registrion_id
);
63 void SendFinished(std::string username
,
65 std::string message_id
);
66 void MessageReceived(std::string username
,
68 IncomingMessage message
);
69 void MessagesDeleted(std::string username
, std::string app_id
);
70 void MessageSendError(std::string username
,
72 std::string message_id
);
73 void LoadingCompleted();
75 std::map
<std::string
, Delegate
*> delegates_
;
79 // The testing code could set this to simulate the server error in order to
80 // test the error scenario.
81 bool simulate_server_error_
;
83 DISALLOW_COPY_AND_ASSIGN(GCMClientMock
);
88 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_