| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "net/cert/ct_policy_enforcer.h" | 10 #include "net/cert/ct_policy_enforcer.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 HttpRequestInfo request_info; | 67 HttpRequestInfo request_info; |
| 68 request_info.url = GURL("http://www.google.com/"); | 68 request_info.url = GURL("http://www.google.com/"); |
| 69 request_info.method = method; | 69 request_info.method = method; |
| 70 request_info.load_flags = LOAD_NORMAL; | 70 request_info.load_flags = LOAD_NORMAL; |
| 71 | 71 |
| 72 std::unique_ptr<HttpTransaction> trans; | 72 std::unique_ptr<HttpTransaction> trans; |
| 73 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); | 73 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| 74 EXPECT_THAT(rv, IsOk()); | 74 EXPECT_THAT(rv, IsOk()); |
| 75 | 75 |
| 76 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | 76 rv = trans->Start(&request_info, callback.callback(), NetLogWithSource()); |
| 77 if (rv == ERR_IO_PENDING) | 77 if (rv == ERR_IO_PENDING) |
| 78 rv = callback.WaitForResult(); | 78 rv = callback.WaitForResult(); |
| 79 ASSERT_THAT(rv, IsOk()); | 79 ASSERT_THAT(rv, IsOk()); |
| 80 | 80 |
| 81 std::string contents; | 81 std::string contents; |
| 82 rv = ReadTransaction(trans.get(), &contents); | 82 rv = ReadTransaction(trans.get(), &contents); |
| 83 EXPECT_THAT(rv, IsOk()); | 83 EXPECT_THAT(rv, IsOk()); |
| 84 EXPECT_EQ(content, contents); | 84 EXPECT_EQ(content, contents); |
| 85 | 85 |
| 86 if (!header.empty()) { | 86 if (!header.empty()) { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 request_info.url = GURL("http://www.google.com/"); | 324 request_info.url = GURL("http://www.google.com/"); |
| 325 request_info.method = "GET"; | 325 request_info.method = "GET"; |
| 326 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 326 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 327 "Foo/1.0"); | 327 "Foo/1.0"); |
| 328 request_info.load_flags = LOAD_NORMAL; | 328 request_info.load_flags = LOAD_NORMAL; |
| 329 | 329 |
| 330 std::unique_ptr<HttpTransaction> trans; | 330 std::unique_ptr<HttpTransaction> trans; |
| 331 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); | 331 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| 332 EXPECT_THAT(rv, IsOk()); | 332 EXPECT_THAT(rv, IsOk()); |
| 333 | 333 |
| 334 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | 334 rv = trans->Start(&request_info, callback.callback(), NetLogWithSource()); |
| 335 rv = callback.GetResult(rv); | 335 rv = callback.GetResult(rv); |
| 336 ASSERT_THAT(rv, IsOk()); | 336 ASSERT_THAT(rv, IsOk()); |
| 337 | 337 |
| 338 std::string contents; | 338 std::string contents; |
| 339 rv = ReadTransaction(trans.get(), &contents); | 339 rv = ReadTransaction(trans.get(), &contents); |
| 340 EXPECT_THAT(rv, IsOk()); | 340 EXPECT_THAT(rv, IsOk()); |
| 341 EXPECT_EQ("hello world", contents); | 341 EXPECT_EQ("hello world", contents); |
| 342 } | 342 } |
| 343 | 343 |
| 344 TEST_F(HttpNetworkLayerTest, NetworkVerified) { | 344 TEST_F(HttpNetworkLayerTest, NetworkVerified) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 363 request_info.url = GURL("http://www.google.com/"); | 363 request_info.url = GURL("http://www.google.com/"); |
| 364 request_info.method = "GET"; | 364 request_info.method = "GET"; |
| 365 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 365 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 366 "Foo/1.0"); | 366 "Foo/1.0"); |
| 367 request_info.load_flags = LOAD_NORMAL; | 367 request_info.load_flags = LOAD_NORMAL; |
| 368 | 368 |
| 369 std::unique_ptr<HttpTransaction> trans; | 369 std::unique_ptr<HttpTransaction> trans; |
| 370 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); | 370 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| 371 EXPECT_THAT(rv, IsOk()); | 371 EXPECT_THAT(rv, IsOk()); |
| 372 | 372 |
| 373 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | 373 rv = trans->Start(&request_info, callback.callback(), NetLogWithSource()); |
| 374 ASSERT_THAT(callback.GetResult(rv), IsOk()); | 374 ASSERT_THAT(callback.GetResult(rv), IsOk()); |
| 375 | 375 |
| 376 EXPECT_TRUE(trans->GetResponseInfo()->network_accessed); | 376 EXPECT_TRUE(trans->GetResponseInfo()->network_accessed); |
| 377 } | 377 } |
| 378 | 378 |
| 379 TEST_F(HttpNetworkLayerTest, NetworkUnVerified) { | 379 TEST_F(HttpNetworkLayerTest, NetworkUnVerified) { |
| 380 MockRead data_reads[] = { | 380 MockRead data_reads[] = { |
| 381 MockRead(ASYNC, ERR_CONNECTION_RESET), | 381 MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 382 }; | 382 }; |
| 383 MockWrite data_writes[] = { | 383 MockWrite data_writes[] = { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 396 request_info.url = GURL("http://www.google.com/"); | 396 request_info.url = GURL("http://www.google.com/"); |
| 397 request_info.method = "GET"; | 397 request_info.method = "GET"; |
| 398 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 398 request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 399 "Foo/1.0"); | 399 "Foo/1.0"); |
| 400 request_info.load_flags = LOAD_NORMAL; | 400 request_info.load_flags = LOAD_NORMAL; |
| 401 | 401 |
| 402 std::unique_ptr<HttpTransaction> trans; | 402 std::unique_ptr<HttpTransaction> trans; |
| 403 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); | 403 int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); |
| 404 EXPECT_THAT(rv, IsOk()); | 404 EXPECT_THAT(rv, IsOk()); |
| 405 | 405 |
| 406 rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); | 406 rv = trans->Start(&request_info, callback.callback(), NetLogWithSource()); |
| 407 ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_RESET)); | 407 ASSERT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_RESET)); |
| 408 | 408 |
| 409 // network_accessed is true; the HTTP stack did try to make a connection. | 409 // network_accessed is true; the HTTP stack did try to make a connection. |
| 410 EXPECT_TRUE(trans->GetResponseInfo()->network_accessed); | 410 EXPECT_TRUE(trans->GetResponseInfo()->network_accessed); |
| 411 } | 411 } |
| 412 | 412 |
| 413 } // namespace | 413 } // namespace |
| 414 | 414 |
| 415 } // namespace net | 415 } // namespace net |
| OLD | NEW |