fake_gcm_profile_service.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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_FAKE_GCM_PROFILE_SERVICE_H_ 6#define CHROME_BROWSER_SERVICES_GCM_FAKE_GCM_PROFILE_SERVICE_H_ 7 8#include <list> 9#include <vector> 10 11#include "chrome/browser/services/gcm/gcm_profile_service.h" 12#include "components/gcm_driver/gcm_driver.h" 13 14namespace content { 15class BrowserContext; 16} // namespace content 17 18namespace gcm { 19 20// Acts as a bridge between GCM API and GCMClient layer for testing purposes. 21class FakeGCMProfileService : public GCMProfileService { 22 public: 23 // Helper function to be used with 24 // KeyedService::SetTestingFactory(). 25 static KeyedService* Build(content::BrowserContext* context); 26 27 explicit FakeGCMProfileService(Profile* profile); 28 virtual ~FakeGCMProfileService(); 29 30 void RegisterFinished(const std::string& app_id, 31 const std::vector<std::string>& sender_ids, 32 const GCMDriver::RegisterCallback& callback); 33 void UnregisterFinished(const std::string& app_id, 34 const GCMDriver::UnregisterCallback& callback); 35 void SendFinished(const std::string& app_id, 36 const std::string& receiver_id, 37 const GCMClient::OutgoingMessage& message, 38 const GCMDriver::SendCallback& callback); 39 40 void AddExpectedUnregisterResponse(GCMClient::Result result); 41 42 const GCMClient::OutgoingMessage& last_sent_message() const { 43 return last_sent_message_; 44 } 45 46 const std::string& last_receiver_id() const { 47 return last_receiver_id_; 48 } 49 50 const std::string& last_registered_app_id() const { 51 return last_registered_app_id_; 52 } 53 54 const std::vector<std::string>& last_registered_sender_ids() const { 55 return last_registered_sender_ids_; 56 } 57 58 void set_collect(bool collect) { 59 collect_ = collect; 60 } 61 62 private: 63 // Indicates whether the serivce will collect paramters of the calls for 64 // furter verification in tests. 65 bool collect_; 66 std::string last_registered_app_id_; 67 std::vector<std::string> last_registered_sender_ids_; 68 std::list<GCMClient::Result> unregister_responses_; 69 GCMClient::OutgoingMessage last_sent_message_; 70 std::string last_receiver_id_; 71 72 DISALLOW_COPY_AND_ASSIGN(FakeGCMProfileService); 73}; 74 75} // namespace gcm 76 77#endif // CHROME_BROWSER_SERVICES_GCM_FAKE_GCM_PROFILE_SERVICE_H_ 78