Chromium Code Reviews| Index: blimp/net/blob_channel/blob_channel_integration_test.cc |
| diff --git a/blimp/net/blob_channel/blob_channel_integration_test.cc b/blimp/net/blob_channel/blob_channel_integration_test.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8aac918cd809aea77716b5f5698f5a8dfdd57ebc |
| --- /dev/null |
| +++ b/blimp/net/blob_channel/blob_channel_integration_test.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/in_memory_blob_cache.h" |
| +#include "blimp/common/blob_cache/test_util.h" |
| +#include "blimp/net/blob_channel/blob_channel_receiver.h" |
| +#include "blimp/net/blob_channel/blob_channel_sender.h" |
| +#include "blimp/net/test_common.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blimp { |
| +namespace { |
| + |
| +using testing::_; |
| +using testing::SaveArg; |
| + |
| +const char kBlobId[] = "foo1"; |
| +const char kBlobPayload[] = "bar1"; |
| + |
| +// Routes sender delegate calls to a receiver delegate object. |
| +// The caller is responsible for ensuring that the receiver delegate is deleted |
| +// after |this| is deleted. |
| +class SenderDelegateProxy : public BlobChannelSender::Delegate { |
| + public: |
| + SenderDelegateProxy() {} |
| + ~SenderDelegateProxy() override {} |
| + |
| + // Returns a receiver object that will receive proxied calls sent to |this|. |
| + std::unique_ptr<BlobChannelReceiver::Delegate> GetReceiverDelegate() { |
| + DCHECK(!receiver_); |
| + receiver_ = new ReceiverDelegate; |
| + return base::WrapUnique(receiver_); |
| + } |
| + |
| + private: |
| + class ReceiverDelegate : public BlobChannelReceiver::Delegate { |
| + public: |
| + using BlobChannelReceiver::Delegate::OnBlobReceived; |
| + }; |
| + |
| + // BlobChannelSender implementation. |
| + void DeliverBlob(const BlobId& id, BlobDataPtr data) override { |
| + receiver_->OnBlobReceived(id, data); |
|
haibinlu
2016/05/10 00:18:38
PostTask to simulate async nature of sender and re
Kevin M
2016/05/10 00:54:23
Done.
|
| + } |
| + |
| + ReceiverDelegate* receiver_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SenderDelegateProxy); |
| +}; |
| + |
| +// Verifies compatibility between the sender and receiver, independent of |
| +// transport-level implementation details. |
| +class BlobChannelIntegrationTest : public testing::Test { |
| + public: |
| + BlobChannelIntegrationTest() { |
| + std::unique_ptr<SenderDelegateProxy> sender_delegate( |
| + new SenderDelegateProxy); |
| + receiver_.reset( |
| + new BlobChannelReceiver(base::WrapUnique(new InMemoryBlobCache), |
| + sender_delegate->GetReceiverDelegate())); |
| + sender_.reset(new BlobChannelSender(base::WrapUnique(new InMemoryBlobCache), |
| + std::move(sender_delegate))); |
| + } |
| + |
| + ~BlobChannelIntegrationTest() override {} |
| + |
| + protected: |
| + std::unique_ptr<BlobChannelReceiver> receiver_; |
| + std::unique_ptr<BlobChannelSender> sender_; |
| +}; |
| + |
| +TEST_F(BlobChannelIntegrationTest, Deliver) { |
| + const std::string blob_id = CalculateBlobId(kBlobId); |
| + |
| + EXPECT_EQ(nullptr, receiver_->Get(blob_id).get()); |
| + sender_->PutBlob(blob_id, CreateBlobDataPtr(kBlobPayload)); |
| + EXPECT_EQ(nullptr, receiver_->Get(blob_id).get()); |
| + |
| + EXPECT_EQ(nullptr, receiver_->Get(blob_id).get()); |
| + sender_->DeliverBlob(blob_id); |
| + EXPECT_EQ(kBlobPayload, receiver_->Get(blob_id)->data); |
| +} |
| + |
| +} // namespace |
| +} // namespace blimp |