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

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: remove redundant callback 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 "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "blimp/common/blob_cache/id_util.h"
11 #include "blimp/common/blob_cache/in_memory_blob_cache.h"
12 #include "blimp/common/blob_cache/test_util.h"
13 #include "blimp/net/blob_channel/blob_channel_receiver.h"
14 #include "blimp/net/blob_channel/blob_channel_sender.h"
15 #include "blimp/net/test_common.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace blimp {
19 namespace {
20
21 using testing::_;
22 using testing::SaveArg;
23
24 const char kBlobId[] = "foo1";
25 const char kBlobPayload[] = "bar1";
26
27 // Routes sender delegate calls to a receiver delegate object.
28 // The caller is responsible for ensuring that the receiver delegate is deleted
29 // after |this| is deleted.
30 class SenderDelegateProxy : public BlobChannelSender::Delegate {
31 public:
32 SenderDelegateProxy() {}
33 ~SenderDelegateProxy() override {}
34
35 // Returns a receiver object that will receive proxied calls sent to |this|.
36 std::unique_ptr<BlobChannelReceiver::Delegate> GetReceiverDelegate() {
37 DCHECK(!receiver_);
38 receiver_ = new ReceiverDelegate;
39 return base::WrapUnique(receiver_);
40 }
41
42 private:
43 class ReceiverDelegate : public BlobChannelReceiver::Delegate {
44 public:
45 using BlobChannelReceiver::Delegate::OnBlobReceived;
46 };
47
48 // BlobChannelSender implementation.
49 void DeliverBlob(const BlobId& id, BlobDataPtr data) override {
50 base::MessageLoop::current()->PostTask(
51 FROM_HERE, base::Bind(&ReceiverDelegate::OnBlobReceived,
52 base::Unretained(receiver_), id, data));
53 }
54
55 ReceiverDelegate* receiver_ = nullptr;
56
57 DISALLOW_COPY_AND_ASSIGN(SenderDelegateProxy);
58 };
59
60 // Verifies compatibility between the sender and receiver, independent of
61 // transport-level implementation details.
62 class BlobChannelIntegrationTest : public testing::Test {
63 public:
64 BlobChannelIntegrationTest() {
65 std::unique_ptr<SenderDelegateProxy> sender_delegate(
66 new SenderDelegateProxy);
67 receiver_.reset(
68 new BlobChannelReceiver(base::WrapUnique(new InMemoryBlobCache),
69 sender_delegate->GetReceiverDelegate()));
70 sender_.reset(new BlobChannelSender(base::WrapUnique(new InMemoryBlobCache),
71 std::move(sender_delegate)));
72 }
73
74 ~BlobChannelIntegrationTest() override {}
75
76 protected:
77 std::unique_ptr<BlobChannelReceiver> receiver_;
78 std::unique_ptr<BlobChannelSender> sender_;
79 base::MessageLoop message_loop_;
80
81 private:
82 DISALLOW_COPY_AND_ASSIGN(BlobChannelIntegrationTest);
83 };
84
85 TEST_F(BlobChannelIntegrationTest, Deliver) {
86 const std::string blob_id = CalculateBlobId(kBlobId);
87
88 EXPECT_EQ(nullptr, receiver_->Get(blob_id).get());
89 sender_->PutBlob(blob_id, CreateBlobDataPtr(kBlobPayload));
90 EXPECT_EQ(nullptr, receiver_->Get(blob_id).get());
91
92 EXPECT_EQ(nullptr, receiver_->Get(blob_id).get());
93 sender_->DeliverBlob(blob_id);
94
95 base::RunLoop().RunUntilIdle();
96 EXPECT_EQ(kBlobPayload, receiver_->Get(blob_id)->data);
97 }
98
99 } // namespace
100 } // 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