diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-03 21:48:34 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-03 21:48:34 +0000 |
commit | 9e1bdd3f9785ed8a84a137c98b781ddaec41b080 (patch) | |
tree | 36d3550cc6d9db08bf3a18fbb42668d440a94b56 /net/http/http_network_layer_unittest.cc | |
parent | 966c57777b2c18313cddd8e36d109665f5377521 (diff) | |
download | chromium_src-9e1bdd3f9785ed8a84a137c98b781ddaec41b080.zip chromium_src-9e1bdd3f9785ed8a84a137c98b781ddaec41b080.tar.gz chromium_src-9e1bdd3f9785ed8a84a137c98b781ddaec41b080.tar.bz2 |
Refactor HttpNetworkSession construction.
Introduce HttpNetworkSession::Params. This should make it easy to add new optionally NULL parameters. I also took this opportunity to eliminate some copy/pastes of TestURLRequestContext and make them use the original. I was also able to remove the need for ClientSocketFactory::GetDefaultFactory() calls and new SpdySessionPool() calls in most places.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6349028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_network_layer_unittest.cc')
-rw-r--r-- | net/http/http_network_layer_unittest.cc | 101 |
1 files changed, 32 insertions, 69 deletions
diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc index f76ffbb..5120fac 100644 --- a/net/http/http_network_layer_unittest.cc +++ b/net/http/http_network_layer_unittest.cc @@ -20,76 +20,57 @@ namespace net { namespace { class HttpNetworkLayerTest : public PlatformTest { + protected: + HttpNetworkLayerTest() + : proxy_service_(ProxyService::CreateDirect()), + ssl_config_service_(new SSLConfigServiceDefaults) { + HttpNetworkSession::Params session_params; + session_params.client_socket_factory = &mock_socket_factory_; + session_params.host_resolver = &host_resolver_; + session_params.cert_verifier = &cert_verifier_; + session_params.proxy_service = proxy_service_; + session_params.ssl_config_service = ssl_config_service_; + network_session_ = new HttpNetworkSession(session_params); + factory_.reset(new HttpNetworkLayer(network_session_)); + } + + MockClientSocketFactory mock_socket_factory_; + MockHostResolver host_resolver_; + CertVerifier cert_verifier_; + const scoped_refptr<ProxyService> proxy_service_; + const scoped_refptr<SSLConfigService> ssl_config_service_; + scoped_refptr<HttpNetworkSession> network_session_; + scoped_ptr<HttpNetworkLayer> factory_; }; TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { - MockClientSocketFactory mock_socket_factory; - MockHostResolver host_resolver; - CertVerifier cert_verifier; - scoped_refptr<HttpNetworkSession> network_session( - new HttpNetworkSession( - &host_resolver, - &cert_verifier, - NULL /* dnsrr_resolver */, - NULL /* dns_cert_checker */, - NULL /* ssl_host_info_factory */, - ProxyService::CreateDirect(), - &mock_socket_factory, - new SSLConfigServiceDefaults, - new SpdySessionPool(NULL), - NULL, - NULL, - NULL)); - - HttpNetworkLayer factory(network_session); - scoped_ptr<HttpTransaction> trans; - int rv = factory.CreateTransaction(&trans); + int rv = factory_->CreateTransaction(&trans); EXPECT_EQ(OK, rv); EXPECT_TRUE(trans.get() != NULL); } TEST_F(HttpNetworkLayerTest, Suspend) { - MockClientSocketFactory mock_socket_factory; - MockHostResolver host_resolver; - CertVerifier cert_verifier; - scoped_refptr<HttpNetworkSession> network_session( - new HttpNetworkSession( - &host_resolver, - &cert_verifier, - NULL /* dnsrr_resolver */, - NULL /* dns_cert_checker */, - NULL /* ssl_host_info_factory */, - ProxyService::CreateDirect(), - &mock_socket_factory, - new SSLConfigServiceDefaults, - new SpdySessionPool(NULL), - NULL, - NULL, - NULL)); - HttpNetworkLayer factory(network_session); - scoped_ptr<HttpTransaction> trans; - int rv = factory.CreateTransaction(&trans); + int rv = factory_->CreateTransaction(&trans); EXPECT_EQ(OK, rv); trans.reset(); - factory.Suspend(true); + factory_->Suspend(true); - rv = factory.CreateTransaction(&trans); + rv = factory_->CreateTransaction(&trans); EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, rv); ASSERT_TRUE(trans == NULL); - factory.Suspend(false); + factory_->Suspend(false); - rv = factory.CreateTransaction(&trans); + rv = factory_->CreateTransaction(&trans); EXPECT_EQ(OK, rv); } TEST_F(HttpNetworkLayerTest, GET) { - MockClientSocketFactory mock_socket_factory; MockRead data_reads[] = { MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), @@ -103,32 +84,10 @@ TEST_F(HttpNetworkLayerTest, GET) { }; StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); - mock_socket_factory.AddSocketDataProvider(&data); - - MockHostResolver host_resolver; - CertVerifier cert_verifier; - scoped_refptr<HttpNetworkSession> network_session( - new HttpNetworkSession( - &host_resolver, - &cert_verifier, - NULL /* dnsrr_resolver */, - NULL /* dns_cert_checker */, - NULL /* ssl_host_info_factory */, - ProxyService::CreateDirect(), - &mock_socket_factory, - new SSLConfigServiceDefaults, - new SpdySessionPool(NULL), - NULL, - NULL, - NULL)); - HttpNetworkLayer factory(network_session); + mock_socket_factory_.AddSocketDataProvider(&data); TestCompletionCallback callback; - scoped_ptr<HttpTransaction> trans; - int rv = factory.CreateTransaction(&trans); - EXPECT_EQ(OK, rv); - HttpRequestInfo request_info; request_info.url = GURL("http://www.google.com/"); request_info.method = "GET"; @@ -136,6 +95,10 @@ TEST_F(HttpNetworkLayerTest, GET) { "Foo/1.0"); request_info.load_flags = LOAD_NORMAL; + scoped_ptr<HttpTransaction> trans; + int rv = factory_->CreateTransaction(&trans); + EXPECT_EQ(OK, rv); + rv = trans->Start(&request_info, &callback, BoundNetLog()); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); |