Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: blimp/net/blob_channel/blob_channel_sender_unittest.cc

Issue 1887013003: Blimp: Add BlobChannelSender implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-blobcache
Patch Set: Sync-only! Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
8 #include "base/memory/ptr_util.h"
9 #include "blimp/common/blob_cache/mock_blob_cache.h"
10 #include "blimp/net/blob_channel/blob_channel_sender.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace blimp {
15 namespace {
16
17 using testing::_;
18 using testing::Pointee;
19 using testing::Return;
20
21 const char kBlobId[] = "blob-1";
22 const char kBlobPayload[] = "blob-1-payload";
23
24 // Helper function for creating a cache payload vector from a string.
25 BlobDataPtr CreatePayload(const std::string& input) {
26 BlobDataPtr output(new BlobData(input));
27 return output;
28 }
29
30 MATCHER_P(BlobDataEqual, expected, "") {
31 return expected->data == arg->data;
32 }
33
34 class MockSenderDelegate : public BlobChannelSender::Delegate {
35 public:
36 MockSenderDelegate() {}
37 ~MockSenderDelegate() override {}
38
39 MOCK_METHOD2(DeliverBlob, void(const BlobId&, BlobDataPtr));
40 };
41
42 class BlobChannelSenderTest : public testing::Test {
43 public:
44 BlobChannelSenderTest()
45 : mock_delegate_(new testing::StrictMock<MockSenderDelegate>),
46 mock_cache_(new testing::StrictMock<MockBlobCache>),
47 blob_sender_(new BlobChannelSender(base::WrapUnique(mock_cache_),
48 base::WrapUnique(mock_delegate_))) {}
49 ~BlobChannelSenderTest() override {}
Wez 2016/05/03 22:11:05 Don't you need to delete the two StrickMocks?
Kevin M 2016/05/03 22:42:57 Nope, blob_sender_ owns the objects themselves.
50
51 testing::StrictMock<MockSenderDelegate>* mock_delegate_;
52 testing::StrictMock<MockBlobCache>* mock_cache_;
53 std::unique_ptr<BlobChannelSender> blob_sender_;
54 };
55
56 TEST_F(BlobChannelSenderTest, TestPut) {
57 EXPECT_CALL(*mock_cache_,
58 Put(kBlobId, BlobDataEqual(CreatePayload(kBlobPayload))));
59 EXPECT_CALL(*mock_cache_, Contains(kBlobId)).WillOnce(Return(false));
60 blob_sender_->Put(kBlobId, CreatePayload(kBlobPayload));
61 }
62
63 TEST_F(BlobChannelSenderTest, TestPutDuplicate) {
64 EXPECT_CALL(*mock_cache_, Contains(kBlobId)).WillOnce(Return(true));
65 blob_sender_->Put(kBlobId, CreatePayload(kBlobPayload));
66 }
67
68 TEST_F(BlobChannelSenderTest, TestPush) {
69 auto payload = CreatePayload(kBlobPayload);
70 EXPECT_CALL(*mock_delegate_, DeliverBlob(kBlobId, BlobDataEqual(payload)));
71 EXPECT_CALL(*mock_cache_, Contains(kBlobId))
72 .WillOnce(Return(false))
73 .WillOnce(Return(true));
74 EXPECT_CALL(*mock_cache_, Put(kBlobId, BlobDataEqual(payload)));
75 EXPECT_CALL(*mock_cache_, Get(kBlobId)).WillOnce(Return(payload));
76 blob_sender_->Put(kBlobId, payload);
77 blob_sender_->DeliverBlob(kBlobId);
78 }
79
80 } // namespace
81 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698