| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 7415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7426 &kGet, &kServerChallenge), | 7426 &kGet, &kServerChallenge), |
| 7427 TestRound(kGetAuth, kSuccess, OK)}}, | 7427 TestRound(kGetAuth, kSuccess, OK)}}, |
| 7428 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, | 7428 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 7429 { TestRound(kConnect, kProxyChallenge, OK), | 7429 { TestRound(kConnect, kProxyChallenge, OK), |
| 7430 TestRound(kConnectProxyAuth, kProxyConnected, OK, | 7430 TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 7431 &kGet, &kServerChallenge), | 7431 &kGet, &kServerChallenge), |
| 7432 TestRound(kGetAuth, kFailure, kAuthErr)}}, | 7432 TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 7433 }; | 7433 }; |
| 7434 | 7434 |
| 7435 SessionDependencies session_deps; | 7435 SessionDependencies session_deps; |
| 7436 HttpAuthHandlerMock::Factory* auth_factory( | |
| 7437 new HttpAuthHandlerMock::Factory()); | |
| 7438 session_deps.http_auth_handler_factory.reset(auth_factory); | |
| 7439 | |
| 7440 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_configs); ++i) { | 7436 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_configs); ++i) { |
| 7437 HttpAuthHandlerMock::Factory* auth_factory( |
| 7438 new HttpAuthHandlerMock::Factory()); |
| 7439 session_deps.http_auth_handler_factory.reset(auth_factory); |
| 7441 const TestConfig& test_config = test_configs[i]; | 7440 const TestConfig& test_config = test_configs[i]; |
| 7442 | 7441 |
| 7443 // Set up authentication handlers as necessary. | 7442 // Set up authentication handlers as necessary. |
| 7444 if (test_config.proxy_auth_timing != AUTH_NONE) { | 7443 if (test_config.proxy_auth_timing != AUTH_NONE) { |
| 7445 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); | 7444 for (int n = 0; n < 2; n++) { |
| 7446 std::string auth_challenge = "Mock realm=proxy"; | 7445 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 7447 GURL origin(test_config.proxy_url); | 7446 std::string auth_challenge = "Mock realm=proxy"; |
| 7448 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), | 7447 GURL origin(test_config.proxy_url); |
| 7449 auth_challenge.end()); | 7448 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 7450 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, | 7449 auth_challenge.end()); |
| 7451 origin, BoundNetLog()); | 7450 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 7452 auth_handler->SetGenerateExpectation( | 7451 origin, BoundNetLog()); |
| 7453 test_config.proxy_auth_timing == AUTH_ASYNC, | 7452 auth_handler->SetGenerateExpectation( |
| 7454 test_config.proxy_auth_rv); | 7453 test_config.proxy_auth_timing == AUTH_ASYNC, |
| 7455 auth_factory->set_mock_handler(auth_handler, HttpAuth::AUTH_PROXY); | 7454 test_config.proxy_auth_rv); |
| 7455 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 7456 } |
| 7456 } | 7457 } |
| 7457 if (test_config.server_auth_timing != AUTH_NONE) { | 7458 if (test_config.server_auth_timing != AUTH_NONE) { |
| 7458 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); | 7459 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 7459 std::string auth_challenge = "Mock realm=server"; | 7460 std::string auth_challenge = "Mock realm=server"; |
| 7460 GURL origin(test_config.server_url); | 7461 GURL origin(test_config.server_url); |
| 7461 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), | 7462 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 7462 auth_challenge.end()); | 7463 auth_challenge.end()); |
| 7463 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, | 7464 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 7464 origin, BoundNetLog()); | 7465 origin, BoundNetLog()); |
| 7465 auth_handler->SetGenerateExpectation( | 7466 auth_handler->SetGenerateExpectation( |
| 7466 test_config.server_auth_timing == AUTH_ASYNC, | 7467 test_config.server_auth_timing == AUTH_ASYNC, |
| 7467 test_config.server_auth_rv); | 7468 test_config.server_auth_rv); |
| 7468 auth_factory->set_mock_handler(auth_handler, HttpAuth::AUTH_SERVER); | 7469 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
| 7469 } | 7470 } |
| 7470 if (test_config.proxy_url) { | 7471 if (test_config.proxy_url) { |
| 7471 session_deps.proxy_service.reset( | 7472 session_deps.proxy_service.reset( |
| 7472 ProxyService::CreateFixed(test_config.proxy_url)); | 7473 ProxyService::CreateFixed(test_config.proxy_url)); |
| 7473 } else { | 7474 } else { |
| 7474 session_deps.proxy_service.reset(ProxyService::CreateDirect()); | 7475 session_deps.proxy_service.reset(ProxyService::CreateDirect()); |
| 7475 } | 7476 } |
| 7476 | 7477 |
| 7477 HttpRequestInfo request; | 7478 HttpRequestInfo request; |
| 7478 request.method = "GET"; | 7479 request.method = "GET"; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7552 session_deps.host_resolver->set_synchronous_mode(true); | 7553 session_deps.host_resolver->set_synchronous_mode(true); |
| 7553 | 7554 |
| 7554 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); | 7555 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 7555 auth_handler->set_connection_based(true); | 7556 auth_handler->set_connection_based(true); |
| 7556 std::string auth_challenge = "Mock realm=server"; | 7557 std::string auth_challenge = "Mock realm=server"; |
| 7557 GURL origin("http://www.example.com"); | 7558 GURL origin("http://www.example.com"); |
| 7558 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), | 7559 HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 7559 auth_challenge.end()); | 7560 auth_challenge.end()); |
| 7560 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, | 7561 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 7561 origin, BoundNetLog()); | 7562 origin, BoundNetLog()); |
| 7562 auth_factory->set_mock_handler(auth_handler, HttpAuth::AUTH_SERVER); | 7563 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
| 7563 | 7564 |
| 7564 int rv = OK; | 7565 int rv = OK; |
| 7565 const HttpResponseInfo* response = NULL; | 7566 const HttpResponseInfo* response = NULL; |
| 7566 HttpRequestInfo request; | 7567 HttpRequestInfo request; |
| 7567 request.method = "GET"; | 7568 request.method = "GET"; |
| 7568 request.url = origin; | 7569 request.url = origin; |
| 7569 request.load_flags = 0; | 7570 request.load_flags = 0; |
| 7570 | 7571 |
| 7571 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 7572 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 7572 | 7573 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7946 // This test ensures that the URL passed into the proxy is upgraded | 7947 // This test ensures that the URL passed into the proxy is upgraded |
| 7947 // to https when doing an Alternate Protocol upgrade. | 7948 // to https when doing an Alternate Protocol upgrade. |
| 7948 HttpStreamFactory::set_use_alternate_protocols(true); | 7949 HttpStreamFactory::set_use_alternate_protocols(true); |
| 7949 HttpStreamFactory::set_next_protos( | 7950 HttpStreamFactory::set_next_protos( |
| 7950 "\x08http/1.1\x07http1.1\x06spdy/2\x04spdy"); | 7951 "\x08http/1.1\x07http1.1\x06spdy/2\x04spdy"); |
| 7951 | 7952 |
| 7952 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); | 7953 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); |
| 7953 HttpAuthHandlerMock::Factory* auth_factory = | 7954 HttpAuthHandlerMock::Factory* auth_factory = |
| 7954 new HttpAuthHandlerMock::Factory(); | 7955 new HttpAuthHandlerMock::Factory(); |
| 7955 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); | 7956 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); |
| 7956 auth_factory->set_mock_handler(auth_handler, HttpAuth::AUTH_PROXY); | 7957 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 7957 auth_factory->set_do_init_from_challenge(true); | 7958 auth_factory->set_do_init_from_challenge(true); |
| 7958 session_deps.http_auth_handler_factory.reset(auth_factory); | 7959 session_deps.http_auth_handler_factory.reset(auth_factory); |
| 7959 | 7960 |
| 7960 HttpRequestInfo request; | 7961 HttpRequestInfo request; |
| 7961 request.method = "GET"; | 7962 request.method = "GET"; |
| 7962 request.url = GURL("http://www.google.com"); | 7963 request.url = GURL("http://www.google.com"); |
| 7963 request.load_flags = 0; | 7964 request.load_flags = 0; |
| 7964 | 7965 |
| 7965 // First round goes unauthenticated through the proxy. | 7966 // First round goes unauthenticated through the proxy. |
| 7966 MockWrite data_writes_1[] = { | 7967 MockWrite data_writes_1[] = { |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8998 EXPECT_TRUE(response->was_fetched_via_spdy); | 8999 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8999 EXPECT_TRUE(response->was_npn_negotiated); | 9000 EXPECT_TRUE(response->was_npn_negotiated); |
| 9000 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | 9001 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9001 EXPECT_EQ("hello!", response_data); | 9002 EXPECT_EQ("hello!", response_data); |
| 9002 | 9003 |
| 9003 HttpStreamFactory::set_next_protos(""); | 9004 HttpStreamFactory::set_next_protos(""); |
| 9004 HttpStreamFactory::set_use_alternate_protocols(false); | 9005 HttpStreamFactory::set_use_alternate_protocols(false); |
| 9005 } | 9006 } |
| 9006 | 9007 |
| 9007 } // namespace net | 9008 } // namespace net |
| OLD | NEW |