| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_network_layer.h" | 5 #include "net/http/http_network_layer.h" |
| 6 | 6 |
| 7 #include "net/base/mock_cert_verifier.h" | 7 #include "net/base/mock_cert_verifier.h" |
| 8 #include "net/base/mock_host_resolver.h" | 8 #include "net/base/mock_host_resolver.h" |
| 9 #include "net/base/net_log.h" | 9 #include "net/base/net_log.h" |
| 10 #include "net/base/ssl_config_service_defaults.h" | 10 #include "net/base/ssl_config_service_defaults.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 scoped_ptr<CertVerifier> cert_verifier_; | 43 scoped_ptr<CertVerifier> cert_verifier_; |
| 44 const scoped_ptr<ProxyService> proxy_service_; | 44 const scoped_ptr<ProxyService> proxy_service_; |
| 45 const scoped_refptr<SSLConfigService> ssl_config_service_; | 45 const scoped_refptr<SSLConfigService> ssl_config_service_; |
| 46 scoped_refptr<HttpNetworkSession> network_session_; | 46 scoped_refptr<HttpNetworkSession> network_session_; |
| 47 scoped_ptr<HttpNetworkLayer> factory_; | 47 scoped_ptr<HttpNetworkLayer> factory_; |
| 48 HttpServerPropertiesImpl http_server_properties_; | 48 HttpServerPropertiesImpl http_server_properties_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { | 51 TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { |
| 52 scoped_ptr<HttpTransaction> trans; | 52 scoped_ptr<HttpTransaction> trans; |
| 53 int rv = factory_->CreateTransaction(&trans); | 53 int rv = factory_->CreateTransaction(&trans, NULL); |
| 54 EXPECT_EQ(OK, rv); | 54 EXPECT_EQ(OK, rv); |
| 55 EXPECT_TRUE(trans.get() != NULL); | 55 EXPECT_TRUE(trans.get() != NULL); |
| 56 } | 56 } |
| 57 | 57 |
| 58 TEST_F(HttpNetworkLayerTest, Suspend) { | 58 TEST_F(HttpNetworkLayerTest, Suspend) { |
| 59 scoped_ptr<HttpTransaction> trans; | 59 scoped_ptr<HttpTransaction> trans; |
| 60 int rv = factory_->CreateTransaction(&trans); | 60 int rv = factory_->CreateTransaction(&trans, NULL); |
| 61 EXPECT_EQ(OK, rv); | 61 EXPECT_EQ(OK, rv); |
| 62 | 62 |
| 63 trans.reset(); | 63 trans.reset(); |
| 64 | 64 |
| 65 factory_->OnSuspend(); | 65 factory_->OnSuspend(); |
| 66 | 66 |
| 67 rv = factory_->CreateTransaction(&trans); | 67 rv = factory_->CreateTransaction(&trans, NULL); |
| 68 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, rv); | 68 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, rv); |
| 69 | 69 |
| 70 ASSERT_TRUE(trans == NULL); | 70 ASSERT_TRUE(trans == NULL); |
| 71 | 71 |
| 72 factory_->OnResume(); | 72 factory_->OnResume(); |
| 73 | 73 |
| 74 rv = factory_->CreateTransaction(&trans); | 74 rv = factory_->CreateTransaction(&trans, NULL); |
| 75 EXPECT_EQ(OK, rv); | 75 EXPECT_EQ(OK, rv); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TEST_F(HttpNetworkLayerTest, GET) { | 78 TEST_F(HttpNetworkLayerTest, GET) { |
| 79 MockRead data_reads[] = { | 79 MockRead data_reads[] = { |
| 80 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 80 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 81 MockRead("hello world"), | 81 MockRead("hello world"), |
| 82 MockRead(SYNCHRONOUS, OK), | 82 MockRead(SYNCHRONOUS, OK), |
| 83 }; | 83 }; |
| 84 MockWrite data_writes[] = { | 84 MockWrite data_writes[] = { |
| 85 MockWrite("GET / HTTP/1.1\r\n" | 85 MockWrite("GET / HTTP/1.1\r\n" |
| 86 "Host: www.google.com\r\n" | 86 "Host: www.google.com\r\n" |
| 87 "Connection: keep-alive\r\n" | 87 "Connection: keep-alive\r\n" |
| 88 "User-Agent: Foo/1.0\r\n\r\n"), | 88 "User-Agent: Foo/1.0\r\n\r\n"), |
| 89 }; | 89 }; |
| 90 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 90 StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 91 data_writes, arraysize(data_writes)); | 91 data_writes, arraysize(data_writes)); |
| 92 mock_socket_factory_.AddSocketDataProvider(&data); | 92 mock_socket_factory_.AddSocketDataProvider(&data); |
| 93 | 93 |
| 94 TestCompletionCallback callback; | 94 TestCompletionCallback callback; |
| 95 | 95 |
| 96 HttpRequestInfo request_info; | 96 HttpRequestInfo request_info; |
| 97 request_info.url = GURL("http://www.google.com/"); | 97 request_info.url = GURL("http://www.google.com/"); |
| 98 request_info.method = "GET"; | 98 request_info.method = "GET"; |
| 99 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 99 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 100 "Foo/1.0"); | 100 "Foo/1.0"); |
| 101 request_info.load_flags = LOAD_NORMAL; | 101 request_info.load_flags = LOAD_NORMAL; |
| 102 | 102 |
| 103 scoped_ptr<HttpTransaction> trans; | 103 scoped_ptr<HttpTransaction> trans; |
| 104 int rv = factory_->CreateTransaction(&trans); | 104 int rv = factory_->CreateTransaction(&trans, NULL); |
| 105 EXPECT_EQ(OK, rv); | 105 EXPECT_EQ(OK, rv); |
| 106 | 106 |
| 107 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | 107 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 108 if (rv == ERR_IO_PENDING) | 108 if (rv == ERR_IO_PENDING) |
| 109 rv = callback.WaitForResult(); | 109 rv = callback.WaitForResult(); |
| 110 ASSERT_EQ(OK, rv); | 110 ASSERT_EQ(OK, rv); |
| 111 | 111 |
| 112 std::string contents; | 112 std::string contents; |
| 113 rv = ReadTransaction(trans.get(), &contents); | 113 rv = ReadTransaction(trans.get(), &contents); |
| 114 EXPECT_EQ(OK, rv); | 114 EXPECT_EQ(OK, rv); |
| 115 EXPECT_EQ("hello world", contents); | 115 EXPECT_EQ("hello world", contents); |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace | 118 } // namespace |
| 119 | 119 |
| 120 } // namespace net | 120 } // namespace net |
| OLD | NEW |