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

Side by Side Diff: google_apis/gcm/engine/mcs_client_unittest.cc

Issue 1873663002: Convert //google_apis from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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 "google_apis/gcm/engine/mcs_client.h" 5 #include "google_apis/gcm/engine/mcs_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9
10 #include <memory>
9 #include <utility> 11 #include <utility>
10 12
11 #include "base/bind.h" 13 #include "base/bind.h"
12 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 15 #include "base/command_line.h"
14 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
15 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/ptr_util.h"
16 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 19 #include "base/run_loop.h"
18 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
19 #include "base/test/simple_test_clock.h" 21 #include "base/test/simple_test_clock.h"
20 #include "base/timer/timer.h" 22 #include "base/timer/timer.h"
21 #include "google_apis/gcm/base/fake_encryptor.h" 23 #include "google_apis/gcm/base/fake_encryptor.h"
22 #include "google_apis/gcm/base/mcs_util.h" 24 #include "google_apis/gcm/base/mcs_util.h"
23 #include "google_apis/gcm/engine/fake_connection_factory.h" 25 #include "google_apis/gcm/engine/fake_connection_factory.h"
24 #include "google_apis/gcm/engine/fake_connection_handler.h" 26 #include "google_apis/gcm/engine/fake_connection_handler.h"
25 #include "google_apis/gcm/engine/gcm_store_impl.h" 27 #include "google_apis/gcm/engine/gcm_store_impl.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 void MessageReceivedCallback(const MCSMessage& message); 162 void MessageReceivedCallback(const MCSMessage& message);
161 void MessageSentCallback(int64_t user_serial_number, 163 void MessageSentCallback(int64_t user_serial_number,
162 const std::string& app_id, 164 const std::string& app_id,
163 const std::string& message_id, 165 const std::string& message_id,
164 MCSClient::MessageSendStatus status); 166 MCSClient::MessageSendStatus status);
165 167
166 base::SimpleTestClock clock_; 168 base::SimpleTestClock clock_;
167 169
168 base::ScopedTempDir temp_directory_; 170 base::ScopedTempDir temp_directory_;
169 base::MessageLoop message_loop_; 171 base::MessageLoop message_loop_;
170 scoped_ptr<base::RunLoop> run_loop_; 172 std::unique_ptr<base::RunLoop> run_loop_;
171 scoped_ptr<GCMStore> gcm_store_; 173 std::unique_ptr<GCMStore> gcm_store_;
172 174
173 FakeConnectionFactory connection_factory_; 175 FakeConnectionFactory connection_factory_;
174 scoped_ptr<TestMCSClient> mcs_client_; 176 std::unique_ptr<TestMCSClient> mcs_client_;
175 bool init_success_; 177 bool init_success_;
176 uint64_t restored_android_id_; 178 uint64_t restored_android_id_;
177 uint64_t restored_security_token_; 179 uint64_t restored_security_token_;
178 scoped_ptr<MCSMessage> received_message_; 180 std::unique_ptr<MCSMessage> received_message_;
179 std::string sent_message_id_; 181 std::string sent_message_id_;
180 MCSClient::MessageSendStatus message_send_status_; 182 MCSClient::MessageSendStatus message_send_status_;
181 183
182 gcm::FakeGCMStatsRecorder recorder_; 184 gcm::FakeGCMStatsRecorder recorder_;
183 }; 185 };
184 186
185 MCSClientTest::MCSClientTest() 187 MCSClientTest::MCSClientTest()
186 : run_loop_(new base::RunLoop()), 188 : run_loop_(new base::RunLoop()),
187 init_success_(true), 189 init_success_(true),
188 restored_android_id_(0), 190 restored_android_id_(0),
189 restored_security_token_(0), 191 restored_security_token_(0),
190 message_send_status_(MCSClient::SENT) { 192 message_send_status_(MCSClient::SENT) {
191 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); 193 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir());
192 run_loop_.reset(new base::RunLoop()); 194 run_loop_.reset(new base::RunLoop());
193 195
194 // Advance the clock to a non-zero time. 196 // Advance the clock to a non-zero time.
195 clock_.Advance(base::TimeDelta::FromSeconds(1)); 197 clock_.Advance(base::TimeDelta::FromSeconds(1));
196 } 198 }
197 199
198 MCSClientTest::~MCSClientTest() {} 200 MCSClientTest::~MCSClientTest() {}
199 201
200 void MCSClientTest::SetUp() { 202 void MCSClientTest::SetUp() {
201 testing::Test::SetUp(); 203 testing::Test::SetUp();
202 } 204 }
203 205
204 void MCSClientTest::BuildMCSClient() { 206 void MCSClientTest::BuildMCSClient() {
205 gcm_store_.reset(new GCMStoreImpl( 207 gcm_store_.reset(
206 temp_directory_.path(), 208 new GCMStoreImpl(temp_directory_.path(), message_loop_.task_runner(),
207 message_loop_.task_runner(), 209 base::WrapUnique<Encryptor>(new FakeEncryptor)));
208 make_scoped_ptr<Encryptor>(new FakeEncryptor)));
209 mcs_client_.reset(new TestMCSClient(&clock_, 210 mcs_client_.reset(new TestMCSClient(&clock_,
210 &connection_factory_, 211 &connection_factory_,
211 gcm_store_.get(), 212 gcm_store_.get(),
212 &recorder_)); 213 &recorder_));
213 } 214 }
214 215
215 void MCSClientTest::InitializeClient() { 216 void MCSClientTest::InitializeClient() {
216 gcm_store_->Load(GCMStore::CREATE_IF_MISSING, base::Bind( 217 gcm_store_->Load(GCMStore::CREATE_IF_MISSING, base::Bind(
217 &MCSClient::Initialize, 218 &MCSClient::Initialize,
218 base::Unretained(mcs_client_.get()), 219 base::Unretained(mcs_client_.get()),
(...skipping 16 matching lines...) Expand all
235 int heartbeat_interval_ms) { 236 int heartbeat_interval_ms) {
236 AddExpectedLoginRequest(acknowledged_ids, heartbeat_interval_ms); 237 AddExpectedLoginRequest(acknowledged_ids, heartbeat_interval_ms);
237 mcs_client_->Login(kAndroidId, kSecurityToken); 238 mcs_client_->Login(kAndroidId, kSecurityToken);
238 run_loop_->Run(); 239 run_loop_->Run();
239 run_loop_.reset(new base::RunLoop()); 240 run_loop_.reset(new base::RunLoop());
240 } 241 }
241 242
242 void MCSClientTest::AddExpectedLoginRequest( 243 void MCSClientTest::AddExpectedLoginRequest(
243 const std::vector<std::string>& acknowledged_ids, 244 const std::vector<std::string>& acknowledged_ids,
244 int heartbeat_interval_ms) { 245 int heartbeat_interval_ms) {
245 scoped_ptr<mcs_proto::LoginRequest> login_request = 246 std::unique_ptr<mcs_proto::LoginRequest> login_request =
246 BuildLoginRequest(kAndroidId, kSecurityToken, ""); 247 BuildLoginRequest(kAndroidId, kSecurityToken, "");
247 for (size_t i = 0; i < acknowledged_ids.size(); ++i) 248 for (size_t i = 0; i < acknowledged_ids.size(); ++i)
248 login_request->add_received_persistent_id(acknowledged_ids[i]); 249 login_request->add_received_persistent_id(acknowledged_ids[i]);
249 if (heartbeat_interval_ms) { 250 if (heartbeat_interval_ms) {
250 mcs_proto::Setting* setting = login_request->add_setting(); 251 mcs_proto::Setting* setting = login_request->add_setting();
251 setting->set_name("hbping"); 252 setting->set_name("hbping");
252 setting->set_value(base::IntToString(heartbeat_interval_ms)); 253 setting->set_value(base::IntToString(heartbeat_interval_ms));
253 } 254 }
254 GetFakeHandler()->ExpectOutgoingMessage( 255 GetFakeHandler()->ExpectOutgoingMessage(
255 MCSMessage(kLoginRequestTag, std::move(login_request))); 256 MCSMessage(kLoginRequestTag, std::move(login_request)));
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 EXPECT_EQ(MCSClient::QUEUED, message_send_status()); 422 EXPECT_EQ(MCSClient::QUEUED, message_send_status());
422 EXPECT_EQ("X", sent_message_id()); 423 EXPECT_EQ("X", sent_message_id());
423 EXPECT_FALSE(GetFakeHandler()->AllOutgoingMessagesReceived()); 424 EXPECT_FALSE(GetFakeHandler()->AllOutgoingMessagesReceived());
424 GetFakeHandler()->set_fail_send(false); 425 GetFakeHandler()->set_fail_send(false);
425 clock()->Advance(base::TimeDelta::FromSeconds(kTTLValue - 1)); 426 clock()->Advance(base::TimeDelta::FromSeconds(kTTLValue - 1));
426 connection_factory()->Connect(); 427 connection_factory()->Connect();
427 WaitForMCSEvent(); // Wait for the login to finish. 428 WaitForMCSEvent(); // Wait for the login to finish.
428 PumpLoop(); // Wait for the send to happen. 429 PumpLoop(); // Wait for the send to happen.
429 430
430 // Receive the ack. 431 // Receive the ack.
431 scoped_ptr<mcs_proto::IqStanza> ack = BuildStreamAck(); 432 std::unique_ptr<mcs_proto::IqStanza> ack = BuildStreamAck();
432 ack->set_last_stream_id_received(2); 433 ack->set_last_stream_id_received(2);
433 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack))); 434 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack)));
434 WaitForMCSEvent(); 435 WaitForMCSEvent();
435 436
436 EXPECT_EQ(MCSClient::SENT, message_send_status()); 437 EXPECT_EQ(MCSClient::SENT, message_send_status());
437 EXPECT_EQ("X", sent_message_id()); 438 EXPECT_EQ("X", sent_message_id());
438 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 439 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
439 } 440 }
440 441
441 // Send a message with RMQ support without receiving an acknowledgement. On 442 // Send a message with RMQ support without receiving an acknowledgement. On
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 MCSMessage message(BuildDataMessage("from", "category", "X", 1, 484 MCSMessage message(BuildDataMessage("from", "category", "X", 1,
484 base::IntToString(i), kTTLValue, 1, 0, 485 base::IntToString(i), kTTLValue, 1, 0,
485 "", 0, IMMEDIATE_ACK_NO)); 486 "", 0, IMMEDIATE_ACK_NO));
486 GetFakeHandler()->ExpectOutgoingMessage(message); 487 GetFakeHandler()->ExpectOutgoingMessage(message);
487 mcs_client()->SendMessage(message); 488 mcs_client()->SendMessage(message);
488 PumpLoop(); 489 PumpLoop();
489 } 490 }
490 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 491 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
491 492
492 // Receive the ack. 493 // Receive the ack.
493 scoped_ptr<mcs_proto::IqStanza> ack = BuildStreamAck(); 494 std::unique_ptr<mcs_proto::IqStanza> ack = BuildStreamAck();
494 ack->set_last_stream_id_received(kMessageBatchSize + 1); 495 ack->set_last_stream_id_received(kMessageBatchSize + 1);
495 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack))); 496 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack)));
496 WaitForMCSEvent(); 497 WaitForMCSEvent();
497 498
498 // Reconnect and ensure no messages are resent. 499 // Reconnect and ensure no messages are resent.
499 StoreCredentials(); 500 StoreCredentials();
500 BuildMCSClient(); 501 BuildMCSClient();
501 InitializeClient(); 502 InitializeClient();
502 LoginClient(std::vector<std::string>()); 503 LoginClient(std::vector<std::string>());
503 PumpLoop(); 504 PumpLoop();
(...skipping 18 matching lines...) Expand all
522 PumpLoop(); 523 PumpLoop();
523 } 524 }
524 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 525 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
525 526
526 // Rebuild the client, and receive an acknowledgment for the messages as 527 // Rebuild the client, and receive an acknowledgment for the messages as
527 // part of the login response. 528 // part of the login response.
528 StoreCredentials(); 529 StoreCredentials();
529 BuildMCSClient(); 530 BuildMCSClient();
530 InitializeClient(); 531 InitializeClient();
531 LoginClient(std::vector<std::string>()); 532 LoginClient(std::vector<std::string>());
532 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(id_list)); 533 std::unique_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(id_list));
533 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack))); 534 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack)));
534 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 535 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
535 } 536 }
536 537
537 // Send messages with RMQ support. On restart, receive a SelectiveAck with 538 // Send messages with RMQ support. On restart, receive a SelectiveAck with
538 // the login response that only acks some messages. The unacked messages should 539 // the login response that only acks some messages. The unacked messages should
539 // be resent. 540 // be resent.
540 TEST_F(MCSClientTest, SendMessageRMQPartialAckOnReconnect) { 541 TEST_F(MCSClientTest, SendMessageRMQPartialAckOnReconnect) {
541 BuildMCSClient(); 542 BuildMCSClient();
542 InitializeClient(); 543 InitializeClient();
(...skipping 25 matching lines...) Expand all
568 id_list.begin() + kMessageBatchSize / 2); 569 id_list.begin() + kMessageBatchSize / 2);
569 remaining_ids.insert(remaining_ids.end(), 570 remaining_ids.insert(remaining_ids.end(),
570 id_list.begin() + kMessageBatchSize / 2, 571 id_list.begin() + kMessageBatchSize / 2,
571 id_list.end()); 572 id_list.end());
572 for (int i = 1; i <= kMessageBatchSize / 2; ++i) { 573 for (int i = 1; i <= kMessageBatchSize / 2; ++i) {
573 MCSMessage message(BuildDataMessage( 574 MCSMessage message(BuildDataMessage(
574 "from", "category", remaining_ids[i - 1], 2, remaining_ids[i - 1], 575 "from", "category", remaining_ids[i - 1], 2, remaining_ids[i - 1],
575 kTTLValue, 1, 0, "", 0, IMMEDIATE_ACK_NO)); 576 kTTLValue, 1, 0, "", 0, IMMEDIATE_ACK_NO));
576 GetFakeHandler()->ExpectOutgoingMessage(message); 577 GetFakeHandler()->ExpectOutgoingMessage(message);
577 } 578 }
578 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids)); 579 std::unique_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids));
579 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack))); 580 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack)));
580 WaitForMCSEvent(); 581 WaitForMCSEvent();
581 PumpLoop(); 582 PumpLoop();
582 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 583 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
583 } 584 }
584 585
585 // Handle a selective ack that only acks some messages. The remaining unacked 586 // Handle a selective ack that only acks some messages. The remaining unacked
586 // messages should be resent. On restart, those same unacked messages should be 587 // messages should be resent. On restart, those same unacked messages should be
587 // resent, and any pending acks for incoming messages should also be resent. 588 // resent, and any pending acks for incoming messages should also be resent.
588 TEST_F(MCSClientTest, SelectiveAckMidStream) { 589 TEST_F(MCSClientTest, SelectiveAckMidStream) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 632
632 // Simulate the last message being dropped by having the server selectively 633 // Simulate the last message being dropped by having the server selectively
633 // ack client message "1". 634 // ack client message "1".
634 // Client message "2" should be resent, acking server stream id 4 (selective 635 // Client message "2" should be resent, acking server stream id 4 (selective
635 // ack). 636 // ack).
636 MCSMessage cMessage3(BuildDataMessage("from", "category", "Y", 4, "2", 637 MCSMessage cMessage3(BuildDataMessage("from", "category", "Y", 4, "2",
637 kTTLValue, 1, 0, "", 0, 638 kTTLValue, 1, 0, "", 0,
638 IMMEDIATE_ACK_NO)); 639 IMMEDIATE_ACK_NO));
639 GetFakeHandler()->ExpectOutgoingMessage(cMessage3); 640 GetFakeHandler()->ExpectOutgoingMessage(cMessage3);
640 std::vector<std::string> acked_ids(1, "1"); 641 std::vector<std::string> acked_ids(1, "1");
641 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids)); 642 std::unique_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids));
642 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack))); 643 GetFakeHandler()->ReceiveMessage(MCSMessage(kIqStanzaTag, std::move(ack)));
643 WaitForMCSEvent(); 644 WaitForMCSEvent();
644 PumpLoop(); 645 PumpLoop();
645 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 646 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
646 647
647 // Rebuild the client without any further acks from server. Note that this 648 // Rebuild the client without any further acks from server. Note that this
648 // resets the stream ids. 649 // resets the stream ids.
649 // Sever message "s2" should be acked as part of login. 650 // Sever message "s2" should be acked as part of login.
650 // Client message "2" should be resent. 651 // Client message "2" should be resent.
651 StoreCredentials(); 652 StoreCredentials();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 } 718 }
718 719
719 // Receive the ack limit in messages, which should trigger an automatic 720 // Receive the ack limit in messages, which should trigger an automatic
720 // stream ack. Receive a heartbeat to confirm the ack. 721 // stream ack. Receive a heartbeat to confirm the ack.
721 TEST_F(MCSClientTest, AckWhenLimitReachedWithHeartbeat) { 722 TEST_F(MCSClientTest, AckWhenLimitReachedWithHeartbeat) {
722 BuildMCSClient(); 723 BuildMCSClient();
723 InitializeClient(); 724 InitializeClient();
724 LoginClient(std::vector<std::string>()); 725 LoginClient(std::vector<std::string>());
725 726
726 // The stream ack. 727 // The stream ack.
727 scoped_ptr<mcs_proto::IqStanza> ack = BuildStreamAck(); 728 std::unique_ptr<mcs_proto::IqStanza> ack = BuildStreamAck();
728 ack->set_last_stream_id_received(kAckLimitSize + 1); 729 ack->set_last_stream_id_received(kAckLimitSize + 1);
729 GetFakeHandler()->ExpectOutgoingMessage( 730 GetFakeHandler()->ExpectOutgoingMessage(
730 MCSMessage(kIqStanzaTag, std::move(ack))); 731 MCSMessage(kIqStanzaTag, std::move(ack)));
731 732
732 // Receive some messages. 733 // Receive some messages.
733 std::vector<std::string> id_list; 734 std::vector<std::string> id_list;
734 for (int i = 1; i <= kAckLimitSize; ++i) { 735 for (int i = 1; i <= kAckLimitSize; ++i) {
735 id_list.push_back(base::IntToString(i)); 736 id_list.push_back(base::IntToString(i));
736 MCSMessage message(BuildDataMessage("from", "category", id_list.back(), 1, 737 MCSMessage message(BuildDataMessage("from", "category", id_list.back(), 1,
737 id_list.back(), kTTLValue, 1, 0, "", 0, 738 id_list.back(), kTTLValue, 1, 0, "", 0,
738 IMMEDIATE_ACK_NO)); 739 IMMEDIATE_ACK_NO));
739 GetFakeHandler()->ReceiveMessage(message); 740 GetFakeHandler()->ReceiveMessage(message);
740 WaitForMCSEvent(); 741 WaitForMCSEvent();
741 PumpLoop(); 742 PumpLoop();
742 } 743 }
743 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 744 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
744 745
745 // Receive a heartbeat confirming the ack (and receive the heartbeat ack). 746 // Receive a heartbeat confirming the ack (and receive the heartbeat ack).
746 scoped_ptr<mcs_proto::HeartbeatPing> heartbeat( 747 std::unique_ptr<mcs_proto::HeartbeatPing> heartbeat(
747 new mcs_proto::HeartbeatPing()); 748 new mcs_proto::HeartbeatPing());
748 heartbeat->set_last_stream_id_received(2); 749 heartbeat->set_last_stream_id_received(2);
749 750
750 scoped_ptr<mcs_proto::HeartbeatAck> heartbeat_ack( 751 std::unique_ptr<mcs_proto::HeartbeatAck> heartbeat_ack(
751 new mcs_proto::HeartbeatAck()); 752 new mcs_proto::HeartbeatAck());
752 heartbeat_ack->set_last_stream_id_received(kAckLimitSize + 2); 753 heartbeat_ack->set_last_stream_id_received(kAckLimitSize + 2);
753 GetFakeHandler()->ExpectOutgoingMessage( 754 GetFakeHandler()->ExpectOutgoingMessage(
754 MCSMessage(kHeartbeatAckTag, std::move(heartbeat_ack))); 755 MCSMessage(kHeartbeatAckTag, std::move(heartbeat_ack)));
755 756
756 GetFakeHandler()->ReceiveMessage( 757 GetFakeHandler()->ReceiveMessage(
757 MCSMessage(kHeartbeatPingTag, std::move(heartbeat))); 758 MCSMessage(kHeartbeatPingTag, std::move(heartbeat)));
758 PumpLoop(); 759 PumpLoop();
759 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 760 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
760 761
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 } 1148 }
1148 1149
1149 // Receive a message with immediate ack request, which should trigger an 1150 // Receive a message with immediate ack request, which should trigger an
1150 // automatic stream ack. 1151 // automatic stream ack.
1151 TEST_F(MCSClientTest, AckWhenImmediateAckRequested) { 1152 TEST_F(MCSClientTest, AckWhenImmediateAckRequested) {
1152 BuildMCSClient(); 1153 BuildMCSClient();
1153 InitializeClient(); 1154 InitializeClient();
1154 LoginClient(std::vector<std::string>()); 1155 LoginClient(std::vector<std::string>());
1155 1156
1156 // The stream ack. 1157 // The stream ack.
1157 scoped_ptr<mcs_proto::IqStanza> ack = BuildStreamAck(); 1158 std::unique_ptr<mcs_proto::IqStanza> ack = BuildStreamAck();
1158 ack->set_last_stream_id_received(kAckLimitSize - 1); 1159 ack->set_last_stream_id_received(kAckLimitSize - 1);
1159 GetFakeHandler()->ExpectOutgoingMessage( 1160 GetFakeHandler()->ExpectOutgoingMessage(
1160 MCSMessage(kIqStanzaTag, std::move(ack))); 1161 MCSMessage(kIqStanzaTag, std::move(ack)));
1161 1162
1162 // Receive some messages. 1163 // Receive some messages.
1163 for (int i = 1; i < kAckLimitSize - 2; ++i) { 1164 for (int i = 1; i < kAckLimitSize - 2; ++i) {
1164 std::string id(base::IntToString(i)); 1165 std::string id(base::IntToString(i));
1165 MCSMessage message(BuildDataMessage("from", "category", id, 1, id, 1166 MCSMessage message(BuildDataMessage("from", "category", id, 1, id,
1166 kTTLValue, 1, 0, "", 0, 1167 kTTLValue, 1, 0, "", 0,
1167 IMMEDIATE_ACK_NO)); 1168 IMMEDIATE_ACK_NO));
(...skipping 11 matching lines...) Expand all
1179 GetFakeHandler()->ReceiveMessage(message); 1180 GetFakeHandler()->ReceiveMessage(message);
1180 WaitForMCSEvent(); 1181 WaitForMCSEvent();
1181 PumpLoop(); 1182 PumpLoop();
1182 1183
1183 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); 1184 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
1184 } 1185 }
1185 1186
1186 } // namespace 1187 } // namespace
1187 1188
1188 } // namespace gcm 1189 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698