OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 #include <memory> | 6 #include <memory> |
7 | 7 |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "blimp/common/blob_cache/mock_blob_cache.h" | 9 #include "blimp/common/blob_cache/mock_blob_cache.h" |
10 #include "blimp/net/blob_channel/blob_channel_sender.h" | 10 #include "blimp/net/blob_channel/blob_channel_sender_impl.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace blimp { | 14 namespace blimp { |
15 namespace { | 15 namespace { |
16 | 16 |
17 using testing::_; | 17 using testing::_; |
18 using testing::Pointee; | 18 using testing::Pointee; |
19 using testing::Return; | 19 using testing::Return; |
20 | 20 |
21 const char kBlobId[] = "blob-1"; | 21 const char kBlobId[] = "blob-1"; |
22 const char kBlobPayload[] = "blob-1-payload"; | 22 const char kBlobPayload[] = "blob-1-payload"; |
23 | 23 |
24 // Helper function for creating a cache payload vector from a string. | 24 // Helper function for creating a cache payload vector from a string. |
25 BlobDataPtr CreatePayload(const std::string& input) { | 25 BlobDataPtr CreatePayload(const std::string& input) { |
26 BlobDataPtr output(new BlobData(input)); | 26 BlobDataPtr output(new BlobData(input)); |
27 return output; | 27 return output; |
28 } | 28 } |
29 | 29 |
30 MATCHER_P(BlobDataEqual, expected, "") { | 30 MATCHER_P(BlobDataEqual, expected, "") { |
31 return expected->data == arg->data; | 31 return expected->data == arg->data; |
32 } | 32 } |
33 | 33 |
34 class MockSenderDelegate : public BlobChannelSender::Delegate { | 34 class MockSenderDelegate : public BlobChannelSenderImpl::Delegate { |
35 public: | 35 public: |
36 MockSenderDelegate() {} | 36 MockSenderDelegate() {} |
37 ~MockSenderDelegate() override {} | 37 ~MockSenderDelegate() override {} |
38 | 38 |
39 MOCK_METHOD2(DeliverBlob, void(const BlobId&, BlobDataPtr)); | 39 MOCK_METHOD2(DeliverBlob, void(const BlobId&, BlobDataPtr)); |
40 }; | 40 }; |
41 | 41 |
42 class BlobChannelSenderTest : public testing::Test { | 42 class BlobChannelSenderTest : public testing::Test { |
43 public: | 43 public: |
44 BlobChannelSenderTest() | 44 BlobChannelSenderTest() |
45 : mock_delegate_(new testing::StrictMock<MockSenderDelegate>), | 45 : mock_delegate_(new testing::StrictMock<MockSenderDelegate>), |
46 mock_cache_(new testing::StrictMock<MockBlobCache>), | 46 mock_cache_(new testing::StrictMock<MockBlobCache>), |
47 blob_sender_(new BlobChannelSender(base::WrapUnique(mock_cache_), | 47 blob_sender_( |
48 base::WrapUnique(mock_delegate_))) {} | 48 new BlobChannelSenderImpl(base::WrapUnique(mock_cache_), |
| 49 base::WrapUnique(mock_delegate_))) {} |
49 ~BlobChannelSenderTest() override {} | 50 ~BlobChannelSenderTest() override {} |
50 | 51 |
51 testing::StrictMock<MockSenderDelegate>* mock_delegate_; | 52 testing::StrictMock<MockSenderDelegate>* mock_delegate_; |
52 testing::StrictMock<MockBlobCache>* mock_cache_; | 53 testing::StrictMock<MockBlobCache>* mock_cache_; |
53 std::unique_ptr<BlobChannelSender> blob_sender_; | 54 std::unique_ptr<BlobChannelSender> blob_sender_; |
54 }; | 55 }; |
55 | 56 |
56 TEST_F(BlobChannelSenderTest, TestPutBlob) { | 57 TEST_F(BlobChannelSenderTest, TestPutBlob) { |
57 EXPECT_CALL(*mock_cache_, | 58 EXPECT_CALL(*mock_cache_, |
58 Put(kBlobId, BlobDataEqual(CreatePayload(kBlobPayload)))); | 59 Put(kBlobId, BlobDataEqual(CreatePayload(kBlobPayload)))); |
(...skipping 13 matching lines...) Expand all Loading... |
72 .WillOnce(Return(false)) | 73 .WillOnce(Return(false)) |
73 .WillOnce(Return(true)); | 74 .WillOnce(Return(true)); |
74 EXPECT_CALL(*mock_cache_, Put(kBlobId, BlobDataEqual(payload))); | 75 EXPECT_CALL(*mock_cache_, Put(kBlobId, BlobDataEqual(payload))); |
75 EXPECT_CALL(*mock_cache_, Get(kBlobId)).WillOnce(Return(payload)); | 76 EXPECT_CALL(*mock_cache_, Get(kBlobId)).WillOnce(Return(payload)); |
76 blob_sender_->PutBlob(kBlobId, payload); | 77 blob_sender_->PutBlob(kBlobId, payload); |
77 blob_sender_->DeliverBlob(kBlobId); | 78 blob_sender_->DeliverBlob(kBlobId); |
78 } | 79 } |
79 | 80 |
80 } // namespace | 81 } // namespace |
81 } // namespace blimp | 82 } // namespace blimp |
OLD | NEW |