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.
5 #ifndef CHROME_BROWSER_SERVICES_GCM_FAKE_GCM_PROFILE_SERVICE_H_
6 #define CHROME_BROWSER_SERVICES_GCM_FAKE_GCM_PROFILE_SERVICE_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/services/gcm/gcm_profile_service.h"
13 #include "components/gcm_driver/gcm_driver.h"
17 } // namespace content
21 // Acts as a bridge between GCM API and GCMClient layer for testing purposes.
22 class FakeGCMProfileService
: public GCMProfileService
{
24 typedef base::Callback
<void(const std::string
&)> UnregisterCallback
;
26 // Helper function to be used with
27 // KeyedService::SetTestingFactory().
28 static scoped_ptr
<KeyedService
> Build(content::BrowserContext
* context
);
30 explicit FakeGCMProfileService(Profile
* profile
);
31 ~FakeGCMProfileService() override
;
33 void RegisterFinished(const std::string
& app_id
,
34 const std::vector
<std::string
>& sender_ids
);
35 void UnregisterFinished(const std::string
& app_id
);
36 void SendFinished(const std::string
& app_id
,
37 const std::string
& receiver_id
,
38 const OutgoingMessage
& message
);
40 void AddExpectedUnregisterResponse(GCMClient::Result result
);
42 void SetUnregisterCallback(const UnregisterCallback
& callback
);
44 const OutgoingMessage
& last_sent_message() const {
45 return last_sent_message_
;
48 const std::string
& last_receiver_id() const {
49 return last_receiver_id_
;
52 const std::string
& last_registered_app_id() const {
53 return last_registered_app_id_
;
56 const std::vector
<std::string
>& last_registered_sender_ids() const {
57 return last_registered_sender_ids_
;
60 void set_collect(bool collect
) {
65 // Indicates whether the service will collect paramters of the calls for
66 // furter verification in tests.
68 // Used to give each registration a unique registration id. Does not decrease
69 // when unregister is called.
70 int registration_count_
;
71 std::string last_registered_app_id_
;
72 std::vector
<std::string
> last_registered_sender_ids_
;
73 std::list
<GCMClient::Result
> unregister_responses_
;
74 OutgoingMessage last_sent_message_
;
75 std::string last_receiver_id_
;
76 UnregisterCallback unregister_callback_
;
78 DISALLOW_COPY_AND_ASSIGN(FakeGCMProfileService
);
83 #endif // CHROME_BROWSER_SERVICES_GCM_FAKE_GCM_PROFILE_SERVICE_H_