Chromium Code Reviews| Index: blimp/net/blob_channel/blob_channel_receiver_unittest.cc |
| diff --git a/blimp/net/blob_channel/blob_channel_receiver_unittest.cc b/blimp/net/blob_channel/blob_channel_receiver_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d52ccc19ecf11a4374e4517f5e589577e16a336e |
| --- /dev/null |
| +++ b/blimp/net/blob_channel/blob_channel_receiver_unittest.cc |
| @@ -0,0 +1,87 @@ |
| +// 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 <algorithm> |
| +#include <memory> |
| +#include <string> |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "blimp/common/blob_cache/mock_blob_cache.h" |
| +#include "blimp/net/blob_channel/blob_channel_receiver.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blimp { |
| +namespace { |
| + |
| +using testing::_; |
| +using testing::Return; |
| + |
| +const char kBlobId1[] = "blob-1"; |
|
Wez
2016/05/03 21:32:20
nit: Can this and the payload just be kBlobId and
Kevin M
2016/05/03 22:29:42
Done.
|
| +const char kBlobPayload1[] = "blob-1-payload"; |
| + |
| +// Helper function for creating a cache payload vector from a string. |
| +BlobDataPtr CreatePayload(const std::string& input) { |
| + return BlobDataPtr(new BlobData(input)); |
| +} |
| + |
| +MATCHER_P(BlobDataEqual, expected, "") { |
| + return expected->data == arg->data; |
| +} |
| + |
| +class NullBlobReceiverDelegate : public BlobChannelReceiver::Delegate { |
| + public: |
| + using BlobChannelReceiver::Delegate::OnBlobReceived; |
| +}; |
| + |
| +class BlobChannelReceiverTest : public testing::Test { |
| + public: |
| + BlobChannelReceiverTest() |
| + : delegate_(new NullBlobReceiverDelegate), |
| + cache_(new testing::StrictMock<MockBlobCache>), |
| + blob_receiver_(new BlobChannelReceiver(base::WrapUnique(cache_), |
| + base::WrapUnique(delegate_))) |
| + |
| + {} |
| + |
| + ~BlobChannelReceiverTest() override {} |
| + |
| + NullBlobReceiverDelegate* delegate_; |
| + testing::StrictMock<MockBlobCache>* cache_; |
| + std::unique_ptr<BlobChannelReceiver> blob_receiver_; |
| +}; |
| + |
| +TEST_F(BlobChannelReceiverTest, GetKnownBlob) { |
| + auto payload = CreatePayload(kBlobPayload1); |
| + EXPECT_CALL(*cache_, Get(kBlobId1)).WillOnce(Return(payload)); |
| + |
| + auto result = blob_receiver_->Get(kBlobId1); |
| + |
| + ASSERT_NE(result.get(), nullptr); |
|
Wez
2016/05/03 21:32:20
nit: These should be ASSERT_OP(expected, actual),
Kevin M
2016/05/03 22:29:42
Done.
|
| + EXPECT_EQ(result->data, payload->data); |
| +} |
| + |
| +TEST_F(BlobChannelReceiverTest, GetFromDelegateReceiveMethod) { |
| + auto payload = CreatePayload(kBlobPayload1); |
| + |
| + EXPECT_CALL(*cache_, Put(kBlobId1, BlobDataEqual(payload))); |
| + delegate_->OnBlobReceived(kBlobId1, payload); |
| + |
| + EXPECT_CALL(*cache_, Get(kBlobId1)).WillOnce(Return(payload)); |
|
Wez
2016/05/03 21:32:20
Don't mix EXPECT_CALL in with actual calls into th
Kevin M
2016/05/03 22:29:42
Done.
|
| + auto result = blob_receiver_->Get(kBlobId1); |
| + |
| + ASSERT_NE(nullptr, result.get()); |
| + EXPECT_EQ(payload->data, result->data); |
| +} |
| + |
| +TEST_F(BlobChannelReceiverTest, GetUnknownBlob) { |
| + EXPECT_CALL(*cache_, Get(kBlobId1)).WillOnce(Return(nullptr)); |
| + auto result = blob_receiver_->Get(kBlobId1); |
| + |
| + ASSERT_EQ(nullptr, result.get()); |
| +} |
| + |
| +} // namespace |
| +} // namespace blimp |