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

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: Use IntToString instead of UintToString 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/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 // static 105 // static
106 KeyedService* FakeGCMProfileService::Build(content::BrowserContext* context) { 106 KeyedService* FakeGCMProfileService::Build(content::BrowserContext* context) {
107 Profile* profile = static_cast<Profile*>(context); 107 Profile* profile = static_cast<Profile*>(context);
108 FakeGCMProfileService* service = new FakeGCMProfileService(profile); 108 FakeGCMProfileService* service = new FakeGCMProfileService(profile);
109 service->SetDriverForTesting(new CustomFakeGCMDriver(service)); 109 service->SetDriverForTesting(new CustomFakeGCMDriver(service));
110 return service; 110 return service;
111 } 111 }
112 112
113 FakeGCMProfileService::FakeGCMProfileService(Profile* profile) 113 FakeGCMProfileService::FakeGCMProfileService(Profile* profile)
114 : collect_(false) { 114 : collect_(false),
115 registration_count_(0) {
115 static_cast<PushMessagingServiceImpl*>(push_messaging_service()) 116 static_cast<PushMessagingServiceImpl*>(push_messaging_service())
116 ->SetProfileForTesting(profile); 117 ->SetProfileForTesting(profile);
117 } 118 }
118 119
119 FakeGCMProfileService::~FakeGCMProfileService() {} 120 FakeGCMProfileService::~FakeGCMProfileService() {}
120 121
121 void FakeGCMProfileService::RegisterFinished( 122 void FakeGCMProfileService::RegisterFinished(
122 const std::string& app_id, 123 const std::string& app_id,
123 const std::vector<std::string>& sender_ids) { 124 const std::vector<std::string>& sender_ids) {
124 if (collect_) { 125 if (collect_) {
125 last_registered_app_id_ = app_id; 126 last_registered_app_id_ = app_id;
126 last_registered_sender_ids_ = sender_ids; 127 last_registered_sender_ids_ = sender_ids;
127 } 128 }
128 129
130 // Generate fake registration IDs with an incrementing count (even for the
131 // same app_id - there's no caching), so tests can distinguish registrations.
132 // The ID also encodes the number of sender IDs which is used by
133 // GcmApiTest.RegisterValidation, but in the most common case of a single
134 // sender ID, this component will be zero (to avoid rebasing existing tests).
135 int registration_id = ++registration_count_ + 1000 * (sender_ids.size() - 1);
fgorski 2014/12/08 22:36:59 why not? int registration_id = registration_count_
johnme 2014/12/10 14:12:53 Ok, I've changed it to a simpler format: sende
136
129 CustomFakeGCMDriver* custom_driver = 137 CustomFakeGCMDriver* custom_driver =
130 static_cast<CustomFakeGCMDriver*>(driver()); 138 static_cast<CustomFakeGCMDriver*>(driver());
131 custom_driver->OnRegisterFinished(app_id, 139 custom_driver->OnRegisterFinished(app_id, base::IntToString(registration_id),
132 base::UintToString(sender_ids.size()), 140 GCMClient::SUCCESS);
133 GCMClient::SUCCESS);
134 } 141 }
135 142
136 void FakeGCMProfileService::UnregisterFinished(const std::string& app_id) { 143 void FakeGCMProfileService::UnregisterFinished(const std::string& app_id) {
137 GCMClient::Result result = GCMClient::SUCCESS; 144 GCMClient::Result result = GCMClient::SUCCESS;
138 if (!unregister_responses_.empty()) { 145 if (!unregister_responses_.empty()) {
139 result = unregister_responses_.front(); 146 result = unregister_responses_.front();
140 unregister_responses_.pop_front(); 147 unregister_responses_.pop_front();
141 } 148 }
142 149
143 CustomFakeGCMDriver* custom_driver = 150 CustomFakeGCMDriver* custom_driver =
(...skipping 22 matching lines...) Expand all
166 GCMClient::Result result) { 173 GCMClient::Result result) {
167 unregister_responses_.push_back(result); 174 unregister_responses_.push_back(result);
168 } 175 }
169 176
170 void FakeGCMProfileService::SetUnregisterCallback( 177 void FakeGCMProfileService::SetUnregisterCallback(
171 const UnregisterCallback& callback) { 178 const UnregisterCallback& callback) {
172 unregister_callback_ = callback; 179 unregister_callback_ = callback;
173 } 180 }
174 181
175 } // namespace gcm 182 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698