OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <memory> |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "blimp/common/blob_cache/id_util.h" |
| 9 #include "blimp/common/blob_cache/test_util.h" |
| 10 #include "blimp/net/blob_channel/helium_blob_receiver_delegate.h" |
| 11 #include "blimp/net/blob_channel/helium_blob_sender_delegate.h" |
| 12 #include "blimp/net/blob_channel/mock_blob_channel_receiver.h" |
| 13 #include "blimp/net/test_common.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 namespace blimp { |
| 18 namespace { |
| 19 |
| 20 using testing::_; |
| 21 using testing::SaveArg; |
| 22 |
| 23 const char kBlobId[] = "foo1"; |
| 24 const char kBlobPayload[] = "bar1"; |
| 25 |
| 26 class HeliumBlobChannelTest : public testing::Test { |
| 27 public: |
| 28 HeliumBlobChannelTest() : receiver_delegate_(new HeliumBlobReceiverDelegate) { |
| 29 receiver_delegate_->SetReceiver(&mock_receiver_); |
| 30 sender_delegate_.set_outgoing_message_processor( |
| 31 base::WrapUnique(receiver_delegate_)); |
| 32 } |
| 33 |
| 34 ~HeliumBlobChannelTest() override {} |
| 35 |
| 36 protected: |
| 37 const std::string blob_id_ = CalculateBlobId(kBlobId); |
| 38 |
| 39 MockBlobChannelReceiver mock_receiver_; |
| 40 HeliumBlobReceiverDelegate* receiver_delegate_; |
| 41 HeliumBlobSenderDelegate sender_delegate_; |
| 42 |
| 43 private: |
| 44 DISALLOW_COPY_AND_ASSIGN(HeliumBlobChannelTest); |
| 45 }; |
| 46 |
| 47 // Verifies the content of BlimpMessages generated by the Sender. |
| 48 TEST_F(HeliumBlobChannelTest, TransferBlobContents) { |
| 49 BlimpMessage captured_msg; |
| 50 MockBlimpMessageProcessor* mock_processor = new MockBlimpMessageProcessor; |
| 51 EXPECT_CALL(*mock_processor, MockableProcessMessage(_, _)) |
| 52 .WillOnce(SaveArg<0>(&captured_msg)); |
| 53 sender_delegate_.set_outgoing_message_processor( |
| 54 base::WrapUnique(mock_processor)); |
| 55 |
| 56 sender_delegate_.DeliverBlob(blob_id_, CreateBlobDataPtr(kBlobPayload)); |
| 57 |
| 58 EXPECT_EQ(BlobChannelMessage::TypeCase::kTransferBlob, |
| 59 captured_msg.blob_channel().type_case()); |
| 60 EXPECT_EQ(blob_id_, captured_msg.blob_channel().transfer_blob().blob_id()); |
| 61 EXPECT_EQ(kBlobPayload, |
| 62 captured_msg.blob_channel().transfer_blob().payload()); |
| 63 } |
| 64 |
| 65 // Verifies that the Receiver understands messages sent by the Sender. |
| 66 TEST_F(HeliumBlobChannelTest, TransferBlobCompatibility) { |
| 67 EXPECT_CALL(mock_receiver_, |
| 68 OnBlobReceived(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); |
| 69 sender_delegate_.DeliverBlob(blob_id_, CreateBlobDataPtr(kBlobPayload)); |
| 70 } |
| 71 |
| 72 } // namespace |
| 73 } // namespace blimp |
OLD | NEW |