OLD | NEW |
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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 541 } |
542 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids)); | 542 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids)); |
543 GetFakeHandler()->ReceiveMessage( | 543 GetFakeHandler()->ReceiveMessage( |
544 MCSMessage(kIqStanzaTag, | 544 MCSMessage(kIqStanzaTag, |
545 ack.PassAs<const google::protobuf::MessageLite>())); | 545 ack.PassAs<const google::protobuf::MessageLite>())); |
546 WaitForMCSEvent(); | 546 WaitForMCSEvent(); |
547 PumpLoop(); | 547 PumpLoop(); |
548 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | 548 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); |
549 } | 549 } |
550 | 550 |
| 551 // Handle a selective ack that only acks some messages. The remaining unacked |
| 552 // messages should be resent. On restart, those same unacked messages should be |
| 553 // resent, and any pending acks for incoming messages should also be resent. |
| 554 TEST_F(MCSClientTest, SelectiveAckMidStream) { |
| 555 BuildMCSClient(); |
| 556 InitializeClient(); |
| 557 LoginClient(std::vector<std::string>()); |
| 558 |
| 559 // Server stream id 2 ("s1"). |
| 560 // Acks client stream id 0 (login). |
| 561 MCSMessage sMessage1(BuildDataMessage( |
| 562 "from", "category", "X", 0, "s1", kTTLValue, 1, 0, "", 0)); |
| 563 GetFakeHandler()->ReceiveMessage(sMessage1); |
| 564 WaitForMCSEvent(); |
| 565 PumpLoop(); |
| 566 |
| 567 // Client stream id 1 ("1"). |
| 568 // Acks server stream id 2 ("s1"). |
| 569 MCSMessage cMessage1(BuildDataMessage( |
| 570 "from", "category", "Y", 2, "1", kTTLValue, 1, 0, "", 0)); |
| 571 GetFakeHandler()->ExpectOutgoingMessage(cMessage1); |
| 572 mcs_client()->SendMessage(cMessage1); |
| 573 PumpLoop(); |
| 574 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); |
| 575 |
| 576 // Server stream id 3 ("s2"). |
| 577 // Acks client stream id 1 ("1"). |
| 578 // Confirms ack of server stream id 2 ("s1"). |
| 579 MCSMessage sMessage2(BuildDataMessage( |
| 580 "from", "category", "X", 1, "s2", kTTLValue, 1, 0, "", 0)); |
| 581 GetFakeHandler()->ReceiveMessage(sMessage2); |
| 582 WaitForMCSEvent(); |
| 583 PumpLoop(); |
| 584 |
| 585 // Client Stream id 2 ("2"). |
| 586 // Acks server stream id 3 ("s2"). |
| 587 MCSMessage cMessage2(BuildDataMessage( |
| 588 "from", "category", "Y", 3, "2", kTTLValue, 1, 0, "", 0)); |
| 589 GetFakeHandler()->ExpectOutgoingMessage(cMessage2); |
| 590 mcs_client()->SendMessage(cMessage2); |
| 591 PumpLoop(); |
| 592 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); |
| 593 |
| 594 // Simulate the last message being dropped by having the server selectively |
| 595 // ack client message "1". |
| 596 // Client message "2" should be resent, acking server stream id 4 (selective |
| 597 // ack). |
| 598 MCSMessage cMessage3(BuildDataMessage( |
| 599 "from", "category", "Y", 4, "2", kTTLValue, 1, 0, "", 0)); |
| 600 GetFakeHandler()->ExpectOutgoingMessage(cMessage3); |
| 601 std::vector<std::string> acked_ids(1, "1"); |
| 602 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids)); |
| 603 GetFakeHandler()->ReceiveMessage( |
| 604 MCSMessage(kIqStanzaTag, |
| 605 ack.PassAs<const google::protobuf::MessageLite>())); |
| 606 WaitForMCSEvent(); |
| 607 PumpLoop(); |
| 608 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); |
| 609 |
| 610 // Rebuild the client without any further acks from server. Note that this |
| 611 // resets the stream ids. |
| 612 // Sever message "s2" should be acked as part of login. |
| 613 // Client message "2" should be resent. |
| 614 StoreCredentials(); |
| 615 BuildMCSClient(); |
| 616 InitializeClient(); |
| 617 |
| 618 acked_ids[0] = "s2"; |
| 619 LoginClient(acked_ids); |
| 620 |
| 621 MCSMessage cMessage4(BuildDataMessage( |
| 622 "from", "category", "Y", 1, "2", kTTLValue, 1, 0, "", 0)); |
| 623 GetFakeHandler()->ExpectOutgoingMessage(cMessage4); |
| 624 PumpLoop(); |
| 625 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); |
| 626 } |
| 627 |
551 // Receive some messages. On restart, the login request should contain the | 628 // Receive some messages. On restart, the login request should contain the |
552 // appropriate acknowledged ids. | 629 // appropriate acknowledged ids. |
553 TEST_F(MCSClientTest, AckOnLogin) { | 630 TEST_F(MCSClientTest, AckOnLogin) { |
554 BuildMCSClient(); | 631 BuildMCSClient(); |
555 InitializeClient(); | 632 InitializeClient(); |
556 LoginClient(std::vector<std::string>()); | 633 LoginClient(std::vector<std::string>()); |
557 | 634 |
558 // Receive some messages. | 635 // Receive some messages. |
559 std::vector<std::string> id_list; | 636 std::vector<std::string> id_list; |
560 for (int i = 1; i <= kMessageBatchSize; ++i) { | 637 for (int i = 1; i <= kMessageBatchSize; ++i) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 | 867 |
791 LoginClient(std::vector<std::string>()); | 868 LoginClient(std::vector<std::string>()); |
792 GetFakeHandler()->ExpectOutgoingMessage(message); | 869 GetFakeHandler()->ExpectOutgoingMessage(message); |
793 GetFakeHandler()->ExpectOutgoingMessage(message2); | 870 GetFakeHandler()->ExpectOutgoingMessage(message2); |
794 PumpLoop(); | 871 PumpLoop(); |
795 } | 872 } |
796 | 873 |
797 } // namespace | 874 } // namespace |
798 | 875 |
799 } // namespace gcm | 876 } // namespace gcm |
OLD | NEW |