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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif | 10 #endif |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 | 592 |
593 TestDelegate d; | 593 TestDelegate d; |
594 BlockingNetworkDelegate network_delegate; | 594 BlockingNetworkDelegate network_delegate; |
595 network_delegate.set_auth_retval( | 595 network_delegate.set_auth_retval( |
596 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); | 596 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); |
597 | 597 |
598 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 598 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
599 context->set_network_delegate(&network_delegate); | 599 context->set_network_delegate(&network_delegate); |
600 context->Init(); | 600 context->Init(); |
601 | 601 |
602 d.set_username(kUser); | 602 d.set_credentials(AuthCredentials(kUser, kSecret)); |
603 d.set_password(kSecret); | |
604 | 603 |
605 { | 604 { |
606 GURL url(test_server_.GetURL("auth-basic")); | 605 GURL url(test_server_.GetURL("auth-basic")); |
607 TestURLRequest r(url, &d); | 606 TestURLRequest r(url, &d); |
608 r.set_context(context); | 607 r.set_context(context); |
609 r.Start(); | 608 r.Start(); |
610 MessageLoop::current()->Run(); | 609 MessageLoop::current()->Run(); |
611 | 610 |
612 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 611 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
613 EXPECT_EQ(0, r.status().error()); | 612 EXPECT_EQ(0, r.status().error()); |
614 EXPECT_EQ(200, r.GetResponseCode()); | 613 EXPECT_EQ(200, r.GetResponseCode()); |
615 EXPECT_TRUE(d.auth_required_called()); | 614 EXPECT_TRUE(d.auth_required_called()); |
616 EXPECT_EQ(1, network_delegate.created_requests()); | 615 EXPECT_EQ(1, network_delegate.created_requests()); |
617 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 616 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
618 } | 617 } |
619 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 618 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
620 } | 619 } |
621 | 620 |
622 // Tests that the network delegate can synchronously complete OnAuthRequired | 621 // Tests that the network delegate can synchronously complete OnAuthRequired |
623 // by setting credentials. | 622 // by setting credentials. |
624 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { | 623 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { |
625 ASSERT_TRUE(test_server_.Start()); | 624 ASSERT_TRUE(test_server_.Start()); |
626 | 625 |
627 TestDelegate d; | 626 TestDelegate d; |
628 BlockingNetworkDelegate network_delegate; | 627 BlockingNetworkDelegate network_delegate; |
629 network_delegate.set_auth_retval( | 628 network_delegate.set_auth_retval( |
630 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 629 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
631 | 630 |
632 AuthCredentials auth_credentials; | 631 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
633 auth_credentials.username = kUser; | |
634 auth_credentials.password = kSecret; | |
635 network_delegate.set_auth_credentials(auth_credentials); | |
636 | 632 |
637 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 633 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
638 context->set_network_delegate(&network_delegate); | 634 context->set_network_delegate(&network_delegate); |
639 context->Init(); | 635 context->Init(); |
640 | 636 |
641 { | 637 { |
642 GURL url(test_server_.GetURL("auth-basic")); | 638 GURL url(test_server_.GetURL("auth-basic")); |
643 TestURLRequest r(url, &d); | 639 TestURLRequest r(url, &d); |
644 r.set_context(context); | 640 r.set_context(context); |
645 r.Start(); | 641 r.Start(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 BlockingNetworkDelegate network_delegate; | 693 BlockingNetworkDelegate network_delegate; |
698 network_delegate.set_auth_retval( | 694 network_delegate.set_auth_retval( |
699 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); | 695 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); |
700 network_delegate.set_auth_callback_retval( | 696 network_delegate.set_auth_callback_retval( |
701 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); | 697 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); |
702 | 698 |
703 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 699 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
704 context->set_network_delegate(&network_delegate); | 700 context->set_network_delegate(&network_delegate); |
705 context->Init(); | 701 context->Init(); |
706 | 702 |
707 d.set_username(kUser); | 703 d.set_credentials(AuthCredentials(kUser, kSecret)); |
708 d.set_password(kSecret); | |
709 | 704 |
710 { | 705 { |
711 GURL url(test_server_.GetURL("auth-basic")); | 706 GURL url(test_server_.GetURL("auth-basic")); |
712 TestURLRequest r(url, &d); | 707 TestURLRequest r(url, &d); |
713 r.set_context(context); | 708 r.set_context(context); |
714 r.Start(); | 709 r.Start(); |
715 MessageLoop::current()->Run(); | 710 MessageLoop::current()->Run(); |
716 | 711 |
717 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 712 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
718 EXPECT_EQ(0, r.status().error()); | 713 EXPECT_EQ(0, r.status().error()); |
(...skipping 10 matching lines...) Expand all Loading... |
729 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { | 724 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { |
730 ASSERT_TRUE(test_server_.Start()); | 725 ASSERT_TRUE(test_server_.Start()); |
731 | 726 |
732 TestDelegate d; | 727 TestDelegate d; |
733 BlockingNetworkDelegate network_delegate; | 728 BlockingNetworkDelegate network_delegate; |
734 network_delegate.set_auth_retval( | 729 network_delegate.set_auth_retval( |
735 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); | 730 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); |
736 network_delegate.set_auth_callback_retval( | 731 network_delegate.set_auth_callback_retval( |
737 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 732 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
738 | 733 |
739 AuthCredentials auth_credentials; | 734 AuthCredentials auth_credentials(kUser, kSecret); |
740 auth_credentials.username = kUser; | |
741 auth_credentials.password = kSecret; | |
742 network_delegate.set_auth_credentials(auth_credentials); | 735 network_delegate.set_auth_credentials(auth_credentials); |
743 | 736 |
744 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 737 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
745 context->set_network_delegate(&network_delegate); | 738 context->set_network_delegate(&network_delegate); |
746 context->Init(); | 739 context->Init(); |
747 | 740 |
748 { | 741 { |
749 GURL url(test_server_.GetURL("auth-basic")); | 742 GURL url(test_server_.GetURL("auth-basic")); |
750 TestURLRequest r(url, &d); | 743 TestURLRequest r(url, &d); |
751 r.set_context(context); | 744 r.set_context(context); |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1944 EXPECT_FALSE(req.was_cached()); | 1937 EXPECT_FALSE(req.was_cached()); |
1945 } | 1938 } |
1946 } | 1939 } |
1947 | 1940 |
1948 TEST_F(URLRequestTestHTTP, BasicAuth) { | 1941 TEST_F(URLRequestTestHTTP, BasicAuth) { |
1949 ASSERT_TRUE(test_server_.Start()); | 1942 ASSERT_TRUE(test_server_.Start()); |
1950 | 1943 |
1951 // populate the cache | 1944 // populate the cache |
1952 { | 1945 { |
1953 TestDelegate d; | 1946 TestDelegate d; |
1954 d.set_username(kUser); | 1947 d.set_credentials(AuthCredentials(kUser, kSecret)); |
1955 d.set_password(kSecret); | |
1956 | 1948 |
1957 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 1949 URLRequest r(test_server_.GetURL("auth-basic"), &d); |
1958 r.set_context(default_context_); | 1950 r.set_context(default_context_); |
1959 r.Start(); | 1951 r.Start(); |
1960 | 1952 |
1961 MessageLoop::current()->Run(); | 1953 MessageLoop::current()->Run(); |
1962 | 1954 |
1963 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1955 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
1964 } | 1956 } |
1965 | 1957 |
1966 // repeat request with end-to-end validation. since auth-basic results in a | 1958 // repeat request with end-to-end validation. since auth-basic results in a |
1967 // cachable page, we expect this test to result in a 304. in which case, the | 1959 // cachable page, we expect this test to result in a 304. in which case, the |
1968 // response should be fetched from the cache. | 1960 // response should be fetched from the cache. |
1969 { | 1961 { |
1970 TestDelegate d; | 1962 TestDelegate d; |
1971 d.set_username(kUser); | 1963 d.set_credentials(AuthCredentials(kUser, kSecret)); |
1972 d.set_password(kSecret); | |
1973 | 1964 |
1974 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 1965 URLRequest r(test_server_.GetURL("auth-basic"), &d); |
1975 r.set_context(default_context_); | 1966 r.set_context(default_context_); |
1976 r.set_load_flags(LOAD_VALIDATE_CACHE); | 1967 r.set_load_flags(LOAD_VALIDATE_CACHE); |
1977 r.Start(); | 1968 r.Start(); |
1978 | 1969 |
1979 MessageLoop::current()->Run(); | 1970 MessageLoop::current()->Run(); |
1980 | 1971 |
1981 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1972 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
1982 | 1973 |
(...skipping 13 matching lines...) Expand all Loading... |
1996 // Request a page that will give a 401 containing a Set-Cookie header. | 1987 // Request a page that will give a 401 containing a Set-Cookie header. |
1997 // Verify that when the transaction is restarted, it includes the new cookie. | 1988 // Verify that when the transaction is restarted, it includes the new cookie. |
1998 { | 1989 { |
1999 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1990 TestNetworkDelegate network_delegate; // must outlive URLRequest |
2000 scoped_refptr<TestURLRequestContext> context( | 1991 scoped_refptr<TestURLRequestContext> context( |
2001 new TestURLRequestContext(true)); | 1992 new TestURLRequestContext(true)); |
2002 context->set_network_delegate(&network_delegate); | 1993 context->set_network_delegate(&network_delegate); |
2003 context->Init(); | 1994 context->Init(); |
2004 | 1995 |
2005 TestDelegate d; | 1996 TestDelegate d; |
2006 d.set_username(kUser); | 1997 d.set_credentials(AuthCredentials(kUser, kSecret)); |
2007 d.set_password(kSecret); | |
2008 | 1998 |
2009 URLRequest r(url_requiring_auth, &d); | 1999 URLRequest r(url_requiring_auth, &d); |
2010 r.set_context(context); | 2000 r.set_context(context); |
2011 r.Start(); | 2001 r.Start(); |
2012 | 2002 |
2013 MessageLoop::current()->Run(); | 2003 MessageLoop::current()->Run(); |
2014 | 2004 |
2015 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 2005 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
2016 | 2006 |
2017 // Make sure we sent the cookie in the restarted transaction. | 2007 // Make sure we sent the cookie in the restarted transaction. |
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3263 // Flaky, see http://crbug.com/25045. | 3253 // Flaky, see http://crbug.com/25045. |
3264 TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPasswordRestart) { | 3254 TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPasswordRestart) { |
3265 ASSERT_TRUE(test_server_.Start()); | 3255 ASSERT_TRUE(test_server_.Start()); |
3266 | 3256 |
3267 FilePath app_path; | 3257 FilePath app_path; |
3268 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 3258 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
3269 app_path = app_path.AppendASCII("LICENSE"); | 3259 app_path = app_path.AppendASCII("LICENSE"); |
3270 TestDelegate d; | 3260 TestDelegate d; |
3271 // Set correct login credentials. The delegate will be asked for them when | 3261 // Set correct login credentials. The delegate will be asked for them when |
3272 // the initial login with wrong credentials will fail. | 3262 // the initial login with wrong credentials will fail. |
3273 d.set_username(kChrome); | 3263 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
3274 d.set_password(kChrome); | |
3275 { | 3264 { |
3276 TestURLRequest r( | 3265 TestURLRequest r( |
3277 test_server_.GetURLWithUserAndPassword("/LICENSE", | 3266 test_server_.GetURLWithUserAndPassword("/LICENSE", |
3278 "chrome", | 3267 "chrome", |
3279 "wrong_password"), | 3268 "wrong_password"), |
3280 &d); | 3269 &d); |
3281 r.set_context(default_context_); | 3270 r.set_context(default_context_); |
3282 r.Start(); | 3271 r.Start(); |
3283 EXPECT_TRUE(r.is_pending()); | 3272 EXPECT_TRUE(r.is_pending()); |
3284 | 3273 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3327 // Flaky, see http://crbug.com/25045. | 3316 // Flaky, see http://crbug.com/25045. |
3328 TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongUserRestart) { | 3317 TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongUserRestart) { |
3329 ASSERT_TRUE(test_server_.Start()); | 3318 ASSERT_TRUE(test_server_.Start()); |
3330 | 3319 |
3331 FilePath app_path; | 3320 FilePath app_path; |
3332 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 3321 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
3333 app_path = app_path.AppendASCII("LICENSE"); | 3322 app_path = app_path.AppendASCII("LICENSE"); |
3334 TestDelegate d; | 3323 TestDelegate d; |
3335 // Set correct login credentials. The delegate will be asked for them when | 3324 // Set correct login credentials. The delegate will be asked for them when |
3336 // the initial login with wrong credentials will fail. | 3325 // the initial login with wrong credentials will fail. |
3337 d.set_username(kChrome); | 3326 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
3338 d.set_password(kChrome); | |
3339 { | 3327 { |
3340 TestURLRequest r( | 3328 TestURLRequest r( |
3341 test_server_.GetURLWithUserAndPassword("/LICENSE", | 3329 test_server_.GetURLWithUserAndPassword("/LICENSE", |
3342 "wrong_user", | 3330 "wrong_user", |
3343 "chrome"), | 3331 "chrome"), |
3344 &d); | 3332 &d); |
3345 r.set_context(default_context_); | 3333 r.set_context(default_context_); |
3346 r.Start(); | 3334 r.Start(); |
3347 EXPECT_TRUE(r.is_pending()); | 3335 EXPECT_TRUE(r.is_pending()); |
3348 | 3336 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3413 TEST_F(URLRequestTestFTP, FLAKY_FTPCacheLoginBoxCredentials) { | 3401 TEST_F(URLRequestTestFTP, FLAKY_FTPCacheLoginBoxCredentials) { |
3414 ASSERT_TRUE(test_server_.Start()); | 3402 ASSERT_TRUE(test_server_.Start()); |
3415 | 3403 |
3416 FilePath app_path; | 3404 FilePath app_path; |
3417 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 3405 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
3418 app_path = app_path.AppendASCII("LICENSE"); | 3406 app_path = app_path.AppendASCII("LICENSE"); |
3419 | 3407 |
3420 scoped_ptr<TestDelegate> d(new TestDelegate); | 3408 scoped_ptr<TestDelegate> d(new TestDelegate); |
3421 // Set correct login credentials. The delegate will be asked for them when | 3409 // Set correct login credentials. The delegate will be asked for them when |
3422 // the initial login with wrong credentials will fail. | 3410 // the initial login with wrong credentials will fail. |
3423 d->set_username(kChrome); | 3411 d->set_credentials(AuthCredentials(kChrome, kChrome)); |
3424 d->set_password(kChrome); | |
3425 { | 3412 { |
3426 TestURLRequest r( | 3413 TestURLRequest r( |
3427 test_server_.GetURLWithUserAndPassword("/LICENSE", | 3414 test_server_.GetURLWithUserAndPassword("/LICENSE", |
3428 "chrome", | 3415 "chrome", |
3429 "wrong_password"), | 3416 "wrong_password"), |
3430 d.get()); | 3417 d.get()); |
3431 r.set_context(default_context_); | 3418 r.set_context(default_context_); |
3432 r.Start(); | 3419 r.Start(); |
3433 EXPECT_TRUE(r.is_pending()); | 3420 EXPECT_TRUE(r.is_pending()); |
3434 | 3421 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3630 req.SetExtraRequestHeaders(headers); | 3617 req.SetExtraRequestHeaders(headers); |
3631 req.Start(); | 3618 req.Start(); |
3632 MessageLoop::current()->Run(); | 3619 MessageLoop::current()->Run(); |
3633 // If the net tests are being run with ChromeFrame then we need to allow for | 3620 // If the net tests are being run with ChromeFrame then we need to allow for |
3634 // the 'chromeframe' suffix which is added to the user agent before the | 3621 // the 'chromeframe' suffix which is added to the user agent before the |
3635 // closing parentheses. | 3622 // closing parentheses. |
3636 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3623 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
3637 } | 3624 } |
3638 | 3625 |
3639 } // namespace net | 3626 } // namespace net |
OLD | NEW |