OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_unittest.h" | 5 #include "net/url_request/url_request_unittest.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 81 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
82 class URLRequestTest : public PlatformTest { | 82 class URLRequestTest : public PlatformTest { |
83 }; | 83 }; |
84 | 84 |
85 TEST_F(URLRequestTest, ProxyTunnelRedirectTest) { | 85 TEST_F(URLRequestTest, ProxyTunnelRedirectTest) { |
86 // In this unit test, we're using the HTTPTestServer as a proxy server and | 86 // In this unit test, we're using the HTTPTestServer as a proxy server and |
87 // issue a CONNECT request with the magic host name "www.redirect.com" to | 87 // issuing a CONNECT request with the magic host name "www.redirect.com". |
88 // it. The HTTPTestServer will return a 302 response, which we should not | 88 // The HTTPTestServer will return a 302 response, which we should not |
89 // follow. | 89 // follow. |
90 scoped_refptr<HTTPTestServer> server = | 90 scoped_refptr<HTTPTestServer> server = |
91 HTTPTestServer::CreateServer(L"", NULL); | 91 HTTPTestServer::CreateServer(L"", NULL); |
92 ASSERT_TRUE(NULL != server.get()); | 92 ASSERT_TRUE(NULL != server.get()); |
93 TestDelegate d; | 93 TestDelegate d; |
94 { | 94 { |
95 URLRequest r(GURL("https://www.redirect.com/"), &d); | 95 URLRequest r(GURL("https://www.redirect.com/"), &d); |
96 std::string proxy("localhost:"); | 96 std::string proxy("localhost:"); |
97 proxy.append(IntToString(kHTTPDefaultPort)); | 97 proxy.append(IntToString(kHTTPDefaultPort)); |
98 r.set_context(new TestURLRequestContext(proxy)); | 98 r.set_context(new TestURLRequestContext(proxy)); |
99 | 99 |
100 r.Start(); | 100 r.Start(); |
101 EXPECT_TRUE(r.is_pending()); | 101 EXPECT_TRUE(r.is_pending()); |
102 | 102 |
103 MessageLoop::current()->Run(); | 103 MessageLoop::current()->Run(); |
104 | 104 |
105 EXPECT_EQ(1, d.response_started_count()); | 105 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
106 // We should have rewritten the 302 response code as 500. | 106 // We should have rewritten the 302 response code as 500. |
107 EXPECT_EQ(500, r.GetResponseCode()); | 107 EXPECT_EQ(500, r.GetResponseCode()); |
| 108 EXPECT_EQ(1, d.response_started_count()); |
108 // We should not have followed the redirect. | 109 // We should not have followed the redirect. |
109 EXPECT_EQ(0, d.received_redirect_count()); | 110 EXPECT_EQ(0, d.received_redirect_count()); |
110 } | 111 } |
111 } | 112 } |
112 | 113 |
| 114 TEST_F(URLRequestTest, UnexpectedServerAuthTest) { |
| 115 // In this unit test, we're using the HTTPTestServer as a proxy server and |
| 116 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
| 117 // The HTTPTestServer will return a 401 response, which we should balk at. |
| 118 scoped_refptr<HTTPTestServer> server = |
| 119 HTTPTestServer::CreateServer(L"", NULL); |
| 120 ASSERT_TRUE(NULL != server.get()); |
| 121 TestDelegate d; |
| 122 { |
| 123 URLRequest r(GURL("https://www.server-auth.com/"), &d); |
| 124 std::string proxy("localhost:"); |
| 125 proxy.append(IntToString(kHTTPDefaultPort)); |
| 126 r.set_context(new TestURLRequestContext(proxy)); |
| 127 |
| 128 r.Start(); |
| 129 EXPECT_TRUE(r.is_pending()); |
| 130 |
| 131 MessageLoop::current()->Run(); |
| 132 |
| 133 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 134 EXPECT_EQ(net::ERR_UNEXPECTED_SERVER_AUTH, r.status().os_error()); |
| 135 } |
| 136 } |
| 137 |
113 TEST_F(URLRequestTest, GetTest_NoCache) { | 138 TEST_F(URLRequestTest, GetTest_NoCache) { |
114 scoped_refptr<HTTPTestServer> server = | 139 scoped_refptr<HTTPTestServer> server = |
115 HTTPTestServer::CreateServer(L"", NULL); | 140 HTTPTestServer::CreateServer(L"", NULL); |
116 ASSERT_TRUE(NULL != server.get()); | 141 ASSERT_TRUE(NULL != server.get()); |
117 TestDelegate d; | 142 TestDelegate d; |
118 { | 143 { |
119 TestURLRequest r(server->TestServerPage(""), &d); | 144 TestURLRequest r(server->TestServerPage(""), &d); |
120 | 145 |
121 r.Start(); | 146 r.Start(); |
122 EXPECT_TRUE(r.is_pending()); | 147 EXPECT_TRUE(r.is_pending()); |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 int64 file_size = 0; | 1084 int64 file_size = 0; |
1060 file_util::GetFileSize(app_path, &file_size); | 1085 file_util::GetFileSize(app_path, &file_size); |
1061 | 1086 |
1062 EXPECT_TRUE(!r.is_pending()); | 1087 EXPECT_TRUE(!r.is_pending()); |
1063 EXPECT_EQ(1, d.response_started_count()); | 1088 EXPECT_EQ(1, d.response_started_count()); |
1064 EXPECT_FALSE(d.received_data_before_response()); | 1089 EXPECT_FALSE(d.received_data_before_response()); |
1065 EXPECT_EQ(d.bytes_received(), 0); | 1090 EXPECT_EQ(d.bytes_received(), 0); |
1066 } | 1091 } |
1067 } | 1092 } |
1068 | 1093 |
OLD | NEW |