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