| 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
|
|
|