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. 4 5 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_ 6 #define CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_ 7 8 #include <map> 9 10 #include "base/compiler_specific.h" 11 #include "google_apis/gcm/gcm_client.h" 12 13 namespace gcm { 14 15 class GCMClientMock : public GCMClient { 16 public: 17 GCMClientMock(); 18 virtual ~GCMClientMock(); 19 20 // Overridden from GCMClient: 21 // Called on IO thread. 22 virtual void CheckIn(const std::string& username, 23 Delegate* delegate) OVERRIDE; 24 virtual void Register(const std::string& username, 25 const std::string& app_id, 26 const std::string& cert, 27 const std::vector<std::string>& sender_ids) OVERRIDE; 28 virtual void Unregister(const std::string& username, 29 const std::string& app_id) OVERRIDE; 30 virtual void Send(const std::string& username, 31 const std::string& app_id, 32 const std::string& receiver_id, 33 const OutgoingMessage& message) OVERRIDE; 34 virtual bool IsLoading() const OVERRIDE; 35 36 // Simulate receiving something from the server. 37 // Called on UI thread. 38 void ReceiveMessage(const std::string& username, 39 const std::string& app_id, 40 const IncomingMessage& message); 41 void DeleteMessages(const std::string& username, const std::string& app_id); 42 43 void set_checkin_failure_enabled(bool checkin_failure_enabled) { 44 checkin_failure_enabled_ = checkin_failure_enabled; 45 } 46 47 CheckInInfo GetCheckInInfoFromUsername(const std::string& username) const; 48 std::string GetRegistrationIdFromSenderIds( 49 const std::vector<std::string>& sender_ids) const; 50 51 private: 52 Delegate* GetDelegate(const std::string& username) const; 53 54 // Called on IO thread. 55 void CheckInFinished(std::string username, CheckInInfo checkin_info); 56 void RegisterFinished(std::string username, 57 std::string app_id, 58 std::string registrion_id); 59 void SendFinished(std::string username, 60 std::string app_id, 61 std::string message_id); 62 void MessageReceived(std::string username, 63 std::string app_id, 64 IncomingMessage message); 65 void MessagesDeleted(std::string username, std::string app_id); 66 void MessageSendError(std::string username, 67 std::string app_id, 68 std::string message_id); 69 70 std::map<std::string, Delegate*> delegates_; 71 72 // The testing code could set this to force the check-in failure in order to 73 // test the error scenario. 74 bool checkin_failure_enabled_; 75 76 DISALLOW_COPY_AND_ASSIGN(GCMClientMock); 77 }; 78 79 } // namespace gcm 80 81 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_ 82