| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 #include "net/http/http_response_headers.h" | 70 #include "net/http/http_response_headers.h" |
| 71 #include "net/http/http_util.h" | 71 #include "net/http/http_util.h" |
| 72 #include "net/log/net_log.h" | 72 #include "net/log/net_log.h" |
| 73 #include "net/log/test_net_log.h" | 73 #include "net/log/test_net_log.h" |
| 74 #include "net/log/test_net_log_entry.h" | 74 #include "net/log/test_net_log_entry.h" |
| 75 #include "net/log/test_net_log_util.h" | 75 #include "net/log/test_net_log_util.h" |
| 76 #include "net/proxy/proxy_service.h" | 76 #include "net/proxy/proxy_service.h" |
| 77 #include "net/socket/ssl_client_socket.h" | 77 #include "net/socket/ssl_client_socket.h" |
| 78 #include "net/ssl/ssl_cipher_suite_names.h" | 78 #include "net/ssl/ssl_cipher_suite_names.h" |
| 79 #include "net/ssl/ssl_connection_status_flags.h" | 79 #include "net/ssl/ssl_connection_status_flags.h" |
| 80 #include "net/ssl/ssl_server_config.h" |
| 80 #include "net/test/cert_test_util.h" | 81 #include "net/test/cert_test_util.h" |
| 81 #include "net/test/embedded_test_server/embedded_test_server.h" | 82 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 82 #include "net/test/embedded_test_server/http_request.h" | 83 #include "net/test/embedded_test_server/http_request.h" |
| 83 #include "net/test/embedded_test_server/http_response.h" | 84 #include "net/test/embedded_test_server/http_response.h" |
| 84 #include "net/test/spawned_test_server/spawned_test_server.h" | 85 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 85 #include "net/test/url_request/url_request_failed_job.h" | 86 #include "net/test/url_request/url_request_failed_job.h" |
| 86 #include "net/url_request/data_protocol_handler.h" | 87 #include "net/url_request/data_protocol_handler.h" |
| 87 #include "net/url_request/static_http_user_agent_settings.h" | 88 #include "net/url_request/static_http_user_agent_settings.h" |
| 88 #include "net/url_request/url_request.h" | 89 #include "net/url_request/url_request.h" |
| 89 #include "net/url_request/url_request_filter.h" | 90 #include "net/url_request/url_request_filter.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 219 } |
| 219 | 220 |
| 220 for (size_t i = 0; i < len; i++) { | 221 for (size_t i = 0; i < len; i++) { |
| 221 buffer[i] = static_cast<char>(rand()); | 222 buffer[i] = static_cast<char>(rand()); |
| 222 if (!buffer[i]) | 223 if (!buffer[i]) |
| 223 buffer[i] = 'g'; | 224 buffer[i] = 'g'; |
| 224 } | 225 } |
| 225 } | 226 } |
| 226 #endif | 227 #endif |
| 227 | 228 |
| 228 #if !defined(OS_IOS) | |
| 229 void TestLoadTimingCacheHitNoNetwork( | 229 void TestLoadTimingCacheHitNoNetwork( |
| 230 const LoadTimingInfo& load_timing_info) { | 230 const LoadTimingInfo& load_timing_info) { |
| 231 EXPECT_FALSE(load_timing_info.socket_reused); | 231 EXPECT_FALSE(load_timing_info.socket_reused); |
| 232 EXPECT_EQ(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 232 EXPECT_EQ(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 233 | 233 |
| 234 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); | 234 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); |
| 235 EXPECT_FALSE(load_timing_info.request_start.is_null()); | 235 EXPECT_FALSE(load_timing_info.request_start.is_null()); |
| 236 | 236 |
| 237 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 237 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 238 EXPECT_LE(load_timing_info.request_start, load_timing_info.send_start); | 238 EXPECT_LE(load_timing_info.request_start, load_timing_info.send_start); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 const GURL& host_url) { | 311 const GURL& host_url) { |
| 312 std::string sent_value; | 312 std::string sent_value; |
| 313 | 313 |
| 314 EXPECT_TRUE(headers.GetHeader("Host", &sent_value)); | 314 EXPECT_TRUE(headers.GetHeader("Host", &sent_value)); |
| 315 EXPECT_EQ(GetHostAndOptionalPort(host_url), sent_value); | 315 EXPECT_EQ(GetHostAndOptionalPort(host_url), sent_value); |
| 316 | 316 |
| 317 EXPECT_TRUE(headers.GetHeader("Connection", &sent_value)); | 317 EXPECT_TRUE(headers.GetHeader("Connection", &sent_value)); |
| 318 EXPECT_EQ("keep-alive", sent_value); | 318 EXPECT_EQ("keep-alive", sent_value); |
| 319 } | 319 } |
| 320 | 320 |
| 321 #if !defined(OS_IOS) |
| 321 bool FingerprintsEqual(const HashValueVector& a, const HashValueVector& b) { | 322 bool FingerprintsEqual(const HashValueVector& a, const HashValueVector& b) { |
| 322 size_t size = a.size(); | 323 size_t size = a.size(); |
| 323 | 324 |
| 324 if (size != b.size()) | 325 if (size != b.size()) |
| 325 return false; | 326 return false; |
| 326 | 327 |
| 327 for (size_t i = 0; i < size; ++i) { | 328 for (size_t i = 0; i < size; ++i) { |
| 328 if (!a[i].Equals(b[i])) | 329 if (!a[i].Equals(b[i])) |
| 329 return false; | 330 return false; |
| 330 } | 331 } |
| (...skipping 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2186 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); | 2187 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
| 2187 | 2188 |
| 2188 req->SetPriority(MAXIMUM_PRIORITY); | 2189 req->SetPriority(MAXIMUM_PRIORITY); |
| 2189 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); | 2190 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
| 2190 | 2191 |
| 2191 req->Start(); | 2192 req->Start(); |
| 2192 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); | 2193 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
| 2193 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority()); | 2194 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority()); |
| 2194 } | 2195 } |
| 2195 | 2196 |
| 2196 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). | |
| 2197 #if !defined(OS_IOS) | |
| 2198 namespace { | 2197 namespace { |
| 2199 | 2198 |
| 2200 // Less verbose way of running a simple testserver for the tests below. | 2199 // Less verbose way of running a simple testserver for the tests below. |
| 2201 class LocalHttpTestServer : public SpawnedTestServer { | 2200 class LocalHttpTestServer : public EmbeddedTestServer { |
| 2202 public: | 2201 public: |
| 2203 explicit LocalHttpTestServer(const base::FilePath& document_root) | 2202 explicit LocalHttpTestServer(const base::FilePath& document_root) { |
| 2204 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, | 2203 AddDefaultHandlers(document_root); |
| 2205 SpawnedTestServer::kLocalhost, | 2204 } |
| 2206 document_root) {} | 2205 |
| 2207 LocalHttpTestServer() | 2206 LocalHttpTestServer() { AddDefaultHandlers(base::FilePath()); } |
| 2208 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, | |
| 2209 SpawnedTestServer::kLocalhost, | |
| 2210 base::FilePath()) {} | |
| 2211 }; | 2207 }; |
| 2212 | 2208 |
| 2213 scoped_ptr<net::test_server::HttpResponse> HandleSetCookieRequest( | |
| 2214 const test_server::HttpRequest& request) { | |
| 2215 scoped_ptr<test_server::BasicHttpResponse> http_response( | |
| 2216 new test_server::BasicHttpResponse()); | |
| 2217 if (request.relative_url.find("/set-cookie?") != 0) { | |
| 2218 http_response->set_code(net::HTTP_NOT_FOUND); | |
| 2219 http_response->set_content("hello"); | |
| 2220 return http_response.Pass(); | |
| 2221 } | |
| 2222 http_response->set_code(net::HTTP_OK); | |
| 2223 http_response->set_content("hello"); | |
| 2224 http_response->set_content_type("text/plain"); | |
| 2225 http_response->AddCustomHeader( | |
| 2226 "Set-Cookie", | |
| 2227 request.relative_url.substr(request.relative_url.find("?") + 1)); | |
| 2228 return http_response.Pass(); | |
| 2229 } | |
| 2230 | |
| 2231 } // namespace | 2209 } // namespace |
| 2232 | 2210 |
| 2233 TEST_F(URLRequestTest, DelayedCookieCallback) { | 2211 TEST_F(URLRequestTest, DelayedCookieCallback) { |
| 2234 LocalHttpTestServer test_server; | 2212 LocalHttpTestServer test_server; |
| 2235 ASSERT_TRUE(test_server.Start()); | 2213 ASSERT_TRUE(test_server.Start()); |
| 2236 | 2214 |
| 2237 TestURLRequestContext context; | 2215 TestURLRequestContext context; |
| 2238 scoped_refptr<DelayedCookieMonster> delayed_cm = | 2216 scoped_refptr<DelayedCookieMonster> delayed_cm = |
| 2239 new DelayedCookieMonster(); | 2217 new DelayedCookieMonster(); |
| 2240 scoped_refptr<CookieStore> cookie_store = delayed_cm; | 2218 scoped_refptr<CookieStore> cookie_store = delayed_cm; |
| 2241 context.set_cookie_store(delayed_cm.get()); | 2219 context.set_cookie_store(delayed_cm.get()); |
| 2242 | 2220 |
| 2243 // Set up a cookie. | 2221 // Set up a cookie. |
| 2244 { | 2222 { |
| 2245 TestNetworkDelegate network_delegate; | 2223 TestNetworkDelegate network_delegate; |
| 2246 context.set_network_delegate(&network_delegate); | 2224 context.set_network_delegate(&network_delegate); |
| 2247 TestDelegate d; | 2225 TestDelegate d; |
| 2248 scoped_ptr<URLRequest> req(context.CreateRequest( | 2226 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2249 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, | 2227 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2250 &d)); | 2228 &d)); |
| 2251 req->Start(); | 2229 req->Start(); |
| 2252 base::RunLoop().Run(); | 2230 base::RunLoop().Run(); |
| 2253 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2231 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2254 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2232 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2255 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2233 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2256 } | 2234 } |
| 2257 | 2235 |
| 2258 // Verify that the cookie is set. | 2236 // Verify that the cookie is set. |
| 2259 { | 2237 { |
| 2260 TestNetworkDelegate network_delegate; | 2238 TestNetworkDelegate network_delegate; |
| 2261 context.set_network_delegate(&network_delegate); | 2239 context.set_network_delegate(&network_delegate); |
| 2262 TestDelegate d; | 2240 TestDelegate d; |
| 2263 scoped_ptr<URLRequest> req(context.CreateRequest( | 2241 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2264 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2242 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2265 req->Start(); | 2243 req->Start(); |
| 2266 base::RunLoop().Run(); | 2244 base::RunLoop().Run(); |
| 2267 | 2245 |
| 2268 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2246 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2269 != std::string::npos); | 2247 != std::string::npos); |
| 2270 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2248 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2271 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2249 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2272 } | 2250 } |
| 2273 } | 2251 } |
| 2274 | 2252 |
| 2275 TEST_F(URLRequestTest, DoNotSendCookies) { | 2253 TEST_F(URLRequestTest, DoNotSendCookies) { |
| 2276 LocalHttpTestServer test_server; | 2254 LocalHttpTestServer test_server; |
| 2277 ASSERT_TRUE(test_server.Start()); | 2255 ASSERT_TRUE(test_server.Start()); |
| 2278 | 2256 |
| 2279 // Set up a cookie. | 2257 // Set up a cookie. |
| 2280 { | 2258 { |
| 2281 TestNetworkDelegate network_delegate; | 2259 TestNetworkDelegate network_delegate; |
| 2282 default_context_.set_network_delegate(&network_delegate); | 2260 default_context_.set_network_delegate(&network_delegate); |
| 2283 TestDelegate d; | 2261 TestDelegate d; |
| 2284 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2262 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2285 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, | 2263 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2286 &d)); | 2264 &d)); |
| 2287 req->Start(); | 2265 req->Start(); |
| 2288 base::RunLoop().Run(); | 2266 base::RunLoop().Run(); |
| 2289 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2267 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2290 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2268 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2291 } | 2269 } |
| 2292 | 2270 |
| 2293 // Verify that the cookie is set. | 2271 // Verify that the cookie is set. |
| 2294 { | 2272 { |
| 2295 TestNetworkDelegate network_delegate; | 2273 TestNetworkDelegate network_delegate; |
| 2296 default_context_.set_network_delegate(&network_delegate); | 2274 default_context_.set_network_delegate(&network_delegate); |
| 2297 TestDelegate d; | 2275 TestDelegate d; |
| 2298 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2276 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2299 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2277 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2300 req->Start(); | 2278 req->Start(); |
| 2301 base::RunLoop().Run(); | 2279 base::RunLoop().Run(); |
| 2302 | 2280 |
| 2303 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2281 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2304 != std::string::npos); | 2282 != std::string::npos); |
| 2305 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2283 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2306 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2284 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2307 } | 2285 } |
| 2308 | 2286 |
| 2309 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 2287 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
| 2310 { | 2288 { |
| 2311 TestNetworkDelegate network_delegate; | 2289 TestNetworkDelegate network_delegate; |
| 2312 default_context_.set_network_delegate(&network_delegate); | 2290 default_context_.set_network_delegate(&network_delegate); |
| 2313 TestDelegate d; | 2291 TestDelegate d; |
| 2314 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2292 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2315 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2293 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2316 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); | 2294 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); |
| 2317 req->Start(); | 2295 req->Start(); |
| 2318 base::RunLoop().Run(); | 2296 base::RunLoop().Run(); |
| 2319 | 2297 |
| 2320 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2298 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2321 == std::string::npos); | 2299 == std::string::npos); |
| 2322 | 2300 |
| 2323 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 2301 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
| 2324 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2302 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2325 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2303 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2326 } | 2304 } |
| 2327 } | 2305 } |
| 2328 | 2306 |
| 2329 TEST_F(URLRequestTest, DoNotSaveCookies) { | 2307 TEST_F(URLRequestTest, DoNotSaveCookies) { |
| 2330 LocalHttpTestServer test_server; | 2308 LocalHttpTestServer test_server; |
| 2331 ASSERT_TRUE(test_server.Start()); | 2309 ASSERT_TRUE(test_server.Start()); |
| 2332 | 2310 |
| 2333 // Set up a cookie. | 2311 // Set up a cookie. |
| 2334 { | 2312 { |
| 2335 TestNetworkDelegate network_delegate; | 2313 TestNetworkDelegate network_delegate; |
| 2336 default_context_.set_network_delegate(&network_delegate); | 2314 default_context_.set_network_delegate(&network_delegate); |
| 2337 TestDelegate d; | 2315 TestDelegate d; |
| 2338 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2316 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2339 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, | 2317 test_server.GetURL("/set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, |
| 2340 &d)); | 2318 &d)); |
| 2341 req->Start(); | 2319 req->Start(); |
| 2342 base::RunLoop().Run(); | 2320 base::RunLoop().Run(); |
| 2343 | 2321 |
| 2344 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2322 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2345 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2323 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2346 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2324 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2347 } | 2325 } |
| 2348 | 2326 |
| 2349 // Try to set-up another cookie and update the previous cookie. | 2327 // Try to set-up another cookie and update the previous cookie. |
| 2350 { | 2328 { |
| 2351 TestNetworkDelegate network_delegate; | 2329 TestNetworkDelegate network_delegate; |
| 2352 default_context_.set_network_delegate(&network_delegate); | 2330 default_context_.set_network_delegate(&network_delegate); |
| 2353 TestDelegate d; | 2331 TestDelegate d; |
| 2354 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2332 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2355 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2333 test_server.GetURL("/set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2356 DEFAULT_PRIORITY, &d)); | 2334 DEFAULT_PRIORITY, &d)); |
| 2357 req->SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES); | 2335 req->SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES); |
| 2358 req->Start(); | 2336 req->Start(); |
| 2359 | 2337 |
| 2360 base::RunLoop().Run(); | 2338 base::RunLoop().Run(); |
| 2361 | 2339 |
| 2362 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 2340 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
| 2363 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2341 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2364 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2342 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2365 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2343 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2366 } | 2344 } |
| 2367 | 2345 |
| 2368 // Verify the cookies weren't saved or updated. | 2346 // Verify the cookies weren't saved or updated. |
| 2369 { | 2347 { |
| 2370 TestNetworkDelegate network_delegate; | 2348 TestNetworkDelegate network_delegate; |
| 2371 default_context_.set_network_delegate(&network_delegate); | 2349 default_context_.set_network_delegate(&network_delegate); |
| 2372 TestDelegate d; | 2350 TestDelegate d; |
| 2373 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2351 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2374 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2352 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2375 req->Start(); | 2353 req->Start(); |
| 2376 base::RunLoop().Run(); | 2354 base::RunLoop().Run(); |
| 2377 | 2355 |
| 2378 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2356 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2379 == std::string::npos); | 2357 == std::string::npos); |
| 2380 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2358 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2381 != std::string::npos); | 2359 != std::string::npos); |
| 2382 | 2360 |
| 2383 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2361 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2384 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2362 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2385 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2363 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2386 } | 2364 } |
| 2387 } | 2365 } |
| 2388 | 2366 |
| 2389 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 2367 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
| 2390 LocalHttpTestServer test_server; | 2368 LocalHttpTestServer test_server; |
| 2391 ASSERT_TRUE(test_server.Start()); | 2369 ASSERT_TRUE(test_server.Start()); |
| 2392 | 2370 |
| 2393 // Set up a cookie. | 2371 // Set up a cookie. |
| 2394 { | 2372 { |
| 2395 TestNetworkDelegate network_delegate; | 2373 TestNetworkDelegate network_delegate; |
| 2396 default_context_.set_network_delegate(&network_delegate); | 2374 default_context_.set_network_delegate(&network_delegate); |
| 2397 TestDelegate d; | 2375 TestDelegate d; |
| 2398 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2376 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2399 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, | 2377 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2400 &d)); | 2378 &d)); |
| 2401 req->Start(); | 2379 req->Start(); |
| 2402 base::RunLoop().Run(); | 2380 base::RunLoop().Run(); |
| 2403 | 2381 |
| 2404 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2382 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2405 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2383 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2406 } | 2384 } |
| 2407 | 2385 |
| 2408 // Verify that the cookie is set. | 2386 // Verify that the cookie is set. |
| 2409 { | 2387 { |
| 2410 TestNetworkDelegate network_delegate; | 2388 TestNetworkDelegate network_delegate; |
| 2411 default_context_.set_network_delegate(&network_delegate); | 2389 default_context_.set_network_delegate(&network_delegate); |
| 2412 TestDelegate d; | 2390 TestDelegate d; |
| 2413 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2391 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2414 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2392 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2415 req->Start(); | 2393 req->Start(); |
| 2416 base::RunLoop().Run(); | 2394 base::RunLoop().Run(); |
| 2417 | 2395 |
| 2418 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2396 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2419 != std::string::npos); | 2397 != std::string::npos); |
| 2420 | 2398 |
| 2421 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2399 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2422 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2400 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2423 } | 2401 } |
| 2424 | 2402 |
| 2425 // Verify that the cookie isn't sent. | 2403 // Verify that the cookie isn't sent. |
| 2426 { | 2404 { |
| 2427 TestNetworkDelegate network_delegate; | 2405 TestNetworkDelegate network_delegate; |
| 2428 default_context_.set_network_delegate(&network_delegate); | 2406 default_context_.set_network_delegate(&network_delegate); |
| 2429 TestDelegate d; | 2407 TestDelegate d; |
| 2430 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2408 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2431 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2409 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2432 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2410 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2433 req->Start(); | 2411 req->Start(); |
| 2434 base::RunLoop().Run(); | 2412 base::RunLoop().Run(); |
| 2435 | 2413 |
| 2436 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2414 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2437 == std::string::npos); | 2415 == std::string::npos); |
| 2438 | 2416 |
| 2439 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2417 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2440 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2418 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2441 } | 2419 } |
| 2442 } | 2420 } |
| 2443 | 2421 |
| 2444 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 2422 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
| 2445 LocalHttpTestServer test_server; | 2423 LocalHttpTestServer test_server; |
| 2446 ASSERT_TRUE(test_server.Start()); | 2424 ASSERT_TRUE(test_server.Start()); |
| 2447 | 2425 |
| 2448 // Set up a cookie. | 2426 // Set up a cookie. |
| 2449 { | 2427 { |
| 2450 TestNetworkDelegate network_delegate; | 2428 TestNetworkDelegate network_delegate; |
| 2451 default_context_.set_network_delegate(&network_delegate); | 2429 default_context_.set_network_delegate(&network_delegate); |
| 2452 TestDelegate d; | 2430 TestDelegate d; |
| 2453 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2431 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2454 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, | 2432 test_server.GetURL("/set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, |
| 2455 &d)); | 2433 &d)); |
| 2456 req->Start(); | 2434 req->Start(); |
| 2457 base::RunLoop().Run(); | 2435 base::RunLoop().Run(); |
| 2458 | 2436 |
| 2459 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2437 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2460 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2438 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2461 } | 2439 } |
| 2462 | 2440 |
| 2463 // Try to set-up another cookie and update the previous cookie. | 2441 // Try to set-up another cookie and update the previous cookie. |
| 2464 { | 2442 { |
| 2465 TestNetworkDelegate network_delegate; | 2443 TestNetworkDelegate network_delegate; |
| 2466 default_context_.set_network_delegate(&network_delegate); | 2444 default_context_.set_network_delegate(&network_delegate); |
| 2467 TestDelegate d; | 2445 TestDelegate d; |
| 2468 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2446 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 2469 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2447 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2470 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2448 test_server.GetURL("/set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2471 DEFAULT_PRIORITY, &d)); | 2449 DEFAULT_PRIORITY, &d)); |
| 2472 req->Start(); | 2450 req->Start(); |
| 2473 | 2451 |
| 2474 base::RunLoop().Run(); | 2452 base::RunLoop().Run(); |
| 2475 | 2453 |
| 2476 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2454 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2477 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2455 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 2478 } | 2456 } |
| 2479 | 2457 |
| 2480 // Verify the cookies weren't saved or updated. | 2458 // Verify the cookies weren't saved or updated. |
| 2481 { | 2459 { |
| 2482 TestNetworkDelegate network_delegate; | 2460 TestNetworkDelegate network_delegate; |
| 2483 default_context_.set_network_delegate(&network_delegate); | 2461 default_context_.set_network_delegate(&network_delegate); |
| 2484 TestDelegate d; | 2462 TestDelegate d; |
| 2485 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2463 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2486 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2464 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2487 req->Start(); | 2465 req->Start(); |
| 2488 base::RunLoop().Run(); | 2466 base::RunLoop().Run(); |
| 2489 | 2467 |
| 2490 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2468 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2491 == std::string::npos); | 2469 == std::string::npos); |
| 2492 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2470 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2493 != std::string::npos); | 2471 != std::string::npos); |
| 2494 | 2472 |
| 2495 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2473 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2496 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2474 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2497 } | 2475 } |
| 2498 } | 2476 } |
| 2499 | 2477 |
| 2500 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 2478 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
| 2501 LocalHttpTestServer test_server; | 2479 LocalHttpTestServer test_server; |
| 2502 ASSERT_TRUE(test_server.Start()); | 2480 ASSERT_TRUE(test_server.Start()); |
| 2503 | 2481 |
| 2504 // Set up an empty cookie. | 2482 // Set up an empty cookie. |
| 2505 { | 2483 { |
| 2506 TestNetworkDelegate network_delegate; | 2484 TestNetworkDelegate network_delegate; |
| 2507 default_context_.set_network_delegate(&network_delegate); | 2485 default_context_.set_network_delegate(&network_delegate); |
| 2508 TestDelegate d; | 2486 TestDelegate d; |
| 2509 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2487 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2510 test_server.GetURL("set-cookie"), DEFAULT_PRIORITY, &d)); | 2488 test_server.GetURL("/set-cookie"), DEFAULT_PRIORITY, &d)); |
| 2511 req->Start(); | 2489 req->Start(); |
| 2512 base::RunLoop().Run(); | 2490 base::RunLoop().Run(); |
| 2513 | 2491 |
| 2514 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2492 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2515 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2493 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2516 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2494 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2517 } | 2495 } |
| 2518 } | 2496 } |
| 2519 | 2497 |
| 2520 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 2498 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
| 2521 LocalHttpTestServer test_server; | 2499 LocalHttpTestServer test_server; |
| 2522 ASSERT_TRUE(test_server.Start()); | 2500 ASSERT_TRUE(test_server.Start()); |
| 2523 | 2501 |
| 2524 // Set up a cookie. | 2502 // Set up a cookie. |
| 2525 { | 2503 { |
| 2526 TestNetworkDelegate network_delegate; | 2504 TestNetworkDelegate network_delegate; |
| 2527 default_context_.set_network_delegate(&network_delegate); | 2505 default_context_.set_network_delegate(&network_delegate); |
| 2528 TestDelegate d; | 2506 TestDelegate d; |
| 2529 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2507 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2530 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, | 2508 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2531 &d)); | 2509 &d)); |
| 2532 req->Start(); | 2510 req->Start(); |
| 2533 base::RunLoop().Run(); | 2511 base::RunLoop().Run(); |
| 2534 | 2512 |
| 2535 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2513 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2536 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2514 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2537 } | 2515 } |
| 2538 | 2516 |
| 2539 // Verify that the cookie is set. | 2517 // Verify that the cookie is set. |
| 2540 { | 2518 { |
| 2541 TestNetworkDelegate network_delegate; | 2519 TestNetworkDelegate network_delegate; |
| 2542 default_context_.set_network_delegate(&network_delegate); | 2520 default_context_.set_network_delegate(&network_delegate); |
| 2543 TestDelegate d; | 2521 TestDelegate d; |
| 2544 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2522 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2545 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2523 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2546 req->Start(); | 2524 req->Start(); |
| 2547 base::RunLoop().Run(); | 2525 base::RunLoop().Run(); |
| 2548 | 2526 |
| 2549 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2527 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2550 != std::string::npos); | 2528 != std::string::npos); |
| 2551 | 2529 |
| 2552 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2530 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2553 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2531 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2554 } | 2532 } |
| 2555 | 2533 |
| 2556 // Verify that the cookie isn't sent. | 2534 // Verify that the cookie isn't sent. |
| 2557 { | 2535 { |
| 2558 TestNetworkDelegate network_delegate; | 2536 TestNetworkDelegate network_delegate; |
| 2559 default_context_.set_network_delegate(&network_delegate); | 2537 default_context_.set_network_delegate(&network_delegate); |
| 2560 TestDelegate d; | 2538 TestDelegate d; |
| 2561 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2539 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2562 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2540 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2563 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2541 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2564 req->Start(); | 2542 req->Start(); |
| 2565 base::RunLoop().Run(); | 2543 base::RunLoop().Run(); |
| 2566 | 2544 |
| 2567 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2545 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2568 == std::string::npos); | 2546 == std::string::npos); |
| 2569 | 2547 |
| 2570 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2548 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2571 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2549 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2572 } | 2550 } |
| 2573 } | 2551 } |
| 2574 | 2552 |
| 2575 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 2553 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
| 2576 LocalHttpTestServer test_server; | 2554 LocalHttpTestServer test_server; |
| 2577 ASSERT_TRUE(test_server.Start()); | 2555 ASSERT_TRUE(test_server.Start()); |
| 2578 | 2556 |
| 2579 // Set up a cookie. | 2557 // Set up a cookie. |
| 2580 { | 2558 { |
| 2581 TestNetworkDelegate network_delegate; | 2559 TestNetworkDelegate network_delegate; |
| 2582 default_context_.set_network_delegate(&network_delegate); | 2560 default_context_.set_network_delegate(&network_delegate); |
| 2583 TestDelegate d; | 2561 TestDelegate d; |
| 2584 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2562 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2585 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, | 2563 test_server.GetURL("/set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, |
| 2586 &d)); | 2564 &d)); |
| 2587 req->Start(); | 2565 req->Start(); |
| 2588 base::RunLoop().Run(); | 2566 base::RunLoop().Run(); |
| 2589 | 2567 |
| 2590 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2568 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2591 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2569 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2592 } | 2570 } |
| 2593 | 2571 |
| 2594 // Try to set-up another cookie and update the previous cookie. | 2572 // Try to set-up another cookie and update the previous cookie. |
| 2595 { | 2573 { |
| 2596 TestNetworkDelegate network_delegate; | 2574 TestNetworkDelegate network_delegate; |
| 2597 default_context_.set_network_delegate(&network_delegate); | 2575 default_context_.set_network_delegate(&network_delegate); |
| 2598 TestDelegate d; | 2576 TestDelegate d; |
| 2599 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2577 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 2600 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2578 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2601 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2579 test_server.GetURL("/set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2602 DEFAULT_PRIORITY, &d)); | 2580 DEFAULT_PRIORITY, &d)); |
| 2603 req->Start(); | 2581 req->Start(); |
| 2604 | 2582 |
| 2605 base::RunLoop().Run(); | 2583 base::RunLoop().Run(); |
| 2606 | 2584 |
| 2607 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2585 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2608 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2586 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 2609 } | 2587 } |
| 2610 | 2588 |
| 2611 // Verify the cookies weren't saved or updated. | 2589 // Verify the cookies weren't saved or updated. |
| 2612 { | 2590 { |
| 2613 TestNetworkDelegate network_delegate; | 2591 TestNetworkDelegate network_delegate; |
| 2614 default_context_.set_network_delegate(&network_delegate); | 2592 default_context_.set_network_delegate(&network_delegate); |
| 2615 TestDelegate d; | 2593 TestDelegate d; |
| 2616 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2594 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2617 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2595 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2618 req->Start(); | 2596 req->Start(); |
| 2619 base::RunLoop().Run(); | 2597 base::RunLoop().Run(); |
| 2620 | 2598 |
| 2621 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2599 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2622 == std::string::npos); | 2600 == std::string::npos); |
| 2623 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2601 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2624 != std::string::npos); | 2602 != std::string::npos); |
| 2625 | 2603 |
| 2626 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2604 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2627 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2605 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2628 } | 2606 } |
| 2629 } | 2607 } |
| 2630 | 2608 |
| 2631 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) { | 2609 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) { |
| 2632 LocalHttpTestServer test_server; | 2610 LocalHttpTestServer test_server; |
| 2633 ASSERT_TRUE(test_server.Start()); | 2611 ASSERT_TRUE(test_server.Start()); |
| 2634 | 2612 |
| 2635 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where | 2613 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where |
| 2636 // LocalHttpTestServer points). | 2614 // LocalHttpTestServer points). |
| 2637 { | 2615 { |
| 2638 TestNetworkDelegate network_delegate; | 2616 TestNetworkDelegate network_delegate; |
| 2639 network_delegate.set_experimental_cookie_features_enabled(true); | 2617 network_delegate.set_experimental_cookie_features_enabled(true); |
| 2640 default_context_.set_network_delegate(&network_delegate); | 2618 default_context_.set_network_delegate(&network_delegate); |
| 2641 | 2619 |
| 2642 TestDelegate d; | 2620 TestDelegate d; |
| 2643 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2621 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2644 test_server.GetURL( | 2622 test_server.GetURL( |
| 2645 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), | 2623 "/set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), |
| 2646 DEFAULT_PRIORITY, &d)); | 2624 DEFAULT_PRIORITY, &d)); |
| 2647 req->Start(); | 2625 req->Start(); |
| 2648 base::RunLoop().Run(); | 2626 base::RunLoop().Run(); |
| 2649 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2627 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2650 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2628 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2651 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2629 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2652 } | 2630 } |
| 2653 | 2631 |
| 2654 // Verify that the cookie is sent for first-party requests. | 2632 // Verify that the cookie is sent for first-party requests. |
| 2655 { | 2633 { |
| 2656 TestNetworkDelegate network_delegate; | 2634 TestNetworkDelegate network_delegate; |
| 2657 network_delegate.set_experimental_cookie_features_enabled(true); | 2635 network_delegate.set_experimental_cookie_features_enabled(true); |
| 2658 default_context_.set_network_delegate(&network_delegate); | 2636 default_context_.set_network_delegate(&network_delegate); |
| 2659 TestDelegate d; | 2637 TestDelegate d; |
| 2660 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2638 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2661 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2639 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2662 req->set_first_party_for_cookies(test_server.GetURL("")); | 2640 req->set_first_party_for_cookies(test_server.GetURL("/")); |
| 2663 req->Start(); | 2641 req->Start(); |
| 2664 base::RunLoop().Run(); | 2642 base::RunLoop().Run(); |
| 2665 | 2643 |
| 2666 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != | 2644 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
| 2667 std::string::npos); | 2645 std::string::npos); |
| 2668 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2646 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2669 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2647 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2670 } | 2648 } |
| 2671 | 2649 |
| 2672 // Verify that the cookie is not-sent for non-first-party requests. | 2650 // Verify that the cookie is not-sent for non-first-party requests. |
| 2673 { | 2651 { |
| 2674 TestNetworkDelegate network_delegate; | 2652 TestNetworkDelegate network_delegate; |
| 2675 network_delegate.set_experimental_cookie_features_enabled(true); | 2653 network_delegate.set_experimental_cookie_features_enabled(true); |
| 2676 default_context_.set_network_delegate(&network_delegate); | 2654 default_context_.set_network_delegate(&network_delegate); |
| 2677 TestDelegate d; | 2655 TestDelegate d; |
| 2678 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2656 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2679 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2657 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2680 req->set_first_party_for_cookies(GURL("http://third-party.test/")); | 2658 req->set_first_party_for_cookies(GURL("http://third-party.test/")); |
| 2681 req->Start(); | 2659 req->Start(); |
| 2682 base::RunLoop().Run(); | 2660 base::RunLoop().Run(); |
| 2683 | 2661 |
| 2684 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == | 2662 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == |
| 2685 std::string::npos); | 2663 std::string::npos); |
| 2686 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2664 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2687 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2665 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2688 } | 2666 } |
| 2689 } | 2667 } |
| 2690 | 2668 |
| 2691 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { | 2669 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { |
| 2692 LocalHttpTestServer test_server; | 2670 LocalHttpTestServer test_server; |
| 2693 ASSERT_TRUE(test_server.Start()); | 2671 ASSERT_TRUE(test_server.Start()); |
| 2694 | 2672 |
| 2695 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where | 2673 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where |
| 2696 // LocalHttpTestServer points). | 2674 // LocalHttpTestServer points). |
| 2697 { | 2675 { |
| 2698 TestNetworkDelegate network_delegate; | 2676 TestNetworkDelegate network_delegate; |
| 2699 network_delegate.set_experimental_cookie_features_enabled(false); | 2677 network_delegate.set_experimental_cookie_features_enabled(false); |
| 2700 default_context_.set_network_delegate(&network_delegate); | 2678 default_context_.set_network_delegate(&network_delegate); |
| 2701 | 2679 |
| 2702 TestDelegate d; | 2680 TestDelegate d; |
| 2703 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2681 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2704 test_server.GetURL( | 2682 test_server.GetURL( |
| 2705 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), | 2683 "/set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), |
| 2706 DEFAULT_PRIORITY, &d)); | 2684 DEFAULT_PRIORITY, &d)); |
| 2707 req->Start(); | 2685 req->Start(); |
| 2708 base::RunLoop().Run(); | 2686 base::RunLoop().Run(); |
| 2709 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2687 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2710 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2688 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2711 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2689 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2712 } | 2690 } |
| 2713 | 2691 |
| 2714 // Verify that the cookie is sent for first-party requests. | 2692 // Verify that the cookie is sent for first-party requests. |
| 2715 { | 2693 { |
| 2716 TestNetworkDelegate network_delegate; | 2694 TestNetworkDelegate network_delegate; |
| 2717 network_delegate.set_experimental_cookie_features_enabled(false); | 2695 network_delegate.set_experimental_cookie_features_enabled(false); |
| 2718 default_context_.set_network_delegate(&network_delegate); | 2696 default_context_.set_network_delegate(&network_delegate); |
| 2719 TestDelegate d; | 2697 TestDelegate d; |
| 2720 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2698 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2721 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2699 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2722 req->set_first_party_for_cookies(test_server.GetURL("")); | 2700 req->set_first_party_for_cookies(test_server.GetURL("/")); |
| 2723 req->Start(); | 2701 req->Start(); |
| 2724 base::RunLoop().Run(); | 2702 base::RunLoop().Run(); |
| 2725 | 2703 |
| 2726 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != | 2704 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
| 2727 std::string::npos); | 2705 std::string::npos); |
| 2728 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2706 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2729 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2707 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2730 } | 2708 } |
| 2731 | 2709 |
| 2732 // Verify that the cookie is also sent for non-first-party requests. | 2710 // Verify that the cookie is also sent for non-first-party requests. |
| 2733 { | 2711 { |
| 2734 TestNetworkDelegate network_delegate; | 2712 TestNetworkDelegate network_delegate; |
| 2735 network_delegate.set_experimental_cookie_features_enabled(false); | 2713 network_delegate.set_experimental_cookie_features_enabled(false); |
| 2736 default_context_.set_network_delegate(&network_delegate); | 2714 default_context_.set_network_delegate(&network_delegate); |
| 2737 TestDelegate d; | 2715 TestDelegate d; |
| 2738 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2716 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2739 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2717 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2740 req->set_first_party_for_cookies(GURL("http://third-party.test/")); | 2718 req->set_first_party_for_cookies(GURL("http://third-party.test/")); |
| 2741 req->Start(); | 2719 req->Start(); |
| 2742 base::RunLoop().Run(); | 2720 base::RunLoop().Run(); |
| 2743 | 2721 |
| 2744 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != | 2722 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
| 2745 std::string::npos); | 2723 std::string::npos); |
| 2746 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2724 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2747 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2725 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2748 } | 2726 } |
| 2749 } | 2727 } |
| 2750 | 2728 |
| 2751 // Tests that $Secure- cookies can't be set on non-secure origins. | 2729 // Tests that $Secure- cookies can't be set on non-secure origins. |
| 2752 TEST_F(URLRequestTest, SecureCookiePrefixOnNonsecureOrigin) { | 2730 TEST_F(URLRequestTest, SecureCookiePrefixOnNonsecureOrigin) { |
| 2753 test_server::EmbeddedTestServer test_server; | 2731 EmbeddedTestServer http_server; |
| 2754 test_server.RegisterRequestHandler(base::Bind(&HandleSetCookieRequest)); | 2732 http_server.AddDefaultHandlers( |
| 2755 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); | |
| 2756 SpawnedTestServer test_server_https( | |
| 2757 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | |
| 2758 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 2733 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 2759 ASSERT_TRUE(test_server_https.Start()); | 2734 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); |
| 2735 https_server.AddDefaultHandlers( |
| 2736 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 2737 ASSERT_TRUE(http_server.Start()); |
| 2738 ASSERT_TRUE(https_server.Start()); |
| 2760 | 2739 |
| 2761 TestExperimentalFeaturesNetworkDelegate network_delegate; | 2740 TestExperimentalFeaturesNetworkDelegate network_delegate; |
| 2762 TestURLRequestContext context(true); | 2741 TestURLRequestContext context(true); |
| 2763 context.set_network_delegate(&network_delegate); | 2742 context.set_network_delegate(&network_delegate); |
| 2764 context.Init(); | 2743 context.Init(); |
| 2765 | 2744 |
| 2766 // Try to set a Secure $Secure- cookie, with experimental features | 2745 // Try to set a Secure $Secure- cookie, with experimental features |
| 2767 // enabled. | 2746 // enabled. |
| 2768 { | 2747 { |
| 2769 TestDelegate d; | 2748 TestDelegate d; |
| 2770 scoped_ptr<URLRequest> req(context.CreateRequest( | 2749 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2771 test_server.GetURL("/set-cookie?$Secure-nonsecure-origin=1;Secure"), | 2750 http_server.GetURL("/set-cookie?$Secure-nonsecure-origin=1;Secure"), |
| 2772 DEFAULT_PRIORITY, &d)); | 2751 DEFAULT_PRIORITY, &d)); |
| 2773 req->Start(); | 2752 req->Start(); |
| 2774 base::RunLoop().Run(); | 2753 base::RunLoop().Run(); |
| 2775 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2754 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2776 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2755 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2777 } | 2756 } |
| 2778 | 2757 |
| 2779 // Verify that the cookie is not set. | 2758 // Verify that the cookie is not set. |
| 2780 { | 2759 { |
| 2781 TestDelegate d; | 2760 TestDelegate d; |
| 2782 scoped_ptr<URLRequest> req(context.CreateRequest( | 2761 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2783 test_server_https.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2762 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2784 req->Start(); | 2763 req->Start(); |
| 2785 base::RunLoop().Run(); | 2764 base::RunLoop().Run(); |
| 2786 | 2765 |
| 2787 EXPECT_TRUE(d.data_received().find("$Secure-nonsecure-origin=1") == | 2766 EXPECT_TRUE(d.data_received().find("$Secure-nonsecure-origin=1") == |
| 2788 std::string::npos); | 2767 std::string::npos); |
| 2789 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2768 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2790 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2769 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2791 } | 2770 } |
| 2792 } | 2771 } |
| 2793 | 2772 |
| 2794 TEST_F(URLRequestTest, SecureCookiePrefixNonexperimental) { | 2773 TEST_F(URLRequestTest, SecureCookiePrefixNonexperimental) { |
| 2795 SpawnedTestServer test_server( | 2774 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); |
| 2796 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | 2775 https_server.AddDefaultHandlers( |
| 2797 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 2776 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 2798 ASSERT_TRUE(test_server.Start()); | 2777 ASSERT_TRUE(https_server.Start()); |
| 2799 | 2778 |
| 2800 TestNetworkDelegate network_delegate; | 2779 TestNetworkDelegate network_delegate; |
| 2801 TestURLRequestContext context(true); | 2780 TestURLRequestContext context(true); |
| 2802 context.set_network_delegate(&network_delegate); | 2781 context.set_network_delegate(&network_delegate); |
| 2803 context.Init(); | 2782 context.Init(); |
| 2804 | 2783 |
| 2805 // Without experimental features, there should be no restrictions on | 2784 // Without experimental features, there should be no restrictions on |
| 2806 // $Secure- cookies. | 2785 // $Secure- cookies. |
| 2807 | 2786 |
| 2808 // Set a non-Secure cookie with the $Secure- prefix. | 2787 // Set a non-Secure cookie with the $Secure- prefix. |
| 2809 { | 2788 { |
| 2810 TestDelegate d; | 2789 TestDelegate d; |
| 2811 scoped_ptr<URLRequest> req(context.CreateRequest( | 2790 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2812 test_server.GetURL("set-cookie?$Secure-nonsecure-not-experimental=1"), | 2791 https_server.GetURL("/set-cookie?$Secure-nonsecure-not-experimental=1"), |
| 2813 DEFAULT_PRIORITY, &d)); | 2792 DEFAULT_PRIORITY, &d)); |
| 2814 req->Start(); | 2793 req->Start(); |
| 2815 base::RunLoop().Run(); | 2794 base::RunLoop().Run(); |
| 2816 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2795 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2817 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2796 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2818 } | 2797 } |
| 2819 | 2798 |
| 2820 // Set a Secure cookie with the $Secure- prefix. | 2799 // Set a Secure cookie with the $Secure- prefix. |
| 2821 { | 2800 { |
| 2822 TestDelegate d; | 2801 TestDelegate d; |
| 2823 scoped_ptr<URLRequest> req(context.CreateRequest( | 2802 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2824 test_server.GetURL( | 2803 https_server.GetURL( |
| 2825 "set-cookie?$Secure-secure-not-experimental=1;Secure"), | 2804 "/set-cookie?$Secure-secure-not-experimental=1;Secure"), |
| 2826 DEFAULT_PRIORITY, &d)); | 2805 DEFAULT_PRIORITY, &d)); |
| 2827 req->Start(); | 2806 req->Start(); |
| 2828 base::RunLoop().Run(); | 2807 base::RunLoop().Run(); |
| 2829 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2808 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2830 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2809 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2831 } | 2810 } |
| 2832 | 2811 |
| 2833 // Verify that the cookies are set. Neither should have any | 2812 // Verify that the cookies are set. Neither should have any |
| 2834 // restrictions because the experimental flag is off. | 2813 // restrictions because the experimental flag is off. |
| 2835 { | 2814 { |
| 2836 TestDelegate d; | 2815 TestDelegate d; |
| 2837 scoped_ptr<URLRequest> req(context.CreateRequest( | 2816 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2838 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2817 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2839 req->Start(); | 2818 req->Start(); |
| 2840 base::RunLoop().Run(); | 2819 base::RunLoop().Run(); |
| 2841 | 2820 |
| 2842 EXPECT_TRUE(d.data_received().find("$Secure-secure-not-experimental=1") != | 2821 EXPECT_TRUE(d.data_received().find("$Secure-secure-not-experimental=1") != |
| 2843 std::string::npos); | 2822 std::string::npos); |
| 2844 EXPECT_TRUE( | 2823 EXPECT_TRUE( |
| 2845 d.data_received().find("$Secure-nonsecure-not-experimental=1") != | 2824 d.data_received().find("$Secure-nonsecure-not-experimental=1") != |
| 2846 std::string::npos); | 2825 std::string::npos); |
| 2847 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2826 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2848 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2827 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2849 } | 2828 } |
| 2850 } | 2829 } |
| 2851 | 2830 |
| 2852 TEST_F(URLRequestTest, SecureCookiePrefixExperimentalNonsecure) { | 2831 TEST_F(URLRequestTest, SecureCookiePrefixExperimentalNonsecure) { |
| 2853 SpawnedTestServer test_server( | 2832 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); |
| 2854 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | 2833 https_server.AddDefaultHandlers( |
| 2855 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 2834 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 2856 ASSERT_TRUE(test_server.Start()); | 2835 ASSERT_TRUE(https_server.Start()); |
| 2857 | 2836 |
| 2858 TestExperimentalFeaturesNetworkDelegate network_delegate; | 2837 TestExperimentalFeaturesNetworkDelegate network_delegate; |
| 2859 TestURLRequestContext context(true); | 2838 TestURLRequestContext context(true); |
| 2860 context.set_network_delegate(&network_delegate); | 2839 context.set_network_delegate(&network_delegate); |
| 2861 context.Init(); | 2840 context.Init(); |
| 2862 | 2841 |
| 2863 // Try to set a non-Secure $Secure- cookie, with experimental features | 2842 // Try to set a non-Secure $Secure- cookie, with experimental features |
| 2864 // enabled. | 2843 // enabled. |
| 2865 { | 2844 { |
| 2866 TestDelegate d; | 2845 TestDelegate d; |
| 2867 scoped_ptr<URLRequest> req(context.CreateRequest( | 2846 scoped_ptr<URLRequest> req( |
| 2868 test_server.GetURL("set-cookie?$Secure-foo=1"), DEFAULT_PRIORITY, &d)); | 2847 context.CreateRequest(https_server.GetURL("/set-cookie?$Secure-foo=1"), |
| 2848 DEFAULT_PRIORITY, &d)); |
| 2869 req->Start(); | 2849 req->Start(); |
| 2870 base::RunLoop().Run(); | 2850 base::RunLoop().Run(); |
| 2871 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2851 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2872 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2852 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2873 } | 2853 } |
| 2874 | 2854 |
| 2875 // Verify that the cookie is not set. | 2855 // Verify that the cookie is not set. |
| 2876 { | 2856 { |
| 2877 TestDelegate d; | 2857 TestDelegate d; |
| 2878 scoped_ptr<URLRequest> req(context.CreateRequest( | 2858 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2879 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2859 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2880 req->Start(); | 2860 req->Start(); |
| 2881 base::RunLoop().Run(); | 2861 base::RunLoop().Run(); |
| 2882 | 2862 |
| 2883 EXPECT_TRUE(d.data_received().find("$Secure-foo=1") == std::string::npos); | 2863 EXPECT_TRUE(d.data_received().find("$Secure-foo=1") == std::string::npos); |
| 2884 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2864 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2885 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2865 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2886 } | 2866 } |
| 2887 } | 2867 } |
| 2888 | 2868 |
| 2889 TEST_F(URLRequestTest, SecureCookiePrefixExperimentalSecure) { | 2869 TEST_F(URLRequestTest, SecureCookiePrefixExperimentalSecure) { |
| 2890 SpawnedTestServer test_server( | 2870 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); |
| 2891 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | 2871 https_server.AddDefaultHandlers( |
| 2892 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 2872 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 2893 ASSERT_TRUE(test_server.Start()); | 2873 ASSERT_TRUE(https_server.Start()); |
| 2894 | 2874 |
| 2895 TestExperimentalFeaturesNetworkDelegate network_delegate; | 2875 TestExperimentalFeaturesNetworkDelegate network_delegate; |
| 2896 TestURLRequestContext context(true); | 2876 TestURLRequestContext context(true); |
| 2897 context.set_network_delegate(&network_delegate); | 2877 context.set_network_delegate(&network_delegate); |
| 2898 context.Init(); | 2878 context.Init(); |
| 2899 | 2879 |
| 2900 // Try to set a Secure $Secure- cookie, with experimental features | 2880 // Try to set a Secure $Secure- cookie, with experimental features |
| 2901 // enabled. | 2881 // enabled. |
| 2902 { | 2882 { |
| 2903 TestDelegate d; | 2883 TestDelegate d; |
| 2904 scoped_ptr<URLRequest> req(context.CreateRequest( | 2884 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2905 test_server.GetURL("set-cookie?$Secure-bar=1;Secure"), DEFAULT_PRIORITY, | 2885 https_server.GetURL("/set-cookie?$Secure-bar=1;Secure"), |
| 2906 &d)); | 2886 DEFAULT_PRIORITY, &d)); |
| 2907 req->Start(); | 2887 req->Start(); |
| 2908 base::RunLoop().Run(); | 2888 base::RunLoop().Run(); |
| 2909 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2889 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2910 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2890 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2911 } | 2891 } |
| 2912 | 2892 |
| 2913 // Verify that the cookie is set. | 2893 // Verify that the cookie is set. |
| 2914 { | 2894 { |
| 2915 TestDelegate d; | 2895 TestDelegate d; |
| 2916 scoped_ptr<URLRequest> req(context.CreateRequest( | 2896 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2917 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2897 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2918 req->Start(); | 2898 req->Start(); |
| 2919 base::RunLoop().Run(); | 2899 base::RunLoop().Run(); |
| 2920 | 2900 |
| 2921 EXPECT_TRUE(d.data_received().find("$Secure-bar=1") != std::string::npos); | 2901 EXPECT_TRUE(d.data_received().find("$Secure-bar=1") != std::string::npos); |
| 2922 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2902 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2923 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2903 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2924 } | 2904 } |
| 2925 } | 2905 } |
| 2926 | 2906 |
| 2927 // Tests that a request is cancelled while entering suspend mode. Uses mocks | 2907 // Tests that a request is cancelled while entering suspend mode. Uses mocks |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3002 LocalHttpTestServer test_server; | 2982 LocalHttpTestServer test_server; |
| 3003 ASSERT_TRUE(test_server.Start()); | 2983 ASSERT_TRUE(test_server.Start()); |
| 3004 | 2984 |
| 3005 // Set up an expired cookie. | 2985 // Set up an expired cookie. |
| 3006 { | 2986 { |
| 3007 TestNetworkDelegate network_delegate; | 2987 TestNetworkDelegate network_delegate; |
| 3008 default_context_.set_network_delegate(&network_delegate); | 2988 default_context_.set_network_delegate(&network_delegate); |
| 3009 TestDelegate d; | 2989 TestDelegate d; |
| 3010 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2990 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3011 test_server.GetURL( | 2991 test_server.GetURL( |
| 3012 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 2992 "/set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), |
| 3013 DEFAULT_PRIORITY, &d)); | 2993 DEFAULT_PRIORITY, &d)); |
| 3014 req->Start(); | 2994 req->Start(); |
| 3015 base::RunLoop().Run(); | 2995 base::RunLoop().Run(); |
| 3016 } | 2996 } |
| 3017 // Verify that the cookie is not set. | 2997 // Verify that the cookie is not set. |
| 3018 { | 2998 { |
| 3019 TestNetworkDelegate network_delegate; | 2999 TestNetworkDelegate network_delegate; |
| 3020 default_context_.set_network_delegate(&network_delegate); | 3000 default_context_.set_network_delegate(&network_delegate); |
| 3021 TestDelegate d; | 3001 TestDelegate d; |
| 3022 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 3002 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3023 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 3003 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 3024 req->Start(); | 3004 req->Start(); |
| 3025 base::RunLoop().Run(); | 3005 base::RunLoop().Run(); |
| 3026 | 3006 |
| 3027 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); | 3007 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); |
| 3028 } | 3008 } |
| 3029 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. | 3009 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. |
| 3030 { | 3010 { |
| 3031 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); | 3011 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); |
| 3032 default_context_.set_network_delegate(&network_delegate); | 3012 default_context_.set_network_delegate(&network_delegate); |
| 3033 TestDelegate d; | 3013 TestDelegate d; |
| 3034 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 3014 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3035 test_server.GetURL( | 3015 test_server.GetURL( |
| 3036 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 3016 "/set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), |
| 3037 DEFAULT_PRIORITY, &d)); | 3017 DEFAULT_PRIORITY, &d)); |
| 3038 req->Start(); | 3018 req->Start(); |
| 3039 base::RunLoop().Run(); | 3019 base::RunLoop().Run(); |
| 3040 } | 3020 } |
| 3041 // Verify that the cookie is set. | 3021 // Verify that the cookie is set. |
| 3042 { | 3022 { |
| 3043 TestNetworkDelegate network_delegate; | 3023 TestNetworkDelegate network_delegate; |
| 3044 default_context_.set_network_delegate(&network_delegate); | 3024 default_context_.set_network_delegate(&network_delegate); |
| 3045 TestDelegate d; | 3025 TestDelegate d; |
| 3046 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 3026 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3047 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 3027 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 3048 req->Start(); | 3028 req->Start(); |
| 3049 base::RunLoop().Run(); | 3029 base::RunLoop().Run(); |
| 3050 | 3030 |
| 3051 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); | 3031 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); |
| 3052 } | 3032 } |
| 3053 } | 3033 } |
| 3054 | 3034 |
| 3055 | 3035 |
| 3056 // Check that it is impossible to change the referrer in the extra headers of | 3036 // Check that it is impossible to change the referrer in the extra headers of |
| 3057 // an URLRequest. | 3037 // an URLRequest. |
| 3058 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 3038 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
| 3059 LocalHttpTestServer test_server; | 3039 LocalHttpTestServer test_server; |
| 3060 ASSERT_TRUE(test_server.Start()); | 3040 ASSERT_TRUE(test_server.Start()); |
| 3061 | 3041 |
| 3062 // If extra headers contain referer and the request contains a referer, | 3042 // If extra headers contain referer and the request contains a referer, |
| 3063 // only the latter shall be respected. | 3043 // only the latter shall be respected. |
| 3064 { | 3044 { |
| 3065 TestDelegate d; | 3045 TestDelegate d; |
| 3066 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 3046 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3067 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 3047 test_server.GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); |
| 3068 req->SetReferrer("http://foo.com/"); | 3048 req->SetReferrer("http://foo.com/"); |
| 3069 | 3049 |
| 3070 HttpRequestHeaders headers; | 3050 HttpRequestHeaders headers; |
| 3071 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 3051 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 3072 req->SetExtraRequestHeaders(headers); | 3052 req->SetExtraRequestHeaders(headers); |
| 3073 | 3053 |
| 3074 req->Start(); | 3054 req->Start(); |
| 3075 base::RunLoop().Run(); | 3055 base::RunLoop().Run(); |
| 3076 | 3056 |
| 3077 EXPECT_EQ("http://foo.com/", d.data_received()); | 3057 EXPECT_EQ("http://foo.com/", d.data_received()); |
| 3078 } | 3058 } |
| 3079 | 3059 |
| 3080 // If extra headers contain a referer but the request does not, no referer | 3060 // If extra headers contain a referer but the request does not, no referer |
| 3081 // shall be sent in the header. | 3061 // shall be sent in the header. |
| 3082 { | 3062 { |
| 3083 TestDelegate d; | 3063 TestDelegate d; |
| 3084 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 3064 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3085 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 3065 test_server.GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); |
| 3086 | 3066 |
| 3087 HttpRequestHeaders headers; | 3067 HttpRequestHeaders headers; |
| 3088 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 3068 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 3089 req->SetExtraRequestHeaders(headers); | 3069 req->SetExtraRequestHeaders(headers); |
| 3090 req->SetLoadFlags(LOAD_VALIDATE_CACHE); | 3070 req->SetLoadFlags(LOAD_VALIDATE_CACHE); |
| 3091 | 3071 |
| 3092 req->Start(); | 3072 req->Start(); |
| 3093 base::RunLoop().Run(); | 3073 base::RunLoop().Run(); |
| 3094 | 3074 |
| 3095 EXPECT_EQ("None", d.data_received()); | 3075 EXPECT_EQ("None", d.data_received()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3201 *ptr++ = marker; | 3181 *ptr++ = marker; |
| 3202 if (++marker > 'z') | 3182 if (++marker > 'z') |
| 3203 marker = 'a'; | 3183 marker = 'a'; |
| 3204 } | 3184 } |
| 3205 } | 3185 } |
| 3206 uploadBytes[kMsgSize] = '\0'; | 3186 uploadBytes[kMsgSize] = '\0'; |
| 3207 | 3187 |
| 3208 for (int i = 0; i < kIterations; ++i) { | 3188 for (int i = 0; i < kIterations; ++i) { |
| 3209 TestDelegate d; | 3189 TestDelegate d; |
| 3210 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 3190 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3211 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d)); | 3191 test_server_.GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 3212 r->set_method(method.c_str()); | 3192 r->set_method(method.c_str()); |
| 3213 | 3193 |
| 3214 r->set_upload(CreateSimpleUploadData(uploadBytes)); | 3194 r->set_upload(CreateSimpleUploadData(uploadBytes)); |
| 3215 | 3195 |
| 3216 r->Start(); | 3196 r->Start(); |
| 3217 EXPECT_TRUE(r->is_pending()); | 3197 EXPECT_TRUE(r->is_pending()); |
| 3218 | 3198 |
| 3219 base::RunLoop().Run(); | 3199 base::RunLoop().Run(); |
| 3220 | 3200 |
| 3221 ASSERT_EQ(1, d.response_started_count()) | 3201 ASSERT_EQ(1, d.response_started_count()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3248 | 3228 |
| 3249 EXPECT_FALSE(d->received_data_before_response()); | 3229 EXPECT_FALSE(d->received_data_before_response()); |
| 3250 | 3230 |
| 3251 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); | 3231 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); |
| 3252 EXPECT_EQ(expected_data, d->data_received()); | 3232 EXPECT_EQ(expected_data, d->data_received()); |
| 3253 } | 3233 } |
| 3254 | 3234 |
| 3255 bool DoManyCookiesRequest(int num_cookies) { | 3235 bool DoManyCookiesRequest(int num_cookies) { |
| 3256 TestDelegate d; | 3236 TestDelegate d; |
| 3257 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 3237 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3258 test_server_.GetURL("set-many-cookies?" + | 3238 test_server_.GetURL("/set-many-cookies?" + |
| 3259 base::IntToString(num_cookies)), | 3239 base::IntToString(num_cookies)), |
| 3260 DEFAULT_PRIORITY, &d)); | 3240 DEFAULT_PRIORITY, &d)); |
| 3261 | 3241 |
| 3262 r->Start(); | 3242 r->Start(); |
| 3263 EXPECT_TRUE(r->is_pending()); | 3243 EXPECT_TRUE(r->is_pending()); |
| 3264 | 3244 |
| 3265 base::RunLoop().Run(); | 3245 base::RunLoop().Run(); |
| 3266 | 3246 |
| 3267 bool is_success = r->status().is_success(); | 3247 bool is_success = r->status().is_success(); |
| 3268 | 3248 |
| 3269 if (!is_success) { | 3249 if (!is_success) |
| 3270 EXPECT_TRUE(r->status().error() == ERR_RESPONSE_HEADERS_TOO_BIG); | 3250 EXPECT_TRUE(r->status().error() == ERR_RESPONSE_HEADERS_TOO_BIG); |
| 3271 // The test server appears to be unable to handle subsequent requests | |
| 3272 // after this error is triggered. Force it to restart. | |
| 3273 EXPECT_TRUE(test_server_.Stop()); | |
| 3274 EXPECT_TRUE(test_server_.Start()); | |
| 3275 } | |
| 3276 | 3251 |
| 3277 return is_success; | 3252 return is_success; |
| 3278 } | 3253 } |
| 3279 | 3254 |
| 3280 LocalHttpTestServer* test_server() { | 3255 LocalHttpTestServer* http_test_server() { return &test_server_; } |
| 3281 return &test_server_; | |
| 3282 } | |
| 3283 | 3256 |
| 3284 protected: | 3257 private: |
| 3285 LocalHttpTestServer test_server_; | 3258 LocalHttpTestServer test_server_; |
| 3286 }; | 3259 }; |
| 3287 | 3260 |
| 3288 // In this unit test, we're using the HTTPTestServer as a proxy server and | 3261 namespace { |
| 3262 |
| 3263 scoped_ptr<test_server::HttpResponse> HandleRedirectConnect( |
| 3264 const test_server::HttpRequest& request) { |
| 3265 if (request.headers.find("Host") == request.headers.end() || |
| 3266 request.headers.at("Host") != "www.redirect.com" || |
| 3267 request.method != test_server::METHOD_CONNECT) { |
| 3268 return nullptr; |
| 3269 } |
| 3270 |
| 3271 scoped_ptr<test_server::BasicHttpResponse> http_response( |
| 3272 new test_server::BasicHttpResponse); |
| 3273 http_response->set_code(HTTP_FOUND); |
| 3274 http_response->AddCustomHeader("Location", |
| 3275 "http://www.destination.com/foo.js"); |
| 3276 return http_response.Pass(); |
| 3277 } |
| 3278 |
| 3279 } // namespace |
| 3280 |
| 3281 // In this unit test, we're using the EmbeddedTestServer as a proxy server and |
| 3289 // issuing a CONNECT request with the magic host name "www.redirect.com". | 3282 // issuing a CONNECT request with the magic host name "www.redirect.com". |
| 3290 // The HTTPTestServer will return a 302 response, which we should not | 3283 // The EmbeddedTestServer will return a 302 response, which we should not |
| 3291 // follow. | 3284 // follow. |
| 3292 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 3285 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
| 3293 ASSERT_TRUE(test_server_.Start()); | 3286 http_test_server()->RegisterRequestHandler( |
| 3287 base::Bind(&HandleRedirectConnect)); |
| 3288 ASSERT_TRUE(http_test_server()->Start()); |
| 3294 | 3289 |
| 3295 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3290 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 3296 TestURLRequestContextWithProxy context( | 3291 TestURLRequestContextWithProxy context( |
| 3297 test_server_.host_port_pair().ToString(), &network_delegate); | 3292 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3298 | 3293 |
| 3299 TestDelegate d; | 3294 TestDelegate d; |
| 3300 { | 3295 { |
| 3301 scoped_ptr<URLRequest> r(context.CreateRequest( | 3296 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3302 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); | 3297 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); |
| 3303 r->Start(); | 3298 r->Start(); |
| 3304 EXPECT_TRUE(r->is_pending()); | 3299 EXPECT_TRUE(r->is_pending()); |
| 3305 | 3300 |
| 3306 base::RunLoop().Run(); | 3301 base::RunLoop().Run(); |
| 3307 | 3302 |
| 3308 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 3303 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 3309 // The proxy server is not set before failure. | 3304 // The proxy server is not set before failure. |
| 3310 EXPECT_TRUE(r->proxy_server().IsEmpty()); | 3305 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
| 3311 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); | 3306 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); |
| 3312 EXPECT_EQ(1, d.response_started_count()); | 3307 EXPECT_EQ(1, d.response_started_count()); |
| 3313 // We should not have followed the redirect. | 3308 // We should not have followed the redirect. |
| 3314 EXPECT_EQ(0, d.received_redirect_count()); | 3309 EXPECT_EQ(0, d.received_redirect_count()); |
| 3315 } | 3310 } |
| 3316 } | 3311 } |
| 3317 | 3312 |
| 3318 // This is the same as the previous test, but checks that the network delegate | 3313 // This is the same as the previous test, but checks that the network delegate |
| 3319 // registers the error. | 3314 // registers the error. |
| 3320 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { | 3315 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { |
| 3321 ASSERT_TRUE(test_server_.Start()); | 3316 ASSERT_TRUE(http_test_server()->Start()); |
| 3322 | 3317 |
| 3323 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3318 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 3324 TestURLRequestContextWithProxy context( | 3319 TestURLRequestContextWithProxy context( |
| 3325 test_server_.host_port_pair().ToString(), &network_delegate); | 3320 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3326 | 3321 |
| 3327 TestDelegate d; | 3322 TestDelegate d; |
| 3328 { | 3323 { |
| 3329 scoped_ptr<URLRequest> r(context.CreateRequest( | 3324 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3330 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); | 3325 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); |
| 3331 r->Start(); | 3326 r->Start(); |
| 3332 EXPECT_TRUE(r->is_pending()); | 3327 EXPECT_TRUE(r->is_pending()); |
| 3333 | 3328 |
| 3334 base::RunLoop().Run(); | 3329 base::RunLoop().Run(); |
| 3335 | 3330 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3348 | 3343 |
| 3349 // Tests that we can block and asynchronously return OK in various stages. | 3344 // Tests that we can block and asynchronously return OK in various stages. |
| 3350 TEST_F(URLRequestTestHTTP, NetworkDelegateBlockAsynchronously) { | 3345 TEST_F(URLRequestTestHTTP, NetworkDelegateBlockAsynchronously) { |
| 3351 static const BlockingNetworkDelegate::Stage blocking_stages[] = { | 3346 static const BlockingNetworkDelegate::Stage blocking_stages[] = { |
| 3352 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | 3347 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 3353 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | 3348 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 3354 BlockingNetworkDelegate::ON_HEADERS_RECEIVED | 3349 BlockingNetworkDelegate::ON_HEADERS_RECEIVED |
| 3355 }; | 3350 }; |
| 3356 static const size_t blocking_stages_length = arraysize(blocking_stages); | 3351 static const size_t blocking_stages_length = arraysize(blocking_stages); |
| 3357 | 3352 |
| 3358 ASSERT_TRUE(test_server_.Start()); | 3353 ASSERT_TRUE(http_test_server()->Start()); |
| 3359 | 3354 |
| 3360 TestDelegate d; | 3355 TestDelegate d; |
| 3361 BlockingNetworkDelegate network_delegate( | 3356 BlockingNetworkDelegate network_delegate( |
| 3362 BlockingNetworkDelegate::USER_CALLBACK); | 3357 BlockingNetworkDelegate::USER_CALLBACK); |
| 3363 network_delegate.set_block_on( | 3358 network_delegate.set_block_on( |
| 3364 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | | 3359 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | |
| 3365 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | | 3360 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | |
| 3366 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 3361 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 3367 | 3362 |
| 3368 TestURLRequestContext context(true); | 3363 TestURLRequestContext context(true); |
| 3369 context.set_network_delegate(&network_delegate); | 3364 context.set_network_delegate(&network_delegate); |
| 3370 context.Init(); | 3365 context.Init(); |
| 3371 | 3366 |
| 3372 { | 3367 { |
| 3373 scoped_ptr<URLRequest> r(context.CreateRequest( | 3368 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3374 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d)); | 3369 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 3375 | 3370 |
| 3376 r->Start(); | 3371 r->Start(); |
| 3377 for (size_t i = 0; i < blocking_stages_length; ++i) { | 3372 for (size_t i = 0; i < blocking_stages_length; ++i) { |
| 3378 base::RunLoop().Run(); | 3373 base::RunLoop().Run(); |
| 3379 EXPECT_EQ(blocking_stages[i], | 3374 EXPECT_EQ(blocking_stages[i], |
| 3380 network_delegate.stage_blocked_for_callback()); | 3375 network_delegate.stage_blocked_for_callback()); |
| 3381 network_delegate.DoCallback(OK); | 3376 network_delegate.DoCallback(OK); |
| 3382 } | 3377 } |
| 3383 base::RunLoop().Run(); | 3378 base::RunLoop().Run(); |
| 3384 EXPECT_EQ(200, r->GetResponseCode()); | 3379 EXPECT_EQ(200, r->GetResponseCode()); |
| 3385 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3380 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3386 EXPECT_EQ(1, network_delegate.created_requests()); | 3381 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3387 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3382 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3388 } | 3383 } |
| 3389 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3384 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3390 } | 3385 } |
| 3391 | 3386 |
| 3392 // Tests that the network delegate can block and cancel a request. | 3387 // Tests that the network delegate can block and cancel a request. |
| 3393 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { | 3388 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { |
| 3394 ASSERT_TRUE(test_server_.Start()); | 3389 ASSERT_TRUE(http_test_server()->Start()); |
| 3395 | 3390 |
| 3396 TestDelegate d; | 3391 TestDelegate d; |
| 3397 BlockingNetworkDelegate network_delegate( | 3392 BlockingNetworkDelegate network_delegate( |
| 3398 BlockingNetworkDelegate::AUTO_CALLBACK); | 3393 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3399 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3394 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3400 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 3395 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
| 3401 | 3396 |
| 3402 TestURLRequestContextWithProxy context( | 3397 TestURLRequestContextWithProxy context( |
| 3403 test_server_.host_port_pair().ToString(), &network_delegate); | 3398 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3404 | 3399 |
| 3405 { | 3400 { |
| 3406 scoped_ptr<URLRequest> r(context.CreateRequest( | 3401 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3407 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 3402 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 3408 | 3403 |
| 3409 r->Start(); | 3404 r->Start(); |
| 3410 base::RunLoop().Run(); | 3405 base::RunLoop().Run(); |
| 3411 | 3406 |
| 3412 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 3407 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 3413 // The proxy server is not set before cancellation. | 3408 // The proxy server is not set before cancellation. |
| 3414 EXPECT_TRUE(r->proxy_server().IsEmpty()); | 3409 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
| 3415 EXPECT_EQ(ERR_EMPTY_RESPONSE, r->status().error()); | 3410 EXPECT_EQ(ERR_EMPTY_RESPONSE, r->status().error()); |
| 3416 EXPECT_EQ(1, network_delegate.created_requests()); | 3411 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3417 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3412 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3447 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r->status().error()); | 3442 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r->status().error()); |
| 3448 EXPECT_EQ(1, network_delegate.created_requests()); | 3443 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3449 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3444 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3450 } | 3445 } |
| 3451 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3446 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3452 } | 3447 } |
| 3453 | 3448 |
| 3454 // The following 3 tests check that the network delegate can cancel a request | 3449 // The following 3 tests check that the network delegate can cancel a request |
| 3455 // synchronously in various stages of the request. | 3450 // synchronously in various stages of the request. |
| 3456 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { | 3451 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { |
| 3457 ASSERT_TRUE(test_server_.Start()); | 3452 ASSERT_TRUE(http_test_server()->Start()); |
| 3458 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, | 3453 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, |
| 3459 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | 3454 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 3460 test_server_.GetURL(std::string())); | 3455 http_test_server()->GetURL("/")); |
| 3461 } | 3456 } |
| 3462 | 3457 |
| 3463 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously2) { | 3458 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously2) { |
| 3464 ASSERT_TRUE(test_server_.Start()); | 3459 ASSERT_TRUE(http_test_server()->Start()); |
| 3465 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, | 3460 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, |
| 3466 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | 3461 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 3467 test_server_.GetURL(std::string())); | 3462 http_test_server()->GetURL("/")); |
| 3468 } | 3463 } |
| 3469 | 3464 |
| 3470 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously3) { | 3465 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously3) { |
| 3471 ASSERT_TRUE(test_server_.Start()); | 3466 ASSERT_TRUE(http_test_server()->Start()); |
| 3472 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, | 3467 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, |
| 3473 BlockingNetworkDelegate::ON_HEADERS_RECEIVED, | 3468 BlockingNetworkDelegate::ON_HEADERS_RECEIVED, |
| 3474 test_server_.GetURL(std::string())); | 3469 http_test_server()->GetURL("/")); |
| 3475 } | 3470 } |
| 3476 | 3471 |
| 3477 // The following 3 tests check that the network delegate can cancel a request | 3472 // The following 3 tests check that the network delegate can cancel a request |
| 3478 // asynchronously in various stages of the request. | 3473 // asynchronously in various stages of the request. |
| 3479 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously1) { | 3474 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously1) { |
| 3480 ASSERT_TRUE(test_server_.Start()); | 3475 ASSERT_TRUE(http_test_server()->Start()); |
| 3481 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, | 3476 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, |
| 3482 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | 3477 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 3483 test_server_.GetURL(std::string())); | 3478 http_test_server()->GetURL("/")); |
| 3484 } | 3479 } |
| 3485 | 3480 |
| 3486 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously2) { | 3481 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously2) { |
| 3487 ASSERT_TRUE(test_server_.Start()); | 3482 ASSERT_TRUE(http_test_server()->Start()); |
| 3488 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, | 3483 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, |
| 3489 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | 3484 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 3490 test_server_.GetURL(std::string())); | 3485 http_test_server()->GetURL("/")); |
| 3491 } | 3486 } |
| 3492 | 3487 |
| 3493 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously3) { | 3488 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously3) { |
| 3494 ASSERT_TRUE(test_server_.Start()); | 3489 ASSERT_TRUE(http_test_server()->Start()); |
| 3495 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, | 3490 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, |
| 3496 BlockingNetworkDelegate::ON_HEADERS_RECEIVED, | 3491 BlockingNetworkDelegate::ON_HEADERS_RECEIVED, |
| 3497 test_server_.GetURL(std::string())); | 3492 http_test_server()->GetURL("/")); |
| 3498 } | 3493 } |
| 3499 | 3494 |
| 3500 // Tests that the network delegate can block and redirect a request to a new | 3495 // Tests that the network delegate can block and redirect a request to a new |
| 3501 // URL. | 3496 // URL. |
| 3502 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { | 3497 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { |
| 3503 ASSERT_TRUE(test_server_.Start()); | 3498 ASSERT_TRUE(http_test_server()->Start()); |
| 3504 | 3499 |
| 3505 TestDelegate d; | 3500 TestDelegate d; |
| 3506 BlockingNetworkDelegate network_delegate( | 3501 BlockingNetworkDelegate network_delegate( |
| 3507 BlockingNetworkDelegate::AUTO_CALLBACK); | 3502 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3508 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3503 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3509 GURL redirect_url(test_server_.GetURL("simple.html")); | 3504 GURL redirect_url(http_test_server()->GetURL("/simple.html")); |
| 3510 network_delegate.set_redirect_url(redirect_url); | 3505 network_delegate.set_redirect_url(redirect_url); |
| 3511 | 3506 |
| 3512 TestURLRequestContextWithProxy context( | 3507 TestURLRequestContextWithProxy context( |
| 3513 test_server_.host_port_pair().ToString(), &network_delegate); | 3508 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3514 | 3509 |
| 3515 { | 3510 { |
| 3516 GURL original_url(test_server_.GetURL("empty.html")); | 3511 GURL original_url(http_test_server()->GetURL("/defaultresponse")); |
| 3517 scoped_ptr<URLRequest> r( | 3512 scoped_ptr<URLRequest> r( |
| 3518 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 3513 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 3519 | 3514 |
| 3520 // Quit after hitting the redirect, so can check the headers. | 3515 // Quit after hitting the redirect, so can check the headers. |
| 3521 d.set_quit_on_redirect(true); | 3516 d.set_quit_on_redirect(true); |
| 3522 r->Start(); | 3517 r->Start(); |
| 3523 base::RunLoop().Run(); | 3518 base::RunLoop().Run(); |
| 3524 | 3519 |
| 3525 // Check headers from URLRequestJob. | 3520 // Check headers from URLRequestJob. |
| 3526 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3521 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3527 EXPECT_EQ(307, r->GetResponseCode()); | 3522 EXPECT_EQ(307, r->GetResponseCode()); |
| 3528 EXPECT_EQ(307, r->response_headers()->response_code()); | 3523 EXPECT_EQ(307, r->response_headers()->response_code()); |
| 3529 std::string location; | 3524 std::string location; |
| 3530 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", | 3525 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", |
| 3531 &location)); | 3526 &location)); |
| 3532 EXPECT_EQ(redirect_url, GURL(location)); | 3527 EXPECT_EQ(redirect_url, GURL(location)); |
| 3533 | 3528 |
| 3534 // Let the request finish. | 3529 // Let the request finish. |
| 3535 r->FollowDeferredRedirect(); | 3530 r->FollowDeferredRedirect(); |
| 3536 base::RunLoop().Run(); | 3531 base::RunLoop().Run(); |
| 3537 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3532 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3538 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair())); | 3533 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); |
| 3539 EXPECT_EQ( | 3534 EXPECT_EQ( |
| 3540 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); | 3535 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); |
| 3541 EXPECT_TRUE( | 3536 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( |
| 3542 network_delegate.last_observed_proxy().Equals( | 3537 http_test_server()->host_port_pair())); |
| 3543 test_server_.host_port_pair())); | |
| 3544 | 3538 |
| 3545 EXPECT_EQ(0, r->status().error()); | 3539 EXPECT_EQ(0, r->status().error()); |
| 3546 EXPECT_EQ(redirect_url, r->url()); | 3540 EXPECT_EQ(redirect_url, r->url()); |
| 3547 EXPECT_EQ(original_url, r->original_url()); | 3541 EXPECT_EQ(original_url, r->original_url()); |
| 3548 EXPECT_EQ(2U, r->url_chain().size()); | 3542 EXPECT_EQ(2U, r->url_chain().size()); |
| 3549 EXPECT_EQ(1, network_delegate.created_requests()); | 3543 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3550 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3544 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3551 } | 3545 } |
| 3552 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3546 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3553 } | 3547 } |
| 3554 | 3548 |
| 3555 // Tests that the network delegate can block and redirect a request to a new | 3549 // Tests that the network delegate can block and redirect a request to a new |
| 3556 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. | 3550 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. |
| 3557 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { | 3551 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { |
| 3558 ASSERT_TRUE(test_server_.Start()); | 3552 ASSERT_TRUE(http_test_server()->Start()); |
| 3559 | 3553 |
| 3560 TestDelegate d; | 3554 TestDelegate d; |
| 3561 BlockingNetworkDelegate network_delegate( | 3555 BlockingNetworkDelegate network_delegate( |
| 3562 BlockingNetworkDelegate::SYNCHRONOUS); | 3556 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3563 GURL redirect_url(test_server_.GetURL("simple.html")); | 3557 GURL redirect_url(http_test_server()->GetURL("/simple.html")); |
| 3564 network_delegate.set_redirect_url(redirect_url); | 3558 network_delegate.set_redirect_url(redirect_url); |
| 3565 | 3559 |
| 3566 TestURLRequestContextWithProxy context( | 3560 TestURLRequestContextWithProxy context( |
| 3567 test_server_.host_port_pair().ToString(), &network_delegate); | 3561 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3568 | 3562 |
| 3569 { | 3563 { |
| 3570 GURL original_url(test_server_.GetURL("empty.html")); | 3564 GURL original_url(http_test_server()->GetURL("/defaultresponse")); |
| 3571 scoped_ptr<URLRequest> r( | 3565 scoped_ptr<URLRequest> r( |
| 3572 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 3566 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 3573 | 3567 |
| 3574 // Quit after hitting the redirect, so can check the headers. | 3568 // Quit after hitting the redirect, so can check the headers. |
| 3575 d.set_quit_on_redirect(true); | 3569 d.set_quit_on_redirect(true); |
| 3576 r->Start(); | 3570 r->Start(); |
| 3577 base::RunLoop().Run(); | 3571 base::RunLoop().Run(); |
| 3578 | 3572 |
| 3579 // Check headers from URLRequestJob. | 3573 // Check headers from URLRequestJob. |
| 3580 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3574 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3581 EXPECT_EQ(307, r->GetResponseCode()); | 3575 EXPECT_EQ(307, r->GetResponseCode()); |
| 3582 EXPECT_EQ(307, r->response_headers()->response_code()); | 3576 EXPECT_EQ(307, r->response_headers()->response_code()); |
| 3583 std::string location; | 3577 std::string location; |
| 3584 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", | 3578 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", |
| 3585 &location)); | 3579 &location)); |
| 3586 EXPECT_EQ(redirect_url, GURL(location)); | 3580 EXPECT_EQ(redirect_url, GURL(location)); |
| 3587 | 3581 |
| 3588 // Let the request finish. | 3582 // Let the request finish. |
| 3589 r->FollowDeferredRedirect(); | 3583 r->FollowDeferredRedirect(); |
| 3590 base::RunLoop().Run(); | 3584 base::RunLoop().Run(); |
| 3591 | 3585 |
| 3592 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3586 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3593 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair())); | 3587 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); |
| 3594 EXPECT_EQ( | 3588 EXPECT_EQ( |
| 3595 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); | 3589 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); |
| 3596 EXPECT_TRUE( | 3590 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( |
| 3597 network_delegate.last_observed_proxy().Equals( | 3591 http_test_server()->host_port_pair())); |
| 3598 test_server_.host_port_pair())); | |
| 3599 EXPECT_EQ(0, r->status().error()); | 3592 EXPECT_EQ(0, r->status().error()); |
| 3600 EXPECT_EQ(redirect_url, r->url()); | 3593 EXPECT_EQ(redirect_url, r->url()); |
| 3601 EXPECT_EQ(original_url, r->original_url()); | 3594 EXPECT_EQ(original_url, r->original_url()); |
| 3602 EXPECT_EQ(2U, r->url_chain().size()); | 3595 EXPECT_EQ(2U, r->url_chain().size()); |
| 3603 EXPECT_EQ(1, network_delegate.created_requests()); | 3596 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3604 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3597 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3605 } | 3598 } |
| 3606 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3599 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3607 } | 3600 } |
| 3608 | 3601 |
| 3609 // Tests that redirects caused by the network delegate preserve POST data. | 3602 // Tests that redirects caused by the network delegate preserve POST data. |
| 3610 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) { | 3603 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) { |
| 3611 ASSERT_TRUE(test_server_.Start()); | 3604 ASSERT_TRUE(http_test_server()->Start()); |
| 3612 | 3605 |
| 3613 const char kData[] = "hello world"; | 3606 const char kData[] = "hello world"; |
| 3614 | 3607 |
| 3615 TestDelegate d; | 3608 TestDelegate d; |
| 3616 BlockingNetworkDelegate network_delegate( | 3609 BlockingNetworkDelegate network_delegate( |
| 3617 BlockingNetworkDelegate::AUTO_CALLBACK); | 3610 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3618 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3611 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3619 GURL redirect_url(test_server_.GetURL("echo")); | 3612 GURL redirect_url(http_test_server()->GetURL("/echo")); |
| 3620 network_delegate.set_redirect_url(redirect_url); | 3613 network_delegate.set_redirect_url(redirect_url); |
| 3621 | 3614 |
| 3622 TestURLRequestContext context(true); | 3615 TestURLRequestContext context(true); |
| 3623 context.set_network_delegate(&network_delegate); | 3616 context.set_network_delegate(&network_delegate); |
| 3624 context.Init(); | 3617 context.Init(); |
| 3625 | 3618 |
| 3626 { | 3619 { |
| 3627 GURL original_url(test_server_.GetURL("empty.html")); | 3620 GURL original_url(http_test_server()->GetURL("/defaultresponse")); |
| 3628 scoped_ptr<URLRequest> r( | 3621 scoped_ptr<URLRequest> r( |
| 3629 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 3622 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 3630 r->set_method("POST"); | 3623 r->set_method("POST"); |
| 3631 r->set_upload(CreateSimpleUploadData(kData)); | 3624 r->set_upload(CreateSimpleUploadData(kData)); |
| 3632 HttpRequestHeaders headers; | 3625 HttpRequestHeaders headers; |
| 3633 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3626 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 3634 base::SizeTToString(arraysize(kData) - 1)); | 3627 base::SizeTToString(arraysize(kData) - 1)); |
| 3635 r->SetExtraRequestHeaders(headers); | 3628 r->SetExtraRequestHeaders(headers); |
| 3636 | 3629 |
| 3637 // Quit after hitting the redirect, so can check the headers. | 3630 // Quit after hitting the redirect, so can check the headers. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3661 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3654 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3662 EXPECT_EQ("POST", r->method()); | 3655 EXPECT_EQ("POST", r->method()); |
| 3663 EXPECT_EQ(kData, d.data_received()); | 3656 EXPECT_EQ(kData, d.data_received()); |
| 3664 } | 3657 } |
| 3665 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3658 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3666 } | 3659 } |
| 3667 | 3660 |
| 3668 // Tests that the network delegate can block and redirect a request to a new | 3661 // Tests that the network delegate can block and redirect a request to a new |
| 3669 // URL during OnHeadersReceived. | 3662 // URL during OnHeadersReceived. |
| 3670 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestOnHeadersReceived) { | 3663 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestOnHeadersReceived) { |
| 3671 ASSERT_TRUE(test_server_.Start()); | 3664 ASSERT_TRUE(http_test_server()->Start()); |
| 3672 | 3665 |
| 3673 TestDelegate d; | 3666 TestDelegate d; |
| 3674 BlockingNetworkDelegate network_delegate( | 3667 BlockingNetworkDelegate network_delegate( |
| 3675 BlockingNetworkDelegate::AUTO_CALLBACK); | 3668 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3676 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 3669 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 3677 GURL redirect_url(test_server_.GetURL("simple.html")); | 3670 GURL redirect_url(http_test_server()->GetURL("/simple.html")); |
| 3678 network_delegate.set_redirect_on_headers_received_url(redirect_url); | 3671 network_delegate.set_redirect_on_headers_received_url(redirect_url); |
| 3679 | 3672 |
| 3680 TestURLRequestContextWithProxy context( | 3673 TestURLRequestContextWithProxy context( |
| 3681 test_server_.host_port_pair().ToString(), &network_delegate); | 3674 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3682 | 3675 |
| 3683 { | 3676 { |
| 3684 GURL original_url(test_server_.GetURL("empty.html")); | 3677 GURL original_url(http_test_server()->GetURL("/defaultresponse")); |
| 3685 scoped_ptr<URLRequest> r( | 3678 scoped_ptr<URLRequest> r( |
| 3686 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 3679 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 3687 | 3680 |
| 3688 r->Start(); | 3681 r->Start(); |
| 3689 base::RunLoop().Run(); | 3682 base::RunLoop().Run(); |
| 3690 | 3683 |
| 3691 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3684 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3692 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair())); | 3685 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); |
| 3693 EXPECT_EQ( | 3686 EXPECT_EQ( |
| 3694 2, network_delegate.observed_before_proxy_headers_sent_callbacks()); | 3687 2, network_delegate.observed_before_proxy_headers_sent_callbacks()); |
| 3695 EXPECT_TRUE( | 3688 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( |
| 3696 network_delegate.last_observed_proxy().Equals( | 3689 http_test_server()->host_port_pair())); |
| 3697 test_server_.host_port_pair())); | |
| 3698 | 3690 |
| 3699 EXPECT_EQ(OK, r->status().error()); | 3691 EXPECT_EQ(OK, r->status().error()); |
| 3700 EXPECT_EQ(redirect_url, r->url()); | 3692 EXPECT_EQ(redirect_url, r->url()); |
| 3701 EXPECT_EQ(original_url, r->original_url()); | 3693 EXPECT_EQ(original_url, r->original_url()); |
| 3702 EXPECT_EQ(2U, r->url_chain().size()); | 3694 EXPECT_EQ(2U, r->url_chain().size()); |
| 3703 EXPECT_EQ(2, network_delegate.created_requests()); | 3695 EXPECT_EQ(2, network_delegate.created_requests()); |
| 3704 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3696 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3705 } | 3697 } |
| 3706 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3698 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3707 } | 3699 } |
| 3708 | 3700 |
| 3709 // Tests that the network delegate can synchronously complete OnAuthRequired | 3701 // Tests that the network delegate can synchronously complete OnAuthRequired |
| 3710 // by taking no action. This indicates that the NetworkDelegate does not want to | 3702 // by taking no action. This indicates that the NetworkDelegate does not want to |
| 3711 // handle the challenge, and is passing the buck along to the | 3703 // handle the challenge, and is passing the buck along to the |
| 3712 // URLRequest::Delegate. | 3704 // URLRequest::Delegate. |
| 3713 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { | 3705 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { |
| 3714 ASSERT_TRUE(test_server_.Start()); | 3706 ASSERT_TRUE(http_test_server()->Start()); |
| 3715 | 3707 |
| 3716 TestDelegate d; | 3708 TestDelegate d; |
| 3717 BlockingNetworkDelegate network_delegate( | 3709 BlockingNetworkDelegate network_delegate( |
| 3718 BlockingNetworkDelegate::SYNCHRONOUS); | 3710 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3719 | 3711 |
| 3720 TestURLRequestContext context(true); | 3712 TestURLRequestContext context(true); |
| 3721 context.set_network_delegate(&network_delegate); | 3713 context.set_network_delegate(&network_delegate); |
| 3722 context.Init(); | 3714 context.Init(); |
| 3723 | 3715 |
| 3724 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3716 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 3725 | 3717 |
| 3726 { | 3718 { |
| 3727 GURL url(test_server_.GetURL("auth-basic")); | 3719 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 3728 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3720 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 3729 r->Start(); | 3721 r->Start(); |
| 3730 | 3722 |
| 3731 base::RunLoop().Run(); | 3723 base::RunLoop().Run(); |
| 3732 | 3724 |
| 3733 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3725 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3734 EXPECT_EQ(0, r->status().error()); | 3726 EXPECT_EQ(0, r->status().error()); |
| 3735 EXPECT_EQ(200, r->GetResponseCode()); | 3727 EXPECT_EQ(200, r->GetResponseCode()); |
| 3736 EXPECT_TRUE(d.auth_required_called()); | 3728 EXPECT_TRUE(d.auth_required_called()); |
| 3737 EXPECT_EQ(1, network_delegate.created_requests()); | 3729 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3738 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3730 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3739 } | 3731 } |
| 3740 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3732 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3741 } | 3733 } |
| 3742 | 3734 |
| 3743 TEST_F(URLRequestTestHTTP, | 3735 TEST_F(URLRequestTestHTTP, |
| 3744 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { | 3736 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { |
| 3745 ASSERT_TRUE(test_server_.Start()); | 3737 ASSERT_TRUE(http_test_server()->Start()); |
| 3746 | 3738 |
| 3747 TestDelegate d; | 3739 TestDelegate d; |
| 3748 BlockingNetworkDelegate network_delegate( | 3740 BlockingNetworkDelegate network_delegate( |
| 3749 BlockingNetworkDelegate::SYNCHRONOUS); | 3741 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3750 | 3742 |
| 3751 TestURLRequestContext context(true); | 3743 TestURLRequestContext context(true); |
| 3752 context.set_network_delegate(&network_delegate); | 3744 context.set_network_delegate(&network_delegate); |
| 3753 context.Init(); | 3745 context.Init(); |
| 3754 | 3746 |
| 3755 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3747 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 3756 | 3748 |
| 3757 { | 3749 { |
| 3758 GURL url(test_server_.GetURL("auth-basic")); | 3750 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 3759 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3751 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 3760 r->Start(); | 3752 r->Start(); |
| 3761 | 3753 |
| 3762 { | 3754 { |
| 3763 HttpRequestHeaders headers; | 3755 HttpRequestHeaders headers; |
| 3764 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); | 3756 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); |
| 3765 EXPECT_FALSE(headers.HasHeader("Authorization")); | 3757 EXPECT_FALSE(headers.HasHeader("Authorization")); |
| 3766 } | 3758 } |
| 3767 | 3759 |
| 3768 base::RunLoop().Run(); | 3760 base::RunLoop().Run(); |
| 3769 | 3761 |
| 3770 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3762 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3771 EXPECT_EQ(0, r->status().error()); | 3763 EXPECT_EQ(0, r->status().error()); |
| 3772 EXPECT_EQ(200, r->GetResponseCode()); | 3764 EXPECT_EQ(200, r->GetResponseCode()); |
| 3773 EXPECT_TRUE(d.auth_required_called()); | 3765 EXPECT_TRUE(d.auth_required_called()); |
| 3774 EXPECT_EQ(1, network_delegate.created_requests()); | 3766 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3775 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3767 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3776 } | 3768 } |
| 3777 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3769 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3778 } | 3770 } |
| 3779 | 3771 |
| 3780 // Tests that the network delegate can synchronously complete OnAuthRequired | 3772 // Tests that the network delegate can synchronously complete OnAuthRequired |
| 3781 // by setting credentials. | 3773 // by setting credentials. |
| 3782 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { | 3774 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { |
| 3783 ASSERT_TRUE(test_server_.Start()); | 3775 ASSERT_TRUE(http_test_server()->Start()); |
| 3784 | 3776 |
| 3785 TestDelegate d; | 3777 TestDelegate d; |
| 3786 BlockingNetworkDelegate network_delegate( | 3778 BlockingNetworkDelegate network_delegate( |
| 3787 BlockingNetworkDelegate::SYNCHRONOUS); | 3779 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3788 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3780 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3789 network_delegate.set_auth_retval( | 3781 network_delegate.set_auth_retval( |
| 3790 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 3782 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 3791 | 3783 |
| 3792 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 3784 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| 3793 | 3785 |
| 3794 TestURLRequestContext context(true); | 3786 TestURLRequestContext context(true); |
| 3795 context.set_network_delegate(&network_delegate); | 3787 context.set_network_delegate(&network_delegate); |
| 3796 context.Init(); | 3788 context.Init(); |
| 3797 | 3789 |
| 3798 { | 3790 { |
| 3799 GURL url(test_server_.GetURL("auth-basic")); | 3791 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 3800 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3792 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 3801 r->Start(); | 3793 r->Start(); |
| 3802 base::RunLoop().Run(); | 3794 base::RunLoop().Run(); |
| 3803 | 3795 |
| 3804 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3796 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3805 EXPECT_EQ(0, r->status().error()); | 3797 EXPECT_EQ(0, r->status().error()); |
| 3806 EXPECT_EQ(200, r->GetResponseCode()); | 3798 EXPECT_EQ(200, r->GetResponseCode()); |
| 3807 EXPECT_FALSE(d.auth_required_called()); | 3799 EXPECT_FALSE(d.auth_required_called()); |
| 3808 EXPECT_EQ(1, network_delegate.created_requests()); | 3800 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3809 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3801 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3810 } | 3802 } |
| 3811 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3803 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3812 } | 3804 } |
| 3813 | 3805 |
| 3814 // Same as above, but also tests that GetFullRequestHeaders returns the proper | 3806 // Same as above, but also tests that GetFullRequestHeaders returns the proper |
| 3815 // headers (for the first or second request) when called at the proper times. | 3807 // headers (for the first or second request) when called at the proper times. |
| 3816 TEST_F(URLRequestTestHTTP, | 3808 TEST_F(URLRequestTestHTTP, |
| 3817 NetworkDelegateOnAuthRequiredSyncSetAuth_GetFullRequestHeaders) { | 3809 NetworkDelegateOnAuthRequiredSyncSetAuth_GetFullRequestHeaders) { |
| 3818 ASSERT_TRUE(test_server_.Start()); | 3810 ASSERT_TRUE(http_test_server()->Start()); |
| 3819 | 3811 |
| 3820 TestDelegate d; | 3812 TestDelegate d; |
| 3821 BlockingNetworkDelegate network_delegate( | 3813 BlockingNetworkDelegate network_delegate( |
| 3822 BlockingNetworkDelegate::SYNCHRONOUS); | 3814 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3823 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3815 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3824 network_delegate.set_auth_retval( | 3816 network_delegate.set_auth_retval( |
| 3825 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 3817 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 3826 | 3818 |
| 3827 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 3819 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| 3828 | 3820 |
| 3829 TestURLRequestContext context(true); | 3821 TestURLRequestContext context(true); |
| 3830 context.set_network_delegate(&network_delegate); | 3822 context.set_network_delegate(&network_delegate); |
| 3831 context.Init(); | 3823 context.Init(); |
| 3832 | 3824 |
| 3833 { | 3825 { |
| 3834 GURL url(test_server_.GetURL("auth-basic")); | 3826 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 3835 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3827 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 3836 r->Start(); | 3828 r->Start(); |
| 3837 base::RunLoop().Run(); | 3829 base::RunLoop().Run(); |
| 3838 | 3830 |
| 3839 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3831 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3840 EXPECT_EQ(0, r->status().error()); | 3832 EXPECT_EQ(0, r->status().error()); |
| 3841 EXPECT_EQ(200, r->GetResponseCode()); | 3833 EXPECT_EQ(200, r->GetResponseCode()); |
| 3842 EXPECT_FALSE(d.auth_required_called()); | 3834 EXPECT_FALSE(d.auth_required_called()); |
| 3843 EXPECT_EQ(1, network_delegate.created_requests()); | 3835 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3844 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3836 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3845 | 3837 |
| 3846 { | 3838 { |
| 3847 HttpRequestHeaders headers; | 3839 HttpRequestHeaders headers; |
| 3848 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); | 3840 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); |
| 3849 EXPECT_TRUE(headers.HasHeader("Authorization")); | 3841 EXPECT_TRUE(headers.HasHeader("Authorization")); |
| 3850 } | 3842 } |
| 3851 } | 3843 } |
| 3852 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3844 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3853 } | 3845 } |
| 3854 | 3846 |
| 3855 // Tests that the network delegate can synchronously complete OnAuthRequired | 3847 // Tests that the network delegate can synchronously complete OnAuthRequired |
| 3856 // by cancelling authentication. | 3848 // by cancelling authentication. |
| 3857 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { | 3849 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { |
| 3858 ASSERT_TRUE(test_server_.Start()); | 3850 ASSERT_TRUE(http_test_server()->Start()); |
| 3859 | 3851 |
| 3860 TestDelegate d; | 3852 TestDelegate d; |
| 3861 BlockingNetworkDelegate network_delegate( | 3853 BlockingNetworkDelegate network_delegate( |
| 3862 BlockingNetworkDelegate::SYNCHRONOUS); | 3854 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3863 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3855 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3864 network_delegate.set_auth_retval( | 3856 network_delegate.set_auth_retval( |
| 3865 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 3857 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 3866 | 3858 |
| 3867 TestURLRequestContext context(true); | 3859 TestURLRequestContext context(true); |
| 3868 context.set_network_delegate(&network_delegate); | 3860 context.set_network_delegate(&network_delegate); |
| 3869 context.Init(); | 3861 context.Init(); |
| 3870 | 3862 |
| 3871 { | 3863 { |
| 3872 GURL url(test_server_.GetURL("auth-basic")); | 3864 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 3873 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3865 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 3874 r->Start(); | 3866 r->Start(); |
| 3875 base::RunLoop().Run(); | 3867 base::RunLoop().Run(); |
| 3876 | 3868 |
| 3877 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3869 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3878 EXPECT_EQ(OK, r->status().error()); | 3870 EXPECT_EQ(OK, r->status().error()); |
| 3879 EXPECT_EQ(401, r->GetResponseCode()); | 3871 EXPECT_EQ(401, r->GetResponseCode()); |
| 3880 EXPECT_FALSE(d.auth_required_called()); | 3872 EXPECT_FALSE(d.auth_required_called()); |
| 3881 EXPECT_EQ(1, network_delegate.created_requests()); | 3873 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3882 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3874 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3883 } | 3875 } |
| 3884 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3876 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3885 } | 3877 } |
| 3886 | 3878 |
| 3887 // Tests that the network delegate can asynchronously complete OnAuthRequired | 3879 // Tests that the network delegate can asynchronously complete OnAuthRequired |
| 3888 // by taking no action. This indicates that the NetworkDelegate does not want | 3880 // by taking no action. This indicates that the NetworkDelegate does not want |
| 3889 // to handle the challenge, and is passing the buck along to the | 3881 // to handle the challenge, and is passing the buck along to the |
| 3890 // URLRequest::Delegate. | 3882 // URLRequest::Delegate. |
| 3891 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) { | 3883 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) { |
| 3892 ASSERT_TRUE(test_server_.Start()); | 3884 ASSERT_TRUE(http_test_server()->Start()); |
| 3893 | 3885 |
| 3894 TestDelegate d; | 3886 TestDelegate d; |
| 3895 BlockingNetworkDelegate network_delegate( | 3887 BlockingNetworkDelegate network_delegate( |
| 3896 BlockingNetworkDelegate::AUTO_CALLBACK); | 3888 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3897 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3889 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3898 | 3890 |
| 3899 TestURLRequestContext context(true); | 3891 TestURLRequestContext context(true); |
| 3900 context.set_network_delegate(&network_delegate); | 3892 context.set_network_delegate(&network_delegate); |
| 3901 context.Init(); | 3893 context.Init(); |
| 3902 | 3894 |
| 3903 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3895 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 3904 | 3896 |
| 3905 { | 3897 { |
| 3906 GURL url(test_server_.GetURL("auth-basic")); | 3898 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 3907 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3899 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 3908 r->Start(); | 3900 r->Start(); |
| 3909 base::RunLoop().Run(); | 3901 base::RunLoop().Run(); |
| 3910 | 3902 |
| 3911 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3903 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3912 EXPECT_EQ(0, r->status().error()); | 3904 EXPECT_EQ(0, r->status().error()); |
| 3913 EXPECT_EQ(200, r->GetResponseCode()); | 3905 EXPECT_EQ(200, r->GetResponseCode()); |
| 3914 EXPECT_TRUE(d.auth_required_called()); | 3906 EXPECT_TRUE(d.auth_required_called()); |
| 3915 EXPECT_EQ(1, network_delegate.created_requests()); | 3907 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3916 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3908 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3917 } | 3909 } |
| 3918 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3910 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3919 } | 3911 } |
| 3920 | 3912 |
| 3921 // Tests that the network delegate can asynchronously complete OnAuthRequired | 3913 // Tests that the network delegate can asynchronously complete OnAuthRequired |
| 3922 // by setting credentials. | 3914 // by setting credentials. |
| 3923 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { | 3915 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { |
| 3924 ASSERT_TRUE(test_server_.Start()); | 3916 ASSERT_TRUE(http_test_server()->Start()); |
| 3925 | 3917 |
| 3926 TestDelegate d; | 3918 TestDelegate d; |
| 3927 BlockingNetworkDelegate network_delegate( | 3919 BlockingNetworkDelegate network_delegate( |
| 3928 BlockingNetworkDelegate::AUTO_CALLBACK); | 3920 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3929 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3921 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3930 network_delegate.set_auth_retval( | 3922 network_delegate.set_auth_retval( |
| 3931 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 3923 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 3932 | 3924 |
| 3933 AuthCredentials auth_credentials(kUser, kSecret); | 3925 AuthCredentials auth_credentials(kUser, kSecret); |
| 3934 network_delegate.set_auth_credentials(auth_credentials); | 3926 network_delegate.set_auth_credentials(auth_credentials); |
| 3935 | 3927 |
| 3936 TestURLRequestContext context(true); | 3928 TestURLRequestContext context(true); |
| 3937 context.set_network_delegate(&network_delegate); | 3929 context.set_network_delegate(&network_delegate); |
| 3938 context.Init(); | 3930 context.Init(); |
| 3939 | 3931 |
| 3940 { | 3932 { |
| 3941 GURL url(test_server_.GetURL("auth-basic")); | 3933 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 3942 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3934 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 3943 r->Start(); | 3935 r->Start(); |
| 3944 base::RunLoop().Run(); | 3936 base::RunLoop().Run(); |
| 3945 | 3937 |
| 3946 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3938 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3947 EXPECT_EQ(0, r->status().error()); | 3939 EXPECT_EQ(0, r->status().error()); |
| 3948 | 3940 |
| 3949 EXPECT_EQ(200, r->GetResponseCode()); | 3941 EXPECT_EQ(200, r->GetResponseCode()); |
| 3950 EXPECT_FALSE(d.auth_required_called()); | 3942 EXPECT_FALSE(d.auth_required_called()); |
| 3951 EXPECT_EQ(1, network_delegate.created_requests()); | 3943 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3952 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3944 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3953 } | 3945 } |
| 3954 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3946 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3955 } | 3947 } |
| 3956 | 3948 |
| 3957 // Tests that the network delegate can asynchronously complete OnAuthRequired | 3949 // Tests that the network delegate can asynchronously complete OnAuthRequired |
| 3958 // by cancelling authentication. | 3950 // by cancelling authentication. |
| 3959 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) { | 3951 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) { |
| 3960 ASSERT_TRUE(test_server_.Start()); | 3952 ASSERT_TRUE(http_test_server()->Start()); |
| 3961 | 3953 |
| 3962 TestDelegate d; | 3954 TestDelegate d; |
| 3963 BlockingNetworkDelegate network_delegate( | 3955 BlockingNetworkDelegate network_delegate( |
| 3964 BlockingNetworkDelegate::AUTO_CALLBACK); | 3956 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3965 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3957 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3966 network_delegate.set_auth_retval( | 3958 network_delegate.set_auth_retval( |
| 3967 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 3959 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 3968 | 3960 |
| 3969 TestURLRequestContext context(true); | 3961 TestURLRequestContext context(true); |
| 3970 context.set_network_delegate(&network_delegate); | 3962 context.set_network_delegate(&network_delegate); |
| 3971 context.Init(); | 3963 context.Init(); |
| 3972 | 3964 |
| 3973 { | 3965 { |
| 3974 GURL url(test_server_.GetURL("auth-basic")); | 3966 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 3975 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3967 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 3976 r->Start(); | 3968 r->Start(); |
| 3977 base::RunLoop().Run(); | 3969 base::RunLoop().Run(); |
| 3978 | 3970 |
| 3979 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 3971 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3980 EXPECT_EQ(OK, r->status().error()); | 3972 EXPECT_EQ(OK, r->status().error()); |
| 3981 EXPECT_EQ(401, r->GetResponseCode()); | 3973 EXPECT_EQ(401, r->GetResponseCode()); |
| 3982 EXPECT_FALSE(d.auth_required_called()); | 3974 EXPECT_FALSE(d.auth_required_called()); |
| 3983 EXPECT_EQ(1, network_delegate.created_requests()); | 3975 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3984 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3976 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3985 } | 3977 } |
| 3986 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3978 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3987 } | 3979 } |
| 3988 | 3980 |
| 3989 // Tests that we can handle when a network request was canceled while we were | 3981 // Tests that we can handle when a network request was canceled while we were |
| 3990 // waiting for the network delegate. | 3982 // waiting for the network delegate. |
| 3991 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. | 3983 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. |
| 3992 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { | 3984 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { |
| 3993 ASSERT_TRUE(test_server_.Start()); | 3985 ASSERT_TRUE(http_test_server()->Start()); |
| 3994 | 3986 |
| 3995 TestDelegate d; | 3987 TestDelegate d; |
| 3996 BlockingNetworkDelegate network_delegate( | 3988 BlockingNetworkDelegate network_delegate( |
| 3997 BlockingNetworkDelegate::USER_CALLBACK); | 3989 BlockingNetworkDelegate::USER_CALLBACK); |
| 3998 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3990 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3999 | 3991 |
| 4000 TestURLRequestContext context(true); | 3992 TestURLRequestContext context(true); |
| 4001 context.set_network_delegate(&network_delegate); | 3993 context.set_network_delegate(&network_delegate); |
| 4002 context.Init(); | 3994 context.Init(); |
| 4003 | 3995 |
| 4004 { | 3996 { |
| 4005 scoped_ptr<URLRequest> r(context.CreateRequest( | 3997 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4006 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 3998 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 4007 | 3999 |
| 4008 r->Start(); | 4000 r->Start(); |
| 4009 base::RunLoop().Run(); | 4001 base::RunLoop().Run(); |
| 4010 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | 4002 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 4011 network_delegate.stage_blocked_for_callback()); | 4003 network_delegate.stage_blocked_for_callback()); |
| 4012 EXPECT_EQ(0, network_delegate.completed_requests()); | 4004 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 4013 // Cancel before callback. | 4005 // Cancel before callback. |
| 4014 r->Cancel(); | 4006 r->Cancel(); |
| 4015 // Ensure that network delegate is notified. | 4007 // Ensure that network delegate is notified. |
| 4016 EXPECT_EQ(1, network_delegate.completed_requests()); | 4008 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 4017 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); | 4009 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 4018 EXPECT_EQ(ERR_ABORTED, r->status().error()); | 4010 EXPECT_EQ(ERR_ABORTED, r->status().error()); |
| 4019 EXPECT_EQ(1, network_delegate.created_requests()); | 4011 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4020 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4012 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4021 } | 4013 } |
| 4022 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4014 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4023 } | 4015 } |
| 4024 | 4016 |
| 4025 // Tests that we can handle when a network request was canceled while we were | 4017 // Tests that we can handle when a network request was canceled while we were |
| 4026 // waiting for the network delegate. | 4018 // waiting for the network delegate. |
| 4027 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback. | 4019 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback. |
| 4028 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) { | 4020 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) { |
| 4029 ASSERT_TRUE(test_server_.Start()); | 4021 ASSERT_TRUE(http_test_server()->Start()); |
| 4030 | 4022 |
| 4031 TestDelegate d; | 4023 TestDelegate d; |
| 4032 BlockingNetworkDelegate network_delegate( | 4024 BlockingNetworkDelegate network_delegate( |
| 4033 BlockingNetworkDelegate::USER_CALLBACK); | 4025 BlockingNetworkDelegate::USER_CALLBACK); |
| 4034 network_delegate.set_block_on( | 4026 network_delegate.set_block_on( |
| 4035 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); | 4027 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); |
| 4036 | 4028 |
| 4037 TestURLRequestContext context(true); | 4029 TestURLRequestContext context(true); |
| 4038 context.set_network_delegate(&network_delegate); | 4030 context.set_network_delegate(&network_delegate); |
| 4039 context.Init(); | 4031 context.Init(); |
| 4040 | 4032 |
| 4041 { | 4033 { |
| 4042 scoped_ptr<URLRequest> r(context.CreateRequest( | 4034 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4043 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 4035 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 4044 | 4036 |
| 4045 r->Start(); | 4037 r->Start(); |
| 4046 base::RunLoop().Run(); | 4038 base::RunLoop().Run(); |
| 4047 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | 4039 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 4048 network_delegate.stage_blocked_for_callback()); | 4040 network_delegate.stage_blocked_for_callback()); |
| 4049 EXPECT_EQ(0, network_delegate.completed_requests()); | 4041 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 4050 // Cancel before callback. | 4042 // Cancel before callback. |
| 4051 r->Cancel(); | 4043 r->Cancel(); |
| 4052 // Ensure that network delegate is notified. | 4044 // Ensure that network delegate is notified. |
| 4053 EXPECT_EQ(1, network_delegate.completed_requests()); | 4045 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 4054 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); | 4046 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 4055 EXPECT_EQ(ERR_ABORTED, r->status().error()); | 4047 EXPECT_EQ(ERR_ABORTED, r->status().error()); |
| 4056 EXPECT_EQ(1, network_delegate.created_requests()); | 4048 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4057 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4049 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4058 } | 4050 } |
| 4059 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4051 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4060 } | 4052 } |
| 4061 | 4053 |
| 4062 // Tests that we can handle when a network request was canceled while we were | 4054 // Tests that we can handle when a network request was canceled while we were |
| 4063 // waiting for the network delegate. | 4055 // waiting for the network delegate. |
| 4064 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback. | 4056 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback. |
| 4065 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { | 4057 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { |
| 4066 ASSERT_TRUE(test_server_.Start()); | 4058 ASSERT_TRUE(http_test_server()->Start()); |
| 4067 | 4059 |
| 4068 TestDelegate d; | 4060 TestDelegate d; |
| 4069 BlockingNetworkDelegate network_delegate( | 4061 BlockingNetworkDelegate network_delegate( |
| 4070 BlockingNetworkDelegate::USER_CALLBACK); | 4062 BlockingNetworkDelegate::USER_CALLBACK); |
| 4071 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 4063 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 4072 | 4064 |
| 4073 TestURLRequestContext context(true); | 4065 TestURLRequestContext context(true); |
| 4074 context.set_network_delegate(&network_delegate); | 4066 context.set_network_delegate(&network_delegate); |
| 4075 context.Init(); | 4067 context.Init(); |
| 4076 | 4068 |
| 4077 { | 4069 { |
| 4078 scoped_ptr<URLRequest> r(context.CreateRequest( | 4070 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4079 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 4071 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 4080 | 4072 |
| 4081 r->Start(); | 4073 r->Start(); |
| 4082 base::RunLoop().Run(); | 4074 base::RunLoop().Run(); |
| 4083 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, | 4075 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, |
| 4084 network_delegate.stage_blocked_for_callback()); | 4076 network_delegate.stage_blocked_for_callback()); |
| 4085 EXPECT_EQ(0, network_delegate.completed_requests()); | 4077 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 4086 // Cancel before callback. | 4078 // Cancel before callback. |
| 4087 r->Cancel(); | 4079 r->Cancel(); |
| 4088 // Ensure that network delegate is notified. | 4080 // Ensure that network delegate is notified. |
| 4089 EXPECT_EQ(1, network_delegate.completed_requests()); | 4081 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 4090 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); | 4082 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 4091 EXPECT_EQ(ERR_ABORTED, r->status().error()); | 4083 EXPECT_EQ(ERR_ABORTED, r->status().error()); |
| 4092 EXPECT_EQ(1, network_delegate.created_requests()); | 4084 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4093 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4085 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4094 } | 4086 } |
| 4095 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4087 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4096 } | 4088 } |
| 4097 | 4089 |
| 4098 // Tests that we can handle when a network request was canceled while we were | 4090 // Tests that we can handle when a network request was canceled while we were |
| 4099 // waiting for the network delegate. | 4091 // waiting for the network delegate. |
| 4100 // Part 4: Request is cancelled while waiting for OnAuthRequired callback. | 4092 // Part 4: Request is cancelled while waiting for OnAuthRequired callback. |
| 4101 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { | 4093 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { |
| 4102 ASSERT_TRUE(test_server_.Start()); | 4094 ASSERT_TRUE(http_test_server()->Start()); |
| 4103 | 4095 |
| 4104 TestDelegate d; | 4096 TestDelegate d; |
| 4105 BlockingNetworkDelegate network_delegate( | 4097 BlockingNetworkDelegate network_delegate( |
| 4106 BlockingNetworkDelegate::USER_CALLBACK); | 4098 BlockingNetworkDelegate::USER_CALLBACK); |
| 4107 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 4099 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 4108 | 4100 |
| 4109 TestURLRequestContext context(true); | 4101 TestURLRequestContext context(true); |
| 4110 context.set_network_delegate(&network_delegate); | 4102 context.set_network_delegate(&network_delegate); |
| 4111 context.Init(); | 4103 context.Init(); |
| 4112 | 4104 |
| 4113 { | 4105 { |
| 4114 scoped_ptr<URLRequest> r(context.CreateRequest( | 4106 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4115 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d)); | 4107 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); |
| 4116 | 4108 |
| 4117 r->Start(); | 4109 r->Start(); |
| 4118 base::RunLoop().Run(); | 4110 base::RunLoop().Run(); |
| 4119 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, | 4111 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, |
| 4120 network_delegate.stage_blocked_for_callback()); | 4112 network_delegate.stage_blocked_for_callback()); |
| 4121 EXPECT_EQ(0, network_delegate.completed_requests()); | 4113 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 4122 // Cancel before callback. | 4114 // Cancel before callback. |
| 4123 r->Cancel(); | 4115 r->Cancel(); |
| 4124 // Ensure that network delegate is notified. | 4116 // Ensure that network delegate is notified. |
| 4125 EXPECT_EQ(1, network_delegate.completed_requests()); | 4117 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 4126 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); | 4118 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 4127 EXPECT_EQ(ERR_ABORTED, r->status().error()); | 4119 EXPECT_EQ(ERR_ABORTED, r->status().error()); |
| 4128 EXPECT_EQ(1, network_delegate.created_requests()); | 4120 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4129 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4121 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4130 } | 4122 } |
| 4131 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4123 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4132 } | 4124 } |
| 4133 | 4125 |
| 4134 // In this unit test, we're using the HTTPTestServer as a proxy server and | 4126 namespace { |
| 4127 |
| 4128 scoped_ptr<test_server::HttpResponse> HandleServerAuthConnect( |
| 4129 const test_server::HttpRequest& request) { |
| 4130 if (request.headers.find("Host") == request.headers.end() || |
| 4131 request.headers.at("Host") != "www.server-auth.com" || |
| 4132 request.method != test_server::METHOD_CONNECT) { |
| 4133 return nullptr; |
| 4134 } |
| 4135 |
| 4136 scoped_ptr<test_server::BasicHttpResponse> http_response( |
| 4137 new test_server::BasicHttpResponse); |
| 4138 http_response->set_code(HTTP_UNAUTHORIZED); |
| 4139 http_response->AddCustomHeader("WWW-Authenticate", |
| 4140 "Basic realm=\"WallyWorld\""); |
| 4141 return http_response.Pass(); |
| 4142 } |
| 4143 |
| 4144 } // namespace |
| 4145 |
| 4146 // In this unit test, we're using the EmbeddedTestServer as a proxy server and |
| 4135 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 4147 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
| 4136 // The HTTPTestServer will return a 401 response, which we should balk at. | 4148 // The EmbeddedTestServer will return a 401 response, which we should balk at. |
| 4137 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 4149 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
| 4138 ASSERT_TRUE(test_server_.Start()); | 4150 http_test_server()->RegisterRequestHandler( |
| 4151 base::Bind(&HandleServerAuthConnect)); |
| 4152 ASSERT_TRUE(http_test_server()->Start()); |
| 4139 | 4153 |
| 4140 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 4154 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 4141 TestURLRequestContextWithProxy context( | 4155 TestURLRequestContextWithProxy context( |
| 4142 test_server_.host_port_pair().ToString(), &network_delegate); | 4156 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 4143 | 4157 |
| 4144 TestDelegate d; | 4158 TestDelegate d; |
| 4145 { | 4159 { |
| 4146 scoped_ptr<URLRequest> r(context.CreateRequest( | 4160 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4147 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d)); | 4161 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d)); |
| 4148 | 4162 |
| 4149 r->Start(); | 4163 r->Start(); |
| 4150 EXPECT_TRUE(r->is_pending()); | 4164 EXPECT_TRUE(r->is_pending()); |
| 4151 | 4165 |
| 4152 base::RunLoop().Run(); | 4166 base::RunLoop().Run(); |
| 4153 | 4167 |
| 4154 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 4168 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 4155 // The proxy server is not set before failure. | 4169 // The proxy server is not set before failure. |
| 4156 EXPECT_TRUE(r->proxy_server().IsEmpty()); | 4170 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
| 4157 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); | 4171 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); |
| 4158 } | 4172 } |
| 4159 } | 4173 } |
| 4160 | 4174 |
| 4161 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 4175 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
| 4162 ASSERT_TRUE(test_server_.Start()); | 4176 ASSERT_TRUE(http_test_server()->Start()); |
| 4163 | 4177 |
| 4164 TestDelegate d; | 4178 TestDelegate d; |
| 4165 { | 4179 { |
| 4166 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 4180 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4167 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 4181 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 4168 | 4182 |
| 4169 r->Start(); | 4183 r->Start(); |
| 4170 EXPECT_TRUE(r->is_pending()); | 4184 EXPECT_TRUE(r->is_pending()); |
| 4171 | 4185 |
| 4172 base::RunLoop().Run(); | 4186 base::RunLoop().Run(); |
| 4173 | 4187 |
| 4174 EXPECT_EQ(1, d.response_started_count()); | 4188 EXPECT_EQ(1, d.response_started_count()); |
| 4175 EXPECT_FALSE(d.received_data_before_response()); | 4189 EXPECT_FALSE(d.received_data_before_response()); |
| 4176 EXPECT_NE(0, d.bytes_received()); | 4190 EXPECT_NE(0, d.bytes_received()); |
| 4177 EXPECT_EQ(test_server_.host_port_pair().host(), | 4191 EXPECT_EQ(http_test_server()->host_port_pair().host(), |
| 4178 r->GetSocketAddress().host()); | 4192 r->GetSocketAddress().host()); |
| 4179 EXPECT_EQ(test_server_.host_port_pair().port(), | 4193 EXPECT_EQ(http_test_server()->host_port_pair().port(), |
| 4180 r->GetSocketAddress().port()); | 4194 r->GetSocketAddress().port()); |
| 4181 | 4195 |
| 4182 // TODO(eroman): Add back the NetLog tests... | 4196 // TODO(eroman): Add back the NetLog tests... |
| 4183 } | 4197 } |
| 4184 } | 4198 } |
| 4185 | 4199 |
| 4186 // This test has the server send a large number of cookies to the client. | 4200 // This test has the server send a large number of cookies to the client. |
| 4187 // To ensure that no number of cookies causes a crash, a galloping binary | 4201 // To ensure that no number of cookies causes a crash, a galloping binary |
| 4188 // search is used to estimate that maximum number of cookies that are accepted | 4202 // search is used to estimate that maximum number of cookies that are accepted |
| 4189 // by the browser. Beyond the maximum number, the request will fail with | 4203 // by the browser. Beyond the maximum number, the request will fail with |
| 4190 // ERR_RESPONSE_HEADERS_TOO_BIG. | 4204 // ERR_RESPONSE_HEADERS_TOO_BIG. |
| 4191 #if defined(OS_WIN) | 4205 #if defined(OS_WIN) |
| 4192 // http://crbug.com/177916 | 4206 // http://crbug.com/177916 |
| 4193 #define MAYBE_GetTest_ManyCookies DISABLED_GetTest_ManyCookies | 4207 #define MAYBE_GetTest_ManyCookies DISABLED_GetTest_ManyCookies |
| 4194 #else | 4208 #else |
| 4195 #define MAYBE_GetTest_ManyCookies GetTest_ManyCookies | 4209 #define MAYBE_GetTest_ManyCookies GetTest_ManyCookies |
| 4196 #endif // defined(OS_WIN) | 4210 #endif // defined(OS_WIN) |
| 4197 TEST_F(URLRequestTestHTTP, MAYBE_GetTest_ManyCookies) { | 4211 TEST_F(URLRequestTestHTTP, MAYBE_GetTest_ManyCookies) { |
| 4198 ASSERT_TRUE(test_server_.Start()); | 4212 ASSERT_TRUE(http_test_server()->Start()); |
| 4199 | 4213 |
| 4200 int lower_bound = 0; | 4214 int lower_bound = 0; |
| 4201 int upper_bound = 1; | 4215 int upper_bound = 1; |
| 4202 | 4216 |
| 4203 // Double the number of cookies until the response header limits are | 4217 // Double the number of cookies until the response header limits are |
| 4204 // exceeded. | 4218 // exceeded. |
| 4205 while (DoManyCookiesRequest(upper_bound)) { | 4219 while (DoManyCookiesRequest(upper_bound)) { |
| 4206 lower_bound = upper_bound; | 4220 lower_bound = upper_bound; |
| 4207 upper_bound *= 2; | 4221 upper_bound *= 2; |
| 4208 ASSERT_LT(upper_bound, 1000000); | 4222 ASSERT_LT(upper_bound, 1000000); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4219 | 4233 |
| 4220 if (DoManyCookiesRequest(num_cookies)) | 4234 if (DoManyCookiesRequest(num_cookies)) |
| 4221 lower_bound = num_cookies; | 4235 lower_bound = num_cookies; |
| 4222 else | 4236 else |
| 4223 upper_bound = num_cookies; | 4237 upper_bound = num_cookies; |
| 4224 } | 4238 } |
| 4225 // Success: the test did not crash. | 4239 // Success: the test did not crash. |
| 4226 } | 4240 } |
| 4227 | 4241 |
| 4228 TEST_F(URLRequestTestHTTP, GetTest) { | 4242 TEST_F(URLRequestTestHTTP, GetTest) { |
| 4229 ASSERT_TRUE(test_server_.Start()); | 4243 ASSERT_TRUE(http_test_server()->Start()); |
| 4230 | 4244 |
| 4231 TestDelegate d; | 4245 TestDelegate d; |
| 4232 { | 4246 { |
| 4233 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 4247 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4234 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 4248 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 4235 | 4249 |
| 4236 r->Start(); | 4250 r->Start(); |
| 4237 EXPECT_TRUE(r->is_pending()); | 4251 EXPECT_TRUE(r->is_pending()); |
| 4238 | 4252 |
| 4239 base::RunLoop().Run(); | 4253 base::RunLoop().Run(); |
| 4240 | 4254 |
| 4241 EXPECT_EQ(1, d.response_started_count()); | 4255 EXPECT_EQ(1, d.response_started_count()); |
| 4242 EXPECT_FALSE(d.received_data_before_response()); | 4256 EXPECT_FALSE(d.received_data_before_response()); |
| 4243 EXPECT_NE(0, d.bytes_received()); | 4257 EXPECT_NE(0, d.bytes_received()); |
| 4244 EXPECT_EQ(test_server_.host_port_pair().host(), | 4258 EXPECT_EQ(http_test_server()->host_port_pair().host(), |
| 4245 r->GetSocketAddress().host()); | 4259 r->GetSocketAddress().host()); |
| 4246 EXPECT_EQ(test_server_.host_port_pair().port(), | 4260 EXPECT_EQ(http_test_server()->host_port_pair().port(), |
| 4247 r->GetSocketAddress().port()); | 4261 r->GetSocketAddress().port()); |
| 4248 } | 4262 } |
| 4249 } | 4263 } |
| 4250 | 4264 |
| 4251 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { | 4265 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { |
| 4252 ASSERT_TRUE(test_server_.Start()); | 4266 ASSERT_TRUE(http_test_server()->Start()); |
| 4253 | 4267 |
| 4254 TestDelegate d; | 4268 TestDelegate d; |
| 4255 { | 4269 { |
| 4256 GURL test_url(test_server_.GetURL(std::string())); | 4270 GURL test_url(http_test_server()->GetURL("/defaultresponse")); |
| 4257 scoped_ptr<URLRequest> r( | 4271 scoped_ptr<URLRequest> r( |
| 4258 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 4272 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); |
| 4259 | 4273 |
| 4260 HttpRequestHeaders headers; | 4274 HttpRequestHeaders headers; |
| 4261 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); | 4275 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); |
| 4262 | 4276 |
| 4263 r->Start(); | 4277 r->Start(); |
| 4264 EXPECT_TRUE(r->is_pending()); | 4278 EXPECT_TRUE(r->is_pending()); |
| 4265 | 4279 |
| 4266 base::RunLoop().Run(); | 4280 base::RunLoop().Run(); |
| 4267 | 4281 |
| 4268 EXPECT_EQ(1, d.response_started_count()); | 4282 EXPECT_EQ(1, d.response_started_count()); |
| 4269 EXPECT_FALSE(d.received_data_before_response()); | 4283 EXPECT_FALSE(d.received_data_before_response()); |
| 4270 EXPECT_NE(0, d.bytes_received()); | 4284 EXPECT_NE(0, d.bytes_received()); |
| 4271 EXPECT_EQ(test_server_.host_port_pair().host(), | 4285 EXPECT_EQ(http_test_server()->host_port_pair().host(), |
| 4272 r->GetSocketAddress().host()); | 4286 r->GetSocketAddress().host()); |
| 4273 EXPECT_EQ(test_server_.host_port_pair().port(), | 4287 EXPECT_EQ(http_test_server()->host_port_pair().port(), |
| 4274 r->GetSocketAddress().port()); | 4288 r->GetSocketAddress().port()); |
| 4275 | 4289 |
| 4276 EXPECT_TRUE(d.have_full_request_headers()); | 4290 EXPECT_TRUE(d.have_full_request_headers()); |
| 4277 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 4291 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
| 4278 } | 4292 } |
| 4279 } | 4293 } |
| 4280 | 4294 |
| 4281 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { | 4295 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { |
| 4282 ASSERT_TRUE(test_server_.Start()); | 4296 ASSERT_TRUE(http_test_server()->Start()); |
| 4283 | 4297 |
| 4284 TestDelegate d; | 4298 TestDelegate d; |
| 4285 { | 4299 { |
| 4286 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 4300 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4287 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 4301 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 4288 | 4302 |
| 4289 r->Start(); | 4303 r->Start(); |
| 4290 EXPECT_TRUE(r->is_pending()); | 4304 EXPECT_TRUE(r->is_pending()); |
| 4291 | 4305 |
| 4292 base::RunLoop().Run(); | 4306 base::RunLoop().Run(); |
| 4293 | 4307 |
| 4294 LoadTimingInfo load_timing_info; | 4308 LoadTimingInfo load_timing_info; |
| 4295 r->GetLoadTimingInfo(&load_timing_info); | 4309 r->GetLoadTimingInfo(&load_timing_info); |
| 4296 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 4310 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 4297 | 4311 |
| 4298 EXPECT_EQ(1, d.response_started_count()); | 4312 EXPECT_EQ(1, d.response_started_count()); |
| 4299 EXPECT_FALSE(d.received_data_before_response()); | 4313 EXPECT_FALSE(d.received_data_before_response()); |
| 4300 EXPECT_NE(0, d.bytes_received()); | 4314 EXPECT_NE(0, d.bytes_received()); |
| 4301 EXPECT_EQ(test_server_.host_port_pair().host(), | 4315 EXPECT_EQ(http_test_server()->host_port_pair().host(), |
| 4302 r->GetSocketAddress().host()); | 4316 r->GetSocketAddress().host()); |
| 4303 EXPECT_EQ(test_server_.host_port_pair().port(), | 4317 EXPECT_EQ(http_test_server()->host_port_pair().port(), |
| 4304 r->GetSocketAddress().port()); | 4318 r->GetSocketAddress().port()); |
| 4305 } | 4319 } |
| 4306 } | 4320 } |
| 4307 | 4321 |
| 4322 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). |
| 4323 #if !defined(OS_IOS) |
| 4308 TEST_F(URLRequestTestHTTP, GetZippedTest) { | 4324 TEST_F(URLRequestTestHTTP, GetZippedTest) { |
| 4309 ASSERT_TRUE(test_server_.Start()); | 4325 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
| 4326 SpawnedTestServer::kLocalhost, |
| 4327 base::FilePath(kTestFilePath)); |
| 4328 |
| 4329 ASSERT_TRUE(test_server.Start()); |
| 4310 | 4330 |
| 4311 // Parameter that specifies the Content-Length field in the response: | 4331 // Parameter that specifies the Content-Length field in the response: |
| 4312 // C - Compressed length. | 4332 // C - Compressed length. |
| 4313 // U - Uncompressed length. | 4333 // U - Uncompressed length. |
| 4314 // L - Large length (larger than both C & U). | 4334 // L - Large length (larger than both C & U). |
| 4315 // M - Medium length (between C & U). | 4335 // M - Medium length (between C & U). |
| 4316 // S - Small length (smaller than both C & U). | 4336 // S - Small length (smaller than both C & U). |
| 4317 const char test_parameters[] = "CULMS"; | 4337 const char test_parameters[] = "CULMS"; |
| 4318 const int num_tests = arraysize(test_parameters)- 1; // Skip NULL. | 4338 const int num_tests = arraysize(test_parameters)- 1; // Skip NULL. |
| 4319 // C & U should be OK. | 4339 // C & U should be OK. |
| 4320 // L & M are larger than the data sent, and show an error. | 4340 // L & M are larger than the data sent, and show an error. |
| 4321 // S has too little data, but we seem to accept it. | 4341 // S has too little data, but we seem to accept it. |
| 4322 const bool test_expect_success[num_tests] = | 4342 const bool test_expect_success[num_tests] = |
| 4323 { true, true, false, false, true }; | 4343 { true, true, false, false, true }; |
| 4324 | 4344 |
| 4325 for (int i = 0; i < num_tests ; i++) { | 4345 for (int i = 0; i < num_tests ; i++) { |
| 4326 TestDelegate d; | 4346 TestDelegate d; |
| 4327 { | 4347 { |
| 4328 std::string test_file = | 4348 std::string test_file = base::StringPrintf( |
| 4329 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", | 4349 "compressedfiles/BullRunSpeech.txt?%c", test_parameters[i]); |
| 4330 test_parameters[i]); | |
| 4331 | 4350 |
| 4332 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 4351 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 4333 TestURLRequestContext context(true); | 4352 TestURLRequestContext context(true); |
| 4334 context.set_network_delegate(&network_delegate); | 4353 context.set_network_delegate(&network_delegate); |
| 4335 context.Init(); | 4354 context.Init(); |
| 4336 | 4355 |
| 4337 scoped_ptr<URLRequest> r(context.CreateRequest( | 4356 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4338 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d)); | 4357 test_server.GetURL(test_file), DEFAULT_PRIORITY, &d)); |
| 4339 r->Start(); | 4358 r->Start(); |
| 4340 EXPECT_TRUE(r->is_pending()); | 4359 EXPECT_TRUE(r->is_pending()); |
| 4341 | 4360 |
| 4342 base::RunLoop().Run(); | 4361 base::RunLoop().Run(); |
| 4343 | 4362 |
| 4344 EXPECT_EQ(1, d.response_started_count()); | 4363 EXPECT_EQ(1, d.response_started_count()); |
| 4345 EXPECT_FALSE(d.received_data_before_response()); | 4364 EXPECT_FALSE(d.received_data_before_response()); |
| 4346 VLOG(1) << " Received " << d.bytes_received() << " bytes" | 4365 VLOG(1) << " Received " << d.bytes_received() << " bytes" |
| 4347 << " status = " << r->status().status() | 4366 << " status = " << r->status().status() |
| 4348 << " error = " << r->status().error(); | 4367 << " error = " << r->status().error(); |
| 4349 if (test_expect_success[i]) { | 4368 if (test_expect_success[i]) { |
| 4350 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()) | 4369 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()) |
| 4351 << " Parameter = \"" << test_file << "\""; | 4370 << " Parameter = \"" << test_file << "\""; |
| 4352 } else { | 4371 } else { |
| 4353 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 4372 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 4354 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) | 4373 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) |
| 4355 << " Parameter = \"" << test_file << "\""; | 4374 << " Parameter = \"" << test_file << "\""; |
| 4356 } | 4375 } |
| 4357 } | 4376 } |
| 4358 } | 4377 } |
| 4359 } | 4378 } |
| 4379 #endif // !defined(OS_IOS) |
| 4360 | 4380 |
| 4361 TEST_F(URLRequestTestHTTP, NetworkQualityEstimator) { | 4381 TEST_F(URLRequestTestHTTP, NetworkQualityEstimator) { |
| 4362 ASSERT_TRUE(test_server_.Start()); | 4382 ASSERT_TRUE(http_test_server()->Start()); |
| 4363 // Enable requests to local host to be used for network quality estimation. | 4383 // Enable requests to local host to be used for network quality estimation. |
| 4364 std::map<std::string, std::string> variation_params; | 4384 std::map<std::string, std::string> variation_params; |
| 4365 NetworkQualityEstimator estimator(scoped_ptr<net::ExternalEstimateProvider>(), | 4385 NetworkQualityEstimator estimator(scoped_ptr<net::ExternalEstimateProvider>(), |
| 4366 variation_params, true, true); | 4386 variation_params, true, true); |
| 4367 | 4387 |
| 4368 TestDelegate d; | 4388 TestDelegate d; |
| 4369 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 4389 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 4370 TestURLRequestContext context(true); | 4390 TestURLRequestContext context(true); |
| 4371 context.set_network_quality_estimator(&estimator); | 4391 context.set_network_quality_estimator(&estimator); |
| 4372 context.set_network_delegate(&network_delegate); | 4392 context.set_network_delegate(&network_delegate); |
| 4373 context.Init(); | 4393 context.Init(); |
| 4374 | 4394 |
| 4375 std::string url = "echo.html"; | 4395 std::string url = "/defaultresponse"; |
| 4376 | 4396 |
| 4377 scoped_ptr<URLRequest> r( | 4397 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4378 context.CreateRequest(test_server_.GetURL(url), DEFAULT_PRIORITY, &d)); | 4398 http_test_server()->GetURL(url), DEFAULT_PRIORITY, &d)); |
| 4379 r->Start(); | 4399 r->Start(); |
| 4380 | 4400 |
| 4381 base::RunLoop().Run(); | 4401 base::RunLoop().Run(); |
| 4382 | 4402 |
| 4383 base::TimeDelta rtt; | 4403 base::TimeDelta rtt; |
| 4384 int32_t kbps; | 4404 int32_t kbps; |
| 4385 EXPECT_TRUE(estimator.GetRTTEstimate(&rtt)); | 4405 EXPECT_TRUE(estimator.GetRTTEstimate(&rtt)); |
| 4386 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); | 4406 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); |
| 4387 EXPECT_GE(rtt, base::TimeDelta()); | 4407 EXPECT_GE(rtt, base::TimeDelta()); |
| 4388 EXPECT_LT(rtt, base::TimeDelta::Max()); | 4408 EXPECT_LT(rtt, base::TimeDelta::Max()); |
| 4389 EXPECT_GT(kbps, 0); | 4409 EXPECT_GT(kbps, 0); |
| 4390 | 4410 |
| 4391 // Verify that histograms are not populated. They should populate only when | 4411 // Verify that histograms are not populated. They should populate only when |
| 4392 // there is a change in ConnectionType. | 4412 // there is a change in ConnectionType. |
| 4393 base::HistogramTester histogram_tester; | 4413 base::HistogramTester histogram_tester; |
| 4394 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); | 4414 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); |
| 4395 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); | 4415 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); |
| 4396 | 4416 |
| 4397 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests( | 4417 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests( |
| 4398 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); | 4418 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); |
| 4399 base::MessageLoop::current()->RunUntilIdle(); | 4419 base::MessageLoop::current()->RunUntilIdle(); |
| 4400 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); | 4420 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); |
| 4401 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); | 4421 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); |
| 4402 } | 4422 } |
| 4403 | 4423 |
| 4404 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { | 4424 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { |
| 4405 ASSERT_TRUE(test_server_.Start()); | 4425 ASSERT_TRUE(http_test_server()->Start()); |
| 4406 | 4426 |
| 4407 GURL destination_url = test_server_.GetURL(std::string()); | 4427 GURL destination_url = http_test_server()->GetURL("/"); |
| 4408 GURL original_url = | 4428 GURL original_url = |
| 4409 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 4429 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); |
| 4410 TestDelegate d; | 4430 TestDelegate d; |
| 4411 scoped_ptr<URLRequest> req( | 4431 scoped_ptr<URLRequest> req( |
| 4412 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 4432 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 4413 req->Start(); | 4433 req->Start(); |
| 4414 base::RunLoop().Run(); | 4434 base::RunLoop().Run(); |
| 4415 | 4435 |
| 4416 EXPECT_EQ(1, d.response_started_count()); | 4436 EXPECT_EQ(1, d.response_started_count()); |
| 4417 EXPECT_EQ(1, d.received_redirect_count()); | 4437 EXPECT_EQ(1, d.received_redirect_count()); |
| 4418 EXPECT_EQ(destination_url, req->url()); | 4438 EXPECT_EQ(destination_url, req->url()); |
| 4419 EXPECT_EQ(original_url, req->original_url()); | 4439 EXPECT_EQ(original_url, req->original_url()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4434 // Check that a new socket was used on redirect, since the server does not | 4454 // Check that a new socket was used on redirect, since the server does not |
| 4435 // supposed keep-alive sockets, and that the times before the redirect are | 4455 // supposed keep-alive sockets, and that the times before the redirect are |
| 4436 // before the ones recorded for the second request. | 4456 // before the ones recorded for the second request. |
| 4437 EXPECT_NE(load_timing_info_before_redirect.socket_log_id, | 4457 EXPECT_NE(load_timing_info_before_redirect.socket_log_id, |
| 4438 load_timing_info.socket_log_id); | 4458 load_timing_info.socket_log_id); |
| 4439 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end, | 4459 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end, |
| 4440 load_timing_info.connect_timing.connect_start); | 4460 load_timing_info.connect_timing.connect_start); |
| 4441 } | 4461 } |
| 4442 | 4462 |
| 4443 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { | 4463 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { |
| 4444 ASSERT_TRUE(test_server_.Start()); | 4464 ASSERT_TRUE(http_test_server()->Start()); |
| 4445 | 4465 |
| 4446 GURL destination_url = test_server_.GetURL(std::string()); | 4466 GURL destination_url = http_test_server()->GetURL("/"); |
| 4447 GURL middle_redirect_url = | 4467 GURL middle_redirect_url = |
| 4448 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 4468 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); |
| 4449 GURL original_url = test_server_.GetURL( | 4469 GURL original_url = http_test_server()->GetURL("/server-redirect?" + |
| 4450 "server-redirect?" + middle_redirect_url.spec()); | 4470 middle_redirect_url.spec()); |
| 4451 TestDelegate d; | 4471 TestDelegate d; |
| 4452 scoped_ptr<URLRequest> req( | 4472 scoped_ptr<URLRequest> req( |
| 4453 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 4473 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 4454 req->Start(); | 4474 req->Start(); |
| 4455 base::RunLoop().Run(); | 4475 base::RunLoop().Run(); |
| 4456 | 4476 |
| 4457 EXPECT_EQ(1, d.response_started_count()); | 4477 EXPECT_EQ(1, d.response_started_count()); |
| 4458 EXPECT_EQ(2, d.received_redirect_count()); | 4478 EXPECT_EQ(2, d.received_redirect_count()); |
| 4459 EXPECT_EQ(destination_url, req->url()); | 4479 EXPECT_EQ(destination_url, req->url()); |
| 4460 EXPECT_EQ(original_url, req->original_url()); | 4480 EXPECT_EQ(original_url, req->original_url()); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4761 TestDelegate::OnReadCompleted(request, bytes_read); | 4781 TestDelegate::OnReadCompleted(request, bytes_read); |
| 4762 } | 4782 } |
| 4763 | 4783 |
| 4764 const CancelStage cancel_stage_; | 4784 const CancelStage cancel_stage_; |
| 4765 | 4785 |
| 4766 DISALLOW_COPY_AND_ASSIGN(AsyncLoggingUrlRequestDelegate); | 4786 DISALLOW_COPY_AND_ASSIGN(AsyncLoggingUrlRequestDelegate); |
| 4767 }; | 4787 }; |
| 4768 | 4788 |
| 4769 // Tests handling of delegate info before a request starts. | 4789 // Tests handling of delegate info before a request starts. |
| 4770 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) { | 4790 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) { |
| 4771 ASSERT_TRUE(test_server_.Start()); | 4791 ASSERT_TRUE(http_test_server()->Start()); |
| 4772 | 4792 |
| 4773 TestDelegate request_delegate; | 4793 TestDelegate request_delegate; |
| 4774 TestURLRequestContext context(true); | 4794 TestURLRequestContext context(true); |
| 4775 context.set_network_delegate(NULL); | 4795 context.set_network_delegate(NULL); |
| 4776 context.set_net_log(&net_log_); | 4796 context.set_net_log(&net_log_); |
| 4777 context.Init(); | 4797 context.Init(); |
| 4778 | 4798 |
| 4779 { | 4799 { |
| 4780 scoped_ptr<URLRequest> r( | 4800 scoped_ptr<URLRequest> r( |
| 4781 context.CreateRequest(test_server_.GetURL("empty.html"), | 4801 context.CreateRequest(http_test_server()->GetURL("/defaultresponse"), |
| 4782 DEFAULT_PRIORITY, &request_delegate)); | 4802 DEFAULT_PRIORITY, &request_delegate)); |
| 4783 LoadStateWithParam load_state = r->GetLoadState(); | 4803 LoadStateWithParam load_state = r->GetLoadState(); |
| 4784 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4804 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 4785 EXPECT_EQ(base::string16(), load_state.param); | 4805 EXPECT_EQ(base::string16(), load_state.param); |
| 4786 | 4806 |
| 4787 AsyncDelegateLogger::Run( | 4807 AsyncDelegateLogger::Run( |
| 4788 r.get(), | 4808 r.get(), |
| 4789 LOAD_STATE_WAITING_FOR_DELEGATE, | 4809 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4790 LOAD_STATE_WAITING_FOR_DELEGATE, | 4810 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4791 LOAD_STATE_IDLE, | 4811 LOAD_STATE_IDLE, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4807 | 4827 |
| 4808 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, log_position); | 4828 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, log_position); |
| 4809 | 4829 |
| 4810 // Nothing else should add any delegate info to the request. | 4830 // Nothing else should add any delegate info to the request. |
| 4811 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4831 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4812 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 4832 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 4813 } | 4833 } |
| 4814 | 4834 |
| 4815 // Tests handling of delegate info from a network delegate. | 4835 // Tests handling of delegate info from a network delegate. |
| 4816 TEST_F(URLRequestTestHTTP, NetworkDelegateInfo) { | 4836 TEST_F(URLRequestTestHTTP, NetworkDelegateInfo) { |
| 4817 ASSERT_TRUE(test_server_.Start()); | 4837 ASSERT_TRUE(http_test_server()->Start()); |
| 4818 | 4838 |
| 4819 TestDelegate request_delegate; | 4839 TestDelegate request_delegate; |
| 4820 AsyncLoggingNetworkDelegate network_delegate; | 4840 AsyncLoggingNetworkDelegate network_delegate; |
| 4821 TestURLRequestContext context(true); | 4841 TestURLRequestContext context(true); |
| 4822 context.set_network_delegate(&network_delegate); | 4842 context.set_network_delegate(&network_delegate); |
| 4823 context.set_net_log(&net_log_); | 4843 context.set_net_log(&net_log_); |
| 4824 context.Init(); | 4844 context.Init(); |
| 4825 | 4845 |
| 4826 { | 4846 { |
| 4827 scoped_ptr<URLRequest> r( | 4847 scoped_ptr<URLRequest> r( |
| 4828 context.CreateRequest(test_server_.GetURL("simple.html"), | 4848 context.CreateRequest(http_test_server()->GetURL("/simple.html"), |
| 4829 DEFAULT_PRIORITY, &request_delegate)); | 4849 DEFAULT_PRIORITY, &request_delegate)); |
| 4830 LoadStateWithParam load_state = r->GetLoadState(); | 4850 LoadStateWithParam load_state = r->GetLoadState(); |
| 4831 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4851 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 4832 EXPECT_EQ(base::string16(), load_state.param); | 4852 EXPECT_EQ(base::string16(), load_state.param); |
| 4833 | 4853 |
| 4834 r->Start(); | 4854 r->Start(); |
| 4835 base::RunLoop().Run(); | 4855 base::RunLoop().Run(); |
| 4836 | 4856 |
| 4837 EXPECT_EQ(200, r->GetResponseCode()); | 4857 EXPECT_EQ(200, r->GetResponseCode()); |
| 4838 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 4858 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4864 } | 4884 } |
| 4865 } | 4885 } |
| 4866 | 4886 |
| 4867 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4887 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4868 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 4888 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 4869 } | 4889 } |
| 4870 | 4890 |
| 4871 // Tests handling of delegate info from a network delegate in the case of an | 4891 // Tests handling of delegate info from a network delegate in the case of an |
| 4872 // HTTP redirect. | 4892 // HTTP redirect. |
| 4873 TEST_F(URLRequestTestHTTP, NetworkDelegateInfoRedirect) { | 4893 TEST_F(URLRequestTestHTTP, NetworkDelegateInfoRedirect) { |
| 4874 ASSERT_TRUE(test_server_.Start()); | 4894 ASSERT_TRUE(http_test_server()->Start()); |
| 4875 | 4895 |
| 4876 TestDelegate request_delegate; | 4896 TestDelegate request_delegate; |
| 4877 AsyncLoggingNetworkDelegate network_delegate; | 4897 AsyncLoggingNetworkDelegate network_delegate; |
| 4878 TestURLRequestContext context(true); | 4898 TestURLRequestContext context(true); |
| 4879 context.set_network_delegate(&network_delegate); | 4899 context.set_network_delegate(&network_delegate); |
| 4880 context.set_net_log(&net_log_); | 4900 context.set_net_log(&net_log_); |
| 4881 context.Init(); | 4901 context.Init(); |
| 4882 | 4902 |
| 4883 { | 4903 { |
| 4884 scoped_ptr<URLRequest> r(context.CreateRequest( | 4904 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4885 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY, | 4905 http_test_server()->GetURL("/server-redirect?simple.html"), |
| 4886 &request_delegate)); | 4906 DEFAULT_PRIORITY, &request_delegate)); |
| 4887 LoadStateWithParam load_state = r->GetLoadState(); | 4907 LoadStateWithParam load_state = r->GetLoadState(); |
| 4888 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4908 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 4889 EXPECT_EQ(base::string16(), load_state.param); | 4909 EXPECT_EQ(base::string16(), load_state.param); |
| 4890 | 4910 |
| 4891 r->Start(); | 4911 r->Start(); |
| 4892 base::RunLoop().Run(); | 4912 base::RunLoop().Run(); |
| 4893 | 4913 |
| 4894 EXPECT_EQ(200, r->GetResponseCode()); | 4914 EXPECT_EQ(200, r->GetResponseCode()); |
| 4895 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 4915 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 4896 EXPECT_EQ(2, network_delegate.created_requests()); | 4916 EXPECT_EQ(2, network_delegate.created_requests()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4946 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 4966 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 4947 } | 4967 } |
| 4948 | 4968 |
| 4949 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4969 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4950 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 4970 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 4951 } | 4971 } |
| 4952 | 4972 |
| 4953 // Tests handling of delegate info from a network delegate in the case of HTTP | 4973 // Tests handling of delegate info from a network delegate in the case of HTTP |
| 4954 // AUTH. | 4974 // AUTH. |
| 4955 TEST_F(URLRequestTestHTTP, NetworkDelegateInfoAuth) { | 4975 TEST_F(URLRequestTestHTTP, NetworkDelegateInfoAuth) { |
| 4956 ASSERT_TRUE(test_server_.Start()); | 4976 ASSERT_TRUE(http_test_server()->Start()); |
| 4957 | 4977 |
| 4958 TestDelegate request_delegate; | 4978 TestDelegate request_delegate; |
| 4959 AsyncLoggingNetworkDelegate network_delegate; | 4979 AsyncLoggingNetworkDelegate network_delegate; |
| 4960 TestURLRequestContext context(true); | 4980 TestURLRequestContext context(true); |
| 4961 context.set_network_delegate(&network_delegate); | 4981 context.set_network_delegate(&network_delegate); |
| 4962 context.set_net_log(&net_log_); | 4982 context.set_net_log(&net_log_); |
| 4963 context.Init(); | 4983 context.Init(); |
| 4964 | 4984 |
| 4965 { | 4985 { |
| 4966 scoped_ptr<URLRequest> r( | 4986 scoped_ptr<URLRequest> r( |
| 4967 context.CreateRequest(test_server_.GetURL("auth-basic"), | 4987 context.CreateRequest(http_test_server()->GetURL("/auth-basic"), |
| 4968 DEFAULT_PRIORITY, &request_delegate)); | 4988 DEFAULT_PRIORITY, &request_delegate)); |
| 4969 LoadStateWithParam load_state = r->GetLoadState(); | 4989 LoadStateWithParam load_state = r->GetLoadState(); |
| 4970 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4990 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 4971 EXPECT_EQ(base::string16(), load_state.param); | 4991 EXPECT_EQ(base::string16(), load_state.param); |
| 4972 | 4992 |
| 4973 r->Start(); | 4993 r->Start(); |
| 4974 base::RunLoop().Run(); | 4994 base::RunLoop().Run(); |
| 4975 | 4995 |
| 4976 EXPECT_EQ(200, r->GetResponseCode()); | 4996 EXPECT_EQ(200, r->GetResponseCode()); |
| 4977 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 4997 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 5003 if (i == 1) { | 5023 if (i == 1) { |
| 5004 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( | 5024 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( |
| 5005 entries, log_position + 1); | 5025 entries, log_position + 1); |
| 5006 } | 5026 } |
| 5007 } | 5027 } |
| 5008 | 5028 |
| 5009 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 5029 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 5010 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 5030 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 5011 } | 5031 } |
| 5012 | 5032 |
| 5033 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). |
| 5034 #if !defined(OS_IOS) |
| 5013 // Tests handling of delegate info from a URLRequest::Delegate. | 5035 // Tests handling of delegate info from a URLRequest::Delegate. |
| 5014 TEST_F(URLRequestTestHTTP, URLRequestDelegateInfo) { | 5036 TEST_F(URLRequestTestHTTP, URLRequestDelegateInfo) { |
| 5015 ASSERT_TRUE(test_server_.Start()); | 5037 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
| 5038 SpawnedTestServer::kLocalhost, |
| 5039 base::FilePath(kTestFilePath)); |
| 5040 |
| 5041 ASSERT_TRUE(test_server.Start()); |
| 5016 | 5042 |
| 5017 AsyncLoggingUrlRequestDelegate request_delegate( | 5043 AsyncLoggingUrlRequestDelegate request_delegate( |
| 5018 AsyncLoggingUrlRequestDelegate::NO_CANCEL); | 5044 AsyncLoggingUrlRequestDelegate::NO_CANCEL); |
| 5019 TestURLRequestContext context(true); | 5045 TestURLRequestContext context(true); |
| 5020 context.set_network_delegate(NULL); | 5046 context.set_network_delegate(NULL); |
| 5021 context.set_net_log(&net_log_); | 5047 context.set_net_log(&net_log_); |
| 5022 context.Init(); | 5048 context.Init(); |
| 5023 | 5049 |
| 5024 { | 5050 { |
| 5025 // A chunked response with delays between chunks is used to make sure that | 5051 // A chunked response with delays between chunks is used to make sure that |
| 5026 // attempts by the URLRequest delegate to log information while reading the | 5052 // attempts by the URLRequest delegate to log information while reading the |
| 5027 // body are ignored. Since they are ignored, this test is robust against | 5053 // body are ignored. Since they are ignored, this test is robust against |
| 5028 // the possibility of multiple reads being combined in the unlikely event | 5054 // the possibility of multiple reads being combined in the unlikely event |
| 5029 // that it occurs. | 5055 // that it occurs. |
| 5030 scoped_ptr<URLRequest> r(context.CreateRequest( | 5056 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 5031 test_server_.GetURL("chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY, | 5057 test_server.GetURL("/chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY, |
| 5032 &request_delegate)); | 5058 &request_delegate)); |
| 5033 LoadStateWithParam load_state = r->GetLoadState(); | 5059 LoadStateWithParam load_state = r->GetLoadState(); |
| 5034 r->Start(); | 5060 r->Start(); |
| 5035 base::RunLoop().Run(); | 5061 base::RunLoop().Run(); |
| 5036 | 5062 |
| 5037 EXPECT_EQ(200, r->GetResponseCode()); | 5063 EXPECT_EQ(200, r->GetResponseCode()); |
| 5038 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 5064 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 5039 } | 5065 } |
| 5040 | 5066 |
| 5041 TestNetLogEntry::List entries; | 5067 TestNetLogEntry::List entries; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5059 | 5085 |
| 5060 ASSERT_LT(log_position, entries.size()); | 5086 ASSERT_LT(log_position, entries.size()); |
| 5061 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); | 5087 EXPECT_EQ(NetLog::TYPE_URL_REQUEST_DELEGATE, entries[log_position].type); |
| 5062 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); | 5088 EXPECT_EQ(NetLog::PHASE_END, entries[log_position].phase); |
| 5063 | 5089 |
| 5064 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 5090 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 5065 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 5091 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 5066 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 5092 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 5067 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); | 5093 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); |
| 5068 } | 5094 } |
| 5095 #endif // !defined(OS_IOS) |
| 5069 | 5096 |
| 5070 // Tests handling of delegate info from a URLRequest::Delegate in the case of | 5097 // Tests handling of delegate info from a URLRequest::Delegate in the case of |
| 5071 // an HTTP redirect. | 5098 // an HTTP redirect. |
| 5072 TEST_F(URLRequestTestHTTP, URLRequestDelegateInfoOnRedirect) { | 5099 TEST_F(URLRequestTestHTTP, URLRequestDelegateInfoOnRedirect) { |
| 5073 ASSERT_TRUE(test_server_.Start()); | 5100 ASSERT_TRUE(http_test_server()->Start()); |
| 5074 | 5101 |
| 5075 AsyncLoggingUrlRequestDelegate request_delegate( | 5102 AsyncLoggingUrlRequestDelegate request_delegate( |
| 5076 AsyncLoggingUrlRequestDelegate::NO_CANCEL); | 5103 AsyncLoggingUrlRequestDelegate::NO_CANCEL); |
| 5077 TestURLRequestContext context(true); | 5104 TestURLRequestContext context(true); |
| 5078 context.set_network_delegate(NULL); | 5105 context.set_network_delegate(NULL); |
| 5079 context.set_net_log(&net_log_); | 5106 context.set_net_log(&net_log_); |
| 5080 context.Init(); | 5107 context.Init(); |
| 5081 | 5108 |
| 5082 { | 5109 { |
| 5083 scoped_ptr<URLRequest> r(context.CreateRequest( | 5110 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 5084 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY, | 5111 http_test_server()->GetURL("/server-redirect?simple.html"), |
| 5085 &request_delegate)); | 5112 DEFAULT_PRIORITY, &request_delegate)); |
| 5086 LoadStateWithParam load_state = r->GetLoadState(); | 5113 LoadStateWithParam load_state = r->GetLoadState(); |
| 5087 r->Start(); | 5114 r->Start(); |
| 5088 base::RunLoop().Run(); | 5115 base::RunLoop().Run(); |
| 5089 | 5116 |
| 5090 EXPECT_EQ(200, r->GetResponseCode()); | 5117 EXPECT_EQ(200, r->GetResponseCode()); |
| 5091 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 5118 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 5092 } | 5119 } |
| 5093 | 5120 |
| 5094 TestNetLogEntry::List entries; | 5121 TestNetLogEntry::List entries; |
| 5095 net_log_.GetEntries(&entries); | 5122 net_log_.GetEntries(&entries); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5119 | 5146 |
| 5120 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 5147 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 5121 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 5148 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 5122 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 5149 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 5123 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); | 5150 entries, log_position + 1, NetLog::TYPE_URL_REQUEST_DELEGATE)); |
| 5124 } | 5151 } |
| 5125 | 5152 |
| 5126 // Tests handling of delegate info from a URLRequest::Delegate in the case of | 5153 // Tests handling of delegate info from a URLRequest::Delegate in the case of |
| 5127 // an HTTP redirect, with cancellation at various points. | 5154 // an HTTP redirect, with cancellation at various points. |
| 5128 TEST_F(URLRequestTestHTTP, URLRequestDelegateOnRedirectCancelled) { | 5155 TEST_F(URLRequestTestHTTP, URLRequestDelegateOnRedirectCancelled) { |
| 5129 ASSERT_TRUE(test_server_.Start()); | 5156 ASSERT_TRUE(http_test_server()->Start()); |
| 5130 | 5157 |
| 5131 const AsyncLoggingUrlRequestDelegate::CancelStage kCancelStages[] = { | 5158 const AsyncLoggingUrlRequestDelegate::CancelStage kCancelStages[] = { |
| 5132 AsyncLoggingUrlRequestDelegate::CANCEL_ON_RECEIVED_REDIRECT, | 5159 AsyncLoggingUrlRequestDelegate::CANCEL_ON_RECEIVED_REDIRECT, |
| 5133 AsyncLoggingUrlRequestDelegate::CANCEL_ON_RESPONSE_STARTED, | 5160 AsyncLoggingUrlRequestDelegate::CANCEL_ON_RESPONSE_STARTED, |
| 5134 AsyncLoggingUrlRequestDelegate::CANCEL_ON_READ_COMPLETED, | 5161 AsyncLoggingUrlRequestDelegate::CANCEL_ON_READ_COMPLETED, |
| 5135 }; | 5162 }; |
| 5136 | 5163 |
| 5137 for (size_t test_case = 0; test_case < arraysize(kCancelStages); | 5164 for (size_t test_case = 0; test_case < arraysize(kCancelStages); |
| 5138 ++test_case) { | 5165 ++test_case) { |
| 5139 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); | 5166 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); |
| 5140 TestURLRequestContext context(true); | 5167 TestURLRequestContext context(true); |
| 5141 TestNetLog net_log; | 5168 TestNetLog net_log; |
| 5142 context.set_network_delegate(NULL); | 5169 context.set_network_delegate(NULL); |
| 5143 context.set_net_log(&net_log); | 5170 context.set_net_log(&net_log); |
| 5144 context.Init(); | 5171 context.Init(); |
| 5145 | 5172 |
| 5146 { | 5173 { |
| 5147 scoped_ptr<URLRequest> r(context.CreateRequest( | 5174 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 5148 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY, | 5175 http_test_server()->GetURL("/server-redirect?simple.html"), |
| 5149 &request_delegate)); | 5176 DEFAULT_PRIORITY, &request_delegate)); |
| 5150 LoadStateWithParam load_state = r->GetLoadState(); | 5177 LoadStateWithParam load_state = r->GetLoadState(); |
| 5151 r->Start(); | 5178 r->Start(); |
| 5152 base::RunLoop().Run(); | 5179 base::RunLoop().Run(); |
| 5153 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); | 5180 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 5154 } | 5181 } |
| 5155 | 5182 |
| 5156 TestNetLogEntry::List entries; | 5183 TestNetLogEntry::List entries; |
| 5157 net_log.GetEntries(&entries); | 5184 net_log.GetEntries(&entries); |
| 5158 | 5185 |
| 5159 // Delegate info is always logged in both OnReceivedRedirect and | 5186 // Delegate info is always logged in both OnReceivedRedirect and |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5198 const RedirectInfo& redirect_info, | 5225 const RedirectInfo& redirect_info, |
| 5199 bool* defer_redirect) override { | 5226 bool* defer_redirect) override { |
| 5200 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect); | 5227 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect); |
| 5201 request->SetExtraRequestHeaderByName(kExtraHeader, kExtraValue, false); | 5228 request->SetExtraRequestHeaderByName(kExtraHeader, kExtraValue, false); |
| 5202 } | 5229 } |
| 5203 }; | 5230 }; |
| 5204 | 5231 |
| 5205 } // namespace | 5232 } // namespace |
| 5206 | 5233 |
| 5207 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { | 5234 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { |
| 5208 ASSERT_TRUE(test_server_.Start()); | 5235 ASSERT_TRUE(http_test_server()->Start()); |
| 5209 | 5236 |
| 5210 GURL destination_url = test_server_.GetURL( | 5237 GURL destination_url = |
| 5211 "echoheader?" + std::string(kExtraHeader)); | 5238 http_test_server()->GetURL("/echoheader?" + std::string(kExtraHeader)); |
| 5212 GURL original_url = test_server_.GetURL( | 5239 GURL original_url = |
| 5213 "server-redirect?" + destination_url.spec()); | 5240 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); |
| 5214 RedirectWithAdditionalHeadersDelegate d; | 5241 RedirectWithAdditionalHeadersDelegate d; |
| 5215 scoped_ptr<URLRequest> req( | 5242 scoped_ptr<URLRequest> req( |
| 5216 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 5243 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 5217 req->Start(); | 5244 req->Start(); |
| 5218 base::RunLoop().Run(); | 5245 base::RunLoop().Run(); |
| 5219 | 5246 |
| 5220 std::string value; | 5247 std::string value; |
| 5221 const HttpRequestHeaders& headers = req->extra_request_headers(); | 5248 const HttpRequestHeaders& headers = req->extra_request_headers(); |
| 5222 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); | 5249 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); |
| 5223 EXPECT_EQ(kExtraValue, value); | 5250 EXPECT_EQ(kExtraValue, value); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5235 const RedirectInfo& redirect_info, | 5262 const RedirectInfo& redirect_info, |
| 5236 bool* defer_redirect) override { | 5263 bool* defer_redirect) override { |
| 5237 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect); | 5264 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect); |
| 5238 request->RemoveRequestHeaderByName(kExtraHeaderToRemove); | 5265 request->RemoveRequestHeaderByName(kExtraHeaderToRemove); |
| 5239 } | 5266 } |
| 5240 }; | 5267 }; |
| 5241 | 5268 |
| 5242 } // namespace | 5269 } // namespace |
| 5243 | 5270 |
| 5244 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { | 5271 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { |
| 5245 ASSERT_TRUE(test_server_.Start()); | 5272 ASSERT_TRUE(http_test_server()->Start()); |
| 5246 | 5273 |
| 5247 GURL destination_url = test_server_.GetURL( | 5274 GURL destination_url = http_test_server()->GetURL( |
| 5248 "echoheader?" + std::string(kExtraHeaderToRemove)); | 5275 "/echoheader?" + std::string(kExtraHeaderToRemove)); |
| 5249 GURL original_url = test_server_.GetURL( | 5276 GURL original_url = |
| 5250 "server-redirect?" + destination_url.spec()); | 5277 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); |
| 5251 RedirectWithHeaderRemovalDelegate d; | 5278 RedirectWithHeaderRemovalDelegate d; |
| 5252 scoped_ptr<URLRequest> req( | 5279 scoped_ptr<URLRequest> req( |
| 5253 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 5280 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 5254 req->SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); | 5281 req->SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); |
| 5255 req->Start(); | 5282 req->Start(); |
| 5256 base::RunLoop().Run(); | 5283 base::RunLoop().Run(); |
| 5257 | 5284 |
| 5258 std::string value; | 5285 std::string value; |
| 5259 const HttpRequestHeaders& headers = req->extra_request_headers(); | 5286 const HttpRequestHeaders& headers = req->extra_request_headers(); |
| 5260 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); | 5287 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5278 | 5305 |
| 5279 // We expect to receive OnResponseStarted even though the request has been | 5306 // We expect to receive OnResponseStarted even though the request has been |
| 5280 // cancelled. | 5307 // cancelled. |
| 5281 EXPECT_EQ(1, d.response_started_count()); | 5308 EXPECT_EQ(1, d.response_started_count()); |
| 5282 EXPECT_EQ(0, d.bytes_received()); | 5309 EXPECT_EQ(0, d.bytes_received()); |
| 5283 EXPECT_FALSE(d.received_data_before_response()); | 5310 EXPECT_FALSE(d.received_data_before_response()); |
| 5284 } | 5311 } |
| 5285 } | 5312 } |
| 5286 | 5313 |
| 5287 TEST_F(URLRequestTestHTTP, CancelTest2) { | 5314 TEST_F(URLRequestTestHTTP, CancelTest2) { |
| 5288 ASSERT_TRUE(test_server_.Start()); | 5315 ASSERT_TRUE(http_test_server()->Start()); |
| 5289 | 5316 |
| 5290 TestDelegate d; | 5317 TestDelegate d; |
| 5291 { | 5318 { |
| 5292 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5319 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5293 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 5320 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 5294 | 5321 |
| 5295 d.set_cancel_in_response_started(true); | 5322 d.set_cancel_in_response_started(true); |
| 5296 | 5323 |
| 5297 r->Start(); | 5324 r->Start(); |
| 5298 EXPECT_TRUE(r->is_pending()); | 5325 EXPECT_TRUE(r->is_pending()); |
| 5299 | 5326 |
| 5300 base::RunLoop().Run(); | 5327 base::RunLoop().Run(); |
| 5301 | 5328 |
| 5302 EXPECT_EQ(1, d.response_started_count()); | 5329 EXPECT_EQ(1, d.response_started_count()); |
| 5303 EXPECT_EQ(0, d.bytes_received()); | 5330 EXPECT_EQ(0, d.bytes_received()); |
| 5304 EXPECT_FALSE(d.received_data_before_response()); | 5331 EXPECT_FALSE(d.received_data_before_response()); |
| 5305 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); | 5332 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 5306 } | 5333 } |
| 5307 } | 5334 } |
| 5308 | 5335 |
| 5309 TEST_F(URLRequestTestHTTP, CancelTest3) { | 5336 TEST_F(URLRequestTestHTTP, CancelTest3) { |
| 5310 ASSERT_TRUE(test_server_.Start()); | 5337 ASSERT_TRUE(http_test_server()->Start()); |
| 5311 | 5338 |
| 5312 TestDelegate d; | 5339 TestDelegate d; |
| 5313 { | 5340 { |
| 5314 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5341 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5315 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 5342 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 5316 | 5343 |
| 5317 d.set_cancel_in_received_data(true); | 5344 d.set_cancel_in_received_data(true); |
| 5318 | 5345 |
| 5319 r->Start(); | 5346 r->Start(); |
| 5320 EXPECT_TRUE(r->is_pending()); | 5347 EXPECT_TRUE(r->is_pending()); |
| 5321 | 5348 |
| 5322 base::RunLoop().Run(); | 5349 base::RunLoop().Run(); |
| 5323 | 5350 |
| 5324 EXPECT_EQ(1, d.response_started_count()); | 5351 EXPECT_EQ(1, d.response_started_count()); |
| 5325 // There is no guarantee about how much data was received | 5352 // There is no guarantee about how much data was received |
| 5326 // before the cancel was issued. It could have been 0 bytes, | 5353 // before the cancel was issued. It could have been 0 bytes, |
| 5327 // or it could have been all the bytes. | 5354 // or it could have been all the bytes. |
| 5328 // EXPECT_EQ(0, d.bytes_received()); | 5355 // EXPECT_EQ(0, d.bytes_received()); |
| 5329 EXPECT_FALSE(d.received_data_before_response()); | 5356 EXPECT_FALSE(d.received_data_before_response()); |
| 5330 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); | 5357 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 5331 } | 5358 } |
| 5332 } | 5359 } |
| 5333 | 5360 |
| 5334 TEST_F(URLRequestTestHTTP, CancelTest4) { | 5361 TEST_F(URLRequestTestHTTP, CancelTest4) { |
| 5335 ASSERT_TRUE(test_server_.Start()); | 5362 ASSERT_TRUE(http_test_server()->Start()); |
| 5336 | 5363 |
| 5337 TestDelegate d; | 5364 TestDelegate d; |
| 5338 { | 5365 { |
| 5339 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5366 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5340 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 5367 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 5341 | 5368 |
| 5342 r->Start(); | 5369 r->Start(); |
| 5343 EXPECT_TRUE(r->is_pending()); | 5370 EXPECT_TRUE(r->is_pending()); |
| 5344 | 5371 |
| 5345 // The request will be implicitly canceled when it is destroyed. The | 5372 // The request will be implicitly canceled when it is destroyed. The |
| 5346 // test delegate must not post a quit message when this happens because | 5373 // test delegate must not post a quit message when this happens because |
| 5347 // this test doesn't actually have a message loop. The quit message would | 5374 // this test doesn't actually have a message loop. The quit message would |
| 5348 // get put on this thread's message queue and the next test would exit | 5375 // get put on this thread's message queue and the next test would exit |
| 5349 // early, causing problems. | 5376 // early, causing problems. |
| 5350 d.set_quit_on_complete(false); | 5377 d.set_quit_on_complete(false); |
| 5351 } | 5378 } |
| 5352 // expect things to just cleanup properly. | 5379 // expect things to just cleanup properly. |
| 5353 | 5380 |
| 5354 // we won't actually get a received reponse here because we've never run the | 5381 // we won't actually get a received reponse here because we've never run the |
| 5355 // message loop | 5382 // message loop |
| 5356 EXPECT_FALSE(d.received_data_before_response()); | 5383 EXPECT_FALSE(d.received_data_before_response()); |
| 5357 EXPECT_EQ(0, d.bytes_received()); | 5384 EXPECT_EQ(0, d.bytes_received()); |
| 5358 } | 5385 } |
| 5359 | 5386 |
| 5360 TEST_F(URLRequestTestHTTP, CancelTest5) { | 5387 TEST_F(URLRequestTestHTTP, CancelTest5) { |
| 5361 ASSERT_TRUE(test_server_.Start()); | 5388 ASSERT_TRUE(http_test_server()->Start()); |
| 5362 | 5389 |
| 5363 // populate cache | 5390 // populate cache |
| 5364 { | 5391 { |
| 5365 TestDelegate d; | 5392 TestDelegate d; |
| 5366 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5393 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5367 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d)); | 5394 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); |
| 5368 r->Start(); | 5395 r->Start(); |
| 5369 base::RunLoop().Run(); | 5396 base::RunLoop().Run(); |
| 5370 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 5397 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 5371 } | 5398 } |
| 5372 | 5399 |
| 5373 // cancel read from cache (see bug 990242) | 5400 // cancel read from cache (see bug 990242) |
| 5374 { | 5401 { |
| 5375 TestDelegate d; | 5402 TestDelegate d; |
| 5376 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5403 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5377 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d)); | 5404 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); |
| 5378 r->Start(); | 5405 r->Start(); |
| 5379 r->Cancel(); | 5406 r->Cancel(); |
| 5380 base::RunLoop().Run(); | 5407 base::RunLoop().Run(); |
| 5381 | 5408 |
| 5382 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); | 5409 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 5383 EXPECT_EQ(1, d.response_started_count()); | 5410 EXPECT_EQ(1, d.response_started_count()); |
| 5384 EXPECT_EQ(0, d.bytes_received()); | 5411 EXPECT_EQ(0, d.bytes_received()); |
| 5385 EXPECT_FALSE(d.received_data_before_response()); | 5412 EXPECT_FALSE(d.received_data_before_response()); |
| 5386 } | 5413 } |
| 5387 } | 5414 } |
| 5388 | 5415 |
| 5389 TEST_F(URLRequestTestHTTP, PostTest) { | 5416 TEST_F(URLRequestTestHTTP, PostTest) { |
| 5390 ASSERT_TRUE(test_server_.Start()); | 5417 ASSERT_TRUE(http_test_server()->Start()); |
| 5391 HTTPUploadDataOperationTest("POST"); | 5418 HTTPUploadDataOperationTest("POST"); |
| 5392 } | 5419 } |
| 5393 | 5420 |
| 5394 TEST_F(URLRequestTestHTTP, PutTest) { | 5421 TEST_F(URLRequestTestHTTP, PutTest) { |
| 5395 ASSERT_TRUE(test_server_.Start()); | 5422 ASSERT_TRUE(http_test_server()->Start()); |
| 5396 HTTPUploadDataOperationTest("PUT"); | 5423 HTTPUploadDataOperationTest("PUT"); |
| 5397 } | 5424 } |
| 5398 | 5425 |
| 5399 TEST_F(URLRequestTestHTTP, PostEmptyTest) { | 5426 TEST_F(URLRequestTestHTTP, PostEmptyTest) { |
| 5400 ASSERT_TRUE(test_server_.Start()); | 5427 ASSERT_TRUE(http_test_server()->Start()); |
| 5401 | 5428 |
| 5402 TestDelegate d; | 5429 TestDelegate d; |
| 5403 { | 5430 { |
| 5404 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5431 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5405 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d)); | 5432 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 5406 r->set_method("POST"); | 5433 r->set_method("POST"); |
| 5407 | 5434 |
| 5408 r->Start(); | 5435 r->Start(); |
| 5409 EXPECT_TRUE(r->is_pending()); | 5436 EXPECT_TRUE(r->is_pending()); |
| 5410 | 5437 |
| 5411 base::RunLoop().Run(); | 5438 base::RunLoop().Run(); |
| 5412 | 5439 |
| 5413 ASSERT_EQ(1, d.response_started_count()) | 5440 ASSERT_EQ(1, d.response_started_count()) |
| 5414 << "request failed: " << r->status().status() | 5441 << "request failed: " << r->status().status() |
| 5415 << ", error: " << r->status().error(); | 5442 << ", error: " << r->status().error(); |
| 5416 | 5443 |
| 5417 EXPECT_FALSE(d.received_data_before_response()); | 5444 EXPECT_FALSE(d.received_data_before_response()); |
| 5418 EXPECT_TRUE(d.data_received().empty()); | 5445 EXPECT_TRUE(d.data_received().empty()); |
| 5419 } | 5446 } |
| 5420 } | 5447 } |
| 5421 | 5448 |
| 5422 TEST_F(URLRequestTestHTTP, PostFileTest) { | 5449 TEST_F(URLRequestTestHTTP, PostFileTest) { |
| 5423 ASSERT_TRUE(test_server_.Start()); | 5450 ASSERT_TRUE(http_test_server()->Start()); |
| 5424 | 5451 |
| 5425 TestDelegate d; | 5452 TestDelegate d; |
| 5426 { | 5453 { |
| 5427 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5454 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5428 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d)); | 5455 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 5429 r->set_method("POST"); | 5456 r->set_method("POST"); |
| 5430 | 5457 |
| 5431 base::FilePath dir; | 5458 base::FilePath dir; |
| 5432 PathService::Get(base::DIR_EXE, &dir); | 5459 PathService::Get(base::DIR_EXE, &dir); |
| 5433 base::SetCurrentDirectory(dir); | 5460 base::SetCurrentDirectory(dir); |
| 5434 | 5461 |
| 5435 ScopedVector<UploadElementReader> element_readers; | 5462 ScopedVector<UploadElementReader> element_readers; |
| 5436 | 5463 |
| 5437 base::FilePath path; | 5464 base::FilePath path; |
| 5438 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 5465 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5462 << ", error: " << r->status().error(); | 5489 << ", error: " << r->status().error(); |
| 5463 | 5490 |
| 5464 EXPECT_FALSE(d.received_data_before_response()); | 5491 EXPECT_FALSE(d.received_data_before_response()); |
| 5465 | 5492 |
| 5466 EXPECT_EQ(size, d.bytes_received()); | 5493 EXPECT_EQ(size, d.bytes_received()); |
| 5467 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); | 5494 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); |
| 5468 } | 5495 } |
| 5469 } | 5496 } |
| 5470 | 5497 |
| 5471 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { | 5498 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { |
| 5472 ASSERT_TRUE(test_server_.Start()); | 5499 ASSERT_TRUE(http_test_server()->Start()); |
| 5473 | 5500 |
| 5474 TestDelegate d; | 5501 TestDelegate d; |
| 5475 { | 5502 { |
| 5476 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5503 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5477 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d)); | 5504 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 5478 r->set_method("POST"); | 5505 r->set_method("POST"); |
| 5479 | 5506 |
| 5480 ScopedVector<UploadElementReader> element_readers; | 5507 ScopedVector<UploadElementReader> element_readers; |
| 5481 | 5508 |
| 5482 element_readers.push_back(new UploadFileElementReader( | 5509 element_readers.push_back(new UploadFileElementReader( |
| 5483 base::ThreadTaskRunnerHandle::Get().get(), | 5510 base::ThreadTaskRunnerHandle::Get().get(), |
| 5484 base::FilePath(FILE_PATH_LITERAL( | 5511 base::FilePath(FILE_PATH_LITERAL( |
| 5485 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | 5512 "c:\\path\\to\\non\\existant\\file.randomness.12345")), |
| 5486 0, kuint64max, base::Time())); | 5513 0, kuint64max, base::Time())); |
| 5487 r->set_upload(make_scoped_ptr<UploadDataStream>( | 5514 r->set_upload(make_scoped_ptr<UploadDataStream>( |
| 5488 new ElementsUploadDataStream(element_readers.Pass(), 0))); | 5515 new ElementsUploadDataStream(element_readers.Pass(), 0))); |
| 5489 | 5516 |
| 5490 r->Start(); | 5517 r->Start(); |
| 5491 EXPECT_TRUE(r->is_pending()); | 5518 EXPECT_TRUE(r->is_pending()); |
| 5492 | 5519 |
| 5493 base::RunLoop().Run(); | 5520 base::RunLoop().Run(); |
| 5494 | 5521 |
| 5495 EXPECT_TRUE(d.request_failed()); | 5522 EXPECT_TRUE(d.request_failed()); |
| 5496 EXPECT_FALSE(d.received_data_before_response()); | 5523 EXPECT_FALSE(d.received_data_before_response()); |
| 5497 EXPECT_EQ(0, d.bytes_received()); | 5524 EXPECT_EQ(0, d.bytes_received()); |
| 5498 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 5525 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 5499 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error()); | 5526 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error()); |
| 5500 } | 5527 } |
| 5501 } | 5528 } |
| 5502 | 5529 |
| 5503 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 5530 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
| 5504 ASSERT_TRUE(test_server_.Start()); | 5531 ASSERT_TRUE(http_test_server()->Start()); |
| 5505 | 5532 |
| 5506 TestDelegate d; | 5533 TestDelegate d; |
| 5507 { | 5534 { |
| 5508 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5535 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5509 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d)); | 5536 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 5510 r->EnableChunkedUpload(); | 5537 r->EnableChunkedUpload(); |
| 5511 r->set_method("POST"); | 5538 r->set_method("POST"); |
| 5512 AddChunksToUpload(r.get()); | 5539 AddChunksToUpload(r.get()); |
| 5513 r->Start(); | 5540 r->Start(); |
| 5514 EXPECT_TRUE(r->is_pending()); | 5541 EXPECT_TRUE(r->is_pending()); |
| 5515 | 5542 |
| 5516 base::RunLoop().Run(); | 5543 base::RunLoop().Run(); |
| 5517 | 5544 |
| 5518 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5545 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 5519 } | 5546 } |
| 5520 } | 5547 } |
| 5521 | 5548 |
| 5522 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { | 5549 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { |
| 5523 ASSERT_TRUE(test_server_.Start()); | 5550 ASSERT_TRUE(http_test_server()->Start()); |
| 5524 | 5551 |
| 5525 TestDelegate d; | 5552 TestDelegate d; |
| 5526 { | 5553 { |
| 5527 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5554 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5528 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d)); | 5555 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 5529 r->EnableChunkedUpload(); | 5556 r->EnableChunkedUpload(); |
| 5530 r->set_method("POST"); | 5557 r->set_method("POST"); |
| 5531 r->Start(); | 5558 r->Start(); |
| 5532 EXPECT_TRUE(r->is_pending()); | 5559 EXPECT_TRUE(r->is_pending()); |
| 5533 AddChunksToUpload(r.get()); | 5560 AddChunksToUpload(r.get()); |
| 5534 base::RunLoop().Run(); | 5561 base::RunLoop().Run(); |
| 5535 | 5562 |
| 5536 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5563 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 5537 } | 5564 } |
| 5538 } | 5565 } |
| 5539 | 5566 |
| 5540 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { | 5567 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { |
| 5541 ASSERT_TRUE(test_server_.Start()); | 5568 ASSERT_TRUE(http_test_server()->Start()); |
| 5542 | 5569 |
| 5543 TestDelegate d; | 5570 TestDelegate d; |
| 5544 { | 5571 { |
| 5545 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 5572 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5546 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d)); | 5573 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); |
| 5547 r->EnableChunkedUpload(); | 5574 r->EnableChunkedUpload(); |
| 5548 r->set_method("POST"); | 5575 r->set_method("POST"); |
| 5549 r->Start(); | 5576 r->Start(); |
| 5550 EXPECT_TRUE(r->is_pending()); | 5577 EXPECT_TRUE(r->is_pending()); |
| 5551 | 5578 |
| 5552 base::RunLoop().RunUntilIdle(); | 5579 base::RunLoop().RunUntilIdle(); |
| 5553 AddChunksToUpload(r.get()); | 5580 AddChunksToUpload(r.get()); |
| 5554 base::RunLoop().Run(); | 5581 base::RunLoop().Run(); |
| 5555 | 5582 |
| 5556 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5583 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 5557 } | 5584 } |
| 5558 } | 5585 } |
| 5559 | 5586 |
| 5560 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 5587 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
| 5561 ASSERT_TRUE(test_server_.Start()); | 5588 ASSERT_TRUE(http_test_server()->Start()); |
| 5562 | 5589 |
| 5563 TestDelegate d; | 5590 TestDelegate d; |
| 5564 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 5591 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5565 test_server_.GetURL("files/with-headers.html"), DEFAULT_PRIORITY, &d)); | 5592 http_test_server()->GetURL("/with-headers.html"), DEFAULT_PRIORITY, &d)); |
| 5566 req->Start(); | 5593 req->Start(); |
| 5567 base::RunLoop().Run(); | 5594 base::RunLoop().Run(); |
| 5568 | 5595 |
| 5569 const HttpResponseHeaders* headers = req->response_headers(); | 5596 const HttpResponseHeaders* headers = req->response_headers(); |
| 5570 | 5597 |
| 5571 // Simple sanity check that response_info() accesses the same data. | 5598 // Simple sanity check that response_info() accesses the same data. |
| 5572 EXPECT_EQ(headers, req->response_info().headers.get()); | 5599 EXPECT_EQ(headers, req->response_info().headers.get()); |
| 5573 | 5600 |
| 5574 std::string header; | 5601 std::string header; |
| 5575 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 5602 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
| 5576 EXPECT_EQ("private", header); | 5603 EXPECT_EQ("private", header); |
| 5577 | 5604 |
| 5578 header.clear(); | 5605 header.clear(); |
| 5579 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); | 5606 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); |
| 5580 EXPECT_EQ("text/html; charset=ISO-8859-1", header); | 5607 EXPECT_EQ("text/html; charset=ISO-8859-1", header); |
| 5581 | 5608 |
| 5582 // The response has two "X-Multiple-Entries" headers. | 5609 // The response has two "X-Multiple-Entries" headers. |
| 5583 // This verfies our output has them concatenated together. | 5610 // This verfies our output has them concatenated together. |
| 5584 header.clear(); | 5611 header.clear(); |
| 5585 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); | 5612 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); |
| 5586 EXPECT_EQ("a, b", header); | 5613 EXPECT_EQ("a, b", header); |
| 5587 } | 5614 } |
| 5588 | 5615 |
| 5616 // TODO(svaldez): iOS tests are flaky with EmbeddedTestServer and transport |
| 5617 // security state. |
| 5618 #if !defined(OS_IOS) |
| 5619 |
| 5589 TEST_F(URLRequestTestHTTP, ProcessSTS) { | 5620 TEST_F(URLRequestTestHTTP, ProcessSTS) { |
| 5590 SpawnedTestServer::SSLOptions ssl_options( | 5621 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5591 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5622 https_test_server.SetSSLConfig( |
| 5592 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 5623 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5593 ssl_options, | 5624 https_test_server.ServeFilesFromSourceDirectory( |
| 5594 base::FilePath(kTestFilePath)); | 5625 base::FilePath(kTestFilePath)); |
| 5595 ASSERT_TRUE(https_test_server.Start()); | 5626 ASSERT_TRUE(https_test_server.Start()); |
| 5596 | 5627 |
| 5597 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5628 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5598 | |
| 5599 TestDelegate d; | 5629 TestDelegate d; |
| 5600 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5630 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5601 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, | 5631 https_test_server.GetURL("/hsts-headers.html"), DEFAULT_PRIORITY, &d)); |
| 5602 &d)); | |
| 5603 request->Start(); | 5632 request->Start(); |
| 5604 base::RunLoop().Run(); | 5633 base::RunLoop().Run(); |
| 5605 | 5634 |
| 5606 TransportSecurityState* security_state = | 5635 TransportSecurityState* security_state = |
| 5607 default_context_.transport_security_state(); | 5636 default_context_.transport_security_state(); |
| 5608 TransportSecurityState::STSState sts_state; | 5637 TransportSecurityState::STSState sts_state; |
| 5609 TransportSecurityState::PKPState pkp_state; | 5638 TransportSecurityState::PKPState pkp_state; |
| 5610 EXPECT_TRUE( | 5639 EXPECT_TRUE( |
| 5611 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 5640 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 5612 EXPECT_FALSE( | 5641 EXPECT_FALSE( |
| 5613 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); | 5642 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); |
| 5614 EXPECT_EQ(TransportSecurityState::STSState::MODE_FORCE_HTTPS, | 5643 EXPECT_EQ(TransportSecurityState::STSState::MODE_FORCE_HTTPS, |
| 5615 sts_state.upgrade_mode); | 5644 sts_state.upgrade_mode); |
| 5616 EXPECT_TRUE(sts_state.include_subdomains); | 5645 EXPECT_TRUE(sts_state.include_subdomains); |
| 5617 EXPECT_FALSE(pkp_state.include_subdomains); | 5646 EXPECT_FALSE(pkp_state.include_subdomains); |
| 5618 #if defined(OS_ANDROID) | 5647 #if defined(OS_ANDROID) |
| 5619 // Android's CertVerifyProc does not (yet) handle pins. | 5648 // Android's CertVerifyProc does not (yet) handle pins. |
| 5620 #else | 5649 #else |
| 5621 EXPECT_FALSE(pkp_state.HasPublicKeyPins()); | 5650 EXPECT_FALSE(pkp_state.HasPublicKeyPins()); |
| 5622 #endif | 5651 #endif |
| 5623 } | 5652 } |
| 5624 | 5653 |
| 5625 TEST_F(URLRequestTestHTTP, STSNotProcessedOnIP) { | 5654 TEST_F(URLRequestTestHTTP, STSNotProcessedOnIP) { |
| 5626 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 5655 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5627 SpawnedTestServer::SSLOptions(), | 5656 https_test_server.ServeFilesFromSourceDirectory( |
| 5628 base::FilePath(kTestFilePath)); | 5657 base::FilePath(kTestFilePath)); |
| 5629 ASSERT_TRUE(https_test_server.Start()); | 5658 ASSERT_TRUE(https_test_server.Start()); |
| 5630 // Make sure this test fails if the test server is changed to not | 5659 // Make sure this test fails if the test server is changed to not |
| 5631 // listen on an IP by default. | 5660 // listen on an IP by default. |
| 5632 ASSERT_TRUE(https_test_server.GetURL("").HostIsIPAddress()); | 5661 ASSERT_TRUE(https_test_server.GetURL("/").HostIsIPAddress()); |
| 5633 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5662 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5634 | 5663 |
| 5635 TestDelegate d; | 5664 TestDelegate d; |
| 5636 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5665 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5637 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, | 5666 https_test_server.GetURL("/hsts-headers.html"), DEFAULT_PRIORITY, &d)); |
| 5638 &d)); | |
| 5639 request->Start(); | 5667 request->Start(); |
| 5640 base::RunLoop().Run(); | 5668 base::RunLoop().Run(); |
| 5641 | |
| 5642 TransportSecurityState* security_state = | 5669 TransportSecurityState* security_state = |
| 5643 default_context_.transport_security_state(); | 5670 default_context_.transport_security_state(); |
| 5644 TransportSecurityState::STSState sts_state; | 5671 TransportSecurityState::STSState sts_state; |
| 5645 EXPECT_FALSE( | 5672 EXPECT_FALSE( |
| 5646 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 5673 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 5647 } | 5674 } |
| 5648 | 5675 |
| 5649 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will | 5676 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will |
| 5650 // reject HPKP headers, and a test setting only HPKP headers will fail (no | 5677 // reject HPKP headers, and a test setting only HPKP headers will fail (no |
| 5651 // PKPState present because header rejected). | 5678 // PKPState present because header rejected). |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5664 #endif | 5691 #endif |
| 5665 | 5692 |
| 5666 namespace { | 5693 namespace { |
| 5667 const char kHPKPReportUri[] = "https://hpkp-report.test"; | 5694 const char kHPKPReportUri[] = "https://hpkp-report.test"; |
| 5668 } // namespace | 5695 } // namespace |
| 5669 | 5696 |
| 5670 // Tests that enabling HPKP on a domain does not affect the HSTS | 5697 // Tests that enabling HPKP on a domain does not affect the HSTS |
| 5671 // validity/expiration. | 5698 // validity/expiration. |
| 5672 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { | 5699 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { |
| 5673 GURL report_uri(kHPKPReportUri); | 5700 GURL report_uri(kHPKPReportUri); |
| 5674 SpawnedTestServer::SSLOptions ssl_options( | 5701 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5675 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5702 https_test_server.SetSSLConfig( |
| 5676 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 5703 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5677 ssl_options, | 5704 https_test_server.ServeFilesFromSourceDirectory( |
| 5678 base::FilePath(kTestFilePath)); | 5705 base::FilePath(kTestFilePath)); |
| 5679 ASSERT_TRUE(https_test_server.Start()); | 5706 ASSERT_TRUE(https_test_server.Start()); |
| 5680 | 5707 |
| 5681 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5708 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5682 | 5709 |
| 5683 TestDelegate d; | 5710 TestDelegate d; |
| 5684 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5711 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5685 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, | 5712 https_test_server.GetURL("/hpkp-headers.html"), DEFAULT_PRIORITY, &d)); |
| 5686 &d)); | |
| 5687 request->Start(); | 5713 request->Start(); |
| 5688 base::RunLoop().Run(); | 5714 base::RunLoop().Run(); |
| 5689 | |
| 5690 TransportSecurityState* security_state = | 5715 TransportSecurityState* security_state = |
| 5691 default_context_.transport_security_state(); | 5716 default_context_.transport_security_state(); |
| 5692 TransportSecurityState::STSState sts_state; | 5717 TransportSecurityState::STSState sts_state; |
| 5693 TransportSecurityState::PKPState pkp_state; | 5718 TransportSecurityState::PKPState pkp_state; |
| 5694 EXPECT_FALSE( | 5719 EXPECT_FALSE( |
| 5695 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 5720 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 5696 EXPECT_TRUE( | 5721 EXPECT_TRUE( |
| 5697 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); | 5722 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); |
| 5698 EXPECT_EQ(TransportSecurityState::STSState::MODE_DEFAULT, | 5723 EXPECT_EQ(TransportSecurityState::STSState::MODE_DEFAULT, |
| 5699 sts_state.upgrade_mode); | 5724 sts_state.upgrade_mode); |
| 5700 EXPECT_FALSE(sts_state.include_subdomains); | 5725 EXPECT_FALSE(sts_state.include_subdomains); |
| 5701 EXPECT_FALSE(pkp_state.include_subdomains); | 5726 EXPECT_FALSE(pkp_state.include_subdomains); |
| 5702 EXPECT_TRUE(pkp_state.HasPublicKeyPins()); | 5727 EXPECT_TRUE(pkp_state.HasPublicKeyPins()); |
| 5703 EXPECT_EQ(report_uri, pkp_state.report_uri); | 5728 EXPECT_EQ(report_uri, pkp_state.report_uri); |
| 5704 EXPECT_NE(sts_state.expiry, pkp_state.expiry); | 5729 EXPECT_NE(sts_state.expiry, pkp_state.expiry); |
| 5705 } | 5730 } |
| 5706 | 5731 |
| 5707 // Tests that reports get sent on HPKP violations when a report-uri is set. | 5732 // Tests that reports get sent on HPKP violations when a report-uri is set. |
| 5708 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKPAndSendReport) { | 5733 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKPAndSendReport) { |
| 5709 GURL report_uri(kHPKPReportUri); | 5734 GURL report_uri(kHPKPReportUri); |
| 5710 SpawnedTestServer::SSLOptions ssl_options( | 5735 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5711 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5736 https_test_server.SetSSLConfig( |
| 5712 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 5737 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5713 ssl_options, | 5738 https_test_server.ServeFilesFromSourceDirectory( |
| 5714 base::FilePath(kTestFilePath)); | 5739 base::FilePath(kTestFilePath)); |
| 5715 | |
| 5716 ASSERT_TRUE(https_test_server.Start()); | 5740 ASSERT_TRUE(https_test_server.Start()); |
| 5717 | 5741 |
| 5718 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5742 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5719 | 5743 |
| 5720 // Set up a pin for |test_server_hostname|. | 5744 // Set up a pin for |test_server_hostname|. |
| 5721 TransportSecurityState security_state; | 5745 TransportSecurityState security_state; |
| 5722 const base::Time current_time(base::Time::Now()); | 5746 const base::Time current_time(base::Time::Now()); |
| 5723 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 5747 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 5724 HashValueVector hashes; | 5748 HashValueVector hashes; |
| 5725 HashValue hash1; | 5749 HashValue hash1; |
| 5726 HashValue hash2; | 5750 HashValue hash2; |
| 5727 // The values here don't matter, as long as they are different from | 5751 // The values here don't matter, as long as they are different from |
| 5728 // the mocked CertVerifyResult below. | 5752 // the mocked CertVerifyResult below. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 5757 TestNetworkDelegate network_delegate; | 5781 TestNetworkDelegate network_delegate; |
| 5758 TestURLRequestContext context(true); | 5782 TestURLRequestContext context(true); |
| 5759 context.set_transport_security_state(&security_state); | 5783 context.set_transport_security_state(&security_state); |
| 5760 context.set_network_delegate(&network_delegate); | 5784 context.set_network_delegate(&network_delegate); |
| 5761 context.set_cert_verifier(&cert_verifier); | 5785 context.set_cert_verifier(&cert_verifier); |
| 5762 context.Init(); | 5786 context.Init(); |
| 5763 | 5787 |
| 5764 // Now send a request to trigger the violation. | 5788 // Now send a request to trigger the violation. |
| 5765 TestDelegate d; | 5789 TestDelegate d; |
| 5766 scoped_ptr<URLRequest> violating_request(context.CreateRequest( | 5790 scoped_ptr<URLRequest> violating_request(context.CreateRequest( |
| 5767 https_test_server.GetURL("files/simple.html"), DEFAULT_PRIORITY, &d)); | 5791 https_test_server.GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); |
| 5768 violating_request->Start(); | 5792 violating_request->Start(); |
| 5769 base::RunLoop().Run(); | 5793 base::RunLoop().Run(); |
| 5770 | 5794 |
| 5771 // Check that a report was sent. | 5795 // Check that a report was sent. |
| 5772 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); | 5796 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); |
| 5773 ASSERT_FALSE(mock_report_sender.latest_report().empty()); | 5797 ASSERT_FALSE(mock_report_sender.latest_report().empty()); |
| 5774 scoped_ptr<base::Value> value( | 5798 scoped_ptr<base::Value> value( |
| 5775 base::JSONReader::Read(mock_report_sender.latest_report())); | 5799 base::JSONReader::Read(mock_report_sender.latest_report())); |
| 5776 ASSERT_TRUE(value); | 5800 ASSERT_TRUE(value); |
| 5777 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 5801 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
| 5778 base::DictionaryValue* report_dict; | 5802 base::DictionaryValue* report_dict; |
| 5779 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); | 5803 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); |
| 5780 std::string report_hostname; | 5804 std::string report_hostname; |
| 5781 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); | 5805 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); |
| 5782 EXPECT_EQ(test_server_hostname, report_hostname); | 5806 EXPECT_EQ(test_server_hostname, report_hostname); |
| 5783 } | 5807 } |
| 5784 | 5808 |
| 5785 // Tests that reports get sent on requests with | 5809 // Tests that reports get sent on requests with |
| 5786 // Public-Key-Pins-Report-Only headers. | 5810 // Public-Key-Pins-Report-Only headers. |
| 5787 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKPReportOnly) { | 5811 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKPReportOnly) { |
| 5788 GURL report_uri(kHPKPReportUri); | 5812 GURL report_uri(kHPKPReportUri); |
| 5789 SpawnedTestServer::SSLOptions ssl_options( | 5813 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5790 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5814 https_test_server.SetSSLConfig( |
| 5791 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 5815 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5792 ssl_options, | 5816 https_test_server.ServeFilesFromSourceDirectory( |
| 5793 base::FilePath(kTestFilePath)); | 5817 base::FilePath(kTestFilePath)); |
| 5794 | |
| 5795 ASSERT_TRUE(https_test_server.Start()); | 5818 ASSERT_TRUE(https_test_server.Start()); |
| 5796 | 5819 |
| 5797 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5820 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5798 | 5821 |
| 5799 TransportSecurityState security_state; | 5822 TransportSecurityState security_state; |
| 5800 MockCertificateReportSender mock_report_sender; | 5823 MockCertificateReportSender mock_report_sender; |
| 5801 security_state.SetReportSender(&mock_report_sender); | 5824 security_state.SetReportSender(&mock_report_sender); |
| 5802 | 5825 |
| 5803 // Set up a MockCertVerifier to violate the pin in the Report-Only | 5826 // Set up a MockCertVerifier to violate the pin in the Report-Only |
| 5804 // header. | 5827 // header. |
| 5805 scoped_refptr<X509Certificate> cert = https_test_server.GetCertificate(); | 5828 scoped_refptr<X509Certificate> cert = https_test_server.GetCertificate(); |
| 5806 ASSERT_TRUE(cert); | 5829 ASSERT_TRUE(cert); |
| 5807 | 5830 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5820 TestNetworkDelegate network_delegate; | 5843 TestNetworkDelegate network_delegate; |
| 5821 TestURLRequestContext context(true); | 5844 TestURLRequestContext context(true); |
| 5822 context.set_transport_security_state(&security_state); | 5845 context.set_transport_security_state(&security_state); |
| 5823 context.set_network_delegate(&network_delegate); | 5846 context.set_network_delegate(&network_delegate); |
| 5824 context.set_cert_verifier(&cert_verifier); | 5847 context.set_cert_verifier(&cert_verifier); |
| 5825 context.Init(); | 5848 context.Init(); |
| 5826 | 5849 |
| 5827 // Now send a request to trigger the violation. | 5850 // Now send a request to trigger the violation. |
| 5828 TestDelegate d; | 5851 TestDelegate d; |
| 5829 scoped_ptr<URLRequest> violating_request(context.CreateRequest( | 5852 scoped_ptr<URLRequest> violating_request(context.CreateRequest( |
| 5830 https_test_server.GetURL("files/hpkp-headers-report-only.html"), | 5853 https_test_server.GetURL("/hpkp-headers-report-only.html"), |
| 5831 DEFAULT_PRIORITY, &d)); | 5854 DEFAULT_PRIORITY, &d)); |
| 5832 violating_request->Start(); | 5855 violating_request->Start(); |
| 5833 base::RunLoop().Run(); | 5856 base::RunLoop().Run(); |
| 5834 | 5857 |
| 5835 // Check that a report was sent. | 5858 // Check that a report was sent. |
| 5836 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); | 5859 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); |
| 5837 ASSERT_FALSE(mock_report_sender.latest_report().empty()); | 5860 ASSERT_FALSE(mock_report_sender.latest_report().empty()); |
| 5838 scoped_ptr<base::Value> value( | 5861 scoped_ptr<base::Value> value( |
| 5839 base::JSONReader::Read(mock_report_sender.latest_report())); | 5862 base::JSONReader::Read(mock_report_sender.latest_report())); |
| 5840 ASSERT_TRUE(value); | 5863 ASSERT_TRUE(value); |
| 5841 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 5864 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
| 5842 base::DictionaryValue* report_dict; | 5865 base::DictionaryValue* report_dict; |
| 5843 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); | 5866 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); |
| 5844 std::string report_hostname; | 5867 std::string report_hostname; |
| 5845 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); | 5868 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); |
| 5846 EXPECT_EQ(test_server_hostname, report_hostname); | 5869 EXPECT_EQ(test_server_hostname, report_hostname); |
| 5847 } | 5870 } |
| 5848 | 5871 |
| 5849 // Tests that reports do not get sent on requests with | 5872 // Tests that reports do not get sent on requests with |
| 5850 // Public-Key-Pins-Report-Only headers that don't have pin violations. | 5873 // Public-Key-Pins-Report-Only headers that don't have pin violations. |
| 5851 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKPReportOnlyWithNoViolation) { | 5874 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKPReportOnlyWithNoViolation) { |
| 5852 GURL report_uri(kHPKPReportUri); | 5875 GURL report_uri(kHPKPReportUri); |
| 5853 SpawnedTestServer::SSLOptions ssl_options( | 5876 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5854 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5877 https_test_server.SetSSLConfig( |
| 5855 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 5878 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5856 ssl_options, | 5879 https_test_server.ServeFilesFromSourceDirectory( |
| 5857 base::FilePath(kTestFilePath)); | 5880 base::FilePath(kTestFilePath)); |
| 5858 | |
| 5859 ASSERT_TRUE(https_test_server.Start()); | 5881 ASSERT_TRUE(https_test_server.Start()); |
| 5860 | 5882 |
| 5861 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5883 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5862 | 5884 |
| 5863 TransportSecurityState security_state; | 5885 TransportSecurityState security_state; |
| 5864 MockCertificateReportSender mock_report_sender; | 5886 MockCertificateReportSender mock_report_sender; |
| 5865 security_state.SetReportSender(&mock_report_sender); | 5887 security_state.SetReportSender(&mock_report_sender); |
| 5866 | 5888 |
| 5867 TestNetworkDelegate network_delegate; | 5889 TestNetworkDelegate network_delegate; |
| 5868 MockCertVerifier mock_cert_verifier; | 5890 MockCertVerifier mock_cert_verifier; |
| 5869 TestURLRequestContext context(true); | 5891 TestURLRequestContext context(true); |
| 5870 context.set_transport_security_state(&security_state); | 5892 context.set_transport_security_state(&security_state); |
| 5871 context.set_network_delegate(&network_delegate); | 5893 context.set_network_delegate(&network_delegate); |
| 5872 context.set_cert_verifier(&mock_cert_verifier); | 5894 context.set_cert_verifier(&mock_cert_verifier); |
| 5873 mock_cert_verifier.set_default_result(OK); | 5895 mock_cert_verifier.set_default_result(OK); |
| 5874 context.Init(); | 5896 context.Init(); |
| 5875 | 5897 |
| 5876 // Now send a request that does not trigger the violation. | 5898 // Now send a request that does not trigger the violation. |
| 5877 TestDelegate d; | 5899 TestDelegate d; |
| 5878 scoped_ptr<URLRequest> request(context.CreateRequest( | 5900 scoped_ptr<URLRequest> request(context.CreateRequest( |
| 5879 https_test_server.GetURL("files/hpkp-headers-report-only.html"), | 5901 https_test_server.GetURL("/hpkp-headers-report-only.html"), |
| 5880 DEFAULT_PRIORITY, &d)); | 5902 DEFAULT_PRIORITY, &d)); |
| 5881 request->Start(); | 5903 request->Start(); |
| 5882 base::RunLoop().Run(); | 5904 base::RunLoop().Run(); |
| 5883 | 5905 |
| 5884 // Check that a report was not sent. | 5906 // Check that a report was not sent. |
| 5885 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); | 5907 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); |
| 5886 EXPECT_EQ(std::string(), mock_report_sender.latest_report()); | 5908 EXPECT_EQ(std::string(), mock_report_sender.latest_report()); |
| 5887 } | 5909 } |
| 5888 | 5910 |
| 5889 TEST_F(URLRequestTestHTTP, PKPNotProcessedOnIP) { | 5911 TEST_F(URLRequestTestHTTP, PKPNotProcessedOnIP) { |
| 5890 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 5912 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5891 SpawnedTestServer::SSLOptions(), | 5913 https_test_server.ServeFilesFromSourceDirectory( |
| 5892 base::FilePath(kTestFilePath)); | 5914 base::FilePath(kTestFilePath)); |
| 5893 ASSERT_TRUE(https_test_server.Start()); | 5915 ASSERT_TRUE(https_test_server.Start()); |
| 5894 // Make sure this test fails if the test server is changed to not | 5916 // Make sure this test fails if the test server is changed to not |
| 5895 // listen on an IP by default. | 5917 // listen on an IP by default. |
| 5896 ASSERT_TRUE(https_test_server.GetURL("").HostIsIPAddress()); | 5918 ASSERT_TRUE(https_test_server.GetURL("/").HostIsIPAddress()); |
| 5897 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5919 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5898 | 5920 |
| 5899 TestDelegate d; | 5921 TestDelegate d; |
| 5900 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5922 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5901 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, | 5923 https_test_server.GetURL("/hpkp-headers.html"), DEFAULT_PRIORITY, &d)); |
| 5902 &d)); | |
| 5903 request->Start(); | 5924 request->Start(); |
| 5904 base::RunLoop().Run(); | 5925 base::RunLoop().Run(); |
| 5905 | 5926 |
| 5906 TransportSecurityState* security_state = | 5927 TransportSecurityState* security_state = |
| 5907 default_context_.transport_security_state(); | 5928 default_context_.transport_security_state(); |
| 5908 TransportSecurityState::PKPState pkp_state; | 5929 TransportSecurityState::PKPState pkp_state; |
| 5909 EXPECT_FALSE( | 5930 EXPECT_FALSE( |
| 5910 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); | 5931 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); |
| 5911 } | 5932 } |
| 5912 | 5933 |
| 5913 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { | 5934 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { |
| 5914 SpawnedTestServer::SSLOptions ssl_options( | 5935 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5915 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5936 https_test_server.SetSSLConfig( |
| 5916 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 5937 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5917 ssl_options, | 5938 https_test_server.ServeFilesFromSourceDirectory( |
| 5918 base::FilePath(kTestFilePath)); | 5939 base::FilePath(kTestFilePath)); |
| 5919 ASSERT_TRUE(https_test_server.Start()); | 5940 ASSERT_TRUE(https_test_server.Start()); |
| 5920 | 5941 |
| 5921 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5942 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5922 | 5943 |
| 5923 TestDelegate d; | 5944 TestDelegate d; |
| 5924 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5945 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5925 https_test_server.GetURL("files/hsts-multiple-headers.html"), | 5946 https_test_server.GetURL("/hsts-multiple-headers.html"), DEFAULT_PRIORITY, |
| 5926 DEFAULT_PRIORITY, &d)); | 5947 &d)); |
| 5927 request->Start(); | 5948 request->Start(); |
| 5928 base::RunLoop().Run(); | 5949 base::RunLoop().Run(); |
| 5929 | 5950 |
| 5930 // We should have set parameters from the first header, not the second. | 5951 // We should have set parameters from the first header, not the second. |
| 5931 TransportSecurityState* security_state = | 5952 TransportSecurityState* security_state = |
| 5932 default_context_.transport_security_state(); | 5953 default_context_.transport_security_state(); |
| 5933 TransportSecurityState::STSState sts_state; | 5954 TransportSecurityState::STSState sts_state; |
| 5934 EXPECT_TRUE( | 5955 EXPECT_TRUE( |
| 5935 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 5956 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 5936 EXPECT_EQ(TransportSecurityState::STSState::MODE_FORCE_HTTPS, | 5957 EXPECT_EQ(TransportSecurityState::STSState::MODE_FORCE_HTTPS, |
| 5937 sts_state.upgrade_mode); | 5958 sts_state.upgrade_mode); |
| 5938 EXPECT_FALSE(sts_state.include_subdomains); | 5959 EXPECT_FALSE(sts_state.include_subdomains); |
| 5939 EXPECT_FALSE(sts_state.include_subdomains); | 5960 EXPECT_FALSE(sts_state.include_subdomains); |
| 5940 } | 5961 } |
| 5941 | 5962 |
| 5942 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { | 5963 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { |
| 5943 SpawnedTestServer::SSLOptions ssl_options( | 5964 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5944 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5965 https_test_server.SetSSLConfig( |
| 5945 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 5966 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5946 ssl_options, | 5967 https_test_server.ServeFilesFromSourceDirectory( |
| 5947 base::FilePath(kTestFilePath)); | 5968 base::FilePath(kTestFilePath)); |
| 5948 ASSERT_TRUE(https_test_server.Start()); | 5969 ASSERT_TRUE(https_test_server.Start()); |
| 5949 | 5970 |
| 5950 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5971 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5951 | 5972 |
| 5952 TestDelegate d; | 5973 TestDelegate d; |
| 5953 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5974 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5954 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), | 5975 https_test_server.GetURL("/hsts-and-hpkp-headers.html"), DEFAULT_PRIORITY, |
| 5955 DEFAULT_PRIORITY, &d)); | 5976 &d)); |
| 5956 request->Start(); | 5977 request->Start(); |
| 5957 base::RunLoop().Run(); | 5978 base::RunLoop().Run(); |
| 5958 | 5979 |
| 5959 // We should have set parameters from the first header, not the second. | 5980 // We should have set parameters from the first header, not the second. |
| 5960 TransportSecurityState* security_state = | 5981 TransportSecurityState* security_state = |
| 5961 default_context_.transport_security_state(); | 5982 default_context_.transport_security_state(); |
| 5962 TransportSecurityState::STSState sts_state; | 5983 TransportSecurityState::STSState sts_state; |
| 5963 TransportSecurityState::PKPState pkp_state; | 5984 TransportSecurityState::PKPState pkp_state; |
| 5964 EXPECT_TRUE( | 5985 EXPECT_TRUE( |
| 5965 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 5986 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5977 // Even though there is an HSTS header asserting includeSubdomains, it is | 5998 // Even though there is an HSTS header asserting includeSubdomains, it is |
| 5978 // the *second* such header, and we MUST process only the first. | 5999 // the *second* such header, and we MUST process only the first. |
| 5979 EXPECT_FALSE(sts_state.include_subdomains); | 6000 EXPECT_FALSE(sts_state.include_subdomains); |
| 5980 // includeSubdomains does not occur in the test HPKP header. | 6001 // includeSubdomains does not occur in the test HPKP header. |
| 5981 EXPECT_FALSE(pkp_state.include_subdomains); | 6002 EXPECT_FALSE(pkp_state.include_subdomains); |
| 5982 } | 6003 } |
| 5983 | 6004 |
| 5984 // Tests that when multiple HPKP headers are present, asserting different | 6005 // Tests that when multiple HPKP headers are present, asserting different |
| 5985 // policies, that only the first such policy is processed. | 6006 // policies, that only the first such policy is processed. |
| 5986 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) { | 6007 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) { |
| 5987 SpawnedTestServer::SSLOptions ssl_options( | 6008 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5988 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 6009 https_test_server.SetSSLConfig( |
| 5989 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 6010 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5990 ssl_options, | 6011 https_test_server.ServeFilesFromSourceDirectory( |
| 5991 base::FilePath(kTestFilePath)); | 6012 base::FilePath(kTestFilePath)); |
| 5992 ASSERT_TRUE(https_test_server.Start()); | 6013 ASSERT_TRUE(https_test_server.Start()); |
| 5993 | 6014 |
| 5994 std::string test_server_hostname = https_test_server.GetURL("").host(); | 6015 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5995 | 6016 |
| 5996 TestDelegate d; | 6017 TestDelegate d; |
| 5997 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 6018 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5998 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), | 6019 https_test_server.GetURL("/hsts-and-hpkp-headers2.html"), |
| 5999 DEFAULT_PRIORITY, &d)); | 6020 DEFAULT_PRIORITY, &d)); |
| 6000 request->Start(); | 6021 request->Start(); |
| 6001 base::RunLoop().Run(); | 6022 base::RunLoop().Run(); |
| 6002 | 6023 |
| 6003 TransportSecurityState* security_state = | 6024 TransportSecurityState* security_state = |
| 6004 default_context_.transport_security_state(); | 6025 default_context_.transport_security_state(); |
| 6005 TransportSecurityState::STSState sts_state; | 6026 TransportSecurityState::STSState sts_state; |
| 6006 TransportSecurityState::PKPState pkp_state; | 6027 TransportSecurityState::PKPState pkp_state; |
| 6007 EXPECT_TRUE( | 6028 EXPECT_TRUE( |
| 6008 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 6029 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 6009 EXPECT_TRUE( | 6030 EXPECT_TRUE( |
| 6010 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); | 6031 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); |
| 6011 EXPECT_EQ(TransportSecurityState::STSState::MODE_FORCE_HTTPS, | 6032 EXPECT_EQ(TransportSecurityState::STSState::MODE_FORCE_HTTPS, |
| 6012 sts_state.upgrade_mode); | 6033 sts_state.upgrade_mode); |
| 6013 #if defined(OS_ANDROID) | 6034 #if defined(OS_ANDROID) |
| 6014 // Android's CertVerifyProc does not (yet) handle pins. | 6035 // Android's CertVerifyProc does not (yet) handle pins. |
| 6015 #else | 6036 #else |
| 6016 EXPECT_TRUE(pkp_state.HasPublicKeyPins()); | 6037 EXPECT_TRUE(pkp_state.HasPublicKeyPins()); |
| 6017 #endif | 6038 #endif |
| 6018 EXPECT_NE(sts_state.expiry, pkp_state.expiry); | 6039 EXPECT_NE(sts_state.expiry, pkp_state.expiry); |
| 6019 | 6040 |
| 6020 EXPECT_TRUE(sts_state.include_subdomains); | 6041 EXPECT_TRUE(sts_state.include_subdomains); |
| 6021 EXPECT_FALSE(pkp_state.include_subdomains); | 6042 EXPECT_FALSE(pkp_state.include_subdomains); |
| 6022 } | 6043 } |
| 6023 | 6044 |
| 6045 #endif // !defined(OS_IOS) |
| 6046 |
| 6024 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { | 6047 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { |
| 6025 ASSERT_TRUE(test_server_.Start()); | 6048 ASSERT_TRUE(http_test_server()->Start()); |
| 6026 | 6049 |
| 6027 TestDelegate d; | 6050 TestDelegate d; |
| 6028 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6051 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6029 test_server_.GetURL("files/content-type-normalization.html"), | 6052 http_test_server()->GetURL("/content-type-normalization.html"), |
| 6030 DEFAULT_PRIORITY, &d)); | 6053 DEFAULT_PRIORITY, &d)); |
| 6031 req->Start(); | 6054 req->Start(); |
| 6032 base::RunLoop().Run(); | 6055 base::RunLoop().Run(); |
| 6033 | 6056 |
| 6034 std::string mime_type; | 6057 std::string mime_type; |
| 6035 req->GetMimeType(&mime_type); | 6058 req->GetMimeType(&mime_type); |
| 6036 EXPECT_EQ("text/html", mime_type); | 6059 EXPECT_EQ("text/html", mime_type); |
| 6037 | 6060 |
| 6038 std::string charset; | 6061 std::string charset; |
| 6039 req->GetCharset(&charset); | 6062 req->GetCharset(&charset); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6057 GURL file_url("file:///foo.txt"); | 6080 GURL file_url("file:///foo.txt"); |
| 6058 FileProtocolHandler file_protocol_handler( | 6081 FileProtocolHandler file_protocol_handler( |
| 6059 base::ThreadTaskRunnerHandle::Get()); | 6082 base::ThreadTaskRunnerHandle::Get()); |
| 6060 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); | 6083 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); |
| 6061 | 6084 |
| 6062 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). | 6085 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
| 6063 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(file_url)); | 6086 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(file_url)); |
| 6064 } | 6087 } |
| 6065 | 6088 |
| 6066 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { | 6089 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { |
| 6067 ASSERT_TRUE(test_server_.Start()); | 6090 ASSERT_TRUE(http_test_server()->Start()); |
| 6068 | 6091 |
| 6069 TestDelegate d; | 6092 TestDelegate d; |
| 6070 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6093 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6071 test_server_.GetURL("files/redirect-to-file.html"), DEFAULT_PRIORITY, | 6094 http_test_server()->GetURL("/redirect-to-file.html"), DEFAULT_PRIORITY, |
| 6072 &d)); | 6095 &d)); |
| 6073 req->Start(); | 6096 req->Start(); |
| 6074 base::RunLoop().Run(); | 6097 base::RunLoop().Run(); |
| 6075 | 6098 |
| 6076 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); | 6099 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 6077 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error()); | 6100 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error()); |
| 6078 } | 6101 } |
| 6079 #endif // !defined(DISABLE_FILE_SUPPORT) | 6102 #endif // !defined(DISABLE_FILE_SUPPORT) |
| 6080 | 6103 |
| 6081 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { | 6104 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { |
| 6082 ASSERT_TRUE(test_server_.Start()); | 6105 ASSERT_TRUE(http_test_server()->Start()); |
| 6083 | 6106 |
| 6084 TestDelegate d; | 6107 TestDelegate d; |
| 6085 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6108 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6086 test_server_.GetURL("files/redirect-to-data.html"), DEFAULT_PRIORITY, | 6109 http_test_server()->GetURL("/redirect-to-data.html"), DEFAULT_PRIORITY, |
| 6087 &d)); | 6110 &d)); |
| 6088 req->Start(); | 6111 req->Start(); |
| 6089 base::MessageLoop::current()->Run(); | 6112 base::MessageLoop::current()->Run(); |
| 6090 | 6113 |
| 6091 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); | 6114 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 6092 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error()); | 6115 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error()); |
| 6093 } | 6116 } |
| 6094 | 6117 |
| 6095 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 6118 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
| 6096 ASSERT_TRUE(test_server_.Start()); | 6119 ASSERT_TRUE(http_test_server()->Start()); |
| 6097 | 6120 |
| 6098 TestDelegate d; | 6121 TestDelegate d; |
| 6099 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6122 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6100 test_server_.GetURL("files/redirect-to-invalid-url.html"), | 6123 http_test_server()->GetURL("/redirect-to-invalid-url.html"), |
| 6101 DEFAULT_PRIORITY, &d)); | 6124 DEFAULT_PRIORITY, &d)); |
| 6102 req->Start(); | 6125 req->Start(); |
| 6103 base::RunLoop().Run(); | 6126 base::RunLoop().Run(); |
| 6104 | 6127 |
| 6105 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); | 6128 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 6106 EXPECT_EQ(ERR_INVALID_URL, req->status().error()); | 6129 EXPECT_EQ(ERR_INVALID_URL, req->status().error()); |
| 6107 } | 6130 } |
| 6108 | 6131 |
| 6109 // Make sure redirects are cached, despite not reading their bodies. | 6132 // Make sure redirects are cached, despite not reading their bodies. |
| 6110 TEST_F(URLRequestTestHTTP, CacheRedirect) { | 6133 TEST_F(URLRequestTestHTTP, CacheRedirect) { |
| 6111 ASSERT_TRUE(test_server_.Start()); | 6134 ASSERT_TRUE(http_test_server()->Start()); |
| 6112 GURL redirect_url = | 6135 GURL redirect_url = |
| 6113 test_server_.GetURL("files/redirect302-to-echo-cacheable"); | 6136 http_test_server()->GetURL("/redirect302-to-echo-cacheable"); |
| 6114 | 6137 |
| 6115 { | 6138 { |
| 6116 TestDelegate d; | 6139 TestDelegate d; |
| 6117 scoped_ptr<URLRequest> req( | 6140 scoped_ptr<URLRequest> req( |
| 6118 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 6141 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); |
| 6119 req->Start(); | 6142 req->Start(); |
| 6120 base::RunLoop().Run(); | 6143 base::RunLoop().Run(); |
| 6121 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6144 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6122 EXPECT_EQ(1, d.received_redirect_count()); | 6145 EXPECT_EQ(1, d.received_redirect_count()); |
| 6123 EXPECT_EQ(test_server_.GetURL("echo"), req->url()); | 6146 EXPECT_EQ(http_test_server()->GetURL("/echo"), req->url()); |
| 6124 } | 6147 } |
| 6125 | 6148 |
| 6126 { | 6149 { |
| 6127 TestDelegate d; | 6150 TestDelegate d; |
| 6128 d.set_quit_on_redirect(true); | 6151 d.set_quit_on_redirect(true); |
| 6129 scoped_ptr<URLRequest> req( | 6152 scoped_ptr<URLRequest> req( |
| 6130 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 6153 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); |
| 6131 req->Start(); | 6154 req->Start(); |
| 6132 base::RunLoop().Run(); | 6155 base::RunLoop().Run(); |
| 6133 | 6156 |
| 6134 EXPECT_EQ(1, d.received_redirect_count()); | 6157 EXPECT_EQ(1, d.received_redirect_count()); |
| 6135 EXPECT_EQ(0, d.response_started_count()); | 6158 EXPECT_EQ(0, d.response_started_count()); |
| 6136 EXPECT_TRUE(req->was_cached()); | 6159 EXPECT_TRUE(req->was_cached()); |
| 6137 | 6160 |
| 6138 req->FollowDeferredRedirect(); | 6161 req->FollowDeferredRedirect(); |
| 6139 base::RunLoop().Run(); | 6162 base::RunLoop().Run(); |
| 6140 EXPECT_EQ(1, d.received_redirect_count()); | 6163 EXPECT_EQ(1, d.received_redirect_count()); |
| 6141 EXPECT_EQ(1, d.response_started_count()); | 6164 EXPECT_EQ(1, d.response_started_count()); |
| 6142 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6165 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6143 EXPECT_EQ(test_server_.GetURL("echo"), req->url()); | 6166 EXPECT_EQ(http_test_server()->GetURL("/echo"), req->url()); |
| 6144 } | 6167 } |
| 6145 } | 6168 } |
| 6146 | 6169 |
| 6147 // Make sure a request isn't cached when a NetworkDelegate forces a redirect | 6170 // Make sure a request isn't cached when a NetworkDelegate forces a redirect |
| 6148 // when the headers are read, since the body won't have been read. | 6171 // when the headers are read, since the body won't have been read. |
| 6149 TEST_F(URLRequestTestHTTP, NoCacheOnNetworkDelegateRedirect) { | 6172 TEST_F(URLRequestTestHTTP, NoCacheOnNetworkDelegateRedirect) { |
| 6150 ASSERT_TRUE(test_server_.Start()); | 6173 ASSERT_TRUE(http_test_server()->Start()); |
| 6151 // URL that is normally cached. | 6174 // URL that is normally cached. |
| 6152 GURL initial_url = test_server_.GetURL("cachetime"); | 6175 GURL initial_url = http_test_server()->GetURL("/cachetime"); |
| 6153 | 6176 |
| 6154 { | 6177 { |
| 6155 // Set up the TestNetworkDelegate tp force a redirect. | 6178 // Set up the TestNetworkDelegate tp force a redirect. |
| 6156 GURL redirect_to_url = test_server_.GetURL("echo"); | 6179 GURL redirect_to_url = http_test_server()->GetURL("/echo"); |
| 6157 default_network_delegate_.set_redirect_on_headers_received_url( | 6180 default_network_delegate_.set_redirect_on_headers_received_url( |
| 6158 redirect_to_url); | 6181 redirect_to_url); |
| 6159 | 6182 |
| 6160 TestDelegate d; | 6183 TestDelegate d; |
| 6161 scoped_ptr<URLRequest> req( | 6184 scoped_ptr<URLRequest> req( |
| 6162 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d)); | 6185 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d)); |
| 6163 req->Start(); | 6186 req->Start(); |
| 6164 base::RunLoop().Run(); | 6187 base::RunLoop().Run(); |
| 6165 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6188 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6166 EXPECT_EQ(1, d.received_redirect_count()); | 6189 EXPECT_EQ(1, d.received_redirect_count()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6177 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6200 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6178 EXPECT_FALSE(req->was_cached()); | 6201 EXPECT_FALSE(req->was_cached()); |
| 6179 EXPECT_EQ(0, d.received_redirect_count()); | 6202 EXPECT_EQ(0, d.received_redirect_count()); |
| 6180 EXPECT_EQ(initial_url, req->url()); | 6203 EXPECT_EQ(initial_url, req->url()); |
| 6181 } | 6204 } |
| 6182 } | 6205 } |
| 6183 | 6206 |
| 6184 // Tests that redirection to an unsafe URL is allowed when it has been marked as | 6207 // Tests that redirection to an unsafe URL is allowed when it has been marked as |
| 6185 // safe. | 6208 // safe. |
| 6186 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { | 6209 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { |
| 6187 ASSERT_TRUE(test_server_.Start()); | 6210 ASSERT_TRUE(http_test_server()->Start()); |
| 6188 | 6211 |
| 6189 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); | 6212 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); |
| 6190 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 6213 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 6191 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 6214 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 6192 | 6215 |
| 6193 TestDelegate d; | 6216 TestDelegate d; |
| 6194 { | 6217 { |
| 6195 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 6218 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6196 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d)); | 6219 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d)); |
| 6197 | 6220 |
| 6198 r->Start(); | 6221 r->Start(); |
| 6199 base::RunLoop().Run(); | 6222 base::RunLoop().Run(); |
| 6200 | 6223 |
| 6201 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 6224 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 6202 | 6225 |
| 6203 EXPECT_EQ(2U, r->url_chain().size()); | 6226 EXPECT_EQ(2U, r->url_chain().size()); |
| 6204 EXPECT_EQ(OK, r->status().error()); | 6227 EXPECT_EQ(OK, r->status().error()); |
| 6205 EXPECT_EQ(unsafe_url, r->url()); | 6228 EXPECT_EQ(unsafe_url, r->url()); |
| 6206 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); | 6229 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); |
| 6207 } | 6230 } |
| 6208 } | 6231 } |
| 6209 | 6232 |
| 6210 // Tests that a redirect to a different unsafe URL is blocked, even after adding | 6233 // Tests that a redirect to a different unsafe URL is blocked, even after adding |
| 6211 // some other URL to the whitelist. | 6234 // some other URL to the whitelist. |
| 6212 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { | 6235 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { |
| 6213 ASSERT_TRUE(test_server_.Start()); | 6236 ASSERT_TRUE(http_test_server()->Start()); |
| 6214 | 6237 |
| 6215 GURL unsafe_url("data:text/html,something"); | 6238 GURL unsafe_url("data:text/html,something"); |
| 6216 GURL different_unsafe_url("data:text/html,something-else"); | 6239 GURL different_unsafe_url("data:text/html,something-else"); |
| 6217 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 6240 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 6218 default_network_delegate_.set_allowed_unsafe_redirect_url( | 6241 default_network_delegate_.set_allowed_unsafe_redirect_url( |
| 6219 different_unsafe_url); | 6242 different_unsafe_url); |
| 6220 | 6243 |
| 6221 TestDelegate d; | 6244 TestDelegate d; |
| 6222 { | 6245 { |
| 6223 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 6246 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6224 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d)); | 6247 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d)); |
| 6225 | 6248 |
| 6226 r->Start(); | 6249 r->Start(); |
| 6227 base::RunLoop().Run(); | 6250 base::RunLoop().Run(); |
| 6228 | 6251 |
| 6229 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 6252 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 6230 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r->status().error()); | 6253 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r->status().error()); |
| 6231 } | 6254 } |
| 6232 } | 6255 } |
| 6233 | 6256 |
| 6234 // Redirects from an URL with fragment to an unsafe URL with fragment should | 6257 // Redirects from an URL with fragment to an unsafe URL with fragment should |
| 6235 // be allowed, and the reference fragment of the target URL should be preserved. | 6258 // be allowed, and the reference fragment of the target URL should be preserved. |
| 6236 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { | 6259 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { |
| 6237 ASSERT_TRUE(test_server_.Start()); | 6260 ASSERT_TRUE(http_test_server()->Start()); |
| 6238 | 6261 |
| 6239 GURL original_url(test_server_.GetURL("original#fragment1")); | 6262 GURL original_url(http_test_server()->GetURL("/original#fragment1")); |
| 6240 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | 6263 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); |
| 6241 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | 6264 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); |
| 6242 | 6265 |
| 6243 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 6266 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 6244 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 6267 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 6245 | 6268 |
| 6246 TestDelegate d; | 6269 TestDelegate d; |
| 6247 { | 6270 { |
| 6248 scoped_ptr<URLRequest> r( | 6271 scoped_ptr<URLRequest> r( |
| 6249 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 6272 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 6250 | 6273 |
| 6251 r->Start(); | 6274 r->Start(); |
| 6252 base::RunLoop().Run(); | 6275 base::RunLoop().Run(); |
| 6253 | 6276 |
| 6254 EXPECT_EQ(2U, r->url_chain().size()); | 6277 EXPECT_EQ(2U, r->url_chain().size()); |
| 6255 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 6278 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 6256 EXPECT_EQ(OK, r->status().error()); | 6279 EXPECT_EQ(OK, r->status().error()); |
| 6257 EXPECT_EQ(original_url, r->original_url()); | 6280 EXPECT_EQ(original_url, r->original_url()); |
| 6258 EXPECT_EQ(expected_url, r->url()); | 6281 EXPECT_EQ(expected_url, r->url()); |
| 6259 } | 6282 } |
| 6260 } | 6283 } |
| 6261 | 6284 |
| 6262 // When a delegate has specified a safe redirect URL, but it does not match the | 6285 // When a delegate has specified a safe redirect URL, but it does not match the |
| 6263 // redirect target, then do not prevent the reference fragment from being added. | 6286 // redirect target, then do not prevent the reference fragment from being added. |
| 6264 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) { | 6287 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) { |
| 6265 ASSERT_TRUE(test_server_.Start()); | 6288 ASSERT_TRUE(http_test_server()->Start()); |
| 6266 | 6289 |
| 6267 GURL original_url(test_server_.GetURL("original#expected-fragment")); | 6290 GURL original_url(http_test_server()->GetURL("/original#expected-fragment")); |
| 6268 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); | 6291 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); |
| 6269 GURL redirect_url(test_server_.GetURL("target")); | 6292 GURL redirect_url(http_test_server()->GetURL("/target")); |
| 6270 GURL expected_redirect_url(test_server_.GetURL("target#expected-fragment")); | 6293 GURL expected_redirect_url( |
| 6294 http_test_server()->GetURL("/target#expected-fragment")); |
| 6271 | 6295 |
| 6272 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); | 6296 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); |
| 6273 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 6297 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 6274 | 6298 |
| 6275 TestDelegate d; | 6299 TestDelegate d; |
| 6276 { | 6300 { |
| 6277 scoped_ptr<URLRequest> r( | 6301 scoped_ptr<URLRequest> r( |
| 6278 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 6302 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 6279 | 6303 |
| 6280 r->Start(); | 6304 r->Start(); |
| 6281 base::RunLoop().Run(); | 6305 base::RunLoop().Run(); |
| 6282 | 6306 |
| 6283 EXPECT_EQ(2U, r->url_chain().size()); | 6307 EXPECT_EQ(2U, r->url_chain().size()); |
| 6284 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 6308 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 6285 EXPECT_EQ(OK, r->status().error()); | 6309 EXPECT_EQ(OK, r->status().error()); |
| 6286 EXPECT_EQ(original_url, r->original_url()); | 6310 EXPECT_EQ(original_url, r->original_url()); |
| 6287 EXPECT_EQ(expected_redirect_url, r->url()); | 6311 EXPECT_EQ(expected_redirect_url, r->url()); |
| 6288 } | 6312 } |
| 6289 } | 6313 } |
| 6290 | 6314 |
| 6291 // When a delegate has specified a safe redirect URL, assume that the redirect | 6315 // When a delegate has specified a safe redirect URL, assume that the redirect |
| 6292 // URL should not be changed. In particular, the reference fragment should not | 6316 // URL should not be changed. In particular, the reference fragment should not |
| 6293 // be modified. | 6317 // be modified. |
| 6294 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { | 6318 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { |
| 6295 ASSERT_TRUE(test_server_.Start()); | 6319 ASSERT_TRUE(http_test_server()->Start()); |
| 6296 | 6320 |
| 6297 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); | 6321 GURL original_url( |
| 6322 http_test_server()->GetURL("/original#should-not-be-appended")); |
| 6298 GURL redirect_url("data:text/html,expect-no-reference-fragment"); | 6323 GURL redirect_url("data:text/html,expect-no-reference-fragment"); |
| 6299 | 6324 |
| 6300 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); | 6325 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); |
| 6301 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); | 6326 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); |
| 6302 | 6327 |
| 6303 TestDelegate d; | 6328 TestDelegate d; |
| 6304 { | 6329 { |
| 6305 scoped_ptr<URLRequest> r( | 6330 scoped_ptr<URLRequest> r( |
| 6306 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 6331 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 6307 | 6332 |
| 6308 r->Start(); | 6333 r->Start(); |
| 6309 base::RunLoop().Run(); | 6334 base::RunLoop().Run(); |
| 6310 | 6335 |
| 6311 EXPECT_EQ(2U, r->url_chain().size()); | 6336 EXPECT_EQ(2U, r->url_chain().size()); |
| 6312 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 6337 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 6313 EXPECT_EQ(OK, r->status().error()); | 6338 EXPECT_EQ(OK, r->status().error()); |
| 6314 EXPECT_EQ(original_url, r->original_url()); | 6339 EXPECT_EQ(original_url, r->original_url()); |
| 6315 EXPECT_EQ(redirect_url, r->url()); | 6340 EXPECT_EQ(redirect_url, r->url()); |
| 6316 } | 6341 } |
| 6317 } | 6342 } |
| 6318 | 6343 |
| 6319 // When a URLRequestRedirectJob is created, the redirection must be followed and | 6344 // When a URLRequestRedirectJob is created, the redirection must be followed and |
| 6320 // the reference fragment of the target URL must not be modified. | 6345 // the reference fragment of the target URL must not be modified. |
| 6321 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { | 6346 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { |
| 6322 ASSERT_TRUE(test_server_.Start()); | 6347 ASSERT_TRUE(http_test_server()->Start()); |
| 6323 | 6348 |
| 6324 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); | 6349 GURL original_url( |
| 6325 GURL redirect_url(test_server_.GetURL("echo")); | 6350 http_test_server()->GetURL("/original#should-not-be-appended")); |
| 6351 GURL redirect_url(http_test_server()->GetURL("/echo")); |
| 6326 | 6352 |
| 6327 TestDelegate d; | 6353 TestDelegate d; |
| 6328 scoped_ptr<URLRequest> r( | 6354 scoped_ptr<URLRequest> r( |
| 6329 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 6355 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 6330 | 6356 |
| 6331 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 6357 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 6332 r.get(), &default_network_delegate_, redirect_url, | 6358 r.get(), &default_network_delegate_, redirect_url, |
| 6333 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); | 6359 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); |
| 6334 AddTestInterceptor()->set_main_intercept_job(job); | 6360 AddTestInterceptor()->set_main_intercept_job(job); |
| 6335 | 6361 |
| 6336 r->Start(); | 6362 r->Start(); |
| 6337 base::RunLoop().Run(); | 6363 base::RunLoop().Run(); |
| 6338 | 6364 |
| 6339 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 6365 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 6340 EXPECT_EQ(OK, r->status().error()); | 6366 EXPECT_EQ(OK, r->status().error()); |
| 6341 EXPECT_EQ(original_url, r->original_url()); | 6367 EXPECT_EQ(original_url, r->original_url()); |
| 6342 EXPECT_EQ(redirect_url, r->url()); | 6368 EXPECT_EQ(redirect_url, r->url()); |
| 6343 } | 6369 } |
| 6344 | 6370 |
| 6345 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 6371 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
| 6346 ASSERT_TRUE(test_server_.Start()); | 6372 ASSERT_TRUE(http_test_server()->Start()); |
| 6347 | 6373 |
| 6348 TestDelegate d; | 6374 TestDelegate d; |
| 6349 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6375 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6350 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 6376 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); |
| 6351 req->SetReferrer("http://user:pass@foo.com/"); | 6377 req->SetReferrer("http://user:pass@foo.com/"); |
| 6352 req->Start(); | 6378 req->Start(); |
| 6353 base::RunLoop().Run(); | 6379 base::RunLoop().Run(); |
| 6354 | 6380 |
| 6355 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 6381 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
| 6356 } | 6382 } |
| 6357 | 6383 |
| 6358 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { | 6384 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { |
| 6359 ASSERT_TRUE(test_server_.Start()); | 6385 ASSERT_TRUE(http_test_server()->Start()); |
| 6360 | 6386 |
| 6361 TestDelegate d; | 6387 TestDelegate d; |
| 6362 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6388 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6363 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 6389 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); |
| 6364 req->SetReferrer("http://foo.com/test#fragment"); | 6390 req->SetReferrer("http://foo.com/test#fragment"); |
| 6365 req->Start(); | 6391 req->Start(); |
| 6366 base::RunLoop().Run(); | 6392 base::RunLoop().Run(); |
| 6367 | 6393 |
| 6368 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); | 6394 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); |
| 6369 } | 6395 } |
| 6370 | 6396 |
| 6371 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { | 6397 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { |
| 6372 ASSERT_TRUE(test_server_.Start()); | 6398 ASSERT_TRUE(http_test_server()->Start()); |
| 6373 | 6399 |
| 6374 TestDelegate d; | 6400 TestDelegate d; |
| 6375 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6401 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6376 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 6402 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); |
| 6377 req->SetReferrer("http://foo.com/test#fragment"); | 6403 req->SetReferrer("http://foo.com/test#fragment"); |
| 6378 req->SetReferrer(""); | 6404 req->SetReferrer(""); |
| 6379 req->Start(); | 6405 req->Start(); |
| 6380 base::RunLoop().Run(); | 6406 base::RunLoop().Run(); |
| 6381 | 6407 |
| 6382 EXPECT_EQ(std::string("None"), d.data_received()); | 6408 EXPECT_EQ(std::string("None"), d.data_received()); |
| 6383 } | 6409 } |
| 6384 | 6410 |
| 6385 // Defer network start and then resume, checking that the request was a success | 6411 // Defer network start and then resume, checking that the request was a success |
| 6386 // and bytes were received. | 6412 // and bytes were received. |
| 6387 TEST_F(URLRequestTestHTTP, DeferredBeforeNetworkStart) { | 6413 TEST_F(URLRequestTestHTTP, DeferredBeforeNetworkStart) { |
| 6388 ASSERT_TRUE(test_server_.Start()); | 6414 ASSERT_TRUE(http_test_server()->Start()); |
| 6389 | 6415 |
| 6390 TestDelegate d; | 6416 TestDelegate d; |
| 6391 { | 6417 { |
| 6392 d.set_quit_on_network_start(true); | 6418 d.set_quit_on_network_start(true); |
| 6393 GURL test_url(test_server_.GetURL("echo")); | 6419 GURL test_url(http_test_server()->GetURL("/echo")); |
| 6394 scoped_ptr<URLRequest> req( | 6420 scoped_ptr<URLRequest> req( |
| 6395 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 6421 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); |
| 6396 | 6422 |
| 6397 req->Start(); | 6423 req->Start(); |
| 6398 base::RunLoop().Run(); | 6424 base::RunLoop().Run(); |
| 6399 | 6425 |
| 6400 EXPECT_EQ(1, d.received_before_network_start_count()); | 6426 EXPECT_EQ(1, d.received_before_network_start_count()); |
| 6401 EXPECT_EQ(0, d.response_started_count()); | 6427 EXPECT_EQ(0, d.response_started_count()); |
| 6402 | 6428 |
| 6403 req->ResumeNetworkStart(); | 6429 req->ResumeNetworkStart(); |
| 6404 base::RunLoop().Run(); | 6430 base::RunLoop().Run(); |
| 6405 | 6431 |
| 6406 EXPECT_EQ(1, d.response_started_count()); | 6432 EXPECT_EQ(1, d.response_started_count()); |
| 6407 EXPECT_NE(0, d.bytes_received()); | 6433 EXPECT_NE(0, d.bytes_received()); |
| 6408 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6434 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6409 } | 6435 } |
| 6410 } | 6436 } |
| 6411 | 6437 |
| 6412 // Check that OnBeforeNetworkStart is only called once even if there is a | 6438 // Check that OnBeforeNetworkStart is only called once even if there is a |
| 6413 // redirect. | 6439 // redirect. |
| 6414 TEST_F(URLRequestTestHTTP, BeforeNetworkStartCalledOnce) { | 6440 TEST_F(URLRequestTestHTTP, BeforeNetworkStartCalledOnce) { |
| 6415 ASSERT_TRUE(test_server_.Start()); | 6441 ASSERT_TRUE(http_test_server()->Start()); |
| 6416 | 6442 |
| 6417 TestDelegate d; | 6443 TestDelegate d; |
| 6418 { | 6444 { |
| 6419 d.set_quit_on_redirect(true); | 6445 d.set_quit_on_redirect(true); |
| 6420 d.set_quit_on_network_start(true); | 6446 d.set_quit_on_network_start(true); |
| 6421 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6447 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6422 test_server_.GetURL("server-redirect?echo"), DEFAULT_PRIORITY, &d)); | 6448 http_test_server()->GetURL("/server-redirect?echo"), DEFAULT_PRIORITY, |
| 6449 &d)); |
| 6423 | 6450 |
| 6424 req->Start(); | 6451 req->Start(); |
| 6425 base::RunLoop().Run(); | 6452 base::RunLoop().Run(); |
| 6426 | 6453 |
| 6427 EXPECT_EQ(1, d.received_before_network_start_count()); | 6454 EXPECT_EQ(1, d.received_before_network_start_count()); |
| 6428 EXPECT_EQ(0, d.response_started_count()); | 6455 EXPECT_EQ(0, d.response_started_count()); |
| 6429 EXPECT_EQ(0, d.received_redirect_count()); | 6456 EXPECT_EQ(0, d.received_redirect_count()); |
| 6430 | 6457 |
| 6431 req->ResumeNetworkStart(); | 6458 req->ResumeNetworkStart(); |
| 6432 base::RunLoop().Run(); | 6459 base::RunLoop().Run(); |
| 6433 | 6460 |
| 6434 EXPECT_EQ(1, d.received_redirect_count()); | 6461 EXPECT_EQ(1, d.received_redirect_count()); |
| 6435 req->FollowDeferredRedirect(); | 6462 req->FollowDeferredRedirect(); |
| 6436 base::RunLoop().Run(); | 6463 base::RunLoop().Run(); |
| 6437 | 6464 |
| 6438 // Check that the redirect's new network transaction does not get propagated | 6465 // Check that the redirect's new network transaction does not get propagated |
| 6439 // to a second OnBeforeNetworkStart() notification. | 6466 // to a second OnBeforeNetworkStart() notification. |
| 6440 EXPECT_EQ(1, d.received_before_network_start_count()); | 6467 EXPECT_EQ(1, d.received_before_network_start_count()); |
| 6441 | 6468 |
| 6442 EXPECT_EQ(1, d.response_started_count()); | 6469 EXPECT_EQ(1, d.response_started_count()); |
| 6443 EXPECT_NE(0, d.bytes_received()); | 6470 EXPECT_NE(0, d.bytes_received()); |
| 6444 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6471 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6445 } | 6472 } |
| 6446 } | 6473 } |
| 6447 | 6474 |
| 6448 // Cancel the request after learning that the request would use the network. | 6475 // Cancel the request after learning that the request would use the network. |
| 6449 TEST_F(URLRequestTestHTTP, CancelOnBeforeNetworkStart) { | 6476 TEST_F(URLRequestTestHTTP, CancelOnBeforeNetworkStart) { |
| 6450 ASSERT_TRUE(test_server_.Start()); | 6477 ASSERT_TRUE(http_test_server()->Start()); |
| 6451 | 6478 |
| 6452 TestDelegate d; | 6479 TestDelegate d; |
| 6453 { | 6480 { |
| 6454 d.set_quit_on_network_start(true); | 6481 d.set_quit_on_network_start(true); |
| 6455 GURL test_url(test_server_.GetURL("echo")); | 6482 GURL test_url(http_test_server()->GetURL("/echo")); |
| 6456 scoped_ptr<URLRequest> req( | 6483 scoped_ptr<URLRequest> req( |
| 6457 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 6484 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); |
| 6458 | 6485 |
| 6459 req->Start(); | 6486 req->Start(); |
| 6460 base::RunLoop().Run(); | 6487 base::RunLoop().Run(); |
| 6461 | 6488 |
| 6462 EXPECT_EQ(1, d.received_before_network_start_count()); | 6489 EXPECT_EQ(1, d.received_before_network_start_count()); |
| 6463 EXPECT_EQ(0, d.response_started_count()); | 6490 EXPECT_EQ(0, d.response_started_count()); |
| 6464 | 6491 |
| 6465 req->Cancel(); | 6492 req->Cancel(); |
| 6466 base::RunLoop().Run(); | 6493 base::RunLoop().Run(); |
| 6467 | 6494 |
| 6468 EXPECT_EQ(1, d.response_started_count()); | 6495 EXPECT_EQ(1, d.response_started_count()); |
| 6469 EXPECT_EQ(0, d.bytes_received()); | 6496 EXPECT_EQ(0, d.bytes_received()); |
| 6470 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 6497 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 6471 } | 6498 } |
| 6472 } | 6499 } |
| 6473 | 6500 |
| 6474 TEST_F(URLRequestTestHTTP, CancelRedirect) { | 6501 TEST_F(URLRequestTestHTTP, CancelRedirect) { |
| 6475 ASSERT_TRUE(test_server_.Start()); | 6502 ASSERT_TRUE(http_test_server()->Start()); |
| 6476 | 6503 |
| 6477 TestDelegate d; | 6504 TestDelegate d; |
| 6478 { | 6505 { |
| 6479 d.set_cancel_in_received_redirect(true); | 6506 d.set_cancel_in_received_redirect(true); |
| 6480 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6507 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6481 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d)); | 6508 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, |
| 6509 &d)); |
| 6482 req->Start(); | 6510 req->Start(); |
| 6483 base::RunLoop().Run(); | 6511 base::RunLoop().Run(); |
| 6484 | 6512 |
| 6485 EXPECT_EQ(1, d.response_started_count()); | 6513 EXPECT_EQ(1, d.response_started_count()); |
| 6486 EXPECT_EQ(0, d.bytes_received()); | 6514 EXPECT_EQ(0, d.bytes_received()); |
| 6487 EXPECT_FALSE(d.received_data_before_response()); | 6515 EXPECT_FALSE(d.received_data_before_response()); |
| 6488 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 6516 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 6489 } | 6517 } |
| 6490 } | 6518 } |
| 6491 | 6519 |
| 6492 TEST_F(URLRequestTestHTTP, DeferredRedirect) { | 6520 TEST_F(URLRequestTestHTTP, DeferredRedirect) { |
| 6493 ASSERT_TRUE(test_server_.Start()); | 6521 ASSERT_TRUE(http_test_server()->Start()); |
| 6494 | 6522 |
| 6495 TestDelegate d; | 6523 TestDelegate d; |
| 6496 { | 6524 { |
| 6497 d.set_quit_on_redirect(true); | 6525 d.set_quit_on_redirect(true); |
| 6498 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | 6526 GURL test_url(http_test_server()->GetURL("/redirect-test.html")); |
| 6499 scoped_ptr<URLRequest> req( | 6527 scoped_ptr<URLRequest> req( |
| 6500 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 6528 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); |
| 6501 | 6529 |
| 6502 req->Start(); | 6530 req->Start(); |
| 6503 base::RunLoop().Run(); | 6531 base::RunLoop().Run(); |
| 6504 | 6532 |
| 6505 EXPECT_EQ(1, d.received_redirect_count()); | 6533 EXPECT_EQ(1, d.received_redirect_count()); |
| 6506 | 6534 |
| 6507 req->FollowDeferredRedirect(); | 6535 req->FollowDeferredRedirect(); |
| 6508 base::RunLoop().Run(); | 6536 base::RunLoop().Run(); |
| 6509 | 6537 |
| 6510 EXPECT_EQ(1, d.response_started_count()); | 6538 EXPECT_EQ(1, d.response_started_count()); |
| 6511 EXPECT_FALSE(d.received_data_before_response()); | 6539 EXPECT_FALSE(d.received_data_before_response()); |
| 6512 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6540 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6513 | 6541 |
| 6514 base::FilePath path; | 6542 base::FilePath path; |
| 6515 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 6543 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 6516 path = path.Append(kTestFilePath); | 6544 path = path.Append(kTestFilePath); |
| 6517 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 6545 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 6518 | 6546 |
| 6519 std::string contents; | 6547 std::string contents; |
| 6520 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 6548 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
| 6521 EXPECT_EQ(contents, d.data_received()); | 6549 EXPECT_EQ(contents, d.data_received()); |
| 6522 } | 6550 } |
| 6523 } | 6551 } |
| 6524 | 6552 |
| 6525 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { | 6553 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { |
| 6526 ASSERT_TRUE(test_server_.Start()); | 6554 ASSERT_TRUE(http_test_server()->Start()); |
| 6527 | 6555 |
| 6528 TestDelegate d; | 6556 TestDelegate d; |
| 6529 { | 6557 { |
| 6530 d.set_quit_on_redirect(true); | 6558 d.set_quit_on_redirect(true); |
| 6531 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | 6559 GURL test_url(http_test_server()->GetURL("/redirect-test.html")); |
| 6532 scoped_ptr<URLRequest> req( | 6560 scoped_ptr<URLRequest> req( |
| 6533 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 6561 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); |
| 6534 | 6562 |
| 6535 EXPECT_FALSE(d.have_full_request_headers()); | 6563 EXPECT_FALSE(d.have_full_request_headers()); |
| 6536 | 6564 |
| 6537 req->Start(); | 6565 req->Start(); |
| 6538 base::RunLoop().Run(); | 6566 base::RunLoop().Run(); |
| 6539 | 6567 |
| 6540 EXPECT_EQ(1, d.received_redirect_count()); | 6568 EXPECT_EQ(1, d.received_redirect_count()); |
| 6541 EXPECT_TRUE(d.have_full_request_headers()); | 6569 EXPECT_TRUE(d.have_full_request_headers()); |
| 6542 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 6570 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
| 6543 d.ClearFullRequestHeaders(); | 6571 d.ClearFullRequestHeaders(); |
| 6544 | 6572 |
| 6545 req->FollowDeferredRedirect(); | 6573 req->FollowDeferredRedirect(); |
| 6546 base::RunLoop().Run(); | 6574 base::RunLoop().Run(); |
| 6547 | 6575 |
| 6548 GURL target_url(test_server_.GetURL("files/with-headers.html")); | 6576 GURL target_url(http_test_server()->GetURL("/with-headers.html")); |
| 6549 EXPECT_EQ(1, d.response_started_count()); | 6577 EXPECT_EQ(1, d.response_started_count()); |
| 6550 EXPECT_TRUE(d.have_full_request_headers()); | 6578 EXPECT_TRUE(d.have_full_request_headers()); |
| 6551 CheckFullRequestHeaders(d.full_request_headers(), target_url); | 6579 CheckFullRequestHeaders(d.full_request_headers(), target_url); |
| 6552 EXPECT_FALSE(d.received_data_before_response()); | 6580 EXPECT_FALSE(d.received_data_before_response()); |
| 6553 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6581 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6554 | 6582 |
| 6555 base::FilePath path; | 6583 base::FilePath path; |
| 6556 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 6584 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 6557 path = path.Append(kTestFilePath); | 6585 path = path.Append(kTestFilePath); |
| 6558 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 6586 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 6559 | 6587 |
| 6560 std::string contents; | 6588 std::string contents; |
| 6561 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 6589 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
| 6562 EXPECT_EQ(contents, d.data_received()); | 6590 EXPECT_EQ(contents, d.data_received()); |
| 6563 } | 6591 } |
| 6564 } | 6592 } |
| 6565 | 6593 |
| 6566 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { | 6594 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { |
| 6567 ASSERT_TRUE(test_server_.Start()); | 6595 ASSERT_TRUE(http_test_server()->Start()); |
| 6568 | 6596 |
| 6569 TestDelegate d; | 6597 TestDelegate d; |
| 6570 { | 6598 { |
| 6571 d.set_quit_on_redirect(true); | 6599 d.set_quit_on_redirect(true); |
| 6572 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6600 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6573 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d)); | 6601 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, |
| 6602 &d)); |
| 6574 req->Start(); | 6603 req->Start(); |
| 6575 base::RunLoop().Run(); | 6604 base::RunLoop().Run(); |
| 6576 | 6605 |
| 6577 EXPECT_EQ(1, d.received_redirect_count()); | 6606 EXPECT_EQ(1, d.received_redirect_count()); |
| 6578 | 6607 |
| 6579 req->Cancel(); | 6608 req->Cancel(); |
| 6580 base::RunLoop().Run(); | 6609 base::RunLoop().Run(); |
| 6581 | 6610 |
| 6582 EXPECT_EQ(1, d.response_started_count()); | 6611 EXPECT_EQ(1, d.response_started_count()); |
| 6583 EXPECT_EQ(0, d.bytes_received()); | 6612 EXPECT_EQ(0, d.bytes_received()); |
| 6584 EXPECT_FALSE(d.received_data_before_response()); | 6613 EXPECT_FALSE(d.received_data_before_response()); |
| 6585 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 6614 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 6586 } | 6615 } |
| 6587 } | 6616 } |
| 6588 | 6617 |
| 6589 TEST_F(URLRequestTestHTTP, VaryHeader) { | 6618 TEST_F(URLRequestTestHTTP, VaryHeader) { |
| 6590 ASSERT_TRUE(test_server_.Start()); | 6619 ASSERT_TRUE(http_test_server()->Start()); |
| 6591 | 6620 |
| 6592 // Populate the cache. | 6621 // Populate the cache. |
| 6593 { | 6622 { |
| 6594 TestDelegate d; | 6623 TestDelegate d; |
| 6595 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6624 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6596 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d)); | 6625 http_test_server()->GetURL("/echoheadercache?foo"), DEFAULT_PRIORITY, |
| 6626 &d)); |
| 6597 HttpRequestHeaders headers; | 6627 HttpRequestHeaders headers; |
| 6598 headers.SetHeader("foo", "1"); | 6628 headers.SetHeader("foo", "1"); |
| 6599 req->SetExtraRequestHeaders(headers); | 6629 req->SetExtraRequestHeaders(headers); |
| 6600 req->Start(); | 6630 req->Start(); |
| 6601 base::RunLoop().Run(); | 6631 base::RunLoop().Run(); |
| 6602 | 6632 |
| 6603 LoadTimingInfo load_timing_info; | 6633 LoadTimingInfo load_timing_info; |
| 6604 req->GetLoadTimingInfo(&load_timing_info); | 6634 req->GetLoadTimingInfo(&load_timing_info); |
| 6605 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 6635 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 6606 } | 6636 } |
| 6607 | 6637 |
| 6608 // Expect a cache hit. | 6638 // Expect a cache hit. |
| 6609 { | 6639 { |
| 6610 TestDelegate d; | 6640 TestDelegate d; |
| 6611 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6641 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6612 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d)); | 6642 http_test_server()->GetURL("/echoheadercache?foo"), DEFAULT_PRIORITY, |
| 6643 &d)); |
| 6613 HttpRequestHeaders headers; | 6644 HttpRequestHeaders headers; |
| 6614 headers.SetHeader("foo", "1"); | 6645 headers.SetHeader("foo", "1"); |
| 6615 req->SetExtraRequestHeaders(headers); | 6646 req->SetExtraRequestHeaders(headers); |
| 6616 req->Start(); | 6647 req->Start(); |
| 6617 base::RunLoop().Run(); | 6648 base::RunLoop().Run(); |
| 6618 | 6649 |
| 6619 EXPECT_TRUE(req->was_cached()); | 6650 EXPECT_TRUE(req->was_cached()); |
| 6620 | 6651 |
| 6621 LoadTimingInfo load_timing_info; | 6652 LoadTimingInfo load_timing_info; |
| 6622 req->GetLoadTimingInfo(&load_timing_info); | 6653 req->GetLoadTimingInfo(&load_timing_info); |
| 6623 TestLoadTimingCacheHitNoNetwork(load_timing_info); | 6654 TestLoadTimingCacheHitNoNetwork(load_timing_info); |
| 6624 } | 6655 } |
| 6625 | 6656 |
| 6626 // Expect a cache miss. | 6657 // Expect a cache miss. |
| 6627 { | 6658 { |
| 6628 TestDelegate d; | 6659 TestDelegate d; |
| 6629 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6660 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6630 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d)); | 6661 http_test_server()->GetURL("/echoheadercache?foo"), DEFAULT_PRIORITY, |
| 6662 &d)); |
| 6631 HttpRequestHeaders headers; | 6663 HttpRequestHeaders headers; |
| 6632 headers.SetHeader("foo", "2"); | 6664 headers.SetHeader("foo", "2"); |
| 6633 req->SetExtraRequestHeaders(headers); | 6665 req->SetExtraRequestHeaders(headers); |
| 6634 req->Start(); | 6666 req->Start(); |
| 6635 base::RunLoop().Run(); | 6667 base::RunLoop().Run(); |
| 6636 | 6668 |
| 6637 EXPECT_FALSE(req->was_cached()); | 6669 EXPECT_FALSE(req->was_cached()); |
| 6638 | 6670 |
| 6639 LoadTimingInfo load_timing_info; | 6671 LoadTimingInfo load_timing_info; |
| 6640 req->GetLoadTimingInfo(&load_timing_info); | 6672 req->GetLoadTimingInfo(&load_timing_info); |
| 6641 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 6673 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 6642 } | 6674 } |
| 6643 } | 6675 } |
| 6644 | 6676 |
| 6645 TEST_F(URLRequestTestHTTP, BasicAuth) { | 6677 TEST_F(URLRequestTestHTTP, BasicAuth) { |
| 6646 ASSERT_TRUE(test_server_.Start()); | 6678 ASSERT_TRUE(http_test_server()->Start()); |
| 6647 | 6679 |
| 6648 // populate the cache | 6680 // populate the cache |
| 6649 { | 6681 { |
| 6650 TestDelegate d; | 6682 TestDelegate d; |
| 6651 d.set_credentials(AuthCredentials(kUser, kSecret)); | 6683 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 6652 | 6684 |
| 6653 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 6685 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6654 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d)); | 6686 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); |
| 6655 r->Start(); | 6687 r->Start(); |
| 6656 | 6688 |
| 6657 base::RunLoop().Run(); | 6689 base::RunLoop().Run(); |
| 6658 | 6690 |
| 6659 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 6691 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 6660 } | 6692 } |
| 6661 | 6693 |
| 6662 // repeat request with end-to-end validation. since auth-basic results in a | 6694 // repeat request with end-to-end validation. since auth-basic results in a |
| 6663 // cachable page, we expect this test to result in a 304. in which case, the | 6695 // cachable page, we expect this test to result in a 304. in which case, the |
| 6664 // response should be fetched from the cache. | 6696 // response should be fetched from the cache. |
| 6665 { | 6697 { |
| 6666 TestDelegate d; | 6698 TestDelegate d; |
| 6667 d.set_credentials(AuthCredentials(kUser, kSecret)); | 6699 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 6668 | 6700 |
| 6669 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 6701 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6670 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d)); | 6702 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); |
| 6671 r->SetLoadFlags(LOAD_VALIDATE_CACHE); | 6703 r->SetLoadFlags(LOAD_VALIDATE_CACHE); |
| 6672 r->Start(); | 6704 r->Start(); |
| 6673 | 6705 |
| 6674 base::RunLoop().Run(); | 6706 base::RunLoop().Run(); |
| 6675 | 6707 |
| 6676 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 6708 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 6677 | 6709 |
| 6678 // Should be the same cached document. | 6710 // Should be the same cached document. |
| 6679 EXPECT_TRUE(r->was_cached()); | 6711 EXPECT_TRUE(r->was_cached()); |
| 6680 } | 6712 } |
| 6681 } | 6713 } |
| 6682 | 6714 |
| 6683 // Check that Set-Cookie headers in 401 responses are respected. | 6715 // Check that Set-Cookie headers in 401 responses are respected. |
| 6684 // http://crbug.com/6450 | 6716 // http://crbug.com/6450 |
| 6685 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { | 6717 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { |
| 6686 ASSERT_TRUE(test_server_.Start()); | 6718 ASSERT_TRUE(http_test_server()->Start()); |
| 6687 | 6719 |
| 6688 GURL url_requiring_auth = | 6720 GURL url_requiring_auth = |
| 6689 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); | 6721 http_test_server()->GetURL("/auth-basic?set-cookie-if-challenged"); |
| 6690 | 6722 |
| 6691 // Request a page that will give a 401 containing a Set-Cookie header. | 6723 // Request a page that will give a 401 containing a Set-Cookie header. |
| 6692 // Verify that when the transaction is restarted, it includes the new cookie. | 6724 // Verify that when the transaction is restarted, it includes the new cookie. |
| 6693 { | 6725 { |
| 6694 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 6726 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 6695 TestURLRequestContext context(true); | 6727 TestURLRequestContext context(true); |
| 6696 context.set_network_delegate(&network_delegate); | 6728 context.set_network_delegate(&network_delegate); |
| 6697 context.Init(); | 6729 context.Init(); |
| 6698 | 6730 |
| 6699 TestDelegate d; | 6731 TestDelegate d; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6736 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 6768 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
| 6737 | 6769 |
| 6738 // Make sure we sent the cookie in the restarted transaction. | 6770 // Make sure we sent the cookie in the restarted transaction. |
| 6739 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 6771 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 6740 != std::string::npos); | 6772 != std::string::npos); |
| 6741 } | 6773 } |
| 6742 } | 6774 } |
| 6743 | 6775 |
| 6744 // Tests that load timing works as expected with auth and the cache. | 6776 // Tests that load timing works as expected with auth and the cache. |
| 6745 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { | 6777 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { |
| 6746 ASSERT_TRUE(test_server_.Start()); | 6778 ASSERT_TRUE(http_test_server()->Start()); |
| 6747 | 6779 |
| 6748 // populate the cache | 6780 // populate the cache |
| 6749 { | 6781 { |
| 6750 TestDelegate d; | 6782 TestDelegate d; |
| 6751 d.set_credentials(AuthCredentials(kUser, kSecret)); | 6783 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 6752 | 6784 |
| 6753 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 6785 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6754 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d)); | 6786 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); |
| 6755 r->Start(); | 6787 r->Start(); |
| 6756 | 6788 |
| 6757 base::RunLoop().Run(); | 6789 base::RunLoop().Run(); |
| 6758 | 6790 |
| 6759 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 6791 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 6760 | 6792 |
| 6761 LoadTimingInfo load_timing_info_before_auth; | 6793 LoadTimingInfo load_timing_info_before_auth; |
| 6762 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( | 6794 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( |
| 6763 &load_timing_info_before_auth)); | 6795 &load_timing_info_before_auth)); |
| 6764 TestLoadTimingNotReused(load_timing_info_before_auth, | 6796 TestLoadTimingNotReused(load_timing_info_before_auth, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6776 } | 6808 } |
| 6777 | 6809 |
| 6778 // Repeat request with end-to-end validation. Since auth-basic results in a | 6810 // Repeat request with end-to-end validation. Since auth-basic results in a |
| 6779 // cachable page, we expect this test to result in a 304. In which case, the | 6811 // cachable page, we expect this test to result in a 304. In which case, the |
| 6780 // response should be fetched from the cache. | 6812 // response should be fetched from the cache. |
| 6781 { | 6813 { |
| 6782 TestDelegate d; | 6814 TestDelegate d; |
| 6783 d.set_credentials(AuthCredentials(kUser, kSecret)); | 6815 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 6784 | 6816 |
| 6785 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 6817 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6786 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d)); | 6818 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); |
| 6787 r->SetLoadFlags(LOAD_VALIDATE_CACHE); | 6819 r->SetLoadFlags(LOAD_VALIDATE_CACHE); |
| 6788 r->Start(); | 6820 r->Start(); |
| 6789 | 6821 |
| 6790 base::RunLoop().Run(); | 6822 base::RunLoop().Run(); |
| 6791 | 6823 |
| 6792 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 6824 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 6793 | 6825 |
| 6794 // Should be the same cached document. | 6826 // Should be the same cached document. |
| 6795 EXPECT_TRUE(r->was_cached()); | 6827 EXPECT_TRUE(r->was_cached()); |
| 6796 | 6828 |
| 6797 // Since there was a request that went over the wire, the load timing | 6829 // Since there was a request that went over the wire, the load timing |
| 6798 // information should include connection times. | 6830 // information should include connection times. |
| 6799 LoadTimingInfo load_timing_info; | 6831 LoadTimingInfo load_timing_info; |
| 6800 r->GetLoadTimingInfo(&load_timing_info); | 6832 r->GetLoadTimingInfo(&load_timing_info); |
| 6801 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 6833 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 6802 } | 6834 } |
| 6803 } | 6835 } |
| 6804 | 6836 |
| 6805 // In this test, we do a POST which the server will 302 redirect. | 6837 // In this test, we do a POST which the server will 302 redirect. |
| 6806 // The subsequent transaction should use GET, and should not send the | 6838 // The subsequent transaction should use GET, and should not send the |
| 6807 // Content-Type header. | 6839 // Content-Type header. |
| 6808 // http://code.google.com/p/chromium/issues/detail?id=843 | 6840 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 6809 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { | 6841 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { |
| 6810 ASSERT_TRUE(test_server_.Start()); | 6842 ASSERT_TRUE(http_test_server()->Start()); |
| 6811 | 6843 |
| 6812 const char kData[] = "hello world"; | 6844 const char kData[] = "hello world"; |
| 6813 | 6845 |
| 6814 TestDelegate d; | 6846 TestDelegate d; |
| 6815 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 6847 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6816 test_server_.GetURL("files/redirect-to-echoall"), DEFAULT_PRIORITY, &d)); | 6848 http_test_server()->GetURL("/redirect-to-echoall"), DEFAULT_PRIORITY, |
| 6849 &d)); |
| 6817 req->set_method("POST"); | 6850 req->set_method("POST"); |
| 6818 req->set_upload(CreateSimpleUploadData(kData)); | 6851 req->set_upload(CreateSimpleUploadData(kData)); |
| 6819 | 6852 |
| 6820 // Set headers (some of which are specific to the POST). | 6853 // Set headers (some of which are specific to the POST). |
| 6821 HttpRequestHeaders headers; | 6854 HttpRequestHeaders headers; |
| 6822 headers.AddHeadersFromString( | 6855 headers.AddHeadersFromString( |
| 6823 "Content-Type: multipart/form-data; " | 6856 "Content-Type: multipart/form-data; " |
| 6824 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 6857 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
| 6825 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | 6858 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
| 6826 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 6859 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6848 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); | 6881 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); |
| 6849 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); | 6882 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); |
| 6850 } | 6883 } |
| 6851 | 6884 |
| 6852 // The following tests check that we handle mutating the request for HTTP | 6885 // The following tests check that we handle mutating the request for HTTP |
| 6853 // redirects as expected. | 6886 // redirects as expected. |
| 6854 // See https://crbug.com/56373, https://crbug.com/102130, and | 6887 // See https://crbug.com/56373, https://crbug.com/102130, and |
| 6855 // https://crbug.com/465517. | 6888 // https://crbug.com/465517. |
| 6856 | 6889 |
| 6857 TEST_F(URLRequestTestHTTP, Redirect301Tests) { | 6890 TEST_F(URLRequestTestHTTP, Redirect301Tests) { |
| 6858 ASSERT_TRUE(test_server_.Start()); | 6891 ASSERT_TRUE(http_test_server()->Start()); |
| 6859 | 6892 |
| 6860 const GURL url = test_server_.GetURL("files/redirect301-to-echo"); | 6893 const GURL url = http_test_server()->GetURL("/redirect301-to-echo"); |
| 6861 const GURL https_redirect_url = | 6894 const GURL https_redirect_url = |
| 6862 test_server_.GetURL("files/redirect301-to-https"); | 6895 http_test_server()->GetURL("/redirect301-to-https"); |
| 6863 | 6896 |
| 6864 HTTPRedirectMethodTest(url, "POST", "GET", true); | 6897 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 6865 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6898 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6866 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6899 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6867 | 6900 |
| 6868 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6901 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
| 6869 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6902 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6870 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); | 6903 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); |
| 6871 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", | 6904 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", |
| 6872 std::string()); | 6905 std::string()); |
| 6873 } | 6906 } |
| 6874 | 6907 |
| 6875 TEST_F(URLRequestTestHTTP, Redirect302Tests) { | 6908 TEST_F(URLRequestTestHTTP, Redirect302Tests) { |
| 6876 ASSERT_TRUE(test_server_.Start()); | 6909 ASSERT_TRUE(http_test_server()->Start()); |
| 6877 | 6910 |
| 6878 const GURL url = test_server_.GetURL("files/redirect302-to-echo"); | 6911 const GURL url = http_test_server()->GetURL("/redirect302-to-echo"); |
| 6879 const GURL https_redirect_url = | 6912 const GURL https_redirect_url = |
| 6880 test_server_.GetURL("files/redirect302-to-https"); | 6913 http_test_server()->GetURL("/redirect302-to-https"); |
| 6881 | 6914 |
| 6882 HTTPRedirectMethodTest(url, "POST", "GET", true); | 6915 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 6883 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6916 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6884 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6917 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6885 | 6918 |
| 6886 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6919 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
| 6887 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6920 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6888 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); | 6921 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); |
| 6889 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", | 6922 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", |
| 6890 std::string()); | 6923 std::string()); |
| 6891 } | 6924 } |
| 6892 | 6925 |
| 6893 TEST_F(URLRequestTestHTTP, Redirect303Tests) { | 6926 TEST_F(URLRequestTestHTTP, Redirect303Tests) { |
| 6894 ASSERT_TRUE(test_server_.Start()); | 6927 ASSERT_TRUE(http_test_server()->Start()); |
| 6895 | 6928 |
| 6896 const GURL url = test_server_.GetURL("files/redirect303-to-echo"); | 6929 const GURL url = http_test_server()->GetURL("/redirect303-to-echo"); |
| 6897 const GURL https_redirect_url = | 6930 const GURL https_redirect_url = |
| 6898 test_server_.GetURL("files/redirect303-to-https"); | 6931 http_test_server()->GetURL("/redirect303-to-https"); |
| 6899 | 6932 |
| 6900 HTTPRedirectMethodTest(url, "POST", "GET", true); | 6933 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 6901 HTTPRedirectMethodTest(url, "PUT", "GET", true); | 6934 HTTPRedirectMethodTest(url, "PUT", "GET", true); |
| 6902 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6935 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6903 | 6936 |
| 6904 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6937 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
| 6905 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6938 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6906 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); | 6939 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); |
| 6907 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", | 6940 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", |
| 6908 std::string()); | 6941 std::string()); |
| 6909 } | 6942 } |
| 6910 | 6943 |
| 6911 TEST_F(URLRequestTestHTTP, Redirect307Tests) { | 6944 TEST_F(URLRequestTestHTTP, Redirect307Tests) { |
| 6912 ASSERT_TRUE(test_server_.Start()); | 6945 ASSERT_TRUE(http_test_server()->Start()); |
| 6913 | 6946 |
| 6914 const GURL url = test_server_.GetURL("files/redirect307-to-echo"); | 6947 const GURL url = http_test_server()->GetURL("/redirect307-to-echo"); |
| 6915 const GURL https_redirect_url = | 6948 const GURL https_redirect_url = |
| 6916 test_server_.GetURL("files/redirect307-to-https"); | 6949 http_test_server()->GetURL("/redirect307-to-https"); |
| 6917 | 6950 |
| 6918 HTTPRedirectMethodTest(url, "POST", "POST", true); | 6951 HTTPRedirectMethodTest(url, "POST", "POST", true); |
| 6919 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6952 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6920 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6953 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6921 | 6954 |
| 6922 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6955 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
| 6923 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6956 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6924 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); | 6957 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); |
| 6925 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "POST", "null"); | 6958 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "POST", "null"); |
| 6926 } | 6959 } |
| 6927 | 6960 |
| 6928 TEST_F(URLRequestTestHTTP, Redirect308Tests) { | 6961 TEST_F(URLRequestTestHTTP, Redirect308Tests) { |
| 6929 ASSERT_TRUE(test_server_.Start()); | 6962 ASSERT_TRUE(http_test_server()->Start()); |
| 6930 | 6963 |
| 6931 const GURL url = test_server_.GetURL("files/redirect308-to-echo"); | 6964 const GURL url = http_test_server()->GetURL("/redirect308-to-echo"); |
| 6932 const GURL https_redirect_url = | 6965 const GURL https_redirect_url = |
| 6933 test_server_.GetURL("files/redirect308-to-https"); | 6966 http_test_server()->GetURL("/redirect308-to-https"); |
| 6934 | 6967 |
| 6935 HTTPRedirectMethodTest(url, "POST", "POST", true); | 6968 HTTPRedirectMethodTest(url, "POST", "POST", true); |
| 6936 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6969 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6937 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6970 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6938 | 6971 |
| 6939 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6972 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
| 6940 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6973 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6941 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); | 6974 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); |
| 6942 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "POST", "null"); | 6975 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "POST", "null"); |
| 6943 } | 6976 } |
| 6944 | 6977 |
| 6945 // Make sure that 308 responses without bodies are not treated as redirects. | 6978 // Make sure that 308 responses without bodies are not treated as redirects. |
| 6946 // Certain legacy apis that pre-date the response code expect this behavior | 6979 // Certain legacy apis that pre-date the response code expect this behavior |
| 6947 // (Like Google Drive). | 6980 // (Like Google Drive). |
| 6948 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { | 6981 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { |
| 6949 ASSERT_TRUE(test_server_.Start()); | 6982 ASSERT_TRUE(http_test_server()->Start()); |
| 6950 | 6983 |
| 6951 TestDelegate d; | 6984 TestDelegate d; |
| 6952 const GURL url = test_server_.GetURL("files/308-without-location-header"); | 6985 const GURL url = http_test_server()->GetURL("/308-without-location-header"); |
| 6953 | 6986 |
| 6954 scoped_ptr<URLRequest> request( | 6987 scoped_ptr<URLRequest> request( |
| 6955 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 6988 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 6956 | 6989 |
| 6957 request->Start(); | 6990 request->Start(); |
| 6958 base::RunLoop().Run(); | 6991 base::RunLoop().Run(); |
| 6959 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status()); | 6992 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status()); |
| 6960 EXPECT_EQ(OK, request->status().error()); | 6993 EXPECT_EQ(OK, request->status().error()); |
| 6961 EXPECT_EQ(0, d.received_redirect_count()); | 6994 EXPECT_EQ(0, d.received_redirect_count()); |
| 6962 EXPECT_EQ(308, request->response_headers()->response_code()); | 6995 EXPECT_EQ(308, request->response_headers()->response_code()); |
| 6963 EXPECT_EQ("This is not a redirect.", d.data_received()); | 6996 EXPECT_EQ("This is not a redirect.", d.data_received()); |
| 6964 } | 6997 } |
| 6965 | 6998 |
| 6966 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { | 6999 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { |
| 6967 ASSERT_TRUE(test_server_.Start()); | 7000 ASSERT_TRUE(http_test_server()->Start()); |
| 6968 | 7001 |
| 6969 GURL original_url(test_server_.GetURL("files/redirect302-to-echo#fragment")); | 7002 GURL original_url( |
| 6970 GURL expected_url(test_server_.GetURL("echo#fragment")); | 7003 http_test_server()->GetURL("/redirect302-to-echo#fragment")); |
| 7004 GURL expected_url(http_test_server()->GetURL("/echo#fragment")); |
| 6971 | 7005 |
| 6972 TestDelegate d; | 7006 TestDelegate d; |
| 6973 { | 7007 { |
| 6974 scoped_ptr<URLRequest> r( | 7008 scoped_ptr<URLRequest> r( |
| 6975 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 7009 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
| 6976 | 7010 |
| 6977 r->Start(); | 7011 r->Start(); |
| 6978 base::RunLoop().Run(); | 7012 base::RunLoop().Run(); |
| 6979 | 7013 |
| 6980 EXPECT_EQ(2U, r->url_chain().size()); | 7014 EXPECT_EQ(2U, r->url_chain().size()); |
| 6981 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 7015 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 6982 EXPECT_EQ(OK, r->status().error()); | 7016 EXPECT_EQ(OK, r->status().error()); |
| 6983 EXPECT_EQ(original_url, r->original_url()); | 7017 EXPECT_EQ(original_url, r->original_url()); |
| 6984 EXPECT_EQ(expected_url, r->url()); | 7018 EXPECT_EQ(expected_url, r->url()); |
| 6985 } | 7019 } |
| 6986 } | 7020 } |
| 6987 | 7021 |
| 6988 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) { | 7022 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) { |
| 6989 ASSERT_TRUE(test_server_.Start()); | 7023 ASSERT_TRUE(http_test_server()->Start()); |
| 6990 | 7024 |
| 6991 GURL url(test_server_.GetURL("files/redirect302-to-echo")); | 7025 GURL url(http_test_server()->GetURL("/redirect302-to-echo")); |
| 6992 GURL first_party_url("http://example.com"); | 7026 GURL first_party_url("http://example.com"); |
| 6993 | 7027 |
| 6994 TestDelegate d; | 7028 TestDelegate d; |
| 6995 { | 7029 { |
| 6996 scoped_ptr<URLRequest> r( | 7030 scoped_ptr<URLRequest> r( |
| 6997 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 7031 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 6998 r->set_first_party_for_cookies(first_party_url); | 7032 r->set_first_party_for_cookies(first_party_url); |
| 6999 | 7033 |
| 7000 r->Start(); | 7034 r->Start(); |
| 7001 base::RunLoop().Run(); | 7035 base::RunLoop().Run(); |
| 7002 | 7036 |
| 7003 EXPECT_EQ(2U, r->url_chain().size()); | 7037 EXPECT_EQ(2U, r->url_chain().size()); |
| 7004 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 7038 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 7005 EXPECT_EQ(OK, r->status().error()); | 7039 EXPECT_EQ(OK, r->status().error()); |
| 7006 EXPECT_EQ(first_party_url, r->first_party_for_cookies()); | 7040 EXPECT_EQ(first_party_url, r->first_party_for_cookies()); |
| 7007 } | 7041 } |
| 7008 } | 7042 } |
| 7009 | 7043 |
| 7010 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) { | 7044 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) { |
| 7011 ASSERT_TRUE(test_server_.Start()); | 7045 ASSERT_TRUE(http_test_server()->Start()); |
| 7012 | 7046 |
| 7013 GURL url(test_server_.GetURL("files/redirect302-to-echo")); | 7047 GURL url(http_test_server()->GetURL("/redirect302-to-echo")); |
| 7014 GURL original_first_party_url("http://example.com"); | 7048 GURL original_first_party_url("http://example.com"); |
| 7015 GURL expected_first_party_url(test_server_.GetURL("echo")); | 7049 GURL expected_first_party_url(http_test_server()->GetURL("/echo")); |
| 7016 | 7050 |
| 7017 TestDelegate d; | 7051 TestDelegate d; |
| 7018 { | 7052 { |
| 7019 scoped_ptr<URLRequest> r( | 7053 scoped_ptr<URLRequest> r( |
| 7020 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 7054 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 7021 r->set_first_party_for_cookies(original_first_party_url); | 7055 r->set_first_party_for_cookies(original_first_party_url); |
| 7022 r->set_first_party_url_policy( | 7056 r->set_first_party_url_policy( |
| 7023 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); | 7057 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); |
| 7024 | 7058 |
| 7025 r->Start(); | 7059 r->Start(); |
| 7026 base::RunLoop().Run(); | 7060 base::RunLoop().Run(); |
| 7027 | 7061 |
| 7028 EXPECT_EQ(2U, r->url_chain().size()); | 7062 EXPECT_EQ(2U, r->url_chain().size()); |
| 7029 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 7063 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 7030 EXPECT_EQ(OK, r->status().error()); | 7064 EXPECT_EQ(OK, r->status().error()); |
| 7031 EXPECT_EQ(expected_first_party_url, r->first_party_for_cookies()); | 7065 EXPECT_EQ(expected_first_party_url, r->first_party_for_cookies()); |
| 7032 } | 7066 } |
| 7033 } | 7067 } |
| 7034 | 7068 |
| 7035 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { | 7069 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { |
| 7036 ASSERT_TRUE(test_server_.Start()); | 7070 ASSERT_TRUE(http_test_server()->Start()); |
| 7037 | 7071 |
| 7038 const char kData[] = "hello world"; | 7072 const char kData[] = "hello world"; |
| 7039 | 7073 |
| 7040 TestDelegate d; | 7074 TestDelegate d; |
| 7041 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7075 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7042 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d)); | 7076 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 7043 req->set_method("POST"); | 7077 req->set_method("POST"); |
| 7044 req->set_upload(CreateSimpleUploadData(kData)); | 7078 req->set_upload(CreateSimpleUploadData(kData)); |
| 7045 HttpRequestHeaders headers; | 7079 HttpRequestHeaders headers; |
| 7046 headers.SetHeader(HttpRequestHeaders::kContentLength, | 7080 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 7047 base::SizeTToString(arraysize(kData) - 1)); | 7081 base::SizeTToString(arraysize(kData) - 1)); |
| 7048 req->SetExtraRequestHeaders(headers); | 7082 req->SetExtraRequestHeaders(headers); |
| 7049 | 7083 |
| 7050 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 7084 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 7051 req.get(), &default_network_delegate_, test_server_.GetURL("echo"), | 7085 req.get(), &default_network_delegate_, |
| 7086 http_test_server()->GetURL("/echo"), |
| 7052 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); | 7087 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); |
| 7053 AddTestInterceptor()->set_main_intercept_job(job); | 7088 AddTestInterceptor()->set_main_intercept_job(job); |
| 7054 | 7089 |
| 7055 req->Start(); | 7090 req->Start(); |
| 7056 base::RunLoop().Run(); | 7091 base::RunLoop().Run(); |
| 7057 EXPECT_EQ("GET", req->method()); | 7092 EXPECT_EQ("GET", req->method()); |
| 7058 } | 7093 } |
| 7059 | 7094 |
| 7060 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 7095 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
| 7061 ASSERT_TRUE(test_server_.Start()); | 7096 ASSERT_TRUE(http_test_server()->Start()); |
| 7062 | 7097 |
| 7063 const char kData[] = "hello world"; | 7098 const char kData[] = "hello world"; |
| 7064 | 7099 |
| 7065 TestDelegate d; | 7100 TestDelegate d; |
| 7066 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7101 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7067 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d)); | 7102 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 7068 req->set_method("POST"); | 7103 req->set_method("POST"); |
| 7069 req->set_upload(CreateSimpleUploadData(kData)); | 7104 req->set_upload(CreateSimpleUploadData(kData)); |
| 7070 HttpRequestHeaders headers; | 7105 HttpRequestHeaders headers; |
| 7071 headers.SetHeader(HttpRequestHeaders::kContentLength, | 7106 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 7072 base::SizeTToString(arraysize(kData) - 1)); | 7107 base::SizeTToString(arraysize(kData) - 1)); |
| 7073 req->SetExtraRequestHeaders(headers); | 7108 req->SetExtraRequestHeaders(headers); |
| 7074 | 7109 |
| 7075 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 7110 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 7076 req.get(), &default_network_delegate_, test_server_.GetURL("echo"), | 7111 req.get(), &default_network_delegate_, |
| 7112 http_test_server()->GetURL("/echo"), |
| 7077 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, | 7113 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, |
| 7078 "Very Good Reason"); | 7114 "Very Good Reason"); |
| 7079 AddTestInterceptor()->set_main_intercept_job(job); | 7115 AddTestInterceptor()->set_main_intercept_job(job); |
| 7080 | 7116 |
| 7081 req->Start(); | 7117 req->Start(); |
| 7082 base::RunLoop().Run(); | 7118 base::RunLoop().Run(); |
| 7083 EXPECT_EQ("POST", req->method()); | 7119 EXPECT_EQ("POST", req->method()); |
| 7084 EXPECT_EQ(kData, d.data_received()); | 7120 EXPECT_EQ(kData, d.data_received()); |
| 7085 } | 7121 } |
| 7086 | 7122 |
| 7087 // Check that default A-L header is sent. | 7123 // Check that default A-L header is sent. |
| 7088 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 7124 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
| 7089 ASSERT_TRUE(test_server_.Start()); | 7125 ASSERT_TRUE(http_test_server()->Start()); |
| 7090 | 7126 |
| 7091 StaticHttpUserAgentSettings settings("en", std::string()); | 7127 StaticHttpUserAgentSettings settings("en", std::string()); |
| 7092 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 7128 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 7093 TestURLRequestContext context(true); | 7129 TestURLRequestContext context(true); |
| 7094 context.set_network_delegate(&network_delegate); | 7130 context.set_network_delegate(&network_delegate); |
| 7095 context.set_http_user_agent_settings(&settings); | 7131 context.set_http_user_agent_settings(&settings); |
| 7096 context.Init(); | 7132 context.Init(); |
| 7097 | 7133 |
| 7098 TestDelegate d; | 7134 TestDelegate d; |
| 7099 scoped_ptr<URLRequest> req(context.CreateRequest( | 7135 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 7100 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d)); | 7136 http_test_server()->GetURL("/echoheader?Accept-Language"), |
| 7137 DEFAULT_PRIORITY, &d)); |
| 7101 req->Start(); | 7138 req->Start(); |
| 7102 base::RunLoop().Run(); | 7139 base::RunLoop().Run(); |
| 7103 EXPECT_EQ("en", d.data_received()); | 7140 EXPECT_EQ("en", d.data_received()); |
| 7104 } | 7141 } |
| 7105 | 7142 |
| 7106 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 7143 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
| 7107 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 7144 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
| 7108 ASSERT_TRUE(test_server_.Start()); | 7145 ASSERT_TRUE(http_test_server()->Start()); |
| 7109 | 7146 |
| 7110 std::string empty_string; // Avoid most vexing parse on line below. | 7147 std::string empty_string; // Avoid most vexing parse on line below. |
| 7111 StaticHttpUserAgentSettings settings(empty_string, empty_string); | 7148 StaticHttpUserAgentSettings settings(empty_string, empty_string); |
| 7112 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 7149 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 7113 TestURLRequestContext context(true); | 7150 TestURLRequestContext context(true); |
| 7114 context.set_network_delegate(&network_delegate); | 7151 context.set_network_delegate(&network_delegate); |
| 7115 context.Init(); | 7152 context.Init(); |
| 7116 // We override the language after initialization because empty entries | 7153 // We override the language after initialization because empty entries |
| 7117 // get overridden by Init(). | 7154 // get overridden by Init(). |
| 7118 context.set_http_user_agent_settings(&settings); | 7155 context.set_http_user_agent_settings(&settings); |
| 7119 | 7156 |
| 7120 TestDelegate d; | 7157 TestDelegate d; |
| 7121 scoped_ptr<URLRequest> req(context.CreateRequest( | 7158 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 7122 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d)); | 7159 http_test_server()->GetURL("/echoheader?Accept-Language"), |
| 7160 DEFAULT_PRIORITY, &d)); |
| 7123 req->Start(); | 7161 req->Start(); |
| 7124 base::RunLoop().Run(); | 7162 base::RunLoop().Run(); |
| 7125 EXPECT_EQ("None", d.data_received()); | 7163 EXPECT_EQ("None", d.data_received()); |
| 7126 } | 7164 } |
| 7127 | 7165 |
| 7128 // Check that if request overrides the A-L header, the default is not appended. | 7166 // Check that if request overrides the A-L header, the default is not appended. |
| 7129 // See http://crbug.com/20894 | 7167 // See http://crbug.com/20894 |
| 7130 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { | 7168 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
| 7131 ASSERT_TRUE(test_server_.Start()); | 7169 ASSERT_TRUE(http_test_server()->Start()); |
| 7132 | 7170 |
| 7133 TestDelegate d; | 7171 TestDelegate d; |
| 7134 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7172 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7135 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d)); | 7173 http_test_server()->GetURL("/echoheader?Accept-Language"), |
| 7174 DEFAULT_PRIORITY, &d)); |
| 7136 HttpRequestHeaders headers; | 7175 HttpRequestHeaders headers; |
| 7137 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); | 7176 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); |
| 7138 req->SetExtraRequestHeaders(headers); | 7177 req->SetExtraRequestHeaders(headers); |
| 7139 req->Start(); | 7178 req->Start(); |
| 7140 base::RunLoop().Run(); | 7179 base::RunLoop().Run(); |
| 7141 EXPECT_EQ(std::string("ru"), d.data_received()); | 7180 EXPECT_EQ(std::string("ru"), d.data_received()); |
| 7142 } | 7181 } |
| 7143 | 7182 |
| 7144 // Check that default A-E header is sent. | 7183 // Check that default A-E header is sent. |
| 7145 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { | 7184 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { |
| 7146 ASSERT_TRUE(test_server_.Start()); | 7185 ASSERT_TRUE(http_test_server()->Start()); |
| 7147 | 7186 |
| 7148 TestDelegate d; | 7187 TestDelegate d; |
| 7149 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7188 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7150 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d)); | 7189 http_test_server()->GetURL("/echoheader?Accept-Encoding"), |
| 7190 DEFAULT_PRIORITY, &d)); |
| 7151 HttpRequestHeaders headers; | 7191 HttpRequestHeaders headers; |
| 7152 req->SetExtraRequestHeaders(headers); | 7192 req->SetExtraRequestHeaders(headers); |
| 7153 req->Start(); | 7193 req->Start(); |
| 7154 base::RunLoop().Run(); | 7194 base::RunLoop().Run(); |
| 7155 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); | 7195 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); |
| 7156 } | 7196 } |
| 7157 | 7197 |
| 7158 // Check that if request overrides the A-E header, the default is not appended. | 7198 // Check that if request overrides the A-E header, the default is not appended. |
| 7159 // See http://crbug.com/47381 | 7199 // See http://crbug.com/47381 |
| 7160 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { | 7200 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { |
| 7161 ASSERT_TRUE(test_server_.Start()); | 7201 ASSERT_TRUE(http_test_server()->Start()); |
| 7162 | 7202 |
| 7163 TestDelegate d; | 7203 TestDelegate d; |
| 7164 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7204 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7165 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d)); | 7205 http_test_server()->GetURL("/echoheader?Accept-Encoding"), |
| 7206 DEFAULT_PRIORITY, &d)); |
| 7166 HttpRequestHeaders headers; | 7207 HttpRequestHeaders headers; |
| 7167 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); | 7208 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); |
| 7168 req->SetExtraRequestHeaders(headers); | 7209 req->SetExtraRequestHeaders(headers); |
| 7169 req->Start(); | 7210 req->Start(); |
| 7170 base::RunLoop().Run(); | 7211 base::RunLoop().Run(); |
| 7171 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); | 7212 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); |
| 7172 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 7213 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
| 7173 } | 7214 } |
| 7174 | 7215 |
| 7175 // Check that setting the A-C header sends the proper header. | 7216 // Check that setting the A-C header sends the proper header. |
| 7176 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { | 7217 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { |
| 7177 ASSERT_TRUE(test_server_.Start()); | 7218 ASSERT_TRUE(http_test_server()->Start()); |
| 7178 | 7219 |
| 7179 TestDelegate d; | 7220 TestDelegate d; |
| 7180 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7221 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7181 test_server_.GetURL("echoheader?Accept-Charset"), DEFAULT_PRIORITY, &d)); | 7222 http_test_server()->GetURL("/echoheader?Accept-Charset"), |
| 7223 DEFAULT_PRIORITY, &d)); |
| 7182 HttpRequestHeaders headers; | 7224 HttpRequestHeaders headers; |
| 7183 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 7225 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
| 7184 req->SetExtraRequestHeaders(headers); | 7226 req->SetExtraRequestHeaders(headers); |
| 7185 req->Start(); | 7227 req->Start(); |
| 7186 base::RunLoop().Run(); | 7228 base::RunLoop().Run(); |
| 7187 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 7229 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
| 7188 } | 7230 } |
| 7189 | 7231 |
| 7190 // Check that default User-Agent header is sent. | 7232 // Check that default User-Agent header is sent. |
| 7191 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { | 7233 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { |
| 7192 ASSERT_TRUE(test_server_.Start()); | 7234 ASSERT_TRUE(http_test_server()->Start()); |
| 7193 | 7235 |
| 7194 TestDelegate d; | 7236 TestDelegate d; |
| 7195 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7237 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7196 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d)); | 7238 http_test_server()->GetURL("/echoheader?User-Agent"), DEFAULT_PRIORITY, |
| 7239 &d)); |
| 7197 req->Start(); | 7240 req->Start(); |
| 7198 base::RunLoop().Run(); | 7241 base::RunLoop().Run(); |
| 7199 EXPECT_EQ(default_context_.http_user_agent_settings()->GetUserAgent(), | 7242 EXPECT_EQ(default_context_.http_user_agent_settings()->GetUserAgent(), |
| 7200 d.data_received()); | 7243 d.data_received()); |
| 7201 } | 7244 } |
| 7202 | 7245 |
| 7203 // Check that if request overrides the User-Agent header, | 7246 // Check that if request overrides the User-Agent header, |
| 7204 // the default is not appended. | 7247 // the default is not appended. |
| 7205 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { | 7248 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { |
| 7206 ASSERT_TRUE(test_server_.Start()); | 7249 ASSERT_TRUE(http_test_server()->Start()); |
| 7207 | 7250 |
| 7208 TestDelegate d; | 7251 TestDelegate d; |
| 7209 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7252 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7210 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d)); | 7253 http_test_server()->GetURL("/echoheader?User-Agent"), DEFAULT_PRIORITY, |
| 7254 &d)); |
| 7211 HttpRequestHeaders headers; | 7255 HttpRequestHeaders headers; |
| 7212 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 7256 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
| 7213 req->SetExtraRequestHeaders(headers); | 7257 req->SetExtraRequestHeaders(headers); |
| 7214 req->Start(); | 7258 req->Start(); |
| 7215 base::RunLoop().Run(); | 7259 base::RunLoop().Run(); |
| 7216 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received()); | 7260 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received()); |
| 7217 } | 7261 } |
| 7218 | 7262 |
| 7219 // Check that a NULL HttpUserAgentSettings causes the corresponding empty | 7263 // Check that a NULL HttpUserAgentSettings causes the corresponding empty |
| 7220 // User-Agent header to be sent but does not send the Accept-Language and | 7264 // User-Agent header to be sent but does not send the Accept-Language and |
| 7221 // Accept-Charset headers. | 7265 // Accept-Charset headers. |
| 7222 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { | 7266 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { |
| 7223 ASSERT_TRUE(test_server_.Start()); | 7267 ASSERT_TRUE(http_test_server()->Start()); |
| 7224 | 7268 |
| 7225 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 7269 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 7226 TestURLRequestContext context(true); | 7270 TestURLRequestContext context(true); |
| 7227 context.set_network_delegate(&network_delegate); | 7271 context.set_network_delegate(&network_delegate); |
| 7228 context.Init(); | 7272 context.Init(); |
| 7229 // We override the HttpUserAgentSettings after initialization because empty | 7273 // We override the HttpUserAgentSettings after initialization because empty |
| 7230 // entries get overridden by Init(). | 7274 // entries get overridden by Init(). |
| 7231 context.set_http_user_agent_settings(NULL); | 7275 context.set_http_user_agent_settings(NULL); |
| 7232 | 7276 |
| 7233 struct { | 7277 struct { |
| 7234 const char* request; | 7278 const char* request; |
| 7235 const char* expected_response; | 7279 const char* expected_response; |
| 7236 } tests[] = { { "echoheader?Accept-Language", "None" }, | 7280 } tests[] = {{"/echoheader?Accept-Language", "None"}, |
| 7237 { "echoheader?Accept-Charset", "None" }, | 7281 {"/echoheader?Accept-Charset", "None"}, |
| 7238 { "echoheader?User-Agent", "" } }; | 7282 {"/echoheader?User-Agent", ""}}; |
| 7239 | 7283 |
| 7240 for (size_t i = 0; i < arraysize(tests); i++) { | 7284 for (size_t i = 0; i < arraysize(tests); i++) { |
| 7241 TestDelegate d; | 7285 TestDelegate d; |
| 7242 scoped_ptr<URLRequest> req(context.CreateRequest( | 7286 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 7243 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d)); | 7287 http_test_server()->GetURL(tests[i].request), DEFAULT_PRIORITY, &d)); |
| 7244 req->Start(); | 7288 req->Start(); |
| 7245 base::RunLoop().Run(); | 7289 base::RunLoop().Run(); |
| 7246 EXPECT_EQ(tests[i].expected_response, d.data_received()) | 7290 EXPECT_EQ(tests[i].expected_response, d.data_received()) |
| 7247 << " Request = \"" << tests[i].request << "\""; | 7291 << " Request = \"" << tests[i].request << "\""; |
| 7248 } | 7292 } |
| 7249 } | 7293 } |
| 7250 | 7294 |
| 7251 // Make sure that URLRequest passes on its priority updates to | 7295 // Make sure that URLRequest passes on its priority updates to |
| 7252 // newly-created jobs after the first one. | 7296 // newly-created jobs after the first one. |
| 7253 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { | 7297 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { |
| 7254 ASSERT_TRUE(test_server_.Start()); | 7298 ASSERT_TRUE(http_test_server()->Start()); |
| 7255 | 7299 |
| 7256 TestDelegate d; | 7300 TestDelegate d; |
| 7257 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7301 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7258 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d)); | 7302 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 7259 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); | 7303 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); |
| 7260 | 7304 |
| 7261 scoped_refptr<URLRequestRedirectJob> redirect_job = | 7305 scoped_refptr<URLRequestRedirectJob> redirect_job = new URLRequestRedirectJob( |
| 7262 new URLRequestRedirectJob( | 7306 req.get(), &default_network_delegate_, |
| 7263 req.get(), &default_network_delegate_, test_server_.GetURL("echo"), | 7307 http_test_server()->GetURL("/echo"), |
| 7264 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); | 7308 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); |
| 7265 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); | 7309 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); |
| 7266 | 7310 |
| 7267 req->SetPriority(LOW); | 7311 req->SetPriority(LOW); |
| 7268 req->Start(); | 7312 req->Start(); |
| 7269 EXPECT_TRUE(req->is_pending()); | 7313 EXPECT_TRUE(req->is_pending()); |
| 7270 | 7314 |
| 7271 scoped_refptr<URLRequestTestJob> job = | 7315 scoped_refptr<URLRequestTestJob> job = |
| 7272 new URLRequestTestJob(req.get(), &default_network_delegate_); | 7316 new URLRequestTestJob(req.get(), &default_network_delegate_); |
| 7273 AddTestInterceptor()->set_main_intercept_job(job.get()); | 7317 AddTestInterceptor()->set_main_intercept_job(job.get()); |
| 7274 | 7318 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7343 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d)); | 7387 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d)); |
| 7344 req->Start(); | 7388 req->Start(); |
| 7345 base::RunLoop().Run(); | 7389 base::RunLoop().Run(); |
| 7346 | 7390 |
| 7347 EXPECT_TRUE(d.request_failed()); | 7391 EXPECT_TRUE(d.request_failed()); |
| 7348 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); | 7392 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 7349 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); | 7393 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); |
| 7350 } | 7394 } |
| 7351 | 7395 |
| 7352 TEST_F(URLRequestTestHTTP, NetworkAccessedSetOnNetworkRequest) { | 7396 TEST_F(URLRequestTestHTTP, NetworkAccessedSetOnNetworkRequest) { |
| 7353 ASSERT_TRUE(test_server_.Start()); | 7397 ASSERT_TRUE(http_test_server()->Start()); |
| 7354 | 7398 |
| 7355 TestDelegate d; | 7399 TestDelegate d; |
| 7356 GURL test_url(test_server_.GetURL(std::string())); | 7400 GURL test_url(http_test_server()->GetURL("/")); |
| 7357 scoped_ptr<URLRequest> req( | 7401 scoped_ptr<URLRequest> req( |
| 7358 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 7402 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); |
| 7359 | 7403 |
| 7360 req->Start(); | 7404 req->Start(); |
| 7361 base::RunLoop().Run(); | 7405 base::RunLoop().Run(); |
| 7362 | 7406 |
| 7363 EXPECT_TRUE(req->response_info().network_accessed); | 7407 EXPECT_TRUE(req->response_info().network_accessed); |
| 7364 } | 7408 } |
| 7365 | 7409 |
| 7366 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnCachedResponse) { | 7410 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnCachedResponse) { |
| 7367 ASSERT_TRUE(test_server_.Start()); | 7411 ASSERT_TRUE(http_test_server()->Start()); |
| 7368 | 7412 |
| 7369 // Populate the cache. | 7413 // Populate the cache. |
| 7370 TestDelegate d; | 7414 TestDelegate d; |
| 7371 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 7415 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7372 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d)); | 7416 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); |
| 7373 req->Start(); | 7417 req->Start(); |
| 7374 base::RunLoop().Run(); | 7418 base::RunLoop().Run(); |
| 7375 | 7419 |
| 7376 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 7420 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 7377 EXPECT_TRUE(req->response_info().network_accessed); | 7421 EXPECT_TRUE(req->response_info().network_accessed); |
| 7378 EXPECT_FALSE(req->response_info().was_cached); | 7422 EXPECT_FALSE(req->response_info().was_cached); |
| 7379 | 7423 |
| 7380 req = default_context_.CreateRequest(test_server_.GetURL("cachetime"), | 7424 req = default_context_.CreateRequest(http_test_server()->GetURL("/cachetime"), |
| 7381 DEFAULT_PRIORITY, &d); | 7425 DEFAULT_PRIORITY, &d); |
| 7382 req->Start(); | 7426 req->Start(); |
| 7383 base::RunLoop().Run(); | 7427 base::RunLoop().Run(); |
| 7384 | 7428 |
| 7385 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 7429 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 7386 EXPECT_FALSE(req->response_info().network_accessed); | 7430 EXPECT_FALSE(req->response_info().network_accessed); |
| 7387 EXPECT_TRUE(req->response_info().was_cached); | 7431 EXPECT_TRUE(req->response_info().was_cached); |
| 7388 } | 7432 } |
| 7389 | 7433 |
| 7390 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnLoadOnlyFromCache) { | 7434 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnLoadOnlyFromCache) { |
| 7391 ASSERT_TRUE(test_server_.Start()); | 7435 ASSERT_TRUE(http_test_server()->Start()); |
| 7392 | 7436 |
| 7393 TestDelegate d; | 7437 TestDelegate d; |
| 7394 GURL test_url(test_server_.GetURL(std::string())); | 7438 GURL test_url(http_test_server()->GetURL("/")); |
| 7395 scoped_ptr<URLRequest> req( | 7439 scoped_ptr<URLRequest> req( |
| 7396 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 7440 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); |
| 7397 req->SetLoadFlags(LOAD_ONLY_FROM_CACHE); | 7441 req->SetLoadFlags(LOAD_ONLY_FROM_CACHE); |
| 7398 | 7442 |
| 7399 req->Start(); | 7443 req->Start(); |
| 7400 base::RunLoop().Run(); | 7444 base::RunLoop().Run(); |
| 7401 | 7445 |
| 7402 EXPECT_FALSE(req->response_info().network_accessed); | 7446 EXPECT_FALSE(req->response_info().network_accessed); |
| 7403 } | 7447 } |
| 7404 | 7448 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 7423 private: | 7467 private: |
| 7424 MockURLRequestInterceptor* interceptor_; | 7468 MockURLRequestInterceptor* interceptor_; |
| 7425 }; | 7469 }; |
| 7426 | 7470 |
| 7427 TEST_F(URLRequestInterceptorTestHTTP, | 7471 TEST_F(URLRequestInterceptorTestHTTP, |
| 7428 NetworkDelegateNotificationOnRedirectIntercept) { | 7472 NetworkDelegateNotificationOnRedirectIntercept) { |
| 7429 interceptor()->set_intercept_redirect(true); | 7473 interceptor()->set_intercept_redirect(true); |
| 7430 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers()); | 7474 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers()); |
| 7431 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data()); | 7475 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data()); |
| 7432 | 7476 |
| 7433 ASSERT_TRUE(test_server()->Start()); | 7477 ASSERT_TRUE(http_test_server()->Start()); |
| 7434 | 7478 |
| 7435 TestDelegate d; | 7479 TestDelegate d; |
| 7436 scoped_ptr<URLRequest> req(default_context().CreateRequest( | 7480 scoped_ptr<URLRequest> req(default_context().CreateRequest( |
| 7437 test_server()->GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d)); | 7481 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, &d)); |
| 7438 req->Start(); | 7482 req->Start(); |
| 7439 base::RunLoop().Run(); | 7483 base::RunLoop().Run(); |
| 7440 | 7484 |
| 7441 EXPECT_TRUE(interceptor()->did_intercept_redirect()); | 7485 EXPECT_TRUE(interceptor()->did_intercept_redirect()); |
| 7442 // Check we got one good response | 7486 // Check we got one good response |
| 7443 EXPECT_TRUE(req->status().is_success()); | 7487 EXPECT_TRUE(req->status().is_success()); |
| 7444 if (req->status().is_success()) | 7488 if (req->status().is_success()) |
| 7445 EXPECT_EQ(200, req->response_headers()->response_code()); | 7489 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 7446 | 7490 |
| 7447 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); | 7491 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); |
| 7448 EXPECT_EQ(1, d.response_started_count()); | 7492 EXPECT_EQ(1, d.response_started_count()); |
| 7449 EXPECT_EQ(0, d.received_redirect_count()); | 7493 EXPECT_EQ(0, d.received_redirect_count()); |
| 7450 | 7494 |
| 7451 EXPECT_EQ(1, default_network_delegate()->created_requests()); | 7495 EXPECT_EQ(1, default_network_delegate()->created_requests()); |
| 7452 EXPECT_EQ(1, default_network_delegate()->before_send_headers_count()); | 7496 EXPECT_EQ(1, default_network_delegate()->before_send_headers_count()); |
| 7453 EXPECT_EQ(1, default_network_delegate()->headers_received_count()); | 7497 EXPECT_EQ(1, default_network_delegate()->headers_received_count()); |
| 7454 } | 7498 } |
| 7455 | 7499 |
| 7456 TEST_F(URLRequestInterceptorTestHTTP, | 7500 TEST_F(URLRequestInterceptorTestHTTP, |
| 7457 NetworkDelegateNotificationOnErrorIntercept) { | 7501 NetworkDelegateNotificationOnErrorIntercept) { |
| 7458 // Intercept that error and respond with an OK response. | 7502 // Intercept that error and respond with an OK response. |
| 7459 interceptor()->set_intercept_final_response(true); | 7503 interceptor()->set_intercept_final_response(true); |
| 7460 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); | 7504 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); |
| 7461 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); | 7505 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); |
| 7462 default_network_delegate()->set_can_be_intercepted_on_error(true); | 7506 default_network_delegate()->set_can_be_intercepted_on_error(true); |
| 7463 | 7507 |
| 7464 ASSERT_TRUE(test_server()->Start()); | 7508 ASSERT_TRUE(http_test_server()->Start()); |
| 7465 | 7509 |
| 7466 TestDelegate d; | 7510 TestDelegate d; |
| 7467 scoped_ptr<URLRequest> req(default_context().CreateRequest( | 7511 scoped_ptr<URLRequest> req(default_context().CreateRequest( |
| 7468 test_server()->GetURL("files/two-content-lengths.html"), DEFAULT_PRIORITY, | 7512 http_test_server()->GetURL("/two-content-lengths.html"), DEFAULT_PRIORITY, |
| 7469 &d)); | 7513 &d)); |
| 7470 req->set_method("GET"); | 7514 req->set_method("GET"); |
| 7471 req->Start(); | 7515 req->Start(); |
| 7472 base::RunLoop().Run(); | 7516 base::RunLoop().Run(); |
| 7473 | 7517 |
| 7474 EXPECT_TRUE(interceptor()->did_intercept_final()); | 7518 EXPECT_TRUE(interceptor()->did_intercept_final()); |
| 7475 | 7519 |
| 7476 // Check we received one good response. | 7520 // Check we received one good response. |
| 7477 EXPECT_TRUE(req->status().is_success()); | 7521 EXPECT_TRUE(req->status().is_success()); |
| 7478 if (req->status().is_success()) | 7522 if (req->status().is_success()) |
| 7479 EXPECT_EQ(200, req->response_headers()->response_code()); | 7523 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 7480 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); | 7524 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); |
| 7481 EXPECT_EQ(1, d.response_started_count()); | 7525 EXPECT_EQ(1, d.response_started_count()); |
| 7482 EXPECT_EQ(0, d.received_redirect_count()); | 7526 EXPECT_EQ(0, d.received_redirect_count()); |
| 7483 | 7527 |
| 7484 EXPECT_EQ(1, default_network_delegate()->created_requests()); | 7528 EXPECT_EQ(1, default_network_delegate()->created_requests()); |
| 7485 EXPECT_EQ(1, default_network_delegate()->before_send_headers_count()); | 7529 EXPECT_EQ(1, default_network_delegate()->before_send_headers_count()); |
| 7486 EXPECT_EQ(0, default_network_delegate()->headers_received_count()); | 7530 EXPECT_EQ(0, default_network_delegate()->headers_received_count()); |
| 7487 } | 7531 } |
| 7488 | 7532 |
| 7489 TEST_F(URLRequestInterceptorTestHTTP, | 7533 TEST_F(URLRequestInterceptorTestHTTP, |
| 7490 NetworkDelegateNotificationOnResponseIntercept) { | 7534 NetworkDelegateNotificationOnResponseIntercept) { |
| 7491 // Intercept that error and respond with an OK response. | 7535 // Intercept that error and respond with an OK response. |
| 7492 interceptor()->set_intercept_final_response(true); | 7536 interceptor()->set_intercept_final_response(true); |
| 7493 | 7537 |
| 7494 // Intercept with a real URLRequestHttpJob. | 7538 // Intercept with a real URLRequestHttpJob. |
| 7495 interceptor()->set_use_url_request_http_job(true); | 7539 interceptor()->set_use_url_request_http_job(true); |
| 7496 | 7540 |
| 7497 ASSERT_TRUE(test_server()->Start()); | 7541 ASSERT_TRUE(http_test_server()->Start()); |
| 7498 | 7542 |
| 7499 TestDelegate d; | 7543 TestDelegate d; |
| 7500 scoped_ptr<URLRequest> req(default_context().CreateRequest( | 7544 scoped_ptr<URLRequest> req(default_context().CreateRequest( |
| 7501 test_server()->GetURL("files/simple.html"), DEFAULT_PRIORITY, &d)); | 7545 http_test_server()->GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); |
| 7502 req->set_method("GET"); | 7546 req->set_method("GET"); |
| 7503 req->Start(); | 7547 req->Start(); |
| 7504 base::RunLoop().Run(); | 7548 base::RunLoop().Run(); |
| 7505 | 7549 |
| 7506 EXPECT_TRUE(interceptor()->did_intercept_final()); | 7550 EXPECT_TRUE(interceptor()->did_intercept_final()); |
| 7507 | 7551 |
| 7508 // Check we received one good response. | 7552 // Check we received one good response. |
| 7509 EXPECT_TRUE(req->status().is_success()); | 7553 EXPECT_TRUE(req->status().is_success()); |
| 7510 if (req->status().is_success()) | 7554 if (req->status().is_success()) |
| 7511 EXPECT_EQ(200, req->response_headers()->response_code()); | 7555 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 7512 EXPECT_EQ("hello", d.data_received()); | 7556 EXPECT_EQ("hello", d.data_received()); |
| 7513 EXPECT_EQ(1, d.response_started_count()); | 7557 EXPECT_EQ(1, d.response_started_count()); |
| 7514 EXPECT_EQ(0, d.received_redirect_count()); | 7558 EXPECT_EQ(0, d.received_redirect_count()); |
| 7515 | 7559 |
| 7516 EXPECT_EQ(1, default_network_delegate()->created_requests()); | 7560 EXPECT_EQ(1, default_network_delegate()->created_requests()); |
| 7517 EXPECT_EQ(2, default_network_delegate()->before_send_headers_count()); | 7561 EXPECT_EQ(2, default_network_delegate()->before_send_headers_count()); |
| 7518 EXPECT_EQ(2, default_network_delegate()->headers_received_count()); | 7562 EXPECT_EQ(2, default_network_delegate()->headers_received_count()); |
| 7519 } | 7563 } |
| 7520 | 7564 |
| 7521 class URLRequestTestReferrerPolicy : public URLRequestTest { | 7565 class URLRequestTestReferrerPolicy : public URLRequestTest { |
| 7522 public: | 7566 public: |
| 7523 URLRequestTestReferrerPolicy() {} | 7567 URLRequestTestReferrerPolicy() {} |
| 7524 | 7568 |
| 7525 void InstantiateSameOriginServers(SpawnedTestServer::Type origin_type) { | 7569 void InstantiateSameOriginServers(bool is_ssl) { |
| 7526 origin_server_.reset(new SpawnedTestServer( | 7570 if (is_ssl) |
| 7527 origin_type, SpawnedTestServer::kLocalhost, | 7571 origin_server_.reset( |
| 7528 origin_type == SpawnedTestServer::TYPE_HTTPS | 7572 new EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 7529 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) | 7573 else |
| 7530 : base::FilePath(kTestFilePath))); | 7574 origin_server_.reset(new EmbeddedTestServer); |
| 7575 if (is_ssl) |
| 7576 origin_server_->AddDefaultHandlers( |
| 7577 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 7578 else { |
| 7579 origin_server_->AddDefaultHandlers(base::FilePath(kTestFilePath)); |
| 7580 } |
| 7531 ASSERT_TRUE(origin_server_->Start()); | 7581 ASSERT_TRUE(origin_server_->Start()); |
| 7532 } | 7582 } |
| 7533 | 7583 |
| 7534 void InstantiateCrossOriginServers(SpawnedTestServer::Type origin_type, | 7584 void InstantiateCrossOriginServers(bool origin_is_ssl, bool dest_is_ssl) { |
| 7535 SpawnedTestServer::Type destination_type) { | 7585 if (origin_is_ssl) { |
| 7536 origin_server_.reset(new SpawnedTestServer( | 7586 origin_server_.reset( |
| 7537 origin_type, SpawnedTestServer::kLocalhost, | 7587 new EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 7538 origin_type == SpawnedTestServer::TYPE_HTTPS | 7588 origin_server_->AddDefaultHandlers( |
| 7539 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) | 7589 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 7540 : base::FilePath(kTestFilePath))); | 7590 } else { |
| 7591 origin_server_.reset(new EmbeddedTestServer); |
| 7592 origin_server_->AddDefaultHandlers(base::FilePath(kTestFilePath)); |
| 7593 } |
| 7541 ASSERT_TRUE(origin_server_->Start()); | 7594 ASSERT_TRUE(origin_server_->Start()); |
| 7542 | 7595 |
| 7543 destination_server_.reset(new SpawnedTestServer( | 7596 if (dest_is_ssl) { |
| 7544 destination_type, SpawnedTestServer::kLocalhost, | 7597 destination_server_.reset( |
| 7545 destination_type == SpawnedTestServer::TYPE_HTTPS | 7598 new EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 7546 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) | 7599 destination_server_->AddDefaultHandlers( |
| 7547 : base::FilePath(kTestFilePath))); | 7600 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 7601 } else { |
| 7602 destination_server_.reset(new EmbeddedTestServer); |
| 7603 destination_server_->AddDefaultHandlers(base::FilePath(kTestFilePath)); |
| 7604 } |
| 7548 ASSERT_TRUE(destination_server_->Start()); | 7605 ASSERT_TRUE(destination_server_->Start()); |
| 7549 } | 7606 } |
| 7550 | 7607 |
| 7551 void VerifyReferrerAfterRedirect(URLRequest::ReferrerPolicy policy, | 7608 void VerifyReferrerAfterRedirect(URLRequest::ReferrerPolicy policy, |
| 7552 const GURL& referrer, | 7609 const GURL& referrer, |
| 7553 const GURL& expected) { | 7610 const GURL& expected) { |
| 7554 // Create and execute the request: we'll only have a |destination_server_| | 7611 // Create and execute the request: we'll only have a |destination_server_| |
| 7555 // if the origins are meant to be distinct. Otherwise, we'll use the | 7612 // if the origins are meant to be distinct. Otherwise, we'll use the |
| 7556 // |origin_server_| for both endpoints. | 7613 // |origin_server_| for both endpoints. |
| 7557 GURL destination_url = | 7614 GURL destination_url = |
| 7558 destination_server_ ? destination_server_->GetURL("echoheader?Referer") | 7615 destination_server_ ? destination_server_->GetURL("/echoheader?Referer") |
| 7559 : origin_server_->GetURL("echoheader?Referer"); | 7616 : origin_server_->GetURL("/echoheader?Referer"); |
| 7560 GURL origin_url = | 7617 GURL origin_url = |
| 7561 origin_server_->GetURL("server-redirect?" + destination_url.spec()); | 7618 origin_server_->GetURL("/server-redirect?" + destination_url.spec()); |
| 7562 | 7619 |
| 7563 TestDelegate d; | 7620 TestDelegate d; |
| 7564 scoped_ptr<URLRequest> req( | 7621 scoped_ptr<URLRequest> req( |
| 7565 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d)); | 7622 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d)); |
| 7566 req->set_referrer_policy(policy); | 7623 req->set_referrer_policy(policy); |
| 7567 req->SetReferrer(referrer.spec()); | 7624 req->SetReferrer(referrer.spec()); |
| 7568 req->Start(); | 7625 req->Start(); |
| 7569 base::RunLoop().Run(); | 7626 base::RunLoop().Run(); |
| 7570 | 7627 |
| 7571 EXPECT_EQ(1, d.response_started_count()); | 7628 EXPECT_EQ(1, d.response_started_count()); |
| 7572 EXPECT_EQ(1, d.received_redirect_count()); | 7629 EXPECT_EQ(1, d.received_redirect_count()); |
| 7573 EXPECT_EQ(destination_url, req->url()); | 7630 EXPECT_EQ(destination_url, req->url()); |
| 7574 EXPECT_TRUE(req->status().is_success()); | 7631 EXPECT_TRUE(req->status().is_success()); |
| 7575 EXPECT_EQ(200, req->response_headers()->response_code()); | 7632 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 7576 | 7633 |
| 7577 EXPECT_EQ(expected.spec(), req->referrer()); | 7634 EXPECT_EQ(expected.spec(), req->referrer()); |
| 7578 if (expected.is_empty()) | 7635 if (expected.is_empty()) |
| 7579 EXPECT_EQ("None", d.data_received()); | 7636 EXPECT_EQ("None", d.data_received()); |
| 7580 else | 7637 else |
| 7581 EXPECT_EQ(expected.spec(), d.data_received()); | 7638 EXPECT_EQ(expected.spec(), d.data_received()); |
| 7582 } | 7639 } |
| 7583 | 7640 |
| 7584 SpawnedTestServer* origin_server() const { return origin_server_.get(); } | 7641 EmbeddedTestServer* origin_server() const { return origin_server_.get(); } |
| 7585 | 7642 |
| 7586 private: | 7643 private: |
| 7587 scoped_ptr<SpawnedTestServer> origin_server_; | 7644 scoped_ptr<EmbeddedTestServer> origin_server_; |
| 7588 scoped_ptr<SpawnedTestServer> destination_server_; | 7645 scoped_ptr<EmbeddedTestServer> destination_server_; |
| 7589 }; | 7646 }; |
| 7590 | 7647 |
| 7591 TEST_F(URLRequestTestReferrerPolicy, HTTPToSameOriginHTTP) { | 7648 TEST_F(URLRequestTestReferrerPolicy, HTTPToSameOriginHTTP) { |
| 7592 InstantiateSameOriginServers(SpawnedTestServer::TYPE_HTTP); | 7649 InstantiateSameOriginServers(false); |
| 7593 | 7650 |
| 7594 VerifyReferrerAfterRedirect( | 7651 VerifyReferrerAfterRedirect( |
| 7595 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 7652 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 7596 origin_server()->GetURL("path/to/file.html"), | 7653 origin_server()->GetURL("/path/to/file.html"), |
| 7597 origin_server()->GetURL("path/to/file.html")); | 7654 origin_server()->GetURL("/path/to/file.html")); |
| 7598 | 7655 |
| 7599 VerifyReferrerAfterRedirect( | 7656 VerifyReferrerAfterRedirect( |
| 7600 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | 7657 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 7601 origin_server()->GetURL("path/to/file.html"), | 7658 origin_server()->GetURL("/path/to/file.html"), |
| 7602 origin_server()->GetURL("path/to/file.html")); | 7659 origin_server()->GetURL("/path/to/file.html")); |
| 7603 | 7660 |
| 7604 VerifyReferrerAfterRedirect( | 7661 VerifyReferrerAfterRedirect( |
| 7605 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | 7662 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 7606 origin_server()->GetURL("path/to/file.html"), | 7663 origin_server()->GetURL("/path/to/file.html"), |
| 7607 origin_server()->GetURL("path/to/file.html")); | 7664 origin_server()->GetURL("/path/to/file.html")); |
| 7608 | 7665 |
| 7609 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | 7666 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 7610 origin_server()->GetURL("path/to/file.html"), | 7667 origin_server()->GetURL("/path/to/file.html"), |
| 7611 origin_server()->GetURL("path/to/file.html")); | 7668 origin_server()->GetURL("/path/to/file.html")); |
| 7612 } | 7669 } |
| 7613 | 7670 |
| 7614 // Can't spin up more than one SpawnedTestServer on Android. | 7671 TEST_F(URLRequestTestReferrerPolicy, HTTPToCrossOriginHTTP) { |
| 7615 #if defined(OS_ANDROID) | 7672 InstantiateCrossOriginServers(false, false); |
| 7616 #define MAYBE_HTTPToCrossOriginHTTP DISABLED_HTTPToCrosOriginHTTP | |
| 7617 #else | |
| 7618 #define MAYBE_HTTPToCrossOriginHTTP HTTPToCrossOriginHTTP | |
| 7619 #endif | |
| 7620 TEST_F(URLRequestTestReferrerPolicy, MAYBE_HTTPToCrossOriginHTTP) { | |
| 7621 InstantiateCrossOriginServers(SpawnedTestServer::TYPE_HTTP, | |
| 7622 SpawnedTestServer::TYPE_HTTP); | |
| 7623 | 7673 |
| 7624 VerifyReferrerAfterRedirect( | 7674 VerifyReferrerAfterRedirect( |
| 7625 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 7675 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 7626 origin_server()->GetURL("path/to/file.html"), | 7676 origin_server()->GetURL("/path/to/file.html"), |
| 7627 origin_server()->GetURL("path/to/file.html")); | 7677 origin_server()->GetURL("/path/to/file.html")); |
| 7628 | 7678 |
| 7629 VerifyReferrerAfterRedirect( | 7679 VerifyReferrerAfterRedirect( |
| 7630 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | 7680 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 7631 origin_server()->GetURL("path/to/file.html"), | 7681 origin_server()->GetURL("/path/to/file.html"), |
| 7632 origin_server()->GetURL(std::string())); | 7682 origin_server()->GetURL("/")); |
| 7633 | 7683 |
| 7634 VerifyReferrerAfterRedirect( | 7684 VerifyReferrerAfterRedirect( |
| 7635 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | 7685 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 7636 origin_server()->GetURL("path/to/file.html"), | 7686 origin_server()->GetURL("/path/to/file.html"), |
| 7637 origin_server()->GetURL(std::string())); | 7687 origin_server()->GetURL("/")); |
| 7638 | 7688 |
| 7639 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | 7689 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 7640 origin_server()->GetURL("path/to/file.html"), | 7690 origin_server()->GetURL("/path/to/file.html"), |
| 7641 origin_server()->GetURL("path/to/file.html")); | 7691 origin_server()->GetURL("/path/to/file.html")); |
| 7642 } | 7692 } |
| 7643 | 7693 |
| 7644 TEST_F(URLRequestTestReferrerPolicy, HTTPSToSameOriginHTTPS) { | 7694 TEST_F(URLRequestTestReferrerPolicy, HTTPSToSameOriginHTTPS) { |
| 7645 InstantiateSameOriginServers(SpawnedTestServer::TYPE_HTTPS); | 7695 InstantiateSameOriginServers(true); |
| 7646 | 7696 |
| 7647 VerifyReferrerAfterRedirect( | 7697 VerifyReferrerAfterRedirect( |
| 7648 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 7698 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 7649 origin_server()->GetURL("path/to/file.html"), | 7699 origin_server()->GetURL("/path/to/file.html"), |
| 7650 origin_server()->GetURL("path/to/file.html")); | 7700 origin_server()->GetURL("/path/to/file.html")); |
| 7651 | 7701 |
| 7652 VerifyReferrerAfterRedirect( | 7702 VerifyReferrerAfterRedirect( |
| 7653 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | 7703 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 7654 origin_server()->GetURL("path/to/file.html"), | 7704 origin_server()->GetURL("/path/to/file.html"), |
| 7655 origin_server()->GetURL("path/to/file.html")); | 7705 origin_server()->GetURL("/path/to/file.html")); |
| 7656 | 7706 |
| 7657 VerifyReferrerAfterRedirect( | 7707 VerifyReferrerAfterRedirect( |
| 7658 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | 7708 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 7659 origin_server()->GetURL("path/to/file.html"), | 7709 origin_server()->GetURL("/path/to/file.html"), |
| 7660 origin_server()->GetURL("path/to/file.html")); | 7710 origin_server()->GetURL("/path/to/file.html")); |
| 7661 | 7711 |
| 7662 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | 7712 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 7663 origin_server()->GetURL("path/to/file.html"), | 7713 origin_server()->GetURL("/path/to/file.html"), |
| 7664 origin_server()->GetURL("path/to/file.html")); | 7714 origin_server()->GetURL("/path/to/file.html")); |
| 7665 } | 7715 } |
| 7666 | 7716 |
| 7667 // Can't spin up more than one SpawnedTestServer on Android. | 7717 TEST_F(URLRequestTestReferrerPolicy, HTTPSToCrossOriginHTTPS) { |
| 7668 #if defined(OS_ANDROID) | 7718 InstantiateCrossOriginServers(true, true); |
| 7669 #define MAYBE_HTTPSToCrossOriginHTTPS DISABLED_HTTPSToCrosOriginHTTPS | |
| 7670 #else | |
| 7671 #define MAYBE_HTTPSToCrossOriginHTTPS HTTPSToCrossOriginHTTPS | |
| 7672 #endif | |
| 7673 TEST_F(URLRequestTestReferrerPolicy, MAYBE_HTTPSToCrossOriginHTTPS) { | |
| 7674 InstantiateCrossOriginServers(SpawnedTestServer::TYPE_HTTPS, | |
| 7675 SpawnedTestServer::TYPE_HTTPS); | |
| 7676 | 7719 |
| 7677 VerifyReferrerAfterRedirect( | 7720 VerifyReferrerAfterRedirect( |
| 7678 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 7721 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 7679 origin_server()->GetURL("path/to/file.html"), | 7722 origin_server()->GetURL("/path/to/file.html"), |
| 7680 origin_server()->GetURL("path/to/file.html")); | 7723 origin_server()->GetURL("/path/to/file.html")); |
| 7681 | 7724 |
| 7682 VerifyReferrerAfterRedirect( | 7725 VerifyReferrerAfterRedirect( |
| 7683 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | 7726 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 7684 origin_server()->GetURL("path/to/file.html"), | 7727 origin_server()->GetURL("/path/to/file.html"), |
| 7685 origin_server()->GetURL(std::string())); | 7728 origin_server()->GetURL("/")); |
| 7686 | 7729 |
| 7687 VerifyReferrerAfterRedirect( | 7730 VerifyReferrerAfterRedirect( |
| 7688 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | 7731 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 7689 origin_server()->GetURL("path/to/file.html"), | 7732 origin_server()->GetURL("/path/to/file.html"), |
| 7690 origin_server()->GetURL(std::string())); | 7733 origin_server()->GetURL("/")); |
| 7691 | 7734 |
| 7692 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | 7735 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 7693 origin_server()->GetURL("path/to/file.html"), | 7736 origin_server()->GetURL("/path/to/file.html"), |
| 7694 origin_server()->GetURL("path/to/file.html")); | 7737 origin_server()->GetURL("/path/to/file.html")); |
| 7695 } | 7738 } |
| 7696 | 7739 |
| 7697 // Can't spin up more than one SpawnedTestServer on Android. | 7740 TEST_F(URLRequestTestReferrerPolicy, HTTPToHTTPS) { |
| 7698 #if defined(OS_ANDROID) | 7741 InstantiateCrossOriginServers(false, true); |
| 7699 #define MAYBE_HTTPToHTTPS DISABLED_HTTPToHTTPS | |
| 7700 #else | |
| 7701 #define MAYBE_HTTPToHTTPS HTTPToHTTPS | |
| 7702 #endif | |
| 7703 TEST_F(URLRequestTestReferrerPolicy, MAYBE_HTTPToHTTPS) { | |
| 7704 InstantiateCrossOriginServers(SpawnedTestServer::TYPE_HTTP, | |
| 7705 SpawnedTestServer::TYPE_HTTPS); | |
| 7706 | 7742 |
| 7707 VerifyReferrerAfterRedirect( | 7743 VerifyReferrerAfterRedirect( |
| 7708 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 7744 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 7709 origin_server()->GetURL("path/to/file.html"), | 7745 origin_server()->GetURL("/path/to/file.html"), |
| 7710 origin_server()->GetURL("path/to/file.html")); | 7746 origin_server()->GetURL("/path/to/file.html")); |
| 7711 | 7747 |
| 7712 VerifyReferrerAfterRedirect( | 7748 VerifyReferrerAfterRedirect( |
| 7713 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | 7749 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 7714 origin_server()->GetURL("path/to/file.html"), | 7750 origin_server()->GetURL("/path/to/file.html"), |
| 7715 origin_server()->GetURL(std::string())); | 7751 origin_server()->GetURL("/")); |
| 7716 | 7752 |
| 7717 VerifyReferrerAfterRedirect( | 7753 VerifyReferrerAfterRedirect( |
| 7718 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | 7754 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 7719 origin_server()->GetURL("path/to/file.html"), | 7755 origin_server()->GetURL("/path/to/file.html"), |
| 7720 origin_server()->GetURL(std::string())); | 7756 origin_server()->GetURL("/")); |
| 7721 | 7757 |
| 7722 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | 7758 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 7723 origin_server()->GetURL("path/to/file.html"), | 7759 origin_server()->GetURL("/path/to/file.html"), |
| 7724 origin_server()->GetURL("path/to/file.html")); | 7760 origin_server()->GetURL("/path/to/file.html")); |
| 7725 } | 7761 } |
| 7726 | 7762 |
| 7727 // Can't spin up more than one SpawnedTestServer on Android. | 7763 TEST_F(URLRequestTestReferrerPolicy, HTTPSToHTTP) { |
| 7728 #if defined(OS_ANDROID) | 7764 InstantiateCrossOriginServers(true, false); |
| 7729 #define MAYBE_HTTPSToHTTP DISABLED_HTTPSToHTTP | |
| 7730 #else | |
| 7731 #define MAYBE_HTTPSToHTTP HTTPSToHTTP | |
| 7732 #endif | |
| 7733 TEST_F(URLRequestTestReferrerPolicy, MAYBE_HTTPSToHTTP) { | |
| 7734 InstantiateCrossOriginServers(SpawnedTestServer::TYPE_HTTPS, | |
| 7735 SpawnedTestServer::TYPE_HTTP); | |
| 7736 | 7765 |
| 7737 VerifyReferrerAfterRedirect( | 7766 VerifyReferrerAfterRedirect( |
| 7738 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 7767 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 7739 origin_server()->GetURL("path/to/file.html"), GURL()); | 7768 origin_server()->GetURL("/path/to/file.html"), GURL()); |
| 7740 | 7769 |
| 7741 VerifyReferrerAfterRedirect( | 7770 VerifyReferrerAfterRedirect( |
| 7742 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | 7771 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, |
| 7743 origin_server()->GetURL("path/to/file.html"), GURL()); | 7772 origin_server()->GetURL("/path/to/file.html"), GURL()); |
| 7744 | 7773 |
| 7745 VerifyReferrerAfterRedirect( | 7774 VerifyReferrerAfterRedirect( |
| 7746 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | 7775 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, |
| 7747 origin_server()->GetURL("path/to/file.html"), | 7776 origin_server()->GetURL("/path/to/file.html"), |
| 7748 origin_server()->GetURL(std::string())); | 7777 origin_server()->GetURL("/")); |
| 7749 | 7778 |
| 7750 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | 7779 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 7751 origin_server()->GetURL("path/to/file.html"), | 7780 origin_server()->GetURL("/path/to/file.html"), |
| 7752 origin_server()->GetURL("path/to/file.html")); | 7781 origin_server()->GetURL("/path/to/file.html")); |
| 7753 } | 7782 } |
| 7754 | 7783 |
| 7755 class HTTPSRequestTest : public testing::Test { | 7784 class HTTPSRequestTest : public testing::Test { |
| 7756 public: | 7785 public: |
| 7757 HTTPSRequestTest() : default_context_(true) { | 7786 HTTPSRequestTest() : default_context_(true) { |
| 7758 default_context_.set_network_delegate(&default_network_delegate_); | 7787 default_context_.set_network_delegate(&default_network_delegate_); |
| 7759 default_context_.Init(); | 7788 default_context_.Init(); |
| 7760 } | 7789 } |
| 7761 ~HTTPSRequestTest() override {} | 7790 ~HTTPSRequestTest() override {} |
| 7762 | 7791 |
| 7763 protected: | 7792 protected: |
| 7764 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 7793 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 7765 TestURLRequestContext default_context_; | 7794 TestURLRequestContext default_context_; |
| 7766 }; | 7795 }; |
| 7767 | 7796 |
| 7768 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 7797 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
| 7769 SpawnedTestServer test_server( | 7798 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 7770 SpawnedTestServer::TYPE_HTTPS, | 7799 test_server.AddDefaultHandlers( |
| 7771 SpawnedTestServer::kLocalhost, | |
| 7772 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 7800 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 7773 ASSERT_TRUE(test_server.Start()); | 7801 ASSERT_TRUE(test_server.Start()); |
| 7774 | 7802 |
| 7775 TestDelegate d; | 7803 TestDelegate d; |
| 7776 { | 7804 { |
| 7777 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 7805 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7778 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 7806 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 7779 r->Start(); | 7807 r->Start(); |
| 7780 EXPECT_TRUE(r->is_pending()); | 7808 EXPECT_TRUE(r->is_pending()); |
| 7781 | 7809 |
| 7782 base::RunLoop().Run(); | 7810 base::RunLoop().Run(); |
| 7783 | 7811 |
| 7784 EXPECT_EQ(1, d.response_started_count()); | 7812 EXPECT_EQ(1, d.response_started_count()); |
| 7785 EXPECT_FALSE(d.received_data_before_response()); | 7813 EXPECT_FALSE(d.received_data_before_response()); |
| 7786 EXPECT_NE(0, d.bytes_received()); | 7814 EXPECT_NE(0, d.bytes_received()); |
| 7787 CheckSSLInfo(r->ssl_info()); | 7815 CheckSSLInfo(r->ssl_info()); |
| 7788 EXPECT_EQ(test_server.host_port_pair().host(), | 7816 EXPECT_EQ(test_server.host_port_pair().host(), |
| 7789 r->GetSocketAddress().host()); | 7817 r->GetSocketAddress().host()); |
| 7790 EXPECT_EQ(test_server.host_port_pair().port(), | 7818 EXPECT_EQ(test_server.host_port_pair().port(), |
| 7791 r->GetSocketAddress().port()); | 7819 r->GetSocketAddress().port()); |
| 7792 } | 7820 } |
| 7793 } | 7821 } |
| 7794 | 7822 |
| 7795 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { | 7823 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { |
| 7796 SpawnedTestServer::SSLOptions ssl_options( | 7824 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 7797 SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME); | 7825 test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 7798 SpawnedTestServer test_server( | 7826 test_server.AddDefaultHandlers( |
| 7799 SpawnedTestServer::TYPE_HTTPS, | |
| 7800 ssl_options, | |
| 7801 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 7827 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 7802 ASSERT_TRUE(test_server.Start()); | 7828 ASSERT_TRUE(test_server.Start()); |
| 7803 | 7829 |
| 7804 bool err_allowed = true; | 7830 bool err_allowed = true; |
| 7805 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 7831 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 7806 TestDelegate d; | 7832 TestDelegate d; |
| 7807 { | 7833 { |
| 7808 d.set_allow_certificate_errors(err_allowed); | 7834 d.set_allow_certificate_errors(err_allowed); |
| 7809 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 7835 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7810 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 7836 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 7811 | 7837 |
| 7812 r->Start(); | 7838 r->Start(); |
| 7813 EXPECT_TRUE(r->is_pending()); | 7839 EXPECT_TRUE(r->is_pending()); |
| 7814 | 7840 |
| 7815 base::RunLoop().Run(); | 7841 base::RunLoop().Run(); |
| 7816 | 7842 |
| 7817 EXPECT_EQ(1, d.response_started_count()); | 7843 EXPECT_EQ(1, d.response_started_count()); |
| 7818 EXPECT_FALSE(d.received_data_before_response()); | 7844 EXPECT_FALSE(d.received_data_before_response()); |
| 7819 EXPECT_TRUE(d.have_certificate_errors()); | 7845 EXPECT_TRUE(d.have_certificate_errors()); |
| 7820 if (err_allowed) { | 7846 if (err_allowed) { |
| 7821 EXPECT_NE(0, d.bytes_received()); | 7847 EXPECT_NE(0, d.bytes_received()); |
| 7822 CheckSSLInfo(r->ssl_info()); | 7848 CheckSSLInfo(r->ssl_info()); |
| 7823 } else { | 7849 } else { |
| 7824 EXPECT_EQ(0, d.bytes_received()); | 7850 EXPECT_EQ(0, d.bytes_received()); |
| 7825 } | 7851 } |
| 7826 } | 7852 } |
| 7827 } | 7853 } |
| 7828 } | 7854 } |
| 7829 | 7855 |
| 7830 TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { | 7856 TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { |
| 7831 SpawnedTestServer::SSLOptions ssl_options( | 7857 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 7832 SpawnedTestServer::SSLOptions::CERT_EXPIRED); | 7858 test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED); |
| 7833 SpawnedTestServer test_server( | 7859 test_server.AddDefaultHandlers( |
| 7834 SpawnedTestServer::TYPE_HTTPS, | |
| 7835 ssl_options, | |
| 7836 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 7860 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 7837 ASSERT_TRUE(test_server.Start()); | 7861 ASSERT_TRUE(test_server.Start()); |
| 7838 | 7862 |
| 7839 // Iterate from false to true, just so that we do the opposite of the | 7863 // Iterate from false to true, just so that we do the opposite of the |
| 7840 // previous test in order to increase test coverage. | 7864 // previous test in order to increase test coverage. |
| 7841 bool err_allowed = false; | 7865 bool err_allowed = false; |
| 7842 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 7866 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 7843 TestDelegate d; | 7867 TestDelegate d; |
| 7844 { | 7868 { |
| 7845 d.set_allow_certificate_errors(err_allowed); | 7869 d.set_allow_certificate_errors(err_allowed); |
| 7846 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 7870 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7847 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 7871 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 7848 | 7872 |
| 7849 r->Start(); | 7873 r->Start(); |
| 7850 EXPECT_TRUE(r->is_pending()); | 7874 EXPECT_TRUE(r->is_pending()); |
| 7851 | 7875 |
| 7852 base::RunLoop().Run(); | 7876 base::RunLoop().Run(); |
| 7853 | 7877 |
| 7854 EXPECT_EQ(1, d.response_started_count()); | 7878 EXPECT_EQ(1, d.response_started_count()); |
| 7855 EXPECT_FALSE(d.received_data_before_response()); | 7879 EXPECT_FALSE(d.received_data_before_response()); |
| 7856 EXPECT_TRUE(d.have_certificate_errors()); | 7880 EXPECT_TRUE(d.have_certificate_errors()); |
| 7857 if (err_allowed) { | 7881 if (err_allowed) { |
| 7858 EXPECT_NE(0, d.bytes_received()); | 7882 EXPECT_NE(0, d.bytes_received()); |
| 7859 CheckSSLInfo(r->ssl_info()); | 7883 CheckSSLInfo(r->ssl_info()); |
| 7860 } else { | 7884 } else { |
| 7861 EXPECT_EQ(0, d.bytes_received()); | 7885 EXPECT_EQ(0, d.bytes_received()); |
| 7862 } | 7886 } |
| 7863 } | 7887 } |
| 7864 } | 7888 } |
| 7865 } | 7889 } |
| 7866 | 7890 |
| 7891 #if !defined(OS_IOS) |
| 7867 // This tests that a load of www.google.com with a certificate error sets | 7892 // This tests that a load of www.google.com with a certificate error sets |
| 7868 // the |certificate_errors_are_fatal| flag correctly. This flag will cause | 7893 // the |certificate_errors_are_fatal| flag correctly. This flag will cause |
| 7869 // the interstitial to be fatal. | 7894 // the interstitial to be fatal. |
| 7870 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { | 7895 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { |
| 7871 SpawnedTestServer::SSLOptions ssl_options( | 7896 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 7872 SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME); | 7897 test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 7873 SpawnedTestServer test_server( | 7898 test_server.ServeFilesFromSourceDirectory("net/data/ssl"); |
| 7874 SpawnedTestServer::TYPE_HTTPS, | |
| 7875 ssl_options, | |
| 7876 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
| 7877 ASSERT_TRUE(test_server.Start()); | 7899 ASSERT_TRUE(test_server.Start()); |
| 7878 | 7900 |
| 7879 // We require that the URL be www.google.com in order to pick up the | 7901 // We require that the URL be www.google.com in order to pick up the |
| 7880 // preloaded HSTS entries in the TransportSecurityState. This means that we | 7902 // preloaded HSTS entries in the TransportSecurityState. This means that we |
| 7881 // have to use a MockHostResolver in order to direct www.google.com to the | 7903 // have to use a MockHostResolver in order to direct www.google.com to the |
| 7882 // testserver. By default, MockHostResolver maps all hosts to 127.0.0.1. | 7904 // testserver. By default, MockHostResolver maps all hosts to 127.0.0.1. |
| 7883 | 7905 |
| 7884 MockHostResolver host_resolver; | 7906 MockHostResolver host_resolver; |
| 7885 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 7907 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 7886 TestURLRequestContext context(true); | 7908 TestURLRequestContext context(true); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 7905 EXPECT_FALSE(d.received_data_before_response()); | 7927 EXPECT_FALSE(d.received_data_before_response()); |
| 7906 EXPECT_TRUE(d.have_certificate_errors()); | 7928 EXPECT_TRUE(d.have_certificate_errors()); |
| 7907 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 7929 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| 7908 } | 7930 } |
| 7909 | 7931 |
| 7910 // This tests that cached HTTPS page loads do not cause any updates to the | 7932 // This tests that cached HTTPS page loads do not cause any updates to the |
| 7911 // TransportSecurityState. | 7933 // TransportSecurityState. |
| 7912 TEST_F(HTTPSRequestTest, HTTPSErrorsNoClobberTSSTest) { | 7934 TEST_F(HTTPSRequestTest, HTTPSErrorsNoClobberTSSTest) { |
| 7913 // The actual problem -- CERT_MISMATCHED_NAME in this case -- doesn't | 7935 // The actual problem -- CERT_MISMATCHED_NAME in this case -- doesn't |
| 7914 // matter. It just has to be any error. | 7936 // matter. It just has to be any error. |
| 7915 SpawnedTestServer::SSLOptions ssl_options( | 7937 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 7916 SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME); | 7938 test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 7917 SpawnedTestServer test_server( | 7939 test_server.ServeFilesFromSourceDirectory("net/data/ssl"); |
| 7918 SpawnedTestServer::TYPE_HTTPS, | |
| 7919 ssl_options, | |
| 7920 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
| 7921 ASSERT_TRUE(test_server.Start()); | 7940 ASSERT_TRUE(test_server.Start()); |
| 7922 | 7941 |
| 7923 // We require that the URL be www.google.com in order to pick up the static | 7942 // We require that the URL be www.google.com in order to pick up the static |
| 7924 // and dynamic STS and PKP entries in the TransportSecurityState. This means | 7943 // and dynamic STS and PKP entries in the TransportSecurityState. This means |
| 7925 // that we have to use a MockHostResolver in order to direct www.google.com to | 7944 // that we have to use a MockHostResolver in order to direct www.google.com to |
| 7926 // the testserver. By default, MockHostResolver maps all hosts to 127.0.0.1. | 7945 // the testserver. By default, MockHostResolver maps all hosts to 127.0.0.1. |
| 7927 | 7946 |
| 7928 MockHostResolver host_resolver; | 7947 MockHostResolver host_resolver; |
| 7929 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 7948 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 7930 TestURLRequestContext context(true); | 7949 TestURLRequestContext context(true); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7982 EXPECT_TRUE(FingerprintsEqual(new_static_pkp_state.spki_hashes, | 8001 EXPECT_TRUE(FingerprintsEqual(new_static_pkp_state.spki_hashes, |
| 7983 static_pkp_state.spki_hashes)); | 8002 static_pkp_state.spki_hashes)); |
| 7984 EXPECT_TRUE(FingerprintsEqual(new_static_pkp_state.bad_spki_hashes, | 8003 EXPECT_TRUE(FingerprintsEqual(new_static_pkp_state.bad_spki_hashes, |
| 7985 static_pkp_state.bad_spki_hashes)); | 8004 static_pkp_state.bad_spki_hashes)); |
| 7986 } | 8005 } |
| 7987 | 8006 |
| 7988 // Make sure HSTS preserves a POST request's method and body. | 8007 // Make sure HSTS preserves a POST request's method and body. |
| 7989 TEST_F(HTTPSRequestTest, HSTSPreservesPosts) { | 8008 TEST_F(HTTPSRequestTest, HSTSPreservesPosts) { |
| 7990 static const char kData[] = "hello world"; | 8009 static const char kData[] = "hello world"; |
| 7991 | 8010 |
| 7992 SpawnedTestServer::SSLOptions ssl_options( | 8011 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 7993 SpawnedTestServer::SSLOptions::CERT_OK); | 8012 test_server.AddDefaultHandlers( |
| 7994 SpawnedTestServer test_server( | |
| 7995 SpawnedTestServer::TYPE_HTTPS, | |
| 7996 ssl_options, | |
| 7997 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 8013 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 7998 ASSERT_TRUE(test_server.Start()); | 8014 ASSERT_TRUE(test_server.Start()); |
| 7999 | 8015 |
| 8000 | 8016 |
| 8001 // Per spec, TransportSecurityState expects a domain name, rather than an IP | 8017 // Per spec, TransportSecurityState expects a domain name, rather than an IP |
| 8002 // address, so a MockHostResolver is needed to redirect www.somewhere.com to | 8018 // address, so a MockHostResolver is needed to redirect www.somewhere.com to |
| 8003 // the SpawnedTestServer. By default, MockHostResolver maps all hosts | 8019 // the EmbeddedTestServer. By default, MockHostResolver maps all hosts |
| 8004 // to 127.0.0.1. | 8020 // to 127.0.0.1. |
| 8005 MockHostResolver host_resolver; | 8021 MockHostResolver host_resolver; |
| 8006 | 8022 |
| 8007 // Force https for www.somewhere.com. | 8023 // Force https for www.somewhere.com. |
| 8008 TransportSecurityState transport_security_state; | 8024 TransportSecurityState transport_security_state; |
| 8009 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); | 8025 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
| 8010 bool include_subdomains = false; | 8026 bool include_subdomains = false; |
| 8011 transport_security_state.AddHSTS("www.somewhere.com", expiry, | 8027 transport_security_state.AddHSTS("www.somewhere.com", expiry, |
| 8012 include_subdomains); | 8028 include_subdomains); |
| 8013 | 8029 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 8041 LoadTimingInfo load_timing_info; | 8057 LoadTimingInfo load_timing_info; |
| 8042 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info); | 8058 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info); |
| 8043 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits | 8059 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits |
| 8044 TestLoadTimingCacheHitNoNetwork(load_timing_info); | 8060 TestLoadTimingCacheHitNoNetwork(load_timing_info); |
| 8045 } | 8061 } |
| 8046 | 8062 |
| 8047 // Make sure that the CORS headers are added to cross-origin HSTS redirects. | 8063 // Make sure that the CORS headers are added to cross-origin HSTS redirects. |
| 8048 TEST_F(HTTPSRequestTest, HSTSCrossOriginAddHeaders) { | 8064 TEST_F(HTTPSRequestTest, HSTSCrossOriginAddHeaders) { |
| 8049 static const char kOriginHeaderValue[] = "http://www.example.com"; | 8065 static const char kOriginHeaderValue[] = "http://www.example.com"; |
| 8050 | 8066 |
| 8051 SpawnedTestServer::SSLOptions ssl_options( | 8067 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 8052 SpawnedTestServer::SSLOptions::CERT_OK); | 8068 test_server.ServeFilesFromSourceDirectory("net/data/ssl"); |
| 8053 SpawnedTestServer test_server( | |
| 8054 SpawnedTestServer::TYPE_HTTPS, | |
| 8055 ssl_options, | |
| 8056 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
| 8057 ASSERT_TRUE(test_server.Start()); | 8069 ASSERT_TRUE(test_server.Start()); |
| 8058 | 8070 |
| 8059 // Per spec, TransportSecurityState expects a domain name, rather than an IP | 8071 // Per spec, TransportSecurityState expects a domain name, rather than an IP |
| 8060 // address, so a MockHostResolver is needed to redirect example.net to the | 8072 // address, so a MockHostResolver is needed to redirect example.net to the |
| 8061 // SpawnedTestServer. MockHostResolver maps all hosts to 127.0.0.1 by default. | 8073 // EmbeddedTestServer. MockHostResolver maps all hosts to 127.0.0.1 by |
| 8074 // default. |
| 8062 MockHostResolver host_resolver; | 8075 MockHostResolver host_resolver; |
| 8063 | 8076 |
| 8064 TransportSecurityState transport_security_state; | 8077 TransportSecurityState transport_security_state; |
| 8065 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1); | 8078 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 8066 bool include_subdomains = false; | 8079 bool include_subdomains = false; |
| 8067 transport_security_state.AddHSTS("example.net", expiry, include_subdomains); | 8080 transport_security_state.AddHSTS("example.net", expiry, include_subdomains); |
| 8068 | 8081 |
| 8069 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 8082 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 8070 | 8083 |
| 8071 MockCertVerifier cert_verifier; | 8084 MockCertVerifier cert_verifier; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8151 }; | 8164 }; |
| 8152 | 8165 |
| 8153 } // namespace | 8166 } // namespace |
| 8154 | 8167 |
| 8155 // TODO(davidben): Test the rest of the code. Specifically, | 8168 // TODO(davidben): Test the rest of the code. Specifically, |
| 8156 // - Filtering which certificates to select. | 8169 // - Filtering which certificates to select. |
| 8157 // - Sending a certificate back. | 8170 // - Sending a certificate back. |
| 8158 // - Getting a certificate request in an SSL renegotiation sending the | 8171 // - Getting a certificate request in an SSL renegotiation sending the |
| 8159 // HTTP request. | 8172 // HTTP request. |
| 8160 TEST_F(HTTPSRequestTest, ClientAuthTest) { | 8173 TEST_F(HTTPSRequestTest, ClientAuthTest) { |
| 8161 SpawnedTestServer::SSLOptions ssl_options; | 8174 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 8162 ssl_options.request_client_certificate = true; | 8175 net::SSLServerConfig ssl_config; |
| 8163 SpawnedTestServer test_server( | 8176 ssl_config.require_client_cert = true; |
| 8164 SpawnedTestServer::TYPE_HTTPS, | 8177 test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, ssl_config); |
| 8165 ssl_options, | 8178 test_server.AddDefaultHandlers( |
| 8166 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 8179 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 8167 ASSERT_TRUE(test_server.Start()); | 8180 ASSERT_TRUE(test_server.Start()); |
| 8168 | 8181 |
| 8169 SSLClientAuthTestDelegate d; | 8182 SSLClientAuthTestDelegate d; |
| 8170 { | 8183 { |
| 8171 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 8184 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8172 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 8185 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
| 8173 | 8186 |
| 8174 r->Start(); | 8187 r->Start(); |
| 8175 EXPECT_TRUE(r->is_pending()); | 8188 EXPECT_TRUE(r->is_pending()); |
| 8176 | 8189 |
| 8177 base::RunLoop().Run(); | 8190 base::RunLoop().Run(); |
| 8178 | 8191 |
| 8179 EXPECT_EQ(1, d.on_certificate_requested_count()); | 8192 EXPECT_EQ(1, d.on_certificate_requested_count()); |
| 8180 EXPECT_FALSE(d.received_data_before_response()); | 8193 EXPECT_FALSE(d.received_data_before_response()); |
| 8181 EXPECT_EQ(0, d.bytes_received()); | 8194 EXPECT_EQ(0, d.bytes_received()); |
| 8182 | 8195 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8367 } // namespace | 8380 } // namespace |
| 8368 | 8381 |
| 8369 // Test that ECDSA is disabled on Windows XP, where ECDSA certificates cannot be | 8382 // Test that ECDSA is disabled on Windows XP, where ECDSA certificates cannot be |
| 8370 // verified. | 8383 // verified. |
| 8371 TEST_F(HTTPSRequestTest, DisableECDSAOnXP) { | 8384 TEST_F(HTTPSRequestTest, DisableECDSAOnXP) { |
| 8372 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 8385 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 8373 LOG(INFO) << "Skipping test on this version."; | 8386 LOG(INFO) << "Skipping test on this version."; |
| 8374 return; | 8387 return; |
| 8375 } | 8388 } |
| 8376 | 8389 |
| 8377 SpawnedTestServer test_server( | 8390 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 8378 SpawnedTestServer::TYPE_HTTPS, | 8391 test_server.ServeFilesFromSourceDirectory("net/data/ssl"); |
| 8379 SpawnedTestServer::kLocalhost, | |
| 8380 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
| 8381 ASSERT_TRUE(test_server.Start()); | 8392 ASSERT_TRUE(test_server.Start()); |
| 8382 | 8393 |
| 8383 TestDelegate d; | 8394 TestDelegate d; |
| 8384 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 8395 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8385 test_server.GetURL("client-cipher-list"), DEFAULT_PRIORITY, &d)); | 8396 test_server.GetURL("/client-cipher-list"), DEFAULT_PRIORITY, &d)); |
| 8386 r->Start(); | 8397 r->Start(); |
| 8387 EXPECT_TRUE(r->is_pending()); | 8398 EXPECT_TRUE(r->is_pending()); |
| 8388 | 8399 |
| 8389 base::RunLoop().Run(); | 8400 base::RunLoop().Run(); |
| 8390 | 8401 |
| 8391 EXPECT_EQ(1, d.response_started_count()); | 8402 EXPECT_EQ(1, d.response_started_count()); |
| 8392 std::vector<std::string> lines = base::SplitString( | 8403 std::vector<std::string> lines = base::SplitString( |
| 8393 d.data_received(), "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 8404 d.data_received(), "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 8394 | 8405 |
| 8395 for (size_t i = 0; i < lines.size(); i++) { | 8406 for (size_t i = 0; i < lines.size(); i++) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8474 DCHECK(!request_); | 8485 DCHECK(!request_); |
| 8475 context_.Init(); | 8486 context_.Init(); |
| 8476 delegate_.set_allow_certificate_errors(true); | 8487 delegate_.set_allow_certificate_errors(true); |
| 8477 | 8488 |
| 8478 SpawnedTestServer test_server( | 8489 SpawnedTestServer test_server( |
| 8479 SpawnedTestServer::TYPE_HTTPS, | 8490 SpawnedTestServer::TYPE_HTTPS, |
| 8480 ssl_options, | 8491 ssl_options, |
| 8481 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 8492 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 8482 ASSERT_TRUE(test_server.Start()); | 8493 ASSERT_TRUE(test_server.Start()); |
| 8483 | 8494 |
| 8484 request_ = context_.CreateRequest(test_server.GetURL(std::string()), | 8495 request_ = context_.CreateRequest(test_server.GetURL("/"), DEFAULT_PRIORITY, |
| 8485 DEFAULT_PRIORITY, &delegate_); | 8496 &delegate_); |
| 8486 request_->Start(); | 8497 request_->Start(); |
| 8487 | 8498 |
| 8488 base::RunLoop().Run(); | 8499 base::RunLoop().Run(); |
| 8489 } | 8500 } |
| 8490 | 8501 |
| 8491 void set_fallback_min_version(uint16 version) { | 8502 void set_fallback_min_version(uint16 version) { |
| 8492 context_.set_fallback_min_version(version); | 8503 context_.set_fallback_min_version(version); |
| 8493 } | 8504 } |
| 8494 | 8505 |
| 8495 void ExpectConnection(int version) { | 8506 void ExpectConnection(int version) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8630 // Make a connection that does a probe fallback to TLSv1 but fails because | 8641 // Make a connection that does a probe fallback to TLSv1 but fails because |
| 8631 // TLSv1 fallback is disabled. We don't wish a session for this connection to | 8642 // TLSv1 fallback is disabled. We don't wish a session for this connection to |
| 8632 // be inserted locally. | 8643 // be inserted locally. |
| 8633 { | 8644 { |
| 8634 TestDelegate delegate; | 8645 TestDelegate delegate; |
| 8635 FallbackTestURLRequestContext context(true); | 8646 FallbackTestURLRequestContext context(true); |
| 8636 | 8647 |
| 8637 context.set_fallback_min_version(SSL_PROTOCOL_VERSION_TLS1_2); | 8648 context.set_fallback_min_version(SSL_PROTOCOL_VERSION_TLS1_2); |
| 8638 context.Init(); | 8649 context.Init(); |
| 8639 scoped_ptr<URLRequest> request(context.CreateRequest( | 8650 scoped_ptr<URLRequest> request(context.CreateRequest( |
| 8640 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &delegate)); | 8651 test_server.GetURL("/"), DEFAULT_PRIORITY, &delegate)); |
| 8641 request->Start(); | 8652 request->Start(); |
| 8642 | 8653 |
| 8643 base::RunLoop().Run(); | 8654 base::RunLoop().Run(); |
| 8644 | 8655 |
| 8645 EXPECT_EQ(1, delegate.response_started_count()); | 8656 EXPECT_EQ(1, delegate.response_started_count()); |
| 8646 EXPECT_FALSE(request->status().is_success()); | 8657 EXPECT_FALSE(request->status().is_success()); |
| 8647 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); | 8658 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); |
| 8648 EXPECT_EQ(ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION, | 8659 EXPECT_EQ(ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION, |
| 8649 request->status().error()); | 8660 request->status().error()); |
| 8650 } | 8661 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8805 // We always overwrite out_cert_status. | 8816 // We always overwrite out_cert_status. |
| 8806 *out_cert_status = 0; | 8817 *out_cert_status = 0; |
| 8807 SpawnedTestServer test_server( | 8818 SpawnedTestServer test_server( |
| 8808 SpawnedTestServer::TYPE_HTTPS, | 8819 SpawnedTestServer::TYPE_HTTPS, |
| 8809 ssl_options, | 8820 ssl_options, |
| 8810 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 8821 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 8811 ASSERT_TRUE(test_server.Start()); | 8822 ASSERT_TRUE(test_server.Start()); |
| 8812 | 8823 |
| 8813 TestDelegate d; | 8824 TestDelegate d; |
| 8814 d.set_allow_certificate_errors(true); | 8825 d.set_allow_certificate_errors(true); |
| 8815 scoped_ptr<URLRequest> r(context_.CreateRequest( | 8826 scoped_ptr<URLRequest> r( |
| 8816 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d)); | 8827 context_.CreateRequest(test_server.GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 8817 r->Start(); | 8828 r->Start(); |
| 8818 | 8829 |
| 8819 base::RunLoop().Run(); | 8830 base::RunLoop().Run(); |
| 8820 | 8831 |
| 8821 EXPECT_EQ(1, d.response_started_count()); | 8832 EXPECT_EQ(1, d.response_started_count()); |
| 8822 *out_cert_status = r->ssl_info().cert_status; | 8833 *out_cert_status = r->ssl_info().cert_status; |
| 8823 } | 8834 } |
| 8824 | 8835 |
| 8825 ~HTTPSOCSPTest() override { | 8836 ~HTTPSOCSPTest() override { |
| 8826 #if defined(USE_NSS_CERTS) || defined(OS_IOS) | 8837 #if defined(USE_NSS_CERTS) || defined(OS_IOS) |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9302 #endif // !defined(OS_IOS) | 9313 #endif // !defined(OS_IOS) |
| 9303 | 9314 |
| 9304 #if !defined(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) | 9315 #if !defined(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) |
| 9305 // These tests aren't passing on Android. Either the RemoteTestServer isn't | 9316 // These tests aren't passing on Android. Either the RemoteTestServer isn't |
| 9306 // starting up successfully, or it can't access the test files. | 9317 // starting up successfully, or it can't access the test files. |
| 9307 // TODO(mmenke): Fix this. See http://crbug.com/495220 | 9318 // TODO(mmenke): Fix this. See http://crbug.com/495220 |
| 9308 class URLRequestTestFTP : public URLRequestTest { | 9319 class URLRequestTestFTP : public URLRequestTest { |
| 9309 public: | 9320 public: |
| 9310 URLRequestTestFTP() | 9321 URLRequestTestFTP() |
| 9311 : ftp_transaction_factory_(&host_resolver_), | 9322 : ftp_transaction_factory_(&host_resolver_), |
| 9312 test_server_(SpawnedTestServer::TYPE_FTP, | 9323 ftp_test_server_(SpawnedTestServer::TYPE_FTP, |
| 9313 SpawnedTestServer::kLocalhost, | 9324 SpawnedTestServer::kLocalhost, |
| 9314 base::FilePath(kTestFilePath)) { | 9325 base::FilePath(kTestFilePath)) { |
| 9315 // Can't use |default_context_|'s HostResolver to set up the | 9326 // Can't use |default_context_|'s HostResolver to set up the |
| 9316 // FTPTransactionFactory because it hasn't been created yet. | 9327 // FTPTransactionFactory because it hasn't been created yet. |
| 9317 default_context_.set_host_resolver(&host_resolver_); | 9328 default_context_.set_host_resolver(&host_resolver_); |
| 9318 } | 9329 } |
| 9319 | 9330 |
| 9320 // URLRequestTest interface: | 9331 // URLRequestTest interface: |
| 9321 void SetUpFactory() override { | 9332 void SetUpFactory() override { |
| 9322 // Add FTP support to the default URLRequestContext. | 9333 // Add FTP support to the default URLRequestContext. |
| 9323 job_factory_impl_->SetProtocolHandler( | 9334 job_factory_impl_->SetProtocolHandler( |
| 9324 "ftp", | 9335 "ftp", |
| 9325 make_scoped_ptr(new FtpProtocolHandler(&ftp_transaction_factory_))); | 9336 make_scoped_ptr(new FtpProtocolHandler(&ftp_transaction_factory_))); |
| 9326 } | 9337 } |
| 9327 | 9338 |
| 9328 std::string GetTestFileContents() { | 9339 std::string GetTestFileContents() { |
| 9329 base::FilePath path; | 9340 base::FilePath path; |
| 9330 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); | 9341 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); |
| 9331 path = path.Append(kTestFilePath); | 9342 path = path.Append(kTestFilePath); |
| 9332 path = path.AppendASCII(kFtpTestFile); | 9343 path = path.AppendASCII(kFtpTestFile); |
| 9333 std::string contents; | 9344 std::string contents; |
| 9334 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 9345 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
| 9335 return contents; | 9346 return contents; |
| 9336 } | 9347 } |
| 9337 | 9348 |
| 9338 protected: | 9349 protected: |
| 9339 MockHostResolver host_resolver_; | 9350 MockHostResolver host_resolver_; |
| 9340 FtpNetworkLayer ftp_transaction_factory_; | 9351 FtpNetworkLayer ftp_transaction_factory_; |
| 9341 | 9352 |
| 9342 SpawnedTestServer test_server_; | 9353 SpawnedTestServer ftp_test_server_; |
| 9343 }; | 9354 }; |
| 9344 | 9355 |
| 9345 // Make sure an FTP request using an unsafe ports fails. | 9356 // Make sure an FTP request using an unsafe ports fails. |
| 9346 TEST_F(URLRequestTestFTP, UnsafePort) { | 9357 TEST_F(URLRequestTestFTP, UnsafePort) { |
| 9347 GURL url("ftp://127.0.0.1:7"); | 9358 GURL url("ftp://127.0.0.1:7"); |
| 9348 | 9359 |
| 9349 TestDelegate d; | 9360 TestDelegate d; |
| 9350 { | 9361 { |
| 9351 scoped_ptr<URLRequest> r( | 9362 scoped_ptr<URLRequest> r( |
| 9352 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 9363 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 9353 r->Start(); | 9364 r->Start(); |
| 9354 EXPECT_TRUE(r->is_pending()); | 9365 EXPECT_TRUE(r->is_pending()); |
| 9355 | 9366 |
| 9356 base::RunLoop().Run(); | 9367 base::RunLoop().Run(); |
| 9357 | 9368 |
| 9358 EXPECT_FALSE(r->is_pending()); | 9369 EXPECT_FALSE(r->is_pending()); |
| 9359 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 9370 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 9360 EXPECT_EQ(ERR_UNSAFE_PORT, r->status().error()); | 9371 EXPECT_EQ(ERR_UNSAFE_PORT, r->status().error()); |
| 9361 } | 9372 } |
| 9362 } | 9373 } |
| 9363 | 9374 |
| 9364 TEST_F(URLRequestTestFTP, FTPDirectoryListing) { | 9375 TEST_F(URLRequestTestFTP, FTPDirectoryListing) { |
| 9365 ASSERT_TRUE(test_server_.Start()); | 9376 ASSERT_TRUE(ftp_test_server_.Start()); |
| 9366 | 9377 |
| 9367 TestDelegate d; | 9378 TestDelegate d; |
| 9368 { | 9379 { |
| 9369 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9380 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9370 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d)); | 9381 ftp_test_server_.GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 9371 r->Start(); | 9382 r->Start(); |
| 9372 EXPECT_TRUE(r->is_pending()); | 9383 EXPECT_TRUE(r->is_pending()); |
| 9373 | 9384 |
| 9374 base::RunLoop().Run(); | 9385 base::RunLoop().Run(); |
| 9375 | 9386 |
| 9376 EXPECT_FALSE(r->is_pending()); | 9387 EXPECT_FALSE(r->is_pending()); |
| 9377 EXPECT_EQ(1, d.response_started_count()); | 9388 EXPECT_EQ(1, d.response_started_count()); |
| 9378 EXPECT_FALSE(d.received_data_before_response()); | 9389 EXPECT_FALSE(d.received_data_before_response()); |
| 9379 EXPECT_LT(0, d.bytes_received()); | 9390 EXPECT_LT(0, d.bytes_received()); |
| 9380 EXPECT_EQ(test_server_.host_port_pair().host(), | 9391 EXPECT_EQ(ftp_test_server_.host_port_pair().host(), |
| 9381 r->GetSocketAddress().host()); | 9392 r->GetSocketAddress().host()); |
| 9382 EXPECT_EQ(test_server_.host_port_pair().port(), | 9393 EXPECT_EQ(ftp_test_server_.host_port_pair().port(), |
| 9383 r->GetSocketAddress().port()); | 9394 r->GetSocketAddress().port()); |
| 9384 } | 9395 } |
| 9385 } | 9396 } |
| 9386 | 9397 |
| 9387 TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) { | 9398 TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) { |
| 9388 ASSERT_TRUE(test_server_.Start()); | 9399 ASSERT_TRUE(ftp_test_server_.Start()); |
| 9389 | 9400 |
| 9390 TestDelegate d; | 9401 TestDelegate d; |
| 9391 { | 9402 { |
| 9392 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9403 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9393 test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, &d)); | 9404 ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, &d)); |
| 9394 r->Start(); | 9405 r->Start(); |
| 9395 EXPECT_TRUE(r->is_pending()); | 9406 EXPECT_TRUE(r->is_pending()); |
| 9396 | 9407 |
| 9397 base::RunLoop().Run(); | 9408 base::RunLoop().Run(); |
| 9398 | 9409 |
| 9399 EXPECT_FALSE(r->is_pending()); | 9410 EXPECT_FALSE(r->is_pending()); |
| 9400 EXPECT_EQ(1, d.response_started_count()); | 9411 EXPECT_EQ(1, d.response_started_count()); |
| 9401 EXPECT_FALSE(d.received_data_before_response()); | 9412 EXPECT_FALSE(d.received_data_before_response()); |
| 9402 EXPECT_EQ(GetTestFileContents(), d.data_received()); | 9413 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 9403 EXPECT_EQ(test_server_.host_port_pair().host(), | 9414 EXPECT_EQ(ftp_test_server_.host_port_pair().host(), |
| 9404 r->GetSocketAddress().host()); | 9415 r->GetSocketAddress().host()); |
| 9405 EXPECT_EQ(test_server_.host_port_pair().port(), | 9416 EXPECT_EQ(ftp_test_server_.host_port_pair().port(), |
| 9406 r->GetSocketAddress().port()); | 9417 r->GetSocketAddress().port()); |
| 9407 } | 9418 } |
| 9408 } | 9419 } |
| 9409 | 9420 |
| 9410 TEST_F(URLRequestTestFTP, FTPGetTest) { | 9421 TEST_F(URLRequestTestFTP, FTPGetTest) { |
| 9411 ASSERT_TRUE(test_server_.Start()); | 9422 ASSERT_TRUE(ftp_test_server_.Start()); |
| 9412 | 9423 |
| 9413 TestDelegate d; | 9424 TestDelegate d; |
| 9414 { | 9425 { |
| 9415 scoped_ptr<URLRequest> r( | 9426 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9416 default_context_.CreateRequest(test_server_.GetURLWithUserAndPassword( | 9427 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 9417 kFtpTestFile, "chrome", "chrome"), | 9428 "chrome"), |
| 9418 DEFAULT_PRIORITY, &d)); | 9429 DEFAULT_PRIORITY, &d)); |
| 9419 r->Start(); | 9430 r->Start(); |
| 9420 EXPECT_TRUE(r->is_pending()); | 9431 EXPECT_TRUE(r->is_pending()); |
| 9421 | 9432 |
| 9422 base::RunLoop().Run(); | 9433 base::RunLoop().Run(); |
| 9423 | 9434 |
| 9424 EXPECT_FALSE(r->is_pending()); | 9435 EXPECT_FALSE(r->is_pending()); |
| 9425 EXPECT_EQ(1, d.response_started_count()); | 9436 EXPECT_EQ(1, d.response_started_count()); |
| 9426 EXPECT_FALSE(d.received_data_before_response()); | 9437 EXPECT_FALSE(d.received_data_before_response()); |
| 9427 EXPECT_EQ(GetTestFileContents(), d.data_received()); | 9438 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 9428 EXPECT_EQ(test_server_.host_port_pair().host(), | 9439 EXPECT_EQ(ftp_test_server_.host_port_pair().host(), |
| 9429 r->GetSocketAddress().host()); | 9440 r->GetSocketAddress().host()); |
| 9430 EXPECT_EQ(test_server_.host_port_pair().port(), | 9441 EXPECT_EQ(ftp_test_server_.host_port_pair().port(), |
| 9431 r->GetSocketAddress().port()); | 9442 r->GetSocketAddress().port()); |
| 9432 | 9443 |
| 9433 LoadTimingInfo load_timing_info; | 9444 LoadTimingInfo load_timing_info; |
| 9434 r->GetLoadTimingInfo(&load_timing_info); | 9445 r->GetLoadTimingInfo(&load_timing_info); |
| 9435 TestLoadTimingNoHttpResponse(load_timing_info); | 9446 TestLoadTimingNoHttpResponse(load_timing_info); |
| 9436 } | 9447 } |
| 9437 } | 9448 } |
| 9438 | 9449 |
| 9439 TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) { | 9450 TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) { |
| 9440 ASSERT_TRUE(test_server_.Start()); | 9451 ASSERT_TRUE(ftp_test_server_.Start()); |
| 9441 | 9452 |
| 9442 TestDelegate d; | 9453 TestDelegate d; |
| 9443 { | 9454 { |
| 9444 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9455 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9445 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", | 9456 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 9446 "wrong_password"), | 9457 "wrong_password"), |
| 9447 DEFAULT_PRIORITY, &d)); | 9458 DEFAULT_PRIORITY, &d)); |
| 9448 r->Start(); | 9459 r->Start(); |
| 9449 EXPECT_TRUE(r->is_pending()); | 9460 EXPECT_TRUE(r->is_pending()); |
| 9450 | 9461 |
| 9451 base::RunLoop().Run(); | 9462 base::RunLoop().Run(); |
| 9452 | 9463 |
| 9453 EXPECT_FALSE(r->is_pending()); | 9464 EXPECT_FALSE(r->is_pending()); |
| 9454 EXPECT_EQ(1, d.response_started_count()); | 9465 EXPECT_EQ(1, d.response_started_count()); |
| 9455 EXPECT_FALSE(d.received_data_before_response()); | 9466 EXPECT_FALSE(d.received_data_before_response()); |
| 9456 EXPECT_EQ(d.bytes_received(), 0); | 9467 EXPECT_EQ(d.bytes_received(), 0); |
| 9457 } | 9468 } |
| 9458 } | 9469 } |
| 9459 | 9470 |
| 9460 TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) { | 9471 TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) { |
| 9461 ASSERT_TRUE(test_server_.Start()); | 9472 ASSERT_TRUE(ftp_test_server_.Start()); |
| 9462 | 9473 |
| 9463 TestDelegate d; | 9474 TestDelegate d; |
| 9464 // Set correct login credentials. The delegate will be asked for them when | 9475 // Set correct login credentials. The delegate will be asked for them when |
| 9465 // the initial login with wrong credentials will fail. | 9476 // the initial login with wrong credentials will fail. |
| 9466 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 9477 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 9467 { | 9478 { |
| 9468 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9479 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9469 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", | 9480 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 9470 "wrong_password"), | 9481 "wrong_password"), |
| 9471 DEFAULT_PRIORITY, &d)); | 9482 DEFAULT_PRIORITY, &d)); |
| 9472 r->Start(); | 9483 r->Start(); |
| 9473 EXPECT_TRUE(r->is_pending()); | 9484 EXPECT_TRUE(r->is_pending()); |
| 9474 | 9485 |
| 9475 base::RunLoop().Run(); | 9486 base::RunLoop().Run(); |
| 9476 | 9487 |
| 9477 EXPECT_FALSE(r->is_pending()); | 9488 EXPECT_FALSE(r->is_pending()); |
| 9478 EXPECT_EQ(1, d.response_started_count()); | 9489 EXPECT_EQ(1, d.response_started_count()); |
| 9479 EXPECT_FALSE(d.received_data_before_response()); | 9490 EXPECT_FALSE(d.received_data_before_response()); |
| 9480 EXPECT_EQ(GetTestFileContents(), d.data_received()); | 9491 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 9481 } | 9492 } |
| 9482 } | 9493 } |
| 9483 | 9494 |
| 9484 TEST_F(URLRequestTestFTP, FTPCheckWrongUser) { | 9495 TEST_F(URLRequestTestFTP, FTPCheckWrongUser) { |
| 9485 ASSERT_TRUE(test_server_.Start()); | 9496 ASSERT_TRUE(ftp_test_server_.Start()); |
| 9486 | 9497 |
| 9487 TestDelegate d; | 9498 TestDelegate d; |
| 9488 { | 9499 { |
| 9489 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9500 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9490 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", | 9501 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", |
| 9491 "chrome"), | 9502 "chrome"), |
| 9492 DEFAULT_PRIORITY, &d)); | 9503 DEFAULT_PRIORITY, &d)); |
| 9493 r->Start(); | 9504 r->Start(); |
| 9494 EXPECT_TRUE(r->is_pending()); | 9505 EXPECT_TRUE(r->is_pending()); |
| 9495 | 9506 |
| 9496 base::RunLoop().Run(); | 9507 base::RunLoop().Run(); |
| 9497 | 9508 |
| 9498 EXPECT_FALSE(r->is_pending()); | 9509 EXPECT_FALSE(r->is_pending()); |
| 9499 EXPECT_EQ(1, d.response_started_count()); | 9510 EXPECT_EQ(1, d.response_started_count()); |
| 9500 EXPECT_FALSE(d.received_data_before_response()); | 9511 EXPECT_FALSE(d.received_data_before_response()); |
| 9501 EXPECT_EQ(0, d.bytes_received()); | 9512 EXPECT_EQ(0, d.bytes_received()); |
| 9502 } | 9513 } |
| 9503 } | 9514 } |
| 9504 | 9515 |
| 9505 TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) { | 9516 TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) { |
| 9506 ASSERT_TRUE(test_server_.Start()); | 9517 ASSERT_TRUE(ftp_test_server_.Start()); |
| 9507 | 9518 |
| 9508 TestDelegate d; | 9519 TestDelegate d; |
| 9509 // Set correct login credentials. The delegate will be asked for them when | 9520 // Set correct login credentials. The delegate will be asked for them when |
| 9510 // the initial login with wrong credentials will fail. | 9521 // the initial login with wrong credentials will fail. |
| 9511 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 9522 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 9512 { | 9523 { |
| 9513 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9524 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9514 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", | 9525 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", |
| 9515 "chrome"), | 9526 "chrome"), |
| 9516 DEFAULT_PRIORITY, &d)); | 9527 DEFAULT_PRIORITY, &d)); |
| 9517 r->Start(); | 9528 r->Start(); |
| 9518 EXPECT_TRUE(r->is_pending()); | 9529 EXPECT_TRUE(r->is_pending()); |
| 9519 | 9530 |
| 9520 base::RunLoop().Run(); | 9531 base::RunLoop().Run(); |
| 9521 | 9532 |
| 9522 EXPECT_FALSE(r->is_pending()); | 9533 EXPECT_FALSE(r->is_pending()); |
| 9523 EXPECT_EQ(1, d.response_started_count()); | 9534 EXPECT_EQ(1, d.response_started_count()); |
| 9524 EXPECT_FALSE(d.received_data_before_response()); | 9535 EXPECT_FALSE(d.received_data_before_response()); |
| 9525 EXPECT_EQ(GetTestFileContents(), d.data_received()); | 9536 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 9526 } | 9537 } |
| 9527 } | 9538 } |
| 9528 | 9539 |
| 9529 TEST_F(URLRequestTestFTP, FTPCacheURLCredentials) { | 9540 TEST_F(URLRequestTestFTP, FTPCacheURLCredentials) { |
| 9530 ASSERT_TRUE(test_server_.Start()); | 9541 ASSERT_TRUE(ftp_test_server_.Start()); |
| 9531 | 9542 |
| 9532 scoped_ptr<TestDelegate> d(new TestDelegate); | 9543 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 9533 { | 9544 { |
| 9534 // Pass correct login identity in the URL. | 9545 // Pass correct login identity in the URL. |
| 9535 scoped_ptr<URLRequest> r( | 9546 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9536 default_context_.CreateRequest(test_server_.GetURLWithUserAndPassword( | 9547 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 9537 kFtpTestFile, "chrome", "chrome"), | 9548 "chrome"), |
| 9538 DEFAULT_PRIORITY, d.get())); | 9549 DEFAULT_PRIORITY, d.get())); |
| 9539 r->Start(); | 9550 r->Start(); |
| 9540 EXPECT_TRUE(r->is_pending()); | 9551 EXPECT_TRUE(r->is_pending()); |
| 9541 | 9552 |
| 9542 base::RunLoop().Run(); | 9553 base::RunLoop().Run(); |
| 9543 | 9554 |
| 9544 EXPECT_FALSE(r->is_pending()); | 9555 EXPECT_FALSE(r->is_pending()); |
| 9545 EXPECT_EQ(1, d->response_started_count()); | 9556 EXPECT_EQ(1, d->response_started_count()); |
| 9546 EXPECT_FALSE(d->received_data_before_response()); | 9557 EXPECT_FALSE(d->received_data_before_response()); |
| 9547 EXPECT_EQ(GetTestFileContents(), d->data_received()); | 9558 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 9548 } | 9559 } |
| 9549 | 9560 |
| 9550 d.reset(new TestDelegate); | 9561 d.reset(new TestDelegate); |
| 9551 { | 9562 { |
| 9552 // This request should use cached identity from previous request. | 9563 // This request should use cached identity from previous request. |
| 9553 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9564 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9554 test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get())); | 9565 ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get())); |
| 9555 r->Start(); | 9566 r->Start(); |
| 9556 EXPECT_TRUE(r->is_pending()); | 9567 EXPECT_TRUE(r->is_pending()); |
| 9557 | 9568 |
| 9558 base::RunLoop().Run(); | 9569 base::RunLoop().Run(); |
| 9559 | 9570 |
| 9560 EXPECT_FALSE(r->is_pending()); | 9571 EXPECT_FALSE(r->is_pending()); |
| 9561 EXPECT_EQ(1, d->response_started_count()); | 9572 EXPECT_EQ(1, d->response_started_count()); |
| 9562 EXPECT_FALSE(d->received_data_before_response()); | 9573 EXPECT_FALSE(d->received_data_before_response()); |
| 9563 EXPECT_EQ(GetTestFileContents(), d->data_received()); | 9574 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 9564 } | 9575 } |
| 9565 } | 9576 } |
| 9566 | 9577 |
| 9567 TEST_F(URLRequestTestFTP, FTPCacheLoginBoxCredentials) { | 9578 TEST_F(URLRequestTestFTP, FTPCacheLoginBoxCredentials) { |
| 9568 ASSERT_TRUE(test_server_.Start()); | 9579 ASSERT_TRUE(ftp_test_server_.Start()); |
| 9569 | 9580 |
| 9570 scoped_ptr<TestDelegate> d(new TestDelegate); | 9581 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 9571 // Set correct login credentials. The delegate will be asked for them when | 9582 // Set correct login credentials. The delegate will be asked for them when |
| 9572 // the initial login with wrong credentials will fail. | 9583 // the initial login with wrong credentials will fail. |
| 9573 d->set_credentials(AuthCredentials(kChrome, kChrome)); | 9584 d->set_credentials(AuthCredentials(kChrome, kChrome)); |
| 9574 { | 9585 { |
| 9575 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9586 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9576 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", | 9587 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 9577 "wrong_password"), | 9588 "wrong_password"), |
| 9578 DEFAULT_PRIORITY, d.get())); | 9589 DEFAULT_PRIORITY, d.get())); |
| 9579 r->Start(); | 9590 r->Start(); |
| 9580 EXPECT_TRUE(r->is_pending()); | 9591 EXPECT_TRUE(r->is_pending()); |
| 9581 | 9592 |
| 9582 base::RunLoop().Run(); | 9593 base::RunLoop().Run(); |
| 9583 | 9594 |
| 9584 EXPECT_FALSE(r->is_pending()); | 9595 EXPECT_FALSE(r->is_pending()); |
| 9585 EXPECT_EQ(1, d->response_started_count()); | 9596 EXPECT_EQ(1, d->response_started_count()); |
| 9586 EXPECT_FALSE(d->received_data_before_response()); | 9597 EXPECT_FALSE(d->received_data_before_response()); |
| 9587 EXPECT_EQ(GetTestFileContents(), d->data_received()); | 9598 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 9588 } | 9599 } |
| 9589 | 9600 |
| 9590 // Use a new delegate without explicit credentials. The cached ones should be | 9601 // Use a new delegate without explicit credentials. The cached ones should be |
| 9591 // used. | 9602 // used. |
| 9592 d.reset(new TestDelegate); | 9603 d.reset(new TestDelegate); |
| 9593 { | 9604 { |
| 9594 // Don't pass wrong credentials in the URL, they would override valid cached | 9605 // Don't pass wrong credentials in the URL, they would override valid cached |
| 9595 // ones. | 9606 // ones. |
| 9596 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9607 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9597 test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get())); | 9608 ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get())); |
| 9598 r->Start(); | 9609 r->Start(); |
| 9599 EXPECT_TRUE(r->is_pending()); | 9610 EXPECT_TRUE(r->is_pending()); |
| 9600 | 9611 |
| 9601 base::RunLoop().Run(); | 9612 base::RunLoop().Run(); |
| 9602 | 9613 |
| 9603 EXPECT_FALSE(r->is_pending()); | 9614 EXPECT_FALSE(r->is_pending()); |
| 9604 EXPECT_EQ(1, d->response_started_count()); | 9615 EXPECT_EQ(1, d->response_started_count()); |
| 9605 EXPECT_FALSE(d->received_data_before_response()); | 9616 EXPECT_FALSE(d->received_data_before_response()); |
| 9606 EXPECT_EQ(GetTestFileContents(), d->data_received()); | 9617 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 9607 } | 9618 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9677 | 9688 |
| 9678 req->Start(); | 9689 req->Start(); |
| 9679 req->Cancel(); | 9690 req->Cancel(); |
| 9680 job->DetachRequest(); | 9691 job->DetachRequest(); |
| 9681 base::RunLoop().RunUntilIdle(); | 9692 base::RunLoop().RunUntilIdle(); |
| 9682 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9693 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 9683 EXPECT_EQ(0, d.received_redirect_count()); | 9694 EXPECT_EQ(0, d.received_redirect_count()); |
| 9684 } | 9695 } |
| 9685 | 9696 |
| 9686 } // namespace net | 9697 } // namespace net |
| OLD | NEW |