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 "components/gcm_driver/gcm_driver_desktop.h" | 5 #include "components/gcm_driver/gcm_driver_desktop.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 PumpIOLoop(); | 222 PumpIOLoop(); |
223 PumpUILoop(); | 223 PumpUILoop(); |
224 } | 224 } |
225 | 225 |
226 void GCMDriverTest::Register(const std::string& app_id, | 226 void GCMDriverTest::Register(const std::string& app_id, |
227 const std::vector<std::string>& sender_ids, | 227 const std::vector<std::string>& sender_ids, |
228 WaitToFinish wait_to_finish) { | 228 WaitToFinish wait_to_finish) { |
229 base::RunLoop run_loop; | 229 base::RunLoop run_loop; |
230 async_operation_completed_callback_ = run_loop.QuitClosure(); | 230 async_operation_completed_callback_ = run_loop.QuitClosure(); |
231 driver_->Register(app_id, | 231 driver_->Register(app_id, |
232 sender_ids, | 232 sender_ids, |
233 base::Bind(&GCMDriverTest::RegisterCompleted, | 233 base::Bind(&GCMDriverTest::RegisterCompleted, |
234 base::Unretained(this))); | 234 base::Unretained(this))); |
235 if (wait_to_finish == WAIT) | 235 if (wait_to_finish == WAIT) |
236 run_loop.Run(); | 236 run_loop.Run(); |
237 } | 237 } |
238 | 238 |
239 void GCMDriverTest::Send(const std::string& app_id, | 239 void GCMDriverTest::Send(const std::string& app_id, |
240 const std::string& receiver_id, | 240 const std::string& receiver_id, |
241 const GCMClient::OutgoingMessage& message, | 241 const GCMClient::OutgoingMessage& message, |
242 WaitToFinish wait_to_finish) { | 242 WaitToFinish wait_to_finish) { |
243 base::RunLoop run_loop; | 243 base::RunLoop run_loop; |
244 async_operation_completed_callback_ = run_loop.QuitClosure(); | 244 async_operation_completed_callback_ = run_loop.QuitClosure(); |
245 driver_->Send(app_id, | 245 driver_->Send(app_id, |
246 receiver_id, | 246 receiver_id, |
247 message, | 247 message, |
248 base::Bind(&GCMDriverTest::SendCompleted, | 248 base::Bind(&GCMDriverTest::SendCompleted, |
249 base::Unretained(this))); | 249 base::Unretained(this))); |
250 if (wait_to_finish == WAIT) | 250 if (wait_to_finish == WAIT) |
251 run_loop.Run(); | 251 run_loop.Run(); |
252 } | 252 } |
253 | 253 |
254 void GCMDriverTest::Unregister(const std::string& app_id, | 254 void GCMDriverTest::Unregister(const std::string& app_id, |
255 WaitToFinish wait_to_finish) { | 255 WaitToFinish wait_to_finish) { |
256 base::RunLoop run_loop; | 256 base::RunLoop run_loop; |
257 async_operation_completed_callback_ = run_loop.QuitClosure(); | 257 async_operation_completed_callback_ = run_loop.QuitClosure(); |
258 driver_->Unregister(app_id, | 258 driver_->Unregister(app_id, |
259 base::Bind(&GCMDriverTest::UnregisterCompleted, | 259 base::Bind(&GCMDriverTest::UnregisterCompleted, |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 WaitForAsyncOperation(); | 790 WaitForAsyncOperation(); |
791 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); | 791 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); |
792 | 792 |
793 // Test that it is ok to register again after unregistration. | 793 // Test that it is ok to register again after unregistration. |
794 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); | 794 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); |
795 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); | 795 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
796 } | 796 } |
797 | 797 |
798 TEST_F(GCMDriverFunctionalTest, Send) { | 798 TEST_F(GCMDriverFunctionalTest, Send) { |
799 GCMClient::OutgoingMessage message; | 799 GCMClient::OutgoingMessage message; |
800 message.id = "1"; | 800 message.id = "1@ack"; |
801 message.data["key1"] = "value1"; | 801 message.data["key1"] = "value1"; |
802 message.data["key2"] = "value2"; | 802 message.data["key2"] = "value2"; |
803 Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT); | 803 Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT); |
804 | 804 |
805 EXPECT_EQ(message.id, send_message_id()); | 805 EXPECT_EQ(message.id, send_message_id()); |
806 EXPECT_EQ(GCMClient::SUCCESS, send_result()); | 806 EXPECT_EQ(GCMClient::SUCCESS, send_result()); |
| 807 |
| 808 gcm_app_handler()->WaitForNotification(); |
| 809 EXPECT_EQ(message.id, gcm_app_handler()->acked_message_id()); |
| 810 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); |
807 } | 811 } |
808 | 812 |
809 TEST_F(GCMDriverFunctionalTest, SendAfterSignOut) { | 813 TEST_F(GCMDriverFunctionalTest, SendAfterSignOut) { |
810 // This will trigger check-out. | 814 // This will trigger check-out. |
811 SignOut(); | 815 SignOut(); |
812 | 816 |
813 GCMClient::OutgoingMessage message; | 817 GCMClient::OutgoingMessage message; |
814 message.id = "1"; | 818 message.id = "1"; |
815 message.data["key1"] = "value1"; | 819 message.data["key1"] = "value1"; |
816 message.data["key2"] = "value2"; | 820 message.data["key2"] = "value2"; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 | 882 |
879 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { | 883 TEST_F(GCMDriverFunctionalTest, MessagesDeleted) { |
880 GetGCMClient()->DeleteMessages(kTestAppID1); | 884 GetGCMClient()->DeleteMessages(kTestAppID1); |
881 gcm_app_handler()->WaitForNotification(); | 885 gcm_app_handler()->WaitForNotification(); |
882 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, | 886 EXPECT_EQ(FakeGCMAppHandler::MESSAGES_DELETED_EVENT, |
883 gcm_app_handler()->received_event()); | 887 gcm_app_handler()->received_event()); |
884 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); | 888 EXPECT_EQ(kTestAppID1, gcm_app_handler()->app_id()); |
885 } | 889 } |
886 | 890 |
887 } // namespace gcm | 891 } // namespace gcm |
OLD | NEW |