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

Side by Side Diff: blimp/net/blimp_message_multiplexer_unittest.cc

Issue 1933053003: Used oneof in blimp_message.proto (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits 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/blimp_message_multiplexer.cc ('k') | blimp/net/blimp_message_output_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "blimp/common/proto/blimp_message.pb.h" 5 #include "blimp/common/proto/blimp_message.pb.h"
6 #include "blimp/common/proto/input.pb.h" 6 #include "blimp/common/proto/input.pb.h"
7 #include "blimp/common/proto/navigation.pb.h" 7 #include "blimp/common/proto/navigation.pb.h"
8 #include "blimp/net/blimp_message_multiplexer.h" 8 #include "blimp/net/blimp_message_multiplexer.h"
9 #include "blimp/net/test_common.h" 9 #include "blimp/net/test_common.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/base/test_completion_callback.h" 11 #include "net/base/test_completion_callback.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using testing::_; 15 using testing::_;
16 using testing::DoAll; 16 using testing::DoAll;
17 using testing::Ref; 17 using testing::Ref;
18 using testing::SaveArg; 18 using testing::SaveArg;
19 19
20 namespace blimp { 20 namespace blimp {
21 namespace { 21 namespace {
22 22
23 class BlimpMessageMultiplexerTest : public testing::Test { 23 class BlimpMessageMultiplexerTest : public testing::Test {
24 public: 24 public:
25 BlimpMessageMultiplexerTest() 25 BlimpMessageMultiplexerTest()
26 : multiplexer_(&mock_output_processor_), 26 : multiplexer_(&mock_output_processor_),
27 input_message_(new BlimpMessage), 27 input_message_(new BlimpMessage),
28 navigation_message_(new BlimpMessage), 28 navigation_message_(new BlimpMessage),
29 input_processor_(multiplexer_.CreateSenderForType(BlimpMessage::INPUT)), 29 input_processor_(multiplexer_.CreateSender(BlimpMessage::kInput)),
30 navigation_processor_( 30 navigation_processor_(
31 multiplexer_.CreateSenderForType(BlimpMessage::NAVIGATION)) {} 31 multiplexer_.CreateSender(BlimpMessage::kNavigation)) {}
32 32
33 void SetUp() override { 33 void SetUp() override {
34 EXPECT_CALL(mock_output_processor_, MockableProcessMessage(_, _)) 34 EXPECT_CALL(mock_output_processor_, MockableProcessMessage(_, _))
35 .WillRepeatedly( 35 .WillRepeatedly(
36 DoAll(SaveArg<0>(&captured_message_), SaveArg<1>(&captured_cb_))); 36 DoAll(SaveArg<0>(&captured_message_), SaveArg<1>(&captured_cb_)));
37 37
38 input_message_->mutable_input()->set_type( 38 input_message_->mutable_input()->set_type(
39 InputMessage::Type_GestureScrollBegin); 39 InputMessage::Type_GestureScrollBegin);
40 navigation_message_->mutable_navigation()->set_type( 40 navigation_message_->mutable_navigation()->set_type(
41 NavigationMessage::LOAD_URL); 41 NavigationMessage::LOAD_URL);
42 } 42 }
43 43
44 protected: 44 protected:
45 MockBlimpMessageProcessor mock_output_processor_; 45 MockBlimpMessageProcessor mock_output_processor_;
46 BlimpMessageMultiplexer multiplexer_; 46 BlimpMessageMultiplexer multiplexer_;
47 std::unique_ptr<BlimpMessage> input_message_; 47 std::unique_ptr<BlimpMessage> input_message_;
48 std::unique_ptr<BlimpMessage> navigation_message_; 48 std::unique_ptr<BlimpMessage> navigation_message_;
49 BlimpMessage captured_message_; 49 BlimpMessage captured_message_;
50 net::CompletionCallback captured_cb_; 50 net::CompletionCallback captured_cb_;
51 std::unique_ptr<BlimpMessageProcessor> input_processor_; 51 std::unique_ptr<BlimpMessageProcessor> input_processor_;
52 std::unique_ptr<BlimpMessageProcessor> navigation_processor_; 52 std::unique_ptr<BlimpMessageProcessor> navigation_processor_;
53 }; 53 };
54 54
55 // Verify that each sender propagates its types and copies the message payload 55 // Verify that each sender propagates its types and copies the message payload
56 // correctly. 56 // correctly.
57 TEST_F(BlimpMessageMultiplexerTest, TypeSetByMux) { 57 TEST_F(BlimpMessageMultiplexerTest, TypeSetByMux) {
58 net::TestCompletionCallback cb_1; 58 net::TestCompletionCallback cb_1;
59 input_processor_->ProcessMessage(std::move(input_message_), cb_1.callback()); 59 input_processor_->ProcessMessage(std::move(input_message_), cb_1.callback());
60 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type()); 60 EXPECT_EQ(BlimpMessage::kInput, captured_message_.feature_case());
61 EXPECT_EQ(InputMessage::Type_GestureScrollBegin, 61 EXPECT_EQ(InputMessage::Type_GestureScrollBegin,
62 captured_message_.input().type()); 62 captured_message_.input().type());
63 captured_cb_.Run(net::OK); 63 captured_cb_.Run(net::OK);
64 EXPECT_EQ(net::OK, cb_1.WaitForResult()); 64 EXPECT_EQ(net::OK, cb_1.WaitForResult());
65 65
66 net::TestCompletionCallback cb_2; 66 net::TestCompletionCallback cb_2;
67 navigation_processor_->ProcessMessage(std::move(navigation_message_), 67 navigation_processor_->ProcessMessage(std::move(navigation_message_),
68 cb_2.callback()); 68 cb_2.callback());
69 EXPECT_EQ(BlimpMessage::NAVIGATION, captured_message_.type()); 69 EXPECT_EQ(BlimpMessage::kNavigation, captured_message_.feature_case());
70 EXPECT_EQ(NavigationMessage::LOAD_URL, captured_message_.navigation().type()); 70 EXPECT_EQ(NavigationMessage::LOAD_URL, captured_message_.navigation().type());
71 captured_cb_.Run(net::ERR_FAILED); 71 captured_cb_.Run(net::ERR_FAILED);
72 EXPECT_EQ(net::ERR_FAILED, cb_2.WaitForResult()); 72 EXPECT_EQ(net::ERR_FAILED, cb_2.WaitForResult());
73 } 73 }
74 74
75 // Verify that the multiplexer allows the caller to supply a message type. 75 // Verify that the multiplexer allows the caller to supply a message type.
76 TEST_F(BlimpMessageMultiplexerTest, TypeSetByCaller) { 76 TEST_F(BlimpMessageMultiplexerTest, TypeSetByCaller) {
77 input_message_->set_type(BlimpMessage::INPUT); 77 input_message_->mutable_input();
78 78
79 net::TestCompletionCallback cb_1; 79 net::TestCompletionCallback cb_1;
80 input_processor_->ProcessMessage(std::move(input_message_), cb_1.callback()); 80 input_processor_->ProcessMessage(std::move(input_message_), cb_1.callback());
81 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type()); 81 EXPECT_EQ(BlimpMessage::kInput, captured_message_.feature_case());
82 EXPECT_EQ(InputMessage::Type_GestureScrollBegin, 82 EXPECT_EQ(InputMessage::Type_GestureScrollBegin,
83 captured_message_.input().type()); 83 captured_message_.input().type());
84 captured_cb_.Run(net::OK); 84 captured_cb_.Run(net::OK);
85 EXPECT_EQ(net::OK, cb_1.WaitForResult()); 85 EXPECT_EQ(net::OK, cb_1.WaitForResult());
86 } 86 }
87 87
88 // Verify that senders for a given type can be torn down and recreated. 88 // Verify that senders for a given type can be torn down and recreated.
89 TEST_F(BlimpMessageMultiplexerTest, SenderTransience) { 89 TEST_F(BlimpMessageMultiplexerTest, SenderTransience) {
90 net::TestCompletionCallback cb_3; 90 net::TestCompletionCallback cb_3;
91 input_processor_ = multiplexer_.CreateSenderForType(BlimpMessage::INPUT); 91 input_processor_ = multiplexer_.CreateSender(BlimpMessage::kInput);
92 input_processor_->ProcessMessage(std::move(input_message_), cb_3.callback()); 92 input_processor_->ProcessMessage(std::move(input_message_), cb_3.callback());
93 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type()); 93 EXPECT_EQ(BlimpMessage::kInput, captured_message_.feature_case());
94 EXPECT_EQ(InputMessage::Type_GestureScrollBegin, 94 EXPECT_EQ(InputMessage::Type_GestureScrollBegin,
95 captured_message_.input().type()); 95 captured_message_.input().type());
96 captured_cb_.Run(net::OK); 96 captured_cb_.Run(net::OK);
97 EXPECT_EQ(net::OK, cb_3.WaitForResult()); 97 EXPECT_EQ(net::OK, cb_3.WaitForResult());
98 } 98 }
99 99
100 // Verify that there is no limit on the number of senders for a given type. 100 // Verify that there is no limit on the number of senders for a given type.
101 TEST_F(BlimpMessageMultiplexerTest, SenderMultiplicity) { 101 TEST_F(BlimpMessageMultiplexerTest, SenderMultiplicity) {
102 net::TestCompletionCallback cb_4; 102 net::TestCompletionCallback cb_4;
103 std::unique_ptr<BlimpMessageProcessor> input_processor_2 = 103 std::unique_ptr<BlimpMessageProcessor> input_processor_2 =
104 multiplexer_.CreateSenderForType(BlimpMessage::INPUT); 104 multiplexer_.CreateSender(BlimpMessage::kInput);
105 input_processor_2->ProcessMessage(std::move(input_message_), cb_4.callback()); 105 input_processor_2->ProcessMessage(std::move(input_message_), cb_4.callback());
106 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type()); 106 EXPECT_EQ(BlimpMessage::kInput, captured_message_.feature_case());
107 EXPECT_EQ(InputMessage::Type_GestureScrollBegin, 107 EXPECT_EQ(InputMessage::Type_GestureScrollBegin,
108 captured_message_.input().type()); 108 captured_message_.input().type());
109 captured_cb_.Run(net::ERR_INVALID_ARGUMENT); 109 captured_cb_.Run(net::ERR_INVALID_ARGUMENT);
110 EXPECT_EQ(net::ERR_INVALID_ARGUMENT, cb_4.WaitForResult()); 110 EXPECT_EQ(net::ERR_INVALID_ARGUMENT, cb_4.WaitForResult());
111 } 111 }
112 112
113 } // namespace 113 } // namespace
114 } // namespace blimp 114 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/blimp_message_multiplexer.cc ('k') | blimp/net/blimp_message_output_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698