OLD | NEW |
| (Empty) |
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 <memory> | |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | |
13 #include "components/gcm_driver/gcm_driver.h" | |
14 #include "components/gcm_driver/gcm_profile_service.h" | |
15 | |
16 class Profile; | |
17 | |
18 namespace content { | |
19 class BrowserContext; | |
20 } // namespace content | |
21 | |
22 namespace gcm { | |
23 | |
24 // Acts as a bridge between GCM API and GCMClient layer for testing purposes. | |
25 class FakeGCMProfileService : public GCMProfileService { | |
26 public: | |
27 typedef base::Callback<void(const std::string&)> UnregisterCallback; | |
28 | |
29 // Helper function to be used with | |
30 // KeyedService::SetTestingFactory(). | |
31 static std::unique_ptr<KeyedService> Build(content::BrowserContext* context); | |
32 | |
33 explicit FakeGCMProfileService(Profile* profile); | |
34 ~FakeGCMProfileService() override; | |
35 | |
36 void RegisterFinished(const std::string& app_id, | |
37 const std::vector<std::string>& sender_ids); | |
38 void UnregisterFinished(const std::string& app_id); | |
39 void SendFinished(const std::string& app_id, | |
40 const std::string& receiver_id, | |
41 const OutgoingMessage& message); | |
42 | |
43 void AddExpectedUnregisterResponse(GCMClient::Result result); | |
44 | |
45 void SetUnregisterCallback(const UnregisterCallback& callback); | |
46 | |
47 void DispatchMessage(const std::string& app_id, | |
48 const IncomingMessage& message); | |
49 | |
50 const OutgoingMessage& last_sent_message() const { | |
51 return last_sent_message_; | |
52 } | |
53 | |
54 const std::string& last_receiver_id() const { | |
55 return last_receiver_id_; | |
56 } | |
57 | |
58 const std::string& last_registered_app_id() const { | |
59 return last_registered_app_id_; | |
60 } | |
61 | |
62 const std::vector<std::string>& last_registered_sender_ids() const { | |
63 return last_registered_sender_ids_; | |
64 } | |
65 | |
66 void set_collect(bool collect) { | |
67 collect_ = collect; | |
68 } | |
69 | |
70 private: | |
71 // Indicates whether the service will collect paramters of the calls for | |
72 // furter verification in tests. | |
73 bool collect_; | |
74 // Used to give each registration a unique registration id. Does not decrease | |
75 // when unregister is called. | |
76 int registration_count_; | |
77 std::string last_registered_app_id_; | |
78 std::vector<std::string> last_registered_sender_ids_; | |
79 std::list<GCMClient::Result> unregister_responses_; | |
80 OutgoingMessage last_sent_message_; | |
81 std::string last_receiver_id_; | |
82 UnregisterCallback unregister_callback_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(FakeGCMProfileService); | |
85 }; | |
86 | |
87 } // namespace gcm | |
88 | |
89 #endif // CHROME_BROWSER_SERVICES_GCM_FAKE_GCM_PROFILE_SERVICE_H_ | |
OLD | NEW |