Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / services / gcm / fake_gcm_profile_service.h
blob499bd835abf75bc54ff16534bff0e8f9059c10a7
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_
8 #include <list>
9 #include <vector>
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"
15 namespace content {
16 class BrowserContext;
17 } // namespace content
19 namespace gcm {
21 // Acts as a bridge between GCM API and GCMClient layer for testing purposes.
22 class FakeGCMProfileService : public GCMProfileService {
23 public:
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) {
61 collect_ = collect;
64 private:
65 // Indicates whether the service will collect paramters of the calls for
66 // furter verification in tests.
67 bool collect_;
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);
81 } // namespace gcm
83 #endif // CHROME_BROWSER_SERVICES_GCM_FAKE_GCM_PROFILE_SERVICE_H_