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

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: Wez feedback. 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::Pointee;
18 using testing::Return;
19
20 const char kBlobId[] = "blob-1";
21 const char kBlobPayload[] = "blob-1-payload";
22
23 // Helper function for creating a cache payload vector from a string.
24 scoped_refptr<RefCountedVector> CreatePayload(const std::string& input) {
25 scoped_refptr<RefCountedVector> output(new RefCountedVector);
26 output->data.assign(input.begin(), input.end());
27 return output;
28 }
29
30 // Checks if a RefCountedVector matches |expected|.
31 MATCHER_P(RefCountedEqualsContainer, expected, "") {
32 return (expected.size() == arg.data.size()) &&
33 std::equal(arg.data.begin(), arg.data.end(), expected.begin());
34 }
35
36 class MockSenderDelegate : public BlobChannelSender::Delegate {
37 public:
38 MockSenderDelegate() {}
39 ~MockSenderDelegate() {}
40
41 MOCK_METHOD2(Deliver, void(const BlobId&, BlobData));
42 };
43
44 class BlobChannelSenderTest : public testing::Test {
45 public:
46 BlobChannelSenderTest() : blob_sender_(&mock_cache_, &mock_delegate_) {}
47 ~BlobChannelSenderTest() override {}
48
49 testing::StrictMock<MockSenderDelegate> mock_delegate_;
50 testing::StrictMock<MockBlobCache> mock_cache_;
51 BlobChannelSender blob_sender_;
52 };
53
54 TEST_F(BlobChannelSenderTest, TestPut) {
55 EXPECT_CALL(mock_cache_, Put(kBlobId, Pointee(RefCountedEqualsContainer(
56 std::string(kBlobPayload)))));
57 EXPECT_CALL(mock_cache_, Contains(kBlobId)).WillOnce(Return(false));
58 blob_sender_.Put(kBlobId, CreatePayload(kBlobPayload));
59 }
60
61 TEST_F(BlobChannelSenderTest, TestPutDuplicate) {
62 EXPECT_CALL(mock_cache_, Contains(kBlobId)).WillOnce(Return(true));
63 blob_sender_.Put(kBlobId, CreatePayload(kBlobPayload));
64 }
65
66 TEST_F(BlobChannelSenderTest, TestPush) {
67 auto payload = CreatePayload(kBlobPayload);
68 EXPECT_CALL(
69 mock_delegate_,
70 Deliver(kBlobId,
71 Pointee(RefCountedEqualsContainer(std::string(kBlobPayload)))));
72 EXPECT_CALL(mock_cache_, Contains(kBlobId))
73 .WillOnce(Return(false))
74 .WillOnce(Return(true));
75 EXPECT_CALL(mock_cache_, Put(kBlobId, Pointee(RefCountedEqualsContainer(
76 std::string(kBlobPayload)))));
77 EXPECT_CALL(mock_cache_, Get(kBlobId)).WillOnce(Return(payload.get()));
78 blob_sender_.Put(
79 kBlobId,
80 CreatePayload(kBlobPayload));
81 blob_sender_.Deliver(kBlobId);
82 }
83
84 } // namespace
85 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698