Chromium Code Reviews| Index: blimp/net/blob_channel/helium_blob_channel_unittest.cc |
| diff --git a/blimp/net/blob_channel/helium_blob_channel_unittest.cc b/blimp/net/blob_channel/helium_blob_channel_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3e5885c0a6425569a69c148c50906b1593723e43 |
| --- /dev/null |
| +++ b/blimp/net/blob_channel/helium_blob_channel_unittest.cc |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <memory> |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "blimp/common/blob_cache/id_util.h" |
| +#include "blimp/common/blob_cache/test_util.h" |
| +#include "blimp/net/blob_channel/helium_blob_receiver_delegate.h" |
| +#include "blimp/net/blob_channel/helium_blob_sender_delegate.h" |
| +#include "blimp/net/blob_channel/mock_blob_channel_receiver.h" |
| +#include "blimp/net/test_common.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blimp { |
| +namespace { |
| + |
| +using testing::_; |
| +using testing::SaveArg; |
| + |
| +const char kBlobId[] = "foo1"; |
| +const char kBlobPayload[] = "bar1"; |
| + |
| +// Proxies ProcessMessage calls to an un-ownedBlimpMessageProcessor* raw |
| +// pointer. Can be used to adapt unique_ptr calls to raw pointer calls. |
| +class BlimpMessageProxy : public BlimpMessageProcessor { |
| + public: |
| + explicit BlimpMessageProxy(BlimpMessageProcessor* sink) : sink_(sink) {} |
| + ~BlimpMessageProxy() override {} |
| + |
| + private: |
| + // BlimpMessageProcessor implementation. |
| + void ProcessMessage(std::unique_ptr<BlimpMessage> message, |
| + const net::CompletionCallback& callback) override { |
| + sink_->ProcessMessage(std::move(message), callback); |
| + } |
| + |
| + BlimpMessageProcessor* sink_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BlimpMessageProxy); |
| +}; |
| + |
| +class HeliumBlobChannelTest : public testing::Test { |
|
haibinlu
2016/05/12 18:20:09
why prefix it with "helium"?
Kevin M
2016/05/13 18:40:24
These tests are Helium-specific; they're not gener
|
| + public: |
| + HeliumBlobChannelTest() { receiver_delegate_.SetReceiver(&mock_receiver_); } |
| + |
| + ~HeliumBlobChannelTest() override {} |
| + |
| + protected: |
| + const std::string blob_id_ = CalculateBlobId(kBlobId); |
| + |
| + MockBlobChannelReceiver mock_receiver_; |
| + HeliumBlobReceiverDelegate receiver_delegate_; |
|
haibinlu
2016/05/12 18:20:09
Can this be a unique_ptr so that BlimpMessageProx
Kevin M
2016/05/13 18:40:24
The receiver takes delegates as unique_ptrs, so th
|
| + HeliumBlobSenderDelegate sender_delegate_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(HeliumBlobChannelTest); |
| +}; |
| + |
| +// Verifies the content of BlimpMessages generated by the Sender. |
| +TEST_F(HeliumBlobChannelTest, TransferBlobContents) { |
| + BlimpMessage captured_msg; |
| + MockBlimpMessageProcessor* mock_processor = new MockBlimpMessageProcessor; |
| + EXPECT_CALL(*mock_processor, MockableProcessMessage(_, _)) |
| + .WillOnce(SaveArg<0>(&captured_msg)); |
| + sender_delegate_.set_outgoing_message_processor( |
| + base::WrapUnique(mock_processor)); |
| + |
| + sender_delegate_.DeliverBlob(blob_id_, CreateBlobDataPtr(kBlobPayload)); |
| + |
| + EXPECT_EQ(BlimpMessage::BLOB_CHANNEL, captured_msg.type()); |
| + EXPECT_EQ(BlobChannelMessage::TRANSFER_BLOB, |
| + captured_msg.blob_channel().type()); |
| + EXPECT_EQ(blob_id_, captured_msg.blob_channel().blob_id()); |
| + EXPECT_EQ(kBlobPayload, captured_msg.blob_channel().payload()); |
| +} |
| + |
| +// Verifies that the Receiver understands messages sent by the Sender. |
| +TEST_F(HeliumBlobChannelTest, TransferBlobCompatibility) { |
| + EXPECT_CALL(mock_receiver_, |
| + OnBlobReceived(blob_id_, BlobDataPtrEqualsString(kBlobPayload))); |
| + sender_delegate_.set_outgoing_message_processor( |
| + base::WrapUnique(new BlimpMessageProxy(&receiver_delegate_))); |
| + sender_delegate_.DeliverBlob(blob_id_, CreateBlobDataPtr(kBlobPayload)); |
| +} |
| + |
| +} // namespace |
| +} // namespace blimp |