diff options
author | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-23 01:41:04 +0000 |
---|---|---|
committer | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-23 01:41:04 +0000 |
commit | d5a4dd65f33e42ff766013a4f4ff3cf4a52673e5 (patch) | |
tree | f9074959ade9d3f4d39e6b07ce08603dd100bd5b /net/socket_stream | |
parent | 222c84bf2c650b7f7afeaef5bfbd0bc738ac8d81 (diff) | |
download | chromium_src-d5a4dd65f33e42ff766013a4f4ff3cf4a52673e5.zip chromium_src-d5a4dd65f33e42ff766013a4f4ff3cf4a52673e5.tar.gz chromium_src-d5a4dd65f33e42ff766013a4f4ff3cf4a52673e5.tar.bz2 |
[net] Switch TestURLRequestContext and other tests to use MockCachingHostResolver or MockHostResolver.
Make explicit when HostResolver::Resolve is expected to never complete in tests.
Clean up TestURLRequestContext API.
BUG=126016,128745
TEST=net_unittests; jingle_unittests; sync_unit_tests
Review URL: https://chromiumcodereview.appspot.com/10408067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138413 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket_stream')
-rw-r--r-- | net/socket_stream/socket_stream.cc | 5 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.h | 3 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_unittest.cc | 35 |
3 files changed, 18 insertions, 25 deletions
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index 4e0eac1..3a3c69a 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -246,11 +246,6 @@ const ProxyServer& SocketStream::proxy_server() const { return proxy_info_.proxy_server(); } -void SocketStream::SetHostResolver(HostResolver* host_resolver) { - DCHECK(host_resolver); - host_resolver_ = host_resolver; -} - void SocketStream::SetClientSocketFactory( ClientSocketFactory* factory) { DCHECK(factory); diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index 2fa3683..a2e5ddb 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -168,9 +168,6 @@ class NET_EXPORT SocketStream const ProxyServer& proxy_server() const; - // Sets an alternative HostResolver. For testing purposes only. - void SetHostResolver(HostResolver* host_resolver); - // Sets an alternative ClientSocketFactory. Doesn't take ownership of // |factory|. For testing purposes only. void SetClientSocketFactory(ClientSocketFactory* factory); diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index a7a0cc7..76bb379 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -16,11 +16,14 @@ #include "net/base/net_log.h" #include "net/base/net_log_unittest.h" #include "net/base/test_completion_callback.h" +#include "net/proxy/proxy_service.h" #include "net/socket/socket_test_util.h" #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +namespace { + struct SocketStreamEvent { enum EventType { EVENT_START_OPEN_CONNECTION, EVENT_CONNECTED, EVENT_SENT_DATA, @@ -175,6 +178,18 @@ class SocketStreamEventRecorder : public net::SocketStream::Delegate { DISALLOW_COPY_AND_ASSIGN(SocketStreamEventRecorder); }; +class TestURLRequestContextWithProxy : public TestURLRequestContext { + public: + explicit TestURLRequestContextWithProxy(const std::string& proxy) + : TestURLRequestContext(true) { + context_storage_.set_proxy_service(net::ProxyService::CreateFixed(proxy)); + Init(); + } + virtual ~TestURLRequestContextWithProxy() {} +}; + +} // namespace + namespace net { class SocketStreamTest : public PlatformTest { @@ -278,14 +293,12 @@ TEST_F(SocketStreamTest, CloseFlushPendingWrite) { &SocketStreamTest::DoCloseFlushPendingWriteTest, base::Unretained(this))); - MockHostResolver host_resolver; TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); socket_stream->set_context(&context); - socket_stream->SetHostResolver(&host_resolver); MockWrite data_writes[] = { MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), @@ -380,11 +393,9 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - MockHostResolver host_resolver; - TestURLRequestContext context("myproxy:70"); + TestURLRequestContextWithProxy context("myproxy:70"); socket_stream->set_context(&context); - socket_stream->SetHostResolver(&host_resolver); socket_stream->SetClientSocketFactory(&mock_socket_factory); socket_stream->Connect(); @@ -418,14 +429,12 @@ TEST_F(SocketStreamTest, IOPending) { delegate->SetOnStartOpenConnection(base::Bind( &SocketStreamTest::DoIOPending, base::Unretained(this))); - MockHostResolver host_resolver; TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); socket_stream->set_context(&context); - socket_stream->SetHostResolver(&host_resolver); MockWrite data_writes[] = { MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), @@ -482,14 +491,12 @@ TEST_F(SocketStreamTest, SwitchToSpdy) { delegate->SetOnStartOpenConnection(base::Bind( &SocketStreamTest::DoSwitchToSpdyTest, base::Unretained(this))); - MockHostResolver host_resolver; TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); socket_stream->set_context(&context); - socket_stream->SetHostResolver(&host_resolver); socket_stream->Connect(); @@ -512,14 +519,12 @@ TEST_F(SocketStreamTest, SwitchAfterPending) { delegate->SetOnStartOpenConnection(base::Bind( &SocketStreamTest::DoIOPending, base::Unretained(this))); - MockHostResolver host_resolver; TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( new SocketStream(GURL("ws://example.com/demo"), delegate.get())); socket_stream->set_context(&context); - socket_stream->SetHostResolver(&host_resolver); socket_stream->Connect(); io_test_callback_.WaitForResult(); @@ -562,8 +567,7 @@ TEST_F(SocketStreamTest, SecureProxyConnectError) { mock_socket_factory.AddSSLSocketDataProvider(&ssl); TestCompletionCallback test_callback; - MockHostResolver host_resolver; - TestURLRequestContext context("https://myproxy:70"); + TestURLRequestContextWithProxy context("https://myproxy:70"); scoped_ptr<SocketStreamEventRecorder> delegate( new SocketStreamEventRecorder(test_callback.callback())); @@ -574,7 +578,6 @@ TEST_F(SocketStreamTest, SecureProxyConnectError) { new SocketStream(GURL("ws://example.com/demo"), delegate.get())); socket_stream->set_context(&context); - socket_stream->SetHostResolver(&host_resolver); socket_stream->SetClientSocketFactory(&mock_socket_factory); socket_stream->Connect(); @@ -615,8 +618,7 @@ TEST_F(SocketStreamTest, SecureProxyConnect) { mock_socket_factory.AddSSLSocketDataProvider(&ssl); TestCompletionCallback test_callback; - MockHostResolver host_resolver; - TestURLRequestContext context("https://myproxy:70"); + TestURLRequestContextWithProxy context("https://myproxy:70"); scoped_ptr<SocketStreamEventRecorder> delegate( new SocketStreamEventRecorder(test_callback.callback())); @@ -627,7 +629,6 @@ TEST_F(SocketStreamTest, SecureProxyConnect) { new SocketStream(GURL("ws://example.com/demo"), delegate.get())); socket_stream->set_context(&context); - socket_stream->SetHostResolver(&host_resolver); socket_stream->SetClientSocketFactory(&mock_socket_factory); socket_stream->Connect(); |