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

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

Issue 2632803002: Remove all blimp network code. (Closed)
Patch Set: merge from origin/master for good measure Created 3 years, 11 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/blimp_transport.h ('k') | blimp/net/blob_channel/blob_channel_receiver.h » ('j') | 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/location.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "blimp/common/blob_cache/id_util.h"
14 #include "blimp/common/blob_cache/in_memory_blob_cache.h"
15 #include "blimp/common/blob_cache/test_util.h"
16 #include "blimp/net/blob_channel/blob_channel_receiver.h"
17 #include "blimp/net/blob_channel/blob_channel_sender.h"
18 #include "blimp/net/blob_channel/blob_channel_sender_impl.h"
19 #include "blimp/net/blob_channel/mock_blob_channel_receiver.h"
20 #include "blimp/net/test_common.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 namespace blimp {
24 namespace {
25
26 using testing::_;
27 using testing::SaveArg;
28
29 const char kBlobId[] = "foo1";
30 const char kBlobPayload[] = "bar1";
31
32 // Routes sender delegate calls to a receiver delegate object.
33 // The caller is responsible for ensuring that the receiver delegate is deleted
34 // after |this| is deleted.
35 class SenderDelegateProxy : public BlobChannelSenderImpl::Delegate {
36 public:
37 explicit SenderDelegateProxy(BlobChannelReceiver* receiver)
38 : receiver_(receiver) {}
39 ~SenderDelegateProxy() override {}
40
41 private:
42 // BlobChannelSender implementation.
43 void DeliverBlob(const BlobId& id, BlobDataPtr data) override {
44 base::ThreadTaskRunnerHandle::Get()->PostTask(
45 FROM_HERE, base::Bind(&BlobChannelReceiver::OnBlobReceived,
46 base::Unretained(receiver_), id, data));
47 }
48
49 BlobChannelReceiver* receiver_;
50
51 DISALLOW_COPY_AND_ASSIGN(SenderDelegateProxy);
52 };
53
54 // Verifies compatibility between the sender and receiver, independent of
55 // transport-level implementation details.
56 class BlobChannelIntegrationTest : public testing::Test {
57 public:
58 BlobChannelIntegrationTest() {
59 BlobChannelReceiver* stored_receiver;
60 std::unique_ptr<MockBlobChannelReceiverDelegate> receiver_delegate(
61 new MockBlobChannelReceiverDelegate);
62 receiver_delegate_ = receiver_delegate.get();
63
64 EXPECT_CALL(*receiver_delegate, SetReceiver(_))
65 .WillOnce(SaveArg<0>(&stored_receiver));
66
67 receiver_ = BlobChannelReceiver::Create(
68 base::WrapUnique(new InMemoryBlobCache), std::move(receiver_delegate));
69
70 EXPECT_EQ(receiver_.get(), stored_receiver);
71
72 sender_.reset(new BlobChannelSenderImpl(
73 base::WrapUnique(new InMemoryBlobCache),
74 base::MakeUnique<SenderDelegateProxy>(receiver_.get())));
75 }
76
77 ~BlobChannelIntegrationTest() override {}
78
79 protected:
80 MockBlobChannelReceiverDelegate* receiver_delegate_;
81 std::unique_ptr<BlobChannelReceiver> receiver_;
82 std::unique_ptr<BlobChannelSender> sender_;
83 base::MessageLoop message_loop_;
84
85 private:
86 DISALLOW_COPY_AND_ASSIGN(BlobChannelIntegrationTest);
87 };
88
89 TEST_F(BlobChannelIntegrationTest, Deliver) {
90 const std::string blob_id = CalculateBlobId(kBlobId);
91
92 EXPECT_EQ(nullptr, receiver_->Get(blob_id).get());
93 sender_->PutBlob(blob_id, CreateBlobDataPtr(kBlobPayload));
94 EXPECT_EQ(nullptr, receiver_->Get(blob_id).get());
95
96 EXPECT_EQ(nullptr, receiver_->Get(blob_id).get());
97 sender_->DeliverBlob(blob_id);
98
99 base::RunLoop().RunUntilIdle();
100 EXPECT_EQ(kBlobPayload, receiver_->Get(blob_id)->data);
101 }
102
103 } // namespace
104 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/blimp_transport.h ('k') | blimp/net/blob_channel/blob_channel_receiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698