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

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

Issue 1876983002: Use Chromium BUILD to approximate Blimp protocol version, and check it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Route EndConnection to OnConnectionError notifications 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
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/net/blimp_connection.h" 5 #include "blimp/net/blimp_connection.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 19 matching lines...) Expand all
30 30
31 namespace blimp { 31 namespace blimp {
32 namespace { 32 namespace {
33 33
34 class BlimpConnectionTest : public testing::Test { 34 class BlimpConnectionTest : public testing::Test {
35 public: 35 public:
36 BlimpConnectionTest() { 36 BlimpConnectionTest() {
37 std::unique_ptr<testing::StrictMock<MockPacketWriter>> writer( 37 std::unique_ptr<testing::StrictMock<MockPacketWriter>> writer(
38 new testing::StrictMock<MockPacketWriter>); 38 new testing::StrictMock<MockPacketWriter>);
39 writer_ = writer.get(); 39 writer_ = writer.get();
40 std::unique_ptr<testing::StrictMock<MockPacketWriter>> reader(
41 new testing::StrictMock<MockPacketWriter>);
40 connection_.reset(new BlimpConnection( 42 connection_.reset(new BlimpConnection(
41 base::WrapUnique(new MockPacketReader), std::move(writer))); 43 base::WrapUnique(new MockPacketReader), std::move(writer)));
42 connection_->AddConnectionErrorObserver(&error_observer1_); 44 connection_->AddConnectionErrorObserver(&error_observer1_);
43 connection_->AddConnectionErrorObserver(&error_observer2_); 45 connection_->AddConnectionErrorObserver(&error_observer2_);
44 connection_->AddConnectionErrorObserver(&error_observer3_); 46 connection_->AddConnectionErrorObserver(&error_observer3_);
45 connection_->RemoveConnectionErrorObserver(&error_observer3_); 47 connection_->RemoveConnectionErrorObserver(&error_observer3_);
46 } 48 }
47 49
48 ~BlimpConnectionTest() override {} 50 ~BlimpConnectionTest() override {}
49 51
(...skipping 27 matching lines...) Expand all
77 79
78 InSequence s; 80 InSequence s;
79 EXPECT_CALL(*writer_, 81 EXPECT_CALL(*writer_,
80 WritePacket(BufferEqualsProto(*CreateInputMessage()), _)) 82 WritePacket(BufferEqualsProto(*CreateInputMessage()), _))
81 .WillOnce(SaveArg<1>(&write_packet_cb)) 83 .WillOnce(SaveArg<1>(&write_packet_cb))
82 .RetiresOnSaturation(); 84 .RetiresOnSaturation();
83 EXPECT_CALL(*writer_, 85 EXPECT_CALL(*writer_,
84 WritePacket(BufferEqualsProto(*CreateControlMessage()), _)) 86 WritePacket(BufferEqualsProto(*CreateControlMessage()), _))
85 .WillOnce(SaveArg<1>(&write_packet_cb)) 87 .WillOnce(SaveArg<1>(&write_packet_cb))
86 .RetiresOnSaturation(); 88 .RetiresOnSaturation();
89 EXPECT_CALL(error_observer1_, OnConnectionError(_)).Times(0);
90 EXPECT_CALL(error_observer2_, OnConnectionError(_)).Times(0);
91 EXPECT_CALL(error_observer3_, OnConnectionError(_)).Times(0);
87 92
88 BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor(); 93 BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor();
89 net::TestCompletionCallback complete_cb_1; 94 net::TestCompletionCallback complete_cb_1;
90 ASSERT_TRUE(write_packet_cb.is_null()); 95 ASSERT_TRUE(write_packet_cb.is_null());
91 sender->ProcessMessage(CreateInputMessage(), 96 sender->ProcessMessage(CreateInputMessage(),
92 complete_cb_1.callback()); 97 complete_cb_1.callback());
93 ASSERT_FALSE(write_packet_cb.is_null()); 98 ASSERT_FALSE(write_packet_cb.is_null());
94 base::ResetAndReturn(&write_packet_cb).Run(net::OK); 99 base::ResetAndReturn(&write_packet_cb).Run(net::OK);
95 EXPECT_EQ(net::OK, complete_cb_1.WaitForResult()); 100 EXPECT_EQ(net::OK, complete_cb_1.WaitForResult());
96 101
(...skipping 15 matching lines...) Expand all
112 EXPECT_CALL(*writer_, 117 EXPECT_CALL(*writer_,
113 WritePacket(BufferEqualsProto(*CreateInputMessage()), _)) 118 WritePacket(BufferEqualsProto(*CreateInputMessage()), _))
114 .WillOnce(SaveArg<1>(&write_packet_cb)) 119 .WillOnce(SaveArg<1>(&write_packet_cb))
115 .RetiresOnSaturation(); 120 .RetiresOnSaturation();
116 EXPECT_CALL(*writer_, 121 EXPECT_CALL(*writer_,
117 WritePacket(BufferEqualsProto(*CreateControlMessage()), _)) 122 WritePacket(BufferEqualsProto(*CreateControlMessage()), _))
118 .WillOnce(SaveArg<1>(&write_packet_cb)) 123 .WillOnce(SaveArg<1>(&write_packet_cb))
119 .RetiresOnSaturation(); 124 .RetiresOnSaturation();
120 EXPECT_CALL(error_observer1_, OnConnectionError(net::ERR_FAILED)); 125 EXPECT_CALL(error_observer1_, OnConnectionError(net::ERR_FAILED));
121 EXPECT_CALL(error_observer2_, OnConnectionError(net::ERR_FAILED)); 126 EXPECT_CALL(error_observer2_, OnConnectionError(net::ERR_FAILED));
127 EXPECT_CALL(error_observer3_, OnConnectionError(_)).Times(0);
122 128
123 BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor(); 129 BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor();
124 net::TestCompletionCallback complete_cb_1; 130 net::TestCompletionCallback complete_cb_1;
125 sender->ProcessMessage(CreateInputMessage(), 131 sender->ProcessMessage(CreateInputMessage(),
126 complete_cb_1.callback()); 132 complete_cb_1.callback());
127 base::ResetAndReturn(&write_packet_cb).Run(net::OK); 133 base::ResetAndReturn(&write_packet_cb).Run(net::OK);
128 EXPECT_EQ(net::OK, complete_cb_1.WaitForResult()); 134 EXPECT_EQ(net::OK, complete_cb_1.WaitForResult());
129 135
130 net::TestCompletionCallback complete_cb_2; 136 net::TestCompletionCallback complete_cb_2;
131 sender->ProcessMessage(CreateControlMessage(), 137 sender->ProcessMessage(CreateControlMessage(),
132 complete_cb_2.callback()); 138 complete_cb_2.callback());
133 base::ResetAndReturn(&write_packet_cb).Run(net::ERR_FAILED); 139 base::ResetAndReturn(&write_packet_cb).Run(net::ERR_FAILED);
134 EXPECT_EQ(net::ERR_FAILED, complete_cb_2.WaitForResult()); 140 EXPECT_EQ(net::ERR_FAILED, complete_cb_2.WaitForResult());
135 } 141 }
136 142
143 // Verifies that EndConnection messages received from the peer are
144 // routed through to registered ConnectionErrorObservers as errors.
145 TEST_F(BlimpConnectionTest, EndConnectionInvokesErrorObservers) {
146 // XXX test of how EndConnection messages are processed goes here.
Kevin M 2016/05/25 21:19:19 Is this a TODO for this CL or for a followup? If i
Wez 2016/05/25 23:11:37 TODO for this CL; wanted to get your input on whet
147 // XXX we should also have a test that we invoke error observers on read
148 // failures!
149 }
150
137 } // namespace 151 } // namespace
138 } // namespace blimp 152 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698