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

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

Issue 1426993008: Serialize a subset of WebInputEvents to protobufs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed more comments Created 5 years 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
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"
(...skipping 17 matching lines...) Expand all
28 navigation_message_(new BlimpMessage), 28 navigation_message_(new BlimpMessage),
29 input_processor_(multiplexer_.CreateSenderForType(BlimpMessage::INPUT)), 29 input_processor_(multiplexer_.CreateSenderForType(BlimpMessage::INPUT)),
30 navigation_processor_( 30 navigation_processor_(
31 multiplexer_.CreateSenderForType(BlimpMessage::NAVIGATION)) {} 31 multiplexer_.CreateSenderForType(BlimpMessage::NAVIGATION)) {}
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(InputMessage::DRAG); 38 input_message_->mutable_input()->set_type(
39 InputMessage::Type_GestureScrollBegin);
39 navigation_message_->mutable_navigation()->set_type( 40 navigation_message_->mutable_navigation()->set_type(
40 NavigationMessage::LOAD_URL); 41 NavigationMessage::LOAD_URL);
41 } 42 }
42 43
43 protected: 44 protected:
44 MockBlimpMessageProcessor mock_output_processor_; 45 MockBlimpMessageProcessor mock_output_processor_;
45 BlimpMessageMultiplexer multiplexer_; 46 BlimpMessageMultiplexer multiplexer_;
46 scoped_ptr<BlimpMessage> input_message_; 47 scoped_ptr<BlimpMessage> input_message_;
47 scoped_ptr<BlimpMessage> navigation_message_; 48 scoped_ptr<BlimpMessage> navigation_message_;
48 BlimpMessage captured_message_; 49 BlimpMessage captured_message_;
49 net::CompletionCallback captured_cb_; 50 net::CompletionCallback captured_cb_;
50 scoped_ptr<BlimpMessageProcessor> input_processor_; 51 scoped_ptr<BlimpMessageProcessor> input_processor_;
51 scoped_ptr<BlimpMessageProcessor> navigation_processor_; 52 scoped_ptr<BlimpMessageProcessor> navigation_processor_;
52 }; 53 };
53 54
54 // 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
55 // correctly. 56 // correctly.
56 TEST_F(BlimpMessageMultiplexerTest, TypeSetByMux) { 57 TEST_F(BlimpMessageMultiplexerTest, TypeSetByMux) {
57 net::TestCompletionCallback cb_1; 58 net::TestCompletionCallback cb_1;
58 input_processor_->ProcessMessage(input_message_.Pass(), cb_1.callback()); 59 input_processor_->ProcessMessage(input_message_.Pass(), cb_1.callback());
59 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type()); 60 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type());
60 EXPECT_EQ(InputMessage::DRAG, captured_message_.input().type()); 61 EXPECT_EQ(InputMessage::Type_GestureScrollBegin,
62 captured_message_.input().type());
61 captured_cb_.Run(net::OK); 63 captured_cb_.Run(net::OK);
62 EXPECT_EQ(net::OK, cb_1.WaitForResult()); 64 EXPECT_EQ(net::OK, cb_1.WaitForResult());
63 65
64 net::TestCompletionCallback cb_2; 66 net::TestCompletionCallback cb_2;
65 navigation_processor_->ProcessMessage(navigation_message_.Pass(), 67 navigation_processor_->ProcessMessage(navigation_message_.Pass(),
66 cb_2.callback()); 68 cb_2.callback());
67 EXPECT_EQ(BlimpMessage::NAVIGATION, captured_message_.type()); 69 EXPECT_EQ(BlimpMessage::NAVIGATION, captured_message_.type());
68 EXPECT_EQ(NavigationMessage::LOAD_URL, captured_message_.navigation().type()); 70 EXPECT_EQ(NavigationMessage::LOAD_URL, captured_message_.navigation().type());
69 captured_cb_.Run(net::ERR_FAILED); 71 captured_cb_.Run(net::ERR_FAILED);
70 EXPECT_EQ(net::ERR_FAILED, cb_2.WaitForResult()); 72 EXPECT_EQ(net::ERR_FAILED, cb_2.WaitForResult());
71 } 73 }
72 74
73 // 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.
74 TEST_F(BlimpMessageMultiplexerTest, TypeSetByCaller) { 76 TEST_F(BlimpMessageMultiplexerTest, TypeSetByCaller) {
75 input_message_->set_type(BlimpMessage::INPUT); 77 input_message_->set_type(BlimpMessage::INPUT);
76 78
77 net::TestCompletionCallback cb_1; 79 net::TestCompletionCallback cb_1;
78 input_processor_->ProcessMessage(input_message_.Pass(), cb_1.callback()); 80 input_processor_->ProcessMessage(input_message_.Pass(), cb_1.callback());
79 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type()); 81 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type());
80 EXPECT_EQ(InputMessage::DRAG, captured_message_.input().type()); 82 EXPECT_EQ(InputMessage::Type_GestureScrollBegin,
83 captured_message_.input().type());
81 captured_cb_.Run(net::OK); 84 captured_cb_.Run(net::OK);
82 EXPECT_EQ(net::OK, cb_1.WaitForResult()); 85 EXPECT_EQ(net::OK, cb_1.WaitForResult());
83 } 86 }
84 87
85 // 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.
86 TEST_F(BlimpMessageMultiplexerTest, SenderTransience) { 89 TEST_F(BlimpMessageMultiplexerTest, SenderTransience) {
87 net::TestCompletionCallback cb_3; 90 net::TestCompletionCallback cb_3;
88 input_processor_ = multiplexer_.CreateSenderForType(BlimpMessage::INPUT); 91 input_processor_ = multiplexer_.CreateSenderForType(BlimpMessage::INPUT);
89 input_processor_->ProcessMessage(input_message_.Pass(), cb_3.callback()); 92 input_processor_->ProcessMessage(input_message_.Pass(), cb_3.callback());
90 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type()); 93 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type());
91 EXPECT_EQ(InputMessage::DRAG, captured_message_.input().type()); 94 EXPECT_EQ(InputMessage::Type_GestureScrollBegin,
95 captured_message_.input().type());
92 captured_cb_.Run(net::OK); 96 captured_cb_.Run(net::OK);
93 EXPECT_EQ(net::OK, cb_3.WaitForResult()); 97 EXPECT_EQ(net::OK, cb_3.WaitForResult());
94 } 98 }
95 99
96 // 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.
97 TEST_F(BlimpMessageMultiplexerTest, SenderMultiplicity) { 101 TEST_F(BlimpMessageMultiplexerTest, SenderMultiplicity) {
98 net::TestCompletionCallback cb_4; 102 net::TestCompletionCallback cb_4;
99 scoped_ptr<BlimpMessageProcessor> input_processor_2 = 103 scoped_ptr<BlimpMessageProcessor> input_processor_2 =
100 multiplexer_.CreateSenderForType(BlimpMessage::INPUT); 104 multiplexer_.CreateSenderForType(BlimpMessage::INPUT);
101 input_processor_2->ProcessMessage(input_message_.Pass(), cb_4.callback()); 105 input_processor_2->ProcessMessage(input_message_.Pass(), cb_4.callback());
102 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type()); 106 EXPECT_EQ(BlimpMessage::INPUT, captured_message_.type());
103 EXPECT_EQ(InputMessage::DRAG, captured_message_.input().type()); 107 EXPECT_EQ(InputMessage::Type_GestureScrollBegin,
108 captured_message_.input().type());
104 captured_cb_.Run(net::ERR_INVALID_ARGUMENT); 109 captured_cb_.Run(net::ERR_INVALID_ARGUMENT);
105 EXPECT_EQ(net::ERR_INVALID_ARGUMENT, cb_4.WaitForResult()); 110 EXPECT_EQ(net::ERR_INVALID_ARGUMENT, cb_4.WaitForResult());
106 } 111 }
107 112
108 } // namespace 113 } // namespace
109 } // namespace blimp 114 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698