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

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

Issue 1891083002: Blimp: Add BlobChannelReceiver and bindings interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-sender
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 #include <string>
8
9 #include "base/memory/ptr_util.h"
10 #include "base/memory/ref_counted.h"
11 #include "blimp/common/blob_cache/in_memory_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";
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 testing::StrictMock<NullBlobReceiverDelegate>),
43 cache_(new InMemoryBlobCache),
44 blob_receiver_(new BlobChannelReceiver(base::WrapUnique(cache_),
45 base::WrapUnique(delegate_)))
46
47 {}
48
49 ~BlobChannelReceiverTest() override {}
50
51 testing::StrictMock<NullBlobReceiverDelegate>* delegate_;
52 InMemoryBlobCache* cache_;
53 std::unique_ptr<BlobChannelReceiver> blob_receiver_;
54 };
55
56 TEST_F(BlobChannelReceiverTest, GetKnownBlob) {
57 auto payload = CreatePayload(kBlobPayload1);
58 cache_->Put(kBlobId1, payload);
59
60 auto result = blob_receiver_->Get(kBlobId1);
61
62 EXPECT_EQ(result->data, payload->data);
63 }
64
65 TEST_F(BlobChannelReceiverTest, GetFromDelegateReceiveMethod) {
66 auto payload = CreatePayload(kBlobPayload1);
67
68 delegate_->OnBlobReceived(kBlobId1, payload);
69
70 EXPECT_THAT(cache_->Get(kBlobId1), BlobDataEqual(payload));
71 }
72
73 TEST_F(BlobChannelReceiverTest, GetUnknownBlob) {
74 auto result = blob_receiver_->Get(kBlobId1);
75
76 ASSERT_EQ(nullptr, result.get());
77 }
78
79 } // namespace
80 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698