Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / services / gcm / gcm_client_mock.h
blobadd87e230f96201a59f74c0e783ba7f307557717
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_
8 #include <map>
10 #include "base/compiler_specific.h"
11 #include "google_apis/gcm/gcm_client.h"
13 namespace gcm {
15 class GCMClientMock : public GCMClient {
16 public:
17 GCMClientMock();
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);
54 private:
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,
61 std::string app_id,
62 std::string registrion_id);
63 void SendFinished(std::string username,
64 std::string app_id,
65 std::string message_id);
66 void MessageReceived(std::string username,
67 std::string app_id,
68 IncomingMessage message);
69 void MessagesDeleted(std::string username, std::string app_id);
70 void MessageSendError(std::string username,
71 std::string app_id,
72 std::string message_id);
73 void LoadingCompleted();
75 std::map<std::string, Delegate*> delegates_;
77 bool is_loading_;
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);
86 } // namespace gcm
88 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_