Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / services / gcm / gcm_client_mock.h
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 "base/compiler_specific.h"
9 #include "google_apis/gcm/gcm_client.h"
10
11 namespace gcm {
12
13 class GCMClientMock : public GCMClient {
14  public:
15   enum Status {
16     NOT_READY,
17     READY
18   };
19
20   enum ErrorSimulation {
21     ALWAYS_SUCCEED,
22     FORCE_ERROR
23   };
24
25   // |status| denotes if the fake client is ready or not at the beginning.
26   // |error_simulation| denotes if we should simulate server error.
27   GCMClientMock(Status status, ErrorSimulation error_simulation);
28   virtual ~GCMClientMock();
29
30   // Overridden from GCMClient:
31   // Called on IO thread.
32   virtual void Initialize(
33       const checkin_proto::ChromeBuildProto& chrome_build_proto,
34       const base::FilePath& store_path,
35       const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
36       const scoped_refptr<net::URLRequestContextGetter>&
37           url_request_context_getter,
38       Delegate* delegate) OVERRIDE;
39   virtual void CheckOut() OVERRIDE;
40   virtual void Register(const std::string& app_id,
41                         const std::string& cert,
42                         const std::vector<std::string>& sender_ids) OVERRIDE;
43   virtual void Unregister(const std::string& app_id) OVERRIDE;
44   virtual void Send(const std::string& app_id,
45                     const std::string& receiver_id,
46                     const OutgoingMessage& message) OVERRIDE;
47   virtual bool IsReady() const OVERRIDE;
48
49   // Simulate receiving something from the server.
50   // Called on UI thread.
51   void ReceiveMessage(const std::string& app_id,
52                       const IncomingMessage& message);
53   void DeleteMessages(const std::string& app_id);
54
55   // Can only transition from non-ready to ready.
56   void SetReady();
57
58   static std::string GetRegistrationIdFromSenderIds(
59       const std::vector<std::string>& sender_ids);
60
61  private:
62   // Called on IO thread.
63   void RegisterFinished(const std::string& app_id,
64                         const std::string& registrion_id);
65   void SendFinished(const std::string& app_id, const std::string& message_id);
66   void MessageReceived(const std::string& app_id,
67                        const IncomingMessage& message);
68   void MessagesDeleted(const std::string& app_id);
69   void MessageSendError(const std::string& app_id,
70                         const std::string& message_id);
71   void SetReadyOnIO();
72
73   Delegate* delegate_;
74   Status status_;
75   ErrorSimulation error_simulation_;
76
77   DISALLOW_COPY_AND_ASSIGN(GCMClientMock);
78 };
79
80 }  // namespace gcm
81
82 #endif  // CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_