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 <algorithm> | |
| 6 #include <memory> | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "blimp/common/blob_cache/mock_blob_cache.h" | |
| 12 #include "blimp/net/blob_channel/blob_channel_receiver.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 namespace blimp { | |
| 17 namespace { | |
| 18 | |
| 19 using testing::_; | |
| 20 using testing::Return; | |
| 21 | |
| 22 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.
| |
| 23 const char kBlobPayload1[] = "blob-1-payload"; | |
| 24 | |
| 25 // Helper function for creating a cache payload vector from a string. | |
| 26 BlobDataPtr CreatePayload(const std::string& input) { | |
| 27 return BlobDataPtr(new BlobData(input)); | |
| 28 } | |
| 29 | |
| 30 MATCHER_P(BlobDataEqual, expected, "") { | |
| 31 return expected->data == arg->data; | |
| 32 } | |
| 33 | |
| 34 class NullBlobReceiverDelegate : public BlobChannelReceiver::Delegate { | |
| 35 public: | |
| 36 using BlobChannelReceiver::Delegate::OnBlobReceived; | |
| 37 }; | |
| 38 | |
| 39 class BlobChannelReceiverTest : public testing::Test { | |
| 40 public: | |
| 41 BlobChannelReceiverTest() | |
| 42 : delegate_(new NullBlobReceiverDelegate), | |
| 43 cache_(new testing::StrictMock<MockBlobCache>), | |
| 44 blob_receiver_(new BlobChannelReceiver(base::WrapUnique(cache_), | |
| 45 base::WrapUnique(delegate_))) | |
| 46 | |
| 47 {} | |
| 48 | |
| 49 ~BlobChannelReceiverTest() override {} | |
| 50 | |
| 51 NullBlobReceiverDelegate* delegate_; | |
| 52 testing::StrictMock<MockBlobCache>* cache_; | |
| 53 std::unique_ptr<BlobChannelReceiver> blob_receiver_; | |
| 54 }; | |
| 55 | |
| 56 TEST_F(BlobChannelReceiverTest, GetKnownBlob) { | |
| 57 auto payload = CreatePayload(kBlobPayload1); | |
| 58 EXPECT_CALL(*cache_, Get(kBlobId1)).WillOnce(Return(payload)); | |
| 59 | |
| 60 auto result = blob_receiver_->Get(kBlobId1); | |
| 61 | |
| 62 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.
| |
| 63 EXPECT_EQ(result->data, payload->data); | |
| 64 } | |
| 65 | |
| 66 TEST_F(BlobChannelReceiverTest, GetFromDelegateReceiveMethod) { | |
| 67 auto payload = CreatePayload(kBlobPayload1); | |
| 68 | |
| 69 EXPECT_CALL(*cache_, Put(kBlobId1, BlobDataEqual(payload))); | |
| 70 delegate_->OnBlobReceived(kBlobId1, payload); | |
| 71 | |
| 72 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.
| |
| 73 auto result = blob_receiver_->Get(kBlobId1); | |
| 74 | |
| 75 ASSERT_NE(nullptr, result.get()); | |
| 76 EXPECT_EQ(payload->data, result->data); | |
| 77 } | |
| 78 | |
| 79 TEST_F(BlobChannelReceiverTest, GetUnknownBlob) { | |
| 80 EXPECT_CALL(*cache_, Get(kBlobId1)).WillOnce(Return(nullptr)); | |
| 81 auto result = blob_receiver_->Get(kBlobId1); | |
| 82 | |
| 83 ASSERT_EQ(nullptr, result.get()); | |
| 84 } | |
| 85 | |
| 86 } // namespace | |
| 87 } // namespace blimp | |
| OLD | NEW |