OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/gcm_profile_service.h" | 5 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 // testing::Test: | 55 // testing::Test: |
56 void SetUp() override; | 56 void SetUp() override; |
57 void TearDown() override; | 57 void TearDown() override; |
58 | 58 |
59 FakeGCMClient* GetGCMClient() const; | 59 FakeGCMClient* GetGCMClient() const; |
60 | 60 |
61 void CreateGCMProfileService(); | 61 void CreateGCMProfileService(); |
62 | 62 |
63 void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids); | 63 void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids); |
64 void UnregisterAndWaitForCompletion(); | 64 void UnregisterAndWaitForCompletion( |
| 65 const std::vector<std::string>& sender_ids); |
65 void SendAndWaitForCompletion(const GCMClient::OutgoingMessage& message); | 66 void SendAndWaitForCompletion(const GCMClient::OutgoingMessage& message); |
66 | 67 |
67 void RegisterCompleted(const base::Closure& callback, | 68 void RegisterCompleted(const base::Closure& callback, |
68 const std::string& registration_id, | 69 const std::string& registration_id, |
69 GCMClient::Result result); | 70 GCMClient::Result result); |
70 void UnregisterCompleted(const base::Closure& callback, | 71 void UnregisterCompleted(const base::Closure& callback, |
71 GCMClient::Result result); | 72 GCMClient::Result result); |
72 void SendCompleted(const base::Closure& callback, | 73 void SendCompleted(const base::Closure& callback, |
73 const std::string& message_id, | 74 const std::string& message_id, |
74 GCMClient::Result result); | 75 GCMClient::Result result); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 base::RunLoop run_loop; | 141 base::RunLoop run_loop; |
141 gcm_profile_service_->driver()->Register( | 142 gcm_profile_service_->driver()->Register( |
142 kTestAppID, | 143 kTestAppID, |
143 sender_ids, | 144 sender_ids, |
144 base::Bind(&GCMProfileServiceTest::RegisterCompleted, | 145 base::Bind(&GCMProfileServiceTest::RegisterCompleted, |
145 base::Unretained(this), | 146 base::Unretained(this), |
146 run_loop.QuitClosure())); | 147 run_loop.QuitClosure())); |
147 run_loop.Run(); | 148 run_loop.Run(); |
148 } | 149 } |
149 | 150 |
150 void GCMProfileServiceTest::UnregisterAndWaitForCompletion() { | 151 void GCMProfileServiceTest::UnregisterAndWaitForCompletion( |
| 152 const std::vector<std::string>& sender_ids) { |
151 base::RunLoop run_loop; | 153 base::RunLoop run_loop; |
152 gcm_profile_service_->driver()->Unregister( | 154 gcm_profile_service_->driver()->Unregister( |
153 kTestAppID, | 155 kTestAppID, |
| 156 sender_ids, |
154 base::Bind(&GCMProfileServiceTest::UnregisterCompleted, | 157 base::Bind(&GCMProfileServiceTest::UnregisterCompleted, |
155 base::Unretained(this), | 158 base::Unretained(this), |
156 run_loop.QuitClosure())); | 159 run_loop.QuitClosure())); |
157 run_loop.Run(); | 160 run_loop.Run(); |
158 } | 161 } |
159 | 162 |
160 void GCMProfileServiceTest::SendAndWaitForCompletion( | 163 void GCMProfileServiceTest::SendAndWaitForCompletion( |
161 const GCMClient::OutgoingMessage& message) { | 164 const GCMClient::OutgoingMessage& message) { |
162 base::RunLoop run_loop; | 165 base::RunLoop run_loop; |
163 gcm_profile_service_->driver()->Send( | 166 gcm_profile_service_->driver()->Send( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 203 |
201 std::vector<std::string> sender_ids; | 204 std::vector<std::string> sender_ids; |
202 sender_ids.push_back("sender"); | 205 sender_ids.push_back("sender"); |
203 RegisterAndWaitForCompletion(sender_ids); | 206 RegisterAndWaitForCompletion(sender_ids); |
204 | 207 |
205 std::string expected_registration_id = | 208 std::string expected_registration_id = |
206 GetGCMClient()->GetRegistrationIdFromSenderIds(sender_ids); | 209 GetGCMClient()->GetRegistrationIdFromSenderIds(sender_ids); |
207 EXPECT_EQ(expected_registration_id, registration_id()); | 210 EXPECT_EQ(expected_registration_id, registration_id()); |
208 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); | 211 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
209 | 212 |
210 UnregisterAndWaitForCompletion(); | 213 UnregisterAndWaitForCompletion(sender_ids); |
211 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); | 214 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); |
212 } | 215 } |
213 | 216 |
214 TEST_F(GCMProfileServiceTest, Send) { | 217 TEST_F(GCMProfileServiceTest, Send) { |
215 CreateGCMProfileService(); | 218 CreateGCMProfileService(); |
216 | 219 |
217 GCMClient::OutgoingMessage message; | 220 GCMClient::OutgoingMessage message; |
218 message.id = "1"; | 221 message.id = "1"; |
219 message.data["key1"] = "value1"; | 222 message.data["key1"] = "value1"; |
220 SendAndWaitForCompletion( message); | 223 SendAndWaitForCompletion( message); |
221 | 224 |
222 EXPECT_EQ(message.id, send_message_id()); | 225 EXPECT_EQ(message.id, send_message_id()); |
223 EXPECT_EQ(GCMClient::SUCCESS, send_result()); | 226 EXPECT_EQ(GCMClient::SUCCESS, send_result()); |
224 } | 227 } |
225 | 228 |
226 } // namespace gcm | 229 } // namespace gcm |
OLD | NEW |