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..f6dd3e9c089f4e6e54e277839e56340341252cab |
--- /dev/null |
+++ b/blimp/net/blob_channel/helium_blob_channel_unittest.cc |
@@ -0,0 +1,91 @@ |
+// 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 |
Wez
2016/05/20 21:46:17
nit: Missing some whitespace?
Kevin M
2016/05/23 20:48:07
Done.
|
+// pointer. Allows the Receiver to own a BlimpMessageProcessor instance with |
+// 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
|
+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 { |
+ public: |
+ HeliumBlobChannelTest() { receiver_delegate_.SetReceiver(&mock_receiver_); } |
+ |
+ ~HeliumBlobChannelTest() override {} |
+ |
+ protected: |
+ const std::string blob_id_ = CalculateBlobId(kBlobId); |
+ |
+ MockBlobChannelReceiver mock_receiver_; |
+ HeliumBlobReceiverDelegate receiver_delegate_; |
+ 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. |
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.
|
+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 |