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

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

Issue 1909143002: Use ConnectionErrorObserver, not callbacks, for error handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed haibinlu feedback. 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_connection.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/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 28 matching lines...) Expand all
39 connection_.reset(new BlimpConnection( 39 connection_.reset(new BlimpConnection(
40 base::WrapUnique(new MockPacketReader), std::move(writer))); 40 base::WrapUnique(new MockPacketReader), std::move(writer)));
41 connection_->AddConnectionErrorObserver(&error_observer1_); 41 connection_->AddConnectionErrorObserver(&error_observer1_);
42 connection_->AddConnectionErrorObserver(&error_observer2_); 42 connection_->AddConnectionErrorObserver(&error_observer2_);
43 connection_->AddConnectionErrorObserver(&error_observer3_); 43 connection_->AddConnectionErrorObserver(&error_observer3_);
44 connection_->RemoveConnectionErrorObserver(&error_observer3_); 44 connection_->RemoveConnectionErrorObserver(&error_observer3_);
45 } 45 }
46 46
47 ~BlimpConnectionTest() override {} 47 ~BlimpConnectionTest() override {}
48 48
49 void DropConnection() { connection_.reset(); }
50
49 protected: 51 protected:
50 std::unique_ptr<BlimpMessage> CreateInputMessage() { 52 std::unique_ptr<BlimpMessage> CreateInputMessage() {
51 std::unique_ptr<BlimpMessage> msg(new BlimpMessage); 53 std::unique_ptr<BlimpMessage> msg(new BlimpMessage);
52 msg->set_type(BlimpMessage::INPUT); 54 msg->set_type(BlimpMessage::INPUT);
53 return msg; 55 return msg;
54 } 56 }
55 57
56 std::unique_ptr<BlimpMessage> CreateControlMessage() { 58 std::unique_ptr<BlimpMessage> CreateControlMessage() {
57 std::unique_ptr<BlimpMessage> msg(new BlimpMessage); 59 std::unique_ptr<BlimpMessage> msg(new BlimpMessage);
58 msg->set_type(BlimpMessage::TAB_CONTROL); 60 msg->set_type(BlimpMessage::TAB_CONTROL);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 InSequence s; 114 InSequence s;
113 EXPECT_CALL(*writer_, 115 EXPECT_CALL(*writer_,
114 WritePacket(BufferEqualsProto(*CreateInputMessage()), _)) 116 WritePacket(BufferEqualsProto(*CreateInputMessage()), _))
115 .WillOnce(SaveArg<1>(&write_packet_cb)) 117 .WillOnce(SaveArg<1>(&write_packet_cb))
116 .RetiresOnSaturation(); 118 .RetiresOnSaturation();
117 EXPECT_CALL(*writer_, 119 EXPECT_CALL(*writer_,
118 WritePacket(BufferEqualsProto(*CreateControlMessage()), _)) 120 WritePacket(BufferEqualsProto(*CreateControlMessage()), _))
119 .WillOnce(SaveArg<1>(&write_packet_cb)) 121 .WillOnce(SaveArg<1>(&write_packet_cb))
120 .RetiresOnSaturation(); 122 .RetiresOnSaturation();
121 EXPECT_CALL(error_observer1_, OnConnectionError(net::ERR_FAILED)); 123 EXPECT_CALL(error_observer1_, OnConnectionError(net::ERR_FAILED));
122 EXPECT_CALL(error_observer2_, OnConnectionError(net::ERR_FAILED)); 124 EXPECT_CALL(error_observer2_, OnConnectionError(net::ERR_FAILED))
125 .WillOnce(testing::InvokeWithoutArgs(
126 this, &BlimpConnectionTest::DropConnection));
Wez 2016/05/25 03:28:35 You don't want to add a separate, dedicated test?
Kevin M 2016/05/25 20:40:25 Done.
123 127
124 BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor(); 128 BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor();
125 net::TestCompletionCallback complete_cb_1; 129 net::TestCompletionCallback complete_cb_1;
126 sender->ProcessMessage(CreateInputMessage(), 130 sender->ProcessMessage(CreateInputMessage(),
127 complete_cb_1.callback()); 131 complete_cb_1.callback());
128 base::ResetAndReturn(&write_packet_cb).Run(net::OK); 132 base::ResetAndReturn(&write_packet_cb).Run(net::OK);
129 EXPECT_EQ(net::OK, complete_cb_1.WaitForResult()); 133 EXPECT_EQ(net::OK, complete_cb_1.WaitForResult());
130 134
131 net::TestCompletionCallback complete_cb_2; 135 net::TestCompletionCallback complete_cb_2;
132 sender->ProcessMessage(CreateControlMessage(), 136 sender->ProcessMessage(CreateControlMessage(),
133 complete_cb_2.callback()); 137 complete_cb_2.callback());
134 base::ResetAndReturn(&write_packet_cb).Run(net::ERR_FAILED); 138 base::ResetAndReturn(&write_packet_cb).Run(net::ERR_FAILED);
135 EXPECT_EQ(net::ERR_FAILED, complete_cb_2.WaitForResult()); 139 EXPECT_EQ(net::ERR_FAILED, complete_cb_2.WaitForResult());
136 } 140 }
137 141
138 } // namespace 142 } // namespace
139 } // namespace blimp 143 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/blimp_connection.cc ('k') | blimp/net/blimp_message_output_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698