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

Side by Side Diff: blimp/net/blob_channel/helium_blob_channel_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: 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
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/test_util.h"
10 #include "blimp/net/blob_channel/helium_blob_receiver_delegate.h"
11 #include "blimp/net/blob_channel/helium_blob_sender_delegate.h"
12 #include "blimp/net/blob_channel/mock_blob_channel_receiver.h"
13 #include "blimp/net/test_common.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace blimp {
18 namespace {
19
20 using testing::_;
21 using testing::SaveArg;
22
23 const char kBlobId[] = "foo1";
24 const char kBlobPayload[] = "bar1";
25
26 // Proxies ProcessMessage calls to an un-ownedBlimpMessageProcessor* raw
27 // pointer. Can be used to adapt unique_ptr calls to raw pointer calls.
28 class BlimpMessageProxy : public BlimpMessageProcessor {
29 public:
30 explicit BlimpMessageProxy(BlimpMessageProcessor* sink) : sink_(sink) {}
31 ~BlimpMessageProxy() override {}
32
33 private:
34 // BlimpMessageProcessor implementation.
35 void ProcessMessage(std::unique_ptr<BlimpMessage> message,
36 const net::CompletionCallback& callback) override {
37 sink_->ProcessMessage(std::move(message), callback);
38 }
39
40 BlimpMessageProcessor* sink_ = nullptr;
41
42 DISALLOW_COPY_AND_ASSIGN(BlimpMessageProxy);
43 };
44
45 class HeliumBlobChannelTest : public testing::Test {
haibinlu 2016/05/12 18:20:09 why prefix it with "helium"?
Kevin M 2016/05/13 18:40:24 These tests are Helium-specific; they're not gener
46 public:
47 HeliumBlobChannelTest() { receiver_delegate_.SetReceiver(&mock_receiver_); }
48
49 ~HeliumBlobChannelTest() override {}
50
51 protected:
52 const std::string blob_id_ = CalculateBlobId(kBlobId);
53
54 MockBlobChannelReceiver mock_receiver_;
55 HeliumBlobReceiverDelegate receiver_delegate_;
haibinlu 2016/05/12 18:20:09 Can this be a unique_ptr so that BlimpMessageProx
Kevin M 2016/05/13 18:40:24 The receiver takes delegates as unique_ptrs, so th
56 HeliumBlobSenderDelegate sender_delegate_;
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(HeliumBlobChannelTest);
60 };
61
62 // Verifies the content of BlimpMessages generated by the Sender.
63 TEST_F(HeliumBlobChannelTest, TransferBlobContents) {
64 BlimpMessage captured_msg;
65 MockBlimpMessageProcessor* mock_processor = new MockBlimpMessageProcessor;
66 EXPECT_CALL(*mock_processor, MockableProcessMessage(_, _))
67 .WillOnce(SaveArg<0>(&captured_msg));
68 sender_delegate_.set_outgoing_message_processor(
69 base::WrapUnique(mock_processor));
70
71 sender_delegate_.DeliverBlob(blob_id_, CreateBlobDataPtr(kBlobPayload));
72
73 EXPECT_EQ(BlimpMessage::BLOB_CHANNEL, captured_msg.type());
74 EXPECT_EQ(BlobChannelMessage::TRANSFER_BLOB,
75 captured_msg.blob_channel().type());
76 EXPECT_EQ(blob_id_, captured_msg.blob_channel().blob_id());
77 EXPECT_EQ(kBlobPayload, captured_msg.blob_channel().payload());
78 }
79
80 // Verifies that the Receiver understands messages sent by the Sender.
81 TEST_F(HeliumBlobChannelTest, TransferBlobCompatibility) {
82 EXPECT_CALL(mock_receiver_,
83 OnBlobReceived(blob_id_, BlobDataPtrEqualsString(kBlobPayload)));
84 sender_delegate_.set_outgoing_message_processor(
85 base::WrapUnique(new BlimpMessageProxy(&receiver_delegate_)));
86 sender_delegate_.DeliverBlob(blob_id_, CreateBlobDataPtr(kBlobPayload));
87 }
88
89 } // namespace
90 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698