1 // Copyright 2014 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 COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_
6 #define COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h"
12 #include "components/gcm_driver/gcm_client.h"
15 class SequencedTaskRunner
;
20 class FakeGCMClient
: public GCMClient
{
22 // For testing purpose.
23 enum StartModeOverridding
{
24 // No change to how delay start is handled.
26 // Force to delay start GCM until PerformDelayedStart is called.
27 FORCE_TO_ALWAYS_DELAY_START_GCM
,
30 // Generate and return the registration ID/token based on parameters for
31 // testing verification.
32 static std::string
GenerateGCMRegistrationID(
33 const std::vector
<std::string
>& sender_ids
);
34 static std::string
GenerateInstanceIDToken(
35 const std::string
& authorized_entity
, const std::string
& scope
);
37 FakeGCMClient(const scoped_refptr
<base::SequencedTaskRunner
>& ui_thread
,
38 const scoped_refptr
<base::SequencedTaskRunner
>& io_thread
);
39 ~FakeGCMClient() override
;
41 // Overridden from GCMClient:
42 // Called on IO thread.
44 const ChromeBuildInfo
& chrome_build_info
,
45 const base::FilePath
& store_path
,
46 const scoped_refptr
<base::SequencedTaskRunner
>& blocking_task_runner
,
47 const scoped_refptr
<net::URLRequestContextGetter
>&
48 url_request_context_getter
,
49 scoped_ptr
<Encryptor
> encryptor
,
50 Delegate
* delegate
) override
;
51 void Start(StartMode start_mode
) override
;
53 void Register(const linked_ptr
<RegistrationInfo
>& registration_info
) override
;
55 const linked_ptr
<RegistrationInfo
>& registration_info
) override
;
56 void Send(const std::string
& app_id
,
57 const std::string
& receiver_id
,
58 const OutgoingMessage
& message
) override
;
59 void SetRecording(bool recording
) override
;
60 void ClearActivityLogs() override
;
61 GCMStatistics
GetStatistics() const override
;
62 void SetAccountTokens(
63 const std::vector
<AccountTokenInfo
>& account_tokens
) override
;
64 void UpdateAccountMapping(const AccountMapping
& account_mapping
) override
;
65 void RemoveAccountMapping(const std::string
& account_id
) override
;
66 void SetLastTokenFetchTime(const base::Time
& time
) override
;
67 void UpdateHeartbeatTimer(scoped_ptr
<base::Timer
> timer
) override
;
68 void AddInstanceIDData(const std::string
& app_id
,
69 const std::string
& instance_id
,
70 const std::string
& extra_data
) override
;
71 void RemoveInstanceIDData(const std::string
& app_id
) override
;
72 void GetInstanceIDData(const std::string
& app_id
,
73 std::string
* instance_id
,
74 std::string
* extra_data
) override
;
75 void AddHeartbeatInterval(const std::string
& scope
, int interval_ms
) override
;
76 void RemoveHeartbeatInterval(const std::string
& scope
) override
;
78 // Initiate the start that has been delayed.
79 // Called on UI thread.
80 void PerformDelayedStart();
82 // Simulate receiving something from the server.
83 // Called on UI thread.
84 void ReceiveMessage(const std::string
& app_id
,
85 const IncomingMessage
& message
);
86 void DeleteMessages(const std::string
& app_id
);
88 void set_start_mode_overridding(StartModeOverridding overridding
) {
89 start_mode_overridding_
= overridding
;
93 // Called on IO thread.
96 void RegisterFinished(
97 const linked_ptr
<RegistrationInfo
>& registration_info
,
98 const std::string
& registrion_id
);
99 void UnregisterFinished(
100 const linked_ptr
<RegistrationInfo
>& registration_info
);
101 void SendFinished(const std::string
& app_id
, const OutgoingMessage
& message
);
102 void MessageReceived(const std::string
& app_id
,
103 const IncomingMessage
& message
);
104 void MessagesDeleted(const std::string
& app_id
);
105 void MessageSendError(const std::string
& app_id
,
106 const SendErrorDetails
& send_error_details
);
107 void SendAcknowledgement(const std::string
& app_id
,
108 const std::string
& message_id
);
112 StartMode start_mode_
;
113 StartModeOverridding start_mode_overridding_
;
114 scoped_refptr
<base::SequencedTaskRunner
> ui_thread_
;
115 scoped_refptr
<base::SequencedTaskRunner
> io_thread_
;
116 std::map
<std::string
, std::pair
<std::string
, std::string
>> instance_id_data_
;
117 base::WeakPtrFactory
<FakeGCMClient
> weak_ptr_factory_
;
119 DISALLOW_COPY_AND_ASSIGN(FakeGCMClient
);
124 #endif // COMPONENTS_GCM_DRIVER_FAKE_GCM_CLIENT_H_