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

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

Issue 1962193002: Add a integration test suite for BlobChannel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « blimp/net/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory>
6
7 #include "base/memory/ptr_util.h"
8 #include "blimp/common/blob_cache/id_util.h"
9 #include "blimp/common/blob_cache/in_memory_blob_cache.h"
10 #include "blimp/common/blob_cache/test_util.h"
11 #include "blimp/net/blob_channel/blob_channel_receiver.h"
12 #include "blimp/net/blob_channel/blob_channel_sender.h"
13 #include "blimp/net/test_common.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace blimp {
17 namespace {
18
19 using testing::_;
20 using testing::SaveArg;
21
22 const char kBlobId[] = "foo1";
23 const char kBlobPayload[] = "bar1";
24
25 // Routes sender delegate calls to a receiver delegate object.
26 // The caller is responsible for ensuring that the receiver delegate is deleted
27 // after |this| is deleted.
28 class SenderDelegateProxy : public BlobChannelSender::Delegate {
29 public:
30 SenderDelegateProxy() {}
31 ~SenderDelegateProxy() override {}
32
33 // Returns a receiver object that will receive proxied calls sent to |this|.
34 std::unique_ptr<BlobChannelReceiver::Delegate> GetReceiverDelegate() {
35 DCHECK(!receiver_);
36 receiver_ = new ReceiverDelegate;
37 return base::WrapUnique(receiver_);
38 }
39
40 private:
41 class ReceiverDelegate : public BlobChannelReceiver::Delegate {
42 public:
43 using BlobChannelReceiver::Delegate::OnBlobReceived;
44 };
45
46 // BlobChannelSender implementation.
47 void DeliverBlob(const BlobId& id, BlobDataPtr data) override {
48 receiver_->OnBlobReceived(id, data);
haibinlu 2016/05/10 00:18:38 PostTask to simulate async nature of sender and re
Kevin M 2016/05/10 00:54:23 Done.
49 }
50
51 ReceiverDelegate* receiver_ = nullptr;
52
53 DISALLOW_COPY_AND_ASSIGN(SenderDelegateProxy);
54 };
55
56 // Verifies compatibility between the sender and receiver, independent of
57 // transport-level implementation details.
58 class BlobChannelIntegrationTest : public testing::Test {
59 public:
60 BlobChannelIntegrationTest() {
61 std::unique_ptr<SenderDelegateProxy> sender_delegate(
62 new SenderDelegateProxy);
63 receiver_.reset(
64 new BlobChannelReceiver(base::WrapUnique(new InMemoryBlobCache),
65 sender_delegate->GetReceiverDelegate()));
66 sender_.reset(new BlobChannelSender(base::WrapUnique(new InMemoryBlobCache),
67 std::move(sender_delegate)));
68 }
69
70 ~BlobChannelIntegrationTest() override {}
71
72 protected:
73 std::unique_ptr<BlobChannelReceiver> receiver_;
74 std::unique_ptr<BlobChannelSender> sender_;
75 };
76
77 TEST_F(BlobChannelIntegrationTest, Deliver) {
78 const std::string blob_id = CalculateBlobId(kBlobId);
79
80 EXPECT_EQ(nullptr, receiver_->Get(blob_id).get());
81 sender_->PutBlob(blob_id, CreateBlobDataPtr(kBlobPayload));
82 EXPECT_EQ(nullptr, receiver_->Get(blob_id).get());
83
84 EXPECT_EQ(nullptr, receiver_->Get(blob_id).get());
85 sender_->DeliverBlob(blob_id);
86 EXPECT_EQ(kBlobPayload, receiver_->Get(blob_id)->data);
87 }
88
89 } // namespace
90 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698