From 0b4e575a9749594defb699b866a236f11d9a5e0f Mon Sep 17 00:00:00 2001 From: "tyoshino@chromium.org" Date: Fri, 7 Jun 2013 09:14:24 +0000 Subject: Test that SocketStream is closed correctly on resolve failure. Review URL: https://chromiumcodereview.appspot.com/16424003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204777 0039d316-1c4b-4281-b951-d872f2087c98 --- net/socket_stream/socket_stream_unittest.cc | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index aed80f2..7f3c5f1 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -416,6 +416,41 @@ TEST_F(SocketStreamTest, CloseFlushPendingWrite) { EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[6].event_type); } +TEST_F(SocketStreamTest, ResolveFailure) { + TestCompletionCallback test_callback; + + scoped_ptr delegate( + new SocketStreamEventRecorder(test_callback.callback())); + + scoped_refptr socket_stream( + new SocketStream(GURL("ws://example.com/demo"), delegate.get())); + + // Make resolver fail. + TestURLRequestContext context; + scoped_ptr mock_host_resolver( + new MockHostResolver()); + mock_host_resolver->rules()->AddSimulatedFailure("example.com"); + context.set_host_resolver(mock_host_resolver.get()); + socket_stream->set_context(&context); + + // No read/write on socket is expected. + StaticSocketDataProvider data_provider(NULL, 0, NULL, 0); + MockClientSocketFactory* mock_socket_factory = + GetMockClientSocketFactory(); + mock_socket_factory->AddSocketDataProvider(&data_provider); + socket_stream->SetClientSocketFactory(mock_socket_factory); + + socket_stream->Connect(); + + test_callback.WaitForResult(); + + const std::vector& events = delegate->GetSeenEvents(); + ASSERT_EQ(2U, events.size()); + + EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[0].event_type); + EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[1].event_type); +} + TEST_F(SocketStreamTest, ExceedMaxPendingSendAllowed) { TestCompletionCallback test_callback; -- cgit v1.1