Chromium Code Reviews| 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 // Proxies ProcessMessage calls to an un-ownedBlimpMessageProcessor* raw | |
|
Wez
2016/05/20 21:46:17
nit: Missing some whitespace?
Kevin M
2016/05/23 20:48:07
Done.
| |
| 27 // pointer. Allows the Receiver to own a BlimpMessageProcessor instance with | |
| 28 // the underlying message processor object living elsewhere. | |
|
Wez
2016/05/20 21:46:17
In other tests we handle this by allocating the ob
Kevin M
2016/05/23 20:48:07
Um, derp, don't know why I went down this path. Do
| |
| 29 class BlimpMessageProxy : public BlimpMessageProcessor { | |
| 30 public: | |
| 31 explicit BlimpMessageProxy(BlimpMessageProcessor* sink) : sink_(sink) {} | |
| 32 ~BlimpMessageProxy() override {} | |
| 33 | |
| 34 private: | |
| 35 // BlimpMessageProcessor implementation. | |
| 36 void ProcessMessage(std::unique_ptr<BlimpMessage> message, | |
| 37 const net::CompletionCallback& callback) override { | |
| 38 sink_->ProcessMessage(std::move(message), callback); | |
| 39 } | |
| 40 | |
| 41 BlimpMessageProcessor* sink_ = nullptr; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(BlimpMessageProxy); | |
| 44 }; | |
| 45 | |
| 46 class HeliumBlobChannelTest : public testing::Test { | |
| 47 public: | |
| 48 HeliumBlobChannelTest() { receiver_delegate_.SetReceiver(&mock_receiver_); } | |
| 49 | |
| 50 ~HeliumBlobChannelTest() override {} | |
| 51 | |
| 52 protected: | |
| 53 const std::string blob_id_ = CalculateBlobId(kBlobId); | |
| 54 | |
| 55 MockBlobChannelReceiver mock_receiver_; | |
| 56 HeliumBlobReceiverDelegate receiver_delegate_; | |
| 57 HeliumBlobSenderDelegate sender_delegate_; | |
| 58 | |
| 59 private: | |
| 60 DISALLOW_COPY_AND_ASSIGN(HeliumBlobChannelTest); | |
| 61 }; | |
| 62 | |
| 63 // Verifies the content of BlimpMessages generated by the Sender. | |
| 64 TEST_F(HeliumBlobChannelTest, TransferBlobContents) { | |
| 65 BlimpMessage captured_msg; | |
| 66 MockBlimpMessageProcessor* mock_processor = new MockBlimpMessageProcessor; | |
| 67 EXPECT_CALL(*mock_processor, MockableProcessMessage(_, _)) | |
| 68 .WillOnce(SaveArg<0>(&captured_msg)); | |
| 69 sender_delegate_.set_outgoing_message_processor( | |
| 70 base::WrapUnique(mock_processor)); | |
| 71 | |
| 72 sender_delegate_.DeliverBlob(blob_id_, CreateBlobDataPtr(kBlobPayload)); | |
| 73 | |
| 74 EXPECT_EQ(BlimpMessage::BLOB_CHANNEL, captured_msg.type()); | |
| 75 EXPECT_EQ(BlobChannelMessage::TRANSFER_BLOB, | |
| 76 captured_msg.blob_channel().type()); | |
| 77 EXPECT_EQ(blob_id_, captured_msg.blob_channel().blob_id()); | |
| 78 EXPECT_EQ(kBlobPayload, captured_msg.blob_channel().payload()); | |
| 79 } | |
| 80 | |
| 81 // Verifies that the Receiver understands messages sent by the Sender. | |
|
Wez
2016/05/20 21:46:17
Rather than having this be helium_blob_channel_uni
Kevin M
2016/05/23 20:48:07
Will do this in a followup patch.
Wez
2016/05/24 01:18:40
Acknowledged.
| |
| 82 TEST_F(HeliumBlobChannelTest, TransferBlobCompatibility) { | |
| 83 EXPECT_CALL(mock_receiver_, | |
| 84 OnBlobReceived(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); | |
| 85 sender_delegate_.set_outgoing_message_processor( | |
| 86 base::WrapUnique(new BlimpMessageProxy(&receiver_delegate_))); | |
| 87 sender_delegate_.DeliverBlob(blob_id_, CreateBlobDataPtr(kBlobPayload)); | |
| 88 } | |
| 89 | |
| 90 } // namespace | |
| 91 } // namespace blimp | |
| OLD | NEW |