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 // Receive some messages. Send some messages. Receive a selective acknowledging | |
552 // the sent messages. Restart. No messages should be resent, and no messages | |
553 // should be acked by the client, as the server acknowledged the stream ack. | |
554 TEST_F(MCSClientTest, SelectiveAckMidStream) { | |
555 BuildMCSClient(); | |
556 InitializeClient(); | |
557 LoginClient(std::vector<std::string>()); | |
558 | |
559 // Server stream id 2. Acknowledges client stream id 0 (login). | |
560 MCSMessage sMessage1(BuildDataMessage( | |
561 "from", "category", "X", 0, "s1", kTTLValue, 1, 0, "", 0)); | |
562 GetFakeHandler()->ReceiveMessage(sMessage1); | |
563 WaitForMCSEvent(); | |
564 PumpLoop(); | |
565 | |
566 // Client stream id 1. Acknowledges server stream id 2. | |
567 MCSMessage cMessage1(BuildDataMessage( | |
568 "from", "category", "Y", 2, "1", kTTLValue, 1, 0, "", 0)); | |
569 GetFakeHandler()->ExpectOutgoingMessage(cMessage1); | |
570 mcs_client()->SendMessage(cMessage1); | |
571 PumpLoop(); | |
572 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | |
573 | |
574 // Server stream id 3. Acknowledges client stream id 1, and ack of server | |
575 // stream id 2. | |
576 MCSMessage sMessage2(BuildDataMessage( | |
577 "from", "category", "X", 1, "s2", kTTLValue, 1, 0, "", 0)); | |
578 GetFakeHandler()->ReceiveMessage(sMessage2); | |
579 WaitForMCSEvent(); | |
580 PumpLoop(); | |
581 | |
582 // Client Stream id 2. Acknowledges server id 3. | |
583 MCSMessage cMessage2(BuildDataMessage( | |
584 "from", "category", "Y", 3, "2", kTTLValue, 1, 0, "", 0)); | |
585 GetFakeHandler()->ExpectOutgoingMessage(cMessage2); | |
586 mcs_client()->SendMessage(cMessage2); | |
587 PumpLoop(); | |
588 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | |
589 | |
590 // Receive an acknowledgment for the client message 1. Should also ack | |
591 // the ack for the server message 2, but not server message. | |
fgorski
2014/07/14 20:59:35
Please use the ids of messages consistently, and p
Nicolas Zea
2014/07/14 21:16:18
Done.
| |
592 // Message "2" should also be resent, acking stream id 4. | |
593 MCSMessage cMessage3(BuildDataMessage( | |
594 "from", "category", "Y", 4, "2", kTTLValue, 1, 0, "", 0)); | |
595 GetFakeHandler()->ExpectOutgoingMessage(cMessage3); | |
596 std::vector<std::string> acked_ids(1, "1"); | |
597 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids)); | |
598 GetFakeHandler()->ReceiveMessage( | |
599 MCSMessage(kIqStanzaTag, | |
600 ack.PassAs<const google::protobuf::MessageLite>())); | |
601 WaitForMCSEvent(); | |
602 PumpLoop(); | |
603 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | |
604 | |
605 // Rebuild the client. Message "20" should be acked as part of login, | |
fgorski
2014/07/14 20:59:35
what do you mean by "20"?
Nicolas Zea
2014/07/14 21:16:18
Oops, typo. Fixed.
| |
606 // and message "2" should be resent. | |
607 StoreCredentials(); | |
608 BuildMCSClient(); | |
609 InitializeClient(); | |
610 | |
611 acked_ids[0] = "s2"; | |
612 LoginClient(acked_ids); | |
613 | |
614 MCSMessage cMessage4(BuildDataMessage( | |
615 "from", "category", "Y", 1, "2", kTTLValue, 1, 0, "", 0)); | |
616 GetFakeHandler()->ExpectOutgoingMessage(cMessage4); | |
617 PumpLoop(); | |
618 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | |
619 } | |
620 | |
551 // Receive some messages. On restart, the login request should contain the | 621 // Receive some messages. On restart, the login request should contain the |
552 // appropriate acknowledged ids. | 622 // appropriate acknowledged ids. |
553 TEST_F(MCSClientTest, AckOnLogin) { | 623 TEST_F(MCSClientTest, AckOnLogin) { |
554 BuildMCSClient(); | 624 BuildMCSClient(); |
555 InitializeClient(); | 625 InitializeClient(); |
556 LoginClient(std::vector<std::string>()); | 626 LoginClient(std::vector<std::string>()); |
557 | 627 |
558 // Receive some messages. | 628 // Receive some messages. |
559 std::vector<std::string> id_list; | 629 std::vector<std::string> id_list; |
560 for (int i = 1; i <= kMessageBatchSize; ++i) { | 630 for (int i = 1; i <= kMessageBatchSize; ++i) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 | 860 |
791 LoginClient(std::vector<std::string>()); | 861 LoginClient(std::vector<std::string>()); |
792 GetFakeHandler()->ExpectOutgoingMessage(message); | 862 GetFakeHandler()->ExpectOutgoingMessage(message); |
793 GetFakeHandler()->ExpectOutgoingMessage(message2); | 863 GetFakeHandler()->ExpectOutgoingMessage(message2); |
794 PumpLoop(); | 864 PumpLoop(); |
795 } | 865 } |
796 | 866 |
797 } // namespace | 867 } // namespace |
798 | 868 |
799 } // namespace gcm | 869 } // namespace gcm |
OLD | NEW |