| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <math.h> // ceil | 5 #include <math.h> // ceil |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 2907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2918 response->auth_challenge = new AuthChallengeInfo(); | 2918 response->auth_challenge = new AuthChallengeInfo(); |
| 2919 response->ssl_info.cert_status = -15; | 2919 response->ssl_info.cert_status = -15; |
| 2920 response->response_time = base::Time::Now(); | 2920 response->response_time = base::Time::Now(); |
| 2921 response->was_cached = true; // (Wouldn't ever actually be true...) | 2921 response->was_cached = true; // (Wouldn't ever actually be true...) |
| 2922 | 2922 |
| 2923 { // Setup state for response_.vary_data | 2923 { // Setup state for response_.vary_data |
| 2924 HttpRequestInfo request; | 2924 HttpRequestInfo request; |
| 2925 std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); | 2925 std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 2926 std::replace(temp.begin(), temp.end(), '\n', '\0'); | 2926 std::replace(temp.begin(), temp.end(), '\n', '\0'); |
| 2927 scoped_refptr<HttpResponseHeaders> headers = new HttpResponseHeaders(temp); | 2927 scoped_refptr<HttpResponseHeaders> headers = new HttpResponseHeaders(temp); |
| 2928 request.extra_headers = "Foo: 1\nbar: 23"; | 2928 request.extra_headers.SetHeader("Foo", "1"); |
| 2929 request.extra_headers.SetHeader("bar", "23"); |
| 2929 EXPECT_TRUE(response->vary_data.Init(request, *headers)); | 2930 EXPECT_TRUE(response->vary_data.Init(request, *headers)); |
| 2930 } | 2931 } |
| 2931 | 2932 |
| 2932 // Cause the above state to be reset. | 2933 // Cause the above state to be reset. |
| 2933 trans->ResetStateForRestart(); | 2934 trans->ResetStateForRestart(); |
| 2934 | 2935 |
| 2935 // Verify that the state that needed to be reset, has been reset. | 2936 // Verify that the state that needed to be reset, has been reset. |
| 2936 EXPECT_TRUE(trans->read_buf_.get() == NULL); | 2937 EXPECT_TRUE(trans->read_buf_.get() == NULL); |
| 2937 EXPECT_EQ(0, trans->read_buf_len_); | 2938 EXPECT_EQ(0, trans->read_buf_len_); |
| 2938 EXPECT_EQ(0U, trans->request_headers_.size()); | 2939 EXPECT_EQ(0U, trans->request_headers_.size()); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3077 } | 3078 } |
| 3078 | 3079 |
| 3079 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { | 3080 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
| 3080 SessionDependencies session_deps; | 3081 SessionDependencies session_deps; |
| 3081 scoped_ptr<HttpTransaction> trans( | 3082 scoped_ptr<HttpTransaction> trans( |
| 3082 new HttpNetworkTransaction(CreateSession(&session_deps))); | 3083 new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 3083 | 3084 |
| 3084 HttpRequestInfo request; | 3085 HttpRequestInfo request; |
| 3085 request.method = "GET"; | 3086 request.method = "GET"; |
| 3086 request.url = GURL("http://www.google.com/"); | 3087 request.url = GURL("http://www.google.com/"); |
| 3087 request.user_agent = "Chromium Ultra Awesome X Edition"; | 3088 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 3089 "Chromium Ultra Awesome X Edition"); |
| 3088 | 3090 |
| 3089 MockWrite data_writes[] = { | 3091 MockWrite data_writes[] = { |
| 3090 MockWrite("GET / HTTP/1.1\r\n" | 3092 MockWrite("GET / HTTP/1.1\r\n" |
| 3091 "Host: www.google.com\r\n" | 3093 "Host: www.google.com\r\n" |
| 3092 "Connection: keep-alive\r\n" | 3094 "Connection: keep-alive\r\n" |
| 3093 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), | 3095 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 3094 }; | 3096 }; |
| 3095 | 3097 |
| 3096 // Lastly, the server responds with the actual content. | 3098 // Lastly, the server responds with the actual content. |
| 3097 MockRead data_reads[] = { | 3099 MockRead data_reads[] = { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3343 } | 3345 } |
| 3344 | 3346 |
| 3345 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { | 3347 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
| 3346 SessionDependencies session_deps; | 3348 SessionDependencies session_deps; |
| 3347 scoped_ptr<HttpTransaction> trans( | 3349 scoped_ptr<HttpTransaction> trans( |
| 3348 new HttpNetworkTransaction(CreateSession(&session_deps))); | 3350 new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 3349 | 3351 |
| 3350 HttpRequestInfo request; | 3352 HttpRequestInfo request; |
| 3351 request.method = "GET"; | 3353 request.method = "GET"; |
| 3352 request.url = GURL("http://www.google.com/"); | 3354 request.url = GURL("http://www.google.com/"); |
| 3353 request.extra_headers = "FooHeader: Bar\r\n"; | 3355 request.extra_headers.SetHeader("FooHeader", "Bar"); |
| 3354 | 3356 |
| 3355 MockWrite data_writes[] = { | 3357 MockWrite data_writes[] = { |
| 3356 MockWrite("GET / HTTP/1.1\r\n" | 3358 MockWrite("GET / HTTP/1.1\r\n" |
| 3357 "Host: www.google.com\r\n" | 3359 "Host: www.google.com\r\n" |
| 3358 "Connection: keep-alive\r\n" | 3360 "Connection: keep-alive\r\n" |
| 3359 "FooHeader: Bar\r\n\r\n"), | 3361 "FooHeader: Bar\r\n\r\n"), |
| 3360 }; | 3362 }; |
| 3361 | 3363 |
| 3362 // Lastly, the server responds with the actual content. | 3364 // Lastly, the server responds with the actual content. |
| 3363 MockRead data_reads[] = { | 3365 MockRead data_reads[] = { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3381 } | 3383 } |
| 3382 | 3384 |
| 3383 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { | 3385 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
| 3384 SessionDependencies session_deps; | 3386 SessionDependencies session_deps; |
| 3385 scoped_ptr<HttpTransaction> trans( | 3387 scoped_ptr<HttpTransaction> trans( |
| 3386 new HttpNetworkTransaction(CreateSession(&session_deps))); | 3388 new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 3387 | 3389 |
| 3388 HttpRequestInfo request; | 3390 HttpRequestInfo request; |
| 3389 request.method = "GET"; | 3391 request.method = "GET"; |
| 3390 request.url = GURL("http://www.google.com/"); | 3392 request.url = GURL("http://www.google.com/"); |
| 3391 request.extra_headers = "referer: www.foo.com\nhEllo: Kitty\rFoO: bar\r\n"; | 3393 request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 3394 request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 3395 request.extra_headers.SetHeader("FoO", "bar"); |
| 3392 | 3396 |
| 3393 MockWrite data_writes[] = { | 3397 MockWrite data_writes[] = { |
| 3394 MockWrite("GET / HTTP/1.1\r\n" | 3398 MockWrite("GET / HTTP/1.1\r\n" |
| 3395 "Host: www.google.com\r\n" | 3399 "Host: www.google.com\r\n" |
| 3396 "Connection: keep-alive\r\n" | 3400 "Connection: keep-alive\r\n" |
| 3397 "hEllo: Kitty\r\n" | 3401 "hEllo: Kitty\r\n" |
| 3398 "FoO: bar\r\n\r\n"), | 3402 "FoO: bar\r\n\r\n"), |
| 3399 }; | 3403 }; |
| 3400 | 3404 |
| 3401 // Lastly, the server responds with the actual content. | 3405 // Lastly, the server responds with the actual content. |
| (...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4678 ASSERT_TRUE(response != NULL); | 4682 ASSERT_TRUE(response != NULL); |
| 4679 ASSERT_TRUE(response->headers != NULL); | 4683 ASSERT_TRUE(response->headers != NULL); |
| 4680 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 4684 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4681 | 4685 |
| 4682 std::string response_data; | 4686 std::string response_data; |
| 4683 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 4687 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4684 EXPECT_EQ("hello world", response_data); | 4688 EXPECT_EQ("hello world", response_data); |
| 4685 } | 4689 } |
| 4686 | 4690 |
| 4687 } // namespace net | 4691 } // namespace net |
| OLD | NEW |