| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 17 #include "net/base/auth.h" | 17 #include "net/base/auth.h" |
| 18 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
| 19 #include "net/base/sdch_observer.h" | 19 #include "net/base/sdch_observer.h" |
| 20 #include "net/cookies/cookie_store_test_helpers.h" | 20 #include "net/cookies/cookie_store_test_helpers.h" |
| 21 #include "net/http/http_transaction_factory.h" | 21 #include "net/http/http_transaction_factory.h" |
| 22 #include "net/http/http_transaction_test_util.h" | 22 #include "net/http/http_transaction_test_util.h" |
| 23 #include "net/log/test_net_log.h" | 23 #include "net/log/test_net_log.h" |
| 24 #include "net/log/test_net_log_entry.h" | 24 #include "net/log/test_net_log_entry.h" |
| 25 #include "net/log/test_net_log_util.h" | 25 #include "net/log/test_net_log_util.h" |
| 26 #include "net/socket/socket_test_util.h" | 26 #include "net/socket/socket_test_util.h" |
| 27 #include "net/test/cert_test_util.h" | 27 #include "net/test/cert_test_util.h" |
| 28 #include "net/test/gtest_util.h" |
| 28 #include "net/test/test_data_directory.h" | 29 #include "net/test/test_data_directory.h" |
| 29 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
| 30 #include "net/url_request/url_request_job_factory_impl.h" | 31 #include "net/url_request/url_request_job_factory_impl.h" |
| 31 #include "net/url_request/url_request_status.h" | 32 #include "net/url_request/url_request_status.h" |
| 32 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
| 33 #include "net/websockets/websocket_handshake_stream_base.h" | 34 #include "net/websockets/websocket_handshake_stream_base.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 37 #include "url/url_constants.h" | 38 #include "url/url_constants.h" |
| 38 | 39 |
| 40 using net::test::IsError; |
| 41 using net::test::IsOk; |
| 42 |
| 39 namespace net { | 43 namespace net { |
| 40 | 44 |
| 41 namespace { | 45 namespace { |
| 42 | 46 |
| 43 using ::testing::Return; | 47 using ::testing::Return; |
| 44 | 48 |
| 45 // Inherit from URLRequestHttpJob to expose the priority and some | 49 // Inherit from URLRequestHttpJob to expose the priority and some |
| 46 // other hidden functions. | 50 // other hidden functions. |
| 47 class TestURLRequestHttpJob : public URLRequestHttpJob { | 51 class TestURLRequestHttpJob : public URLRequestHttpJob { |
| 48 public: | 52 public: |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // Issue another request, and backoff logic should apply. | 402 // Issue another request, and backoff logic should apply. |
| 399 TestDelegate delegate2; | 403 TestDelegate delegate2; |
| 400 std::unique_ptr<URLRequest> request2 = context_->CreateRequest( | 404 std::unique_ptr<URLRequest> request2 = context_->CreateRequest( |
| 401 GURL("https://www.example.com"), DEFAULT_PRIORITY, &delegate2); | 405 GURL("https://www.example.com"), DEFAULT_PRIORITY, &delegate2); |
| 402 | 406 |
| 403 request2->Start(); | 407 request2->Start(); |
| 404 ASSERT_TRUE(request2->is_pending()); | 408 ASSERT_TRUE(request2->is_pending()); |
| 405 base::RunLoop().Run(); | 409 base::RunLoop().Run(); |
| 406 | 410 |
| 407 EXPECT_FALSE(request2->status().is_success()); | 411 EXPECT_FALSE(request2->status().is_success()); |
| 408 EXPECT_EQ(ERR_TEMPORARY_BACKOFF, request2->status().error()); | 412 EXPECT_THAT(request2->status().error(), IsError(ERR_TEMPORARY_BACKOFF)); |
| 409 EXPECT_EQ(0, delegate2.received_before_network_start_count()); | 413 EXPECT_EQ(0, delegate2.received_before_network_start_count()); |
| 410 } | 414 } |
| 411 | 415 |
| 412 // Tests that a user-initiated request is not throttled. | 416 // Tests that a user-initiated request is not throttled. |
| 413 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeaderUserGesture) { | 417 TEST_F(URLRequestHttpJobWithMockSocketsTest, BackoffHeaderUserGesture) { |
| 414 MockWrite writes[] = { | 418 MockWrite writes[] = { |
| 415 MockWrite("GET / HTTP/1.1\r\n" | 419 MockWrite("GET / HTTP/1.1\r\n" |
| 416 "Host: www.example.com\r\n" | 420 "Host: www.example.com\r\n" |
| 417 "Connection: keep-alive\r\n" | 421 "Connection: keep-alive\r\n" |
| 418 "User-Agent:\r\n" | 422 "User-Agent:\r\n" |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 } | 979 } |
| 976 | 980 |
| 977 private: | 981 private: |
| 978 bool initialize_stream_was_called_; | 982 bool initialize_stream_was_called_; |
| 979 }; | 983 }; |
| 980 | 984 |
| 981 TEST_F(URLRequestHttpJobWebSocketTest, RejectedWithoutCreateHelper) { | 985 TEST_F(URLRequestHttpJobWebSocketTest, RejectedWithoutCreateHelper) { |
| 982 req_->Start(); | 986 req_->Start(); |
| 983 base::RunLoop().RunUntilIdle(); | 987 base::RunLoop().RunUntilIdle(); |
| 984 EXPECT_EQ(URLRequestStatus::FAILED, req_->status().status()); | 988 EXPECT_EQ(URLRequestStatus::FAILED, req_->status().status()); |
| 985 EXPECT_EQ(ERR_DISALLOWED_URL_SCHEME, req_->status().error()); | 989 EXPECT_THAT(req_->status().error(), IsError(ERR_DISALLOWED_URL_SCHEME)); |
| 986 } | 990 } |
| 987 | 991 |
| 988 TEST_F(URLRequestHttpJobWebSocketTest, CreateHelperPassedThrough) { | 992 TEST_F(URLRequestHttpJobWebSocketTest, CreateHelperPassedThrough) { |
| 989 std::unique_ptr<MockCreateHelper> create_helper( | 993 std::unique_ptr<MockCreateHelper> create_helper( |
| 990 new ::testing::StrictMock<MockCreateHelper>()); | 994 new ::testing::StrictMock<MockCreateHelper>()); |
| 991 FakeWebSocketHandshakeStream* fake_handshake_stream( | 995 FakeWebSocketHandshakeStream* fake_handshake_stream( |
| 992 new FakeWebSocketHandshakeStream); | 996 new FakeWebSocketHandshakeStream); |
| 993 // Ownership of fake_handshake_stream is transferred when CreateBasicStream() | 997 // Ownership of fake_handshake_stream is transferred when CreateBasicStream() |
| 994 // is called. | 998 // is called. |
| 995 EXPECT_CALL(*create_helper, CreateBasicStreamMock()) | 999 EXPECT_CALL(*create_helper, CreateBasicStreamMock()) |
| 996 .WillOnce(Return(fake_handshake_stream)); | 1000 .WillOnce(Return(fake_handshake_stream)); |
| 997 req_->SetUserData(WebSocketHandshakeStreamBase::CreateHelper::DataKey(), | 1001 req_->SetUserData(WebSocketHandshakeStreamBase::CreateHelper::DataKey(), |
| 998 create_helper.release()); | 1002 create_helper.release()); |
| 999 req_->SetLoadFlags(LOAD_DISABLE_CACHE); | 1003 req_->SetLoadFlags(LOAD_DISABLE_CACHE); |
| 1000 req_->Start(); | 1004 req_->Start(); |
| 1001 base::RunLoop().RunUntilIdle(); | 1005 base::RunLoop().RunUntilIdle(); |
| 1002 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 1006 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
| 1003 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 1007 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 1004 } | 1008 } |
| 1005 | 1009 |
| 1006 #endif // defined(ENABLE_WEBSOCKETS) | 1010 #endif // defined(ENABLE_WEBSOCKETS) |
| 1007 | 1011 |
| 1008 } // namespace | 1012 } // namespace |
| 1009 | 1013 |
| 1010 } // namespace net | 1014 } // namespace net |
| OLD | NEW |