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

Unified 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: Fix Android to use GetVersionNumber() 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/net/blimp_connection.cc ('k') | blimp/net/connection_error_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/net/blimp_connection_unittest.cc
diff --git a/blimp/net/blimp_connection_unittest.cc b/blimp/net/blimp_connection_unittest.cc
index 76683299c29eeba07dc4d4390a069c2f093be7aa..d7d62d340efa48029e6fe9e4d31b44d6a0d18239 100644
--- a/blimp/net/blimp_connection_unittest.cc
+++ b/blimp/net/blimp_connection_unittest.cc
@@ -37,8 +37,11 @@ class BlimpConnectionTest : public testing::Test {
std::unique_ptr<testing::StrictMock<MockPacketWriter>> writer(
new testing::StrictMock<MockPacketWriter>);
writer_ = writer.get();
- connection_.reset(new BlimpConnection(
- base::WrapUnique(new MockPacketReader), std::move(writer)));
+ std::unique_ptr<testing::StrictMock<MockPacketReader>> reader(
+ new testing::StrictMock<MockPacketReader>);
+ reader_ = reader.get();
+ connection_.reset(
+ new BlimpConnection(std::move(reader), std::move(writer)));
connection_->AddConnectionErrorObserver(&error_observer1_);
connection_->AddConnectionErrorObserver(&error_observer2_);
connection_->AddConnectionErrorObserver(&error_observer3_);
@@ -61,6 +64,7 @@ class BlimpConnectionTest : public testing::Test {
}
base::MessageLoop message_loop_;
+ testing::StrictMock<MockPacketReader>* reader_;
testing::StrictMock<MockPacketWriter>* writer_;
testing::StrictMock<MockConnectionErrorObserver> error_observer1_;
testing::StrictMock<MockConnectionErrorObserver> error_observer2_;
@@ -86,6 +90,9 @@ TEST_F(BlimpConnectionTest, AsyncTwoPacketsWrite) {
WritePacket(BufferEqualsProto(*CreateControlMessage()), _))
.WillOnce(SaveArg<1>(&write_packet_cb))
.RetiresOnSaturation();
+ EXPECT_CALL(error_observer1_, OnConnectionError(_)).Times(0);
+ EXPECT_CALL(error_observer2_, OnConnectionError(_)).Times(0);
+ EXPECT_CALL(error_observer3_, OnConnectionError(_)).Times(0);
BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor();
net::TestCompletionCallback complete_cb_1;
@@ -121,6 +128,7 @@ TEST_F(BlimpConnectionTest, AsyncTwoPacketsWriteWithError) {
.RetiresOnSaturation();
EXPECT_CALL(error_observer1_, OnConnectionError(net::ERR_FAILED));
EXPECT_CALL(error_observer2_, OnConnectionError(net::ERR_FAILED));
+ EXPECT_CALL(error_observer3_, OnConnectionError(_)).Times(0);
BlimpMessageProcessor* sender = connection_->GetOutgoingMessageProcessor();
net::TestCompletionCallback complete_cb_1;
@@ -156,5 +164,66 @@ TEST_F(BlimpConnectionTest, DeleteHappyObserversAreOK) {
EXPECT_EQ(net::ERR_FAILED, complete_cb_1.WaitForResult());
}
+// Verifies that a ReadPacket error causes ErrorObservers to be notified.
+TEST_F(BlimpConnectionTest, ReadPacketErrorInvokesErrorObservers) {
+ scoped_refptr<net::GrowableIOBuffer> read_packet_buffer;
+ net::CompletionCallback read_packet_cb;
+
+ EXPECT_CALL(*reader_, ReadPacket(_, _))
+ .WillOnce(
+ DoAll(SaveArg<0>(&read_packet_buffer), SaveArg<1>(&read_packet_cb)))
+ .RetiresOnSaturation();
+
+ EXPECT_CALL(error_observer1_, OnConnectionError(net::ERR_FAILED));
+ EXPECT_CALL(error_observer2_, OnConnectionError(net::ERR_FAILED));
+ EXPECT_CALL(error_observer3_, OnConnectionError(_)).Times(0);
+
+ EXPECT_CALL(receiver_, MockableProcessMessage(_, _)).Times(0);
+
+ // Trigger the first ReadPacket() call by setting the MessageProcessor.
+ connection_->SetIncomingMessageProcessor(&receiver_);
+ EXPECT_TRUE(read_packet_buffer);
+ EXPECT_FALSE(read_packet_cb.is_null());
+
+ // Signal an error back from the ReadPacket operation.
+ base::ResetAndReturn(&read_packet_cb).Run(net::ERR_FAILED);
+}
+
+// Verifies that EndConnection messages received from the peer are
+// routed through to registered ConnectionErrorObservers as errors.
+TEST_F(BlimpConnectionTest, EndConnectionInvokesErrorObservers) {
+ scoped_refptr<net::GrowableIOBuffer> read_packet_buffer;
+ net::CompletionCallback read_packet_cb;
+
+ EXPECT_CALL(*reader_, ReadPacket(_, _))
+ .WillOnce(
+ DoAll(SaveArg<0>(&read_packet_buffer), SaveArg<1>(&read_packet_cb)))
+ .WillOnce(Return())
+ .RetiresOnSaturation();
+
+ EXPECT_CALL(error_observer1_,
+ OnConnectionError(EndConnectionMessage::PROTOCOL_MISMATCH));
+ EXPECT_CALL(error_observer2_,
+ OnConnectionError(EndConnectionMessage::PROTOCOL_MISMATCH));
+ EXPECT_CALL(error_observer3_, OnConnectionError(_)).Times(0);
+
+ EXPECT_CALL(receiver_, MockableProcessMessage(_, _)).Times(0);
+
+ // Trigger the first ReadPacket() call by setting the MessageProcessor.
+ connection_->SetIncomingMessageProcessor(&receiver_);
+ EXPECT_TRUE(read_packet_buffer);
+ EXPECT_FALSE(read_packet_cb.is_null());
+
+ // Create an EndConnection message to return from ReadPacket.
+ std::unique_ptr<BlimpMessage> message =
+ CreateEndConnectionMessage(EndConnectionMessage::PROTOCOL_MISMATCH);
+
+ // Put the EndConnection message in the buffer and invoke the read callback.
+ read_packet_buffer->SetCapacity(message->ByteSize());
+ ASSERT_TRUE(message->SerializeToArray(read_packet_buffer->data(),
+ message->GetCachedSize()));
+ base::ResetAndReturn(&read_packet_cb).Run(message->ByteSize());
+}
+
} // namespace
} // namespace blimp
« no previous file with comments | « blimp/net/blimp_connection.cc ('k') | blimp/net/connection_error_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698