Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: chrome/browser/services/gcm/fake_gcm_profile_service.cc

Issue 785983002: Have FakeGCMProfileService return different registration IDs each time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak argument wrapping Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" 5 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/format_macros.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
11 #include "components/gcm_driver/fake_gcm_client_factory.h" 13 #include "components/gcm_driver/fake_gcm_client_factory.h"
12 #include "components/gcm_driver/fake_gcm_driver.h" 14 #include "components/gcm_driver/fake_gcm_driver.h"
13 #include "components/gcm_driver/gcm_driver.h" 15 #include "components/gcm_driver/gcm_driver.h"
14 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
15 17
16 namespace gcm { 18 namespace gcm {
17 19
18 namespace { 20 namespace {
19 21
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 106
105 // static 107 // static
106 KeyedService* FakeGCMProfileService::Build(content::BrowserContext* context) { 108 KeyedService* FakeGCMProfileService::Build(content::BrowserContext* context) {
107 Profile* profile = static_cast<Profile*>(context); 109 Profile* profile = static_cast<Profile*>(context);
108 FakeGCMProfileService* service = new FakeGCMProfileService(profile); 110 FakeGCMProfileService* service = new FakeGCMProfileService(profile);
109 service->SetDriverForTesting(new CustomFakeGCMDriver(service)); 111 service->SetDriverForTesting(new CustomFakeGCMDriver(service));
110 return service; 112 return service;
111 } 113 }
112 114
113 FakeGCMProfileService::FakeGCMProfileService(Profile* profile) 115 FakeGCMProfileService::FakeGCMProfileService(Profile* profile)
114 : collect_(false) { 116 : collect_(false),
117 registration_count_(0) {
115 static_cast<PushMessagingServiceImpl*>(push_messaging_service()) 118 static_cast<PushMessagingServiceImpl*>(push_messaging_service())
116 ->SetProfileForTesting(profile); 119 ->SetProfileForTesting(profile);
117 } 120 }
118 121
119 FakeGCMProfileService::~FakeGCMProfileService() {} 122 FakeGCMProfileService::~FakeGCMProfileService() {}
120 123
121 void FakeGCMProfileService::RegisterFinished( 124 void FakeGCMProfileService::RegisterFinished(
122 const std::string& app_id, 125 const std::string& app_id,
123 const std::vector<std::string>& sender_ids) { 126 const std::vector<std::string>& sender_ids) {
124 if (collect_) { 127 if (collect_) {
125 last_registered_app_id_ = app_id; 128 last_registered_app_id_ = app_id;
126 last_registered_sender_ids_ = sender_ids; 129 last_registered_sender_ids_ = sender_ids;
127 } 130 }
128 131
132 // Generate fake registration IDs, encoding the number of sender IDs (used by
133 // GcmApiTest.RegisterValidation), then an incrementing count (even for the
134 // same app_id - there's no caching) so tests can distinguish registrations.
135 std::string registration_id = base::StringPrintf("%" PRIuS "-%d",
136 sender_ids.size(),
137 registration_count_);
138 ++registration_count_;
139
129 CustomFakeGCMDriver* custom_driver = 140 CustomFakeGCMDriver* custom_driver =
130 static_cast<CustomFakeGCMDriver*>(driver()); 141 static_cast<CustomFakeGCMDriver*>(driver());
131 custom_driver->OnRegisterFinished(app_id, 142 custom_driver->OnRegisterFinished(
132 base::UintToString(sender_ids.size()), 143 app_id, registration_id, GCMClient::SUCCESS);
133 GCMClient::SUCCESS);
134 } 144 }
135 145
136 void FakeGCMProfileService::UnregisterFinished(const std::string& app_id) { 146 void FakeGCMProfileService::UnregisterFinished(const std::string& app_id) {
137 GCMClient::Result result = GCMClient::SUCCESS; 147 GCMClient::Result result = GCMClient::SUCCESS;
138 if (!unregister_responses_.empty()) { 148 if (!unregister_responses_.empty()) {
139 result = unregister_responses_.front(); 149 result = unregister_responses_.front();
140 unregister_responses_.pop_front(); 150 unregister_responses_.pop_front();
141 } 151 }
142 152
143 CustomFakeGCMDriver* custom_driver = 153 CustomFakeGCMDriver* custom_driver =
(...skipping 22 matching lines...) Expand all
166 GCMClient::Result result) { 176 GCMClient::Result result) {
167 unregister_responses_.push_back(result); 177 unregister_responses_.push_back(result);
168 } 178 }
169 179
170 void FakeGCMProfileService::SetUnregisterCallback( 180 void FakeGCMProfileService::SetUnregisterCallback(
171 const UnregisterCallback& callback) { 181 const UnregisterCallback& callback) {
172 unregister_callback_ = callback; 182 unregister_callback_ = callback;
173 } 183 }
174 184
175 } // namespace gcm 185 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/fake_gcm_profile_service.h ('k') | chrome/browser/services/gcm/push_messaging_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698