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

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

Issue 1970463004: Blimp: Add BlobChannel Helium messages and delegate impls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
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 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "blimp/common/blob_cache/mock_blob_cache.h" 11 #include "blimp/common/blob_cache/mock_blob_cache.h"
12 #include "blimp/net/blob_channel/blob_channel_receiver.h" 12 #include "blimp/net/blob_channel/blob_channel_receiver.h"
13 #include "blimp/net/blob_channel/mock_blob_channel_receiver.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace blimp { 17 namespace blimp {
17 namespace { 18 namespace {
18 19
19 using testing::_; 20 using testing::_;
20 using testing::Return; 21 using testing::Return;
22 using testing::SaveArg;
21 23
22 const char kBlobId[] = "blob-1"; 24 const char kBlobId[] = "blob-1";
23 const char kBlobPayload[] = "blob-1-payload"; 25 const char kBlobPayload[] = "blob-1-payload";
24 26
25 // Helper function for creating a cache payload vector from a string. 27 // Helper function for creating a cache payload vector from a string.
26 BlobDataPtr CreatePayload(const std::string& input) { 28 BlobDataPtr CreatePayload(const std::string& input) {
27 return BlobDataPtr(new BlobData(input)); 29 return BlobDataPtr(new BlobData(input));
28 } 30 }
29 31
30 MATCHER_P(BlobDataEqual, expected, "") { 32 MATCHER_P(BlobDataEqual, expected, "") {
31 return expected->data == arg->data; 33 return expected->data == arg->data;
32 } 34 }
33 35
34 class NullBlobReceiverDelegate : public BlobChannelReceiver::Delegate {
35 public:
36 using BlobChannelReceiver::Delegate::OnBlobReceived;
37 };
38
39 class BlobChannelReceiverTest : public testing::Test { 36 class BlobChannelReceiverTest : public testing::Test {
40 public: 37 public:
41 BlobChannelReceiverTest() 38 BlobChannelReceiverTest() : cache_(new testing::StrictMock<MockBlobCache>) {
42 : delegate_(new NullBlobReceiverDelegate), 39 BlobChannelReceiver* stored_receiver;
43 cache_(new testing::StrictMock<MockBlobCache>), 40 std::unique_ptr<MockBlobChannelReceiverDelegate> receiver_delegate(
44 blob_receiver_(new BlobChannelReceiver(base::WrapUnique(cache_), 41 new MockBlobChannelReceiverDelegate);
45 base::WrapUnique(delegate_))) 42 receiver_delegate_ = receiver_delegate.get();
46 43
47 {} 44 EXPECT_CALL(*receiver_delegate, SetReceiver(_))
45 .WillOnce(SaveArg<0>(&stored_receiver));
46
47 blob_receiver_ = BlobChannelReceiver::Create(base::WrapUnique(cache_),
48 std::move(receiver_delegate));
49 }
48 50
49 ~BlobChannelReceiverTest() override {} 51 ~BlobChannelReceiverTest() override {}
50 52
51 NullBlobReceiverDelegate* delegate_;
52 testing::StrictMock<MockBlobCache>* cache_; 53 testing::StrictMock<MockBlobCache>* cache_;
53 std::unique_ptr<BlobChannelReceiver> blob_receiver_; 54 std::unique_ptr<BlobChannelReceiver> blob_receiver_;
55 MockBlobChannelReceiverDelegate* receiver_delegate_;
54 }; 56 };
55 57
56 TEST_F(BlobChannelReceiverTest, GetKnownBlob) { 58 TEST_F(BlobChannelReceiverTest, GetKnownBlob) {
57 auto payload = CreatePayload(kBlobPayload); 59 auto payload = CreatePayload(kBlobPayload);
58 EXPECT_CALL(*cache_, Get(kBlobId)).WillOnce(Return(payload)); 60 EXPECT_CALL(*cache_, Get(kBlobId)).WillOnce(Return(payload));
59 61
60 auto result = blob_receiver_->Get(kBlobId); 62 auto result = blob_receiver_->Get(kBlobId);
61 63
62 ASSERT_NE(nullptr, result.get()); 64 ASSERT_NE(nullptr, result.get());
63 EXPECT_EQ(result->data, payload->data); 65 EXPECT_EQ(result->data, payload->data);
64 } 66 }
65 67
66 TEST_F(BlobChannelReceiverTest, GetFromDelegateReceiveMethod) { 68 TEST_F(BlobChannelReceiverTest, GetFromDelegateReceiveMethod) {
67 auto payload = CreatePayload(kBlobPayload); 69 auto payload = CreatePayload(kBlobPayload);
68 70
69 EXPECT_CALL(*cache_, Put(kBlobId, BlobDataEqual(payload))); 71 EXPECT_CALL(*cache_, Put(kBlobId, BlobDataEqual(payload)));
70 EXPECT_CALL(*cache_, Get(kBlobId)).WillOnce(Return(payload)); 72 EXPECT_CALL(*cache_, Get(kBlobId)).WillOnce(Return(payload));
71 73
72 delegate_->OnBlobReceived(kBlobId, payload); 74 blob_receiver_->OnBlobReceived(kBlobId, payload);
73 75
74 auto result = blob_receiver_->Get(kBlobId); 76 auto result = blob_receiver_->Get(kBlobId);
75 77
76 ASSERT_NE(nullptr, result.get()); 78 ASSERT_NE(nullptr, result.get());
77 EXPECT_EQ(payload->data, result->data); 79 EXPECT_EQ(payload->data, result->data);
78 } 80 }
79 81
80 TEST_F(BlobChannelReceiverTest, GetUnknownBlob) { 82 TEST_F(BlobChannelReceiverTest, GetUnknownBlob) {
81 EXPECT_CALL(*cache_, Get(kBlobId)).WillOnce(Return(nullptr)); 83 EXPECT_CALL(*cache_, Get(kBlobId)).WillOnce(Return(nullptr));
82 auto result = blob_receiver_->Get(kBlobId); 84 auto result = blob_receiver_->Get(kBlobId);
83 85
84 ASSERT_EQ(nullptr, result.get()); 86 ASSERT_EQ(nullptr, result.get());
85 } 87 }
86 88
87 } // namespace 89 } // namespace
88 } // namespace blimp 90 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/blob_channel/blob_channel_receiver.cc ('k') | blimp/net/blob_channel/helium_blob_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698