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 4185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4196 URLRequest req( | 4196 URLRequest req( |
4197 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); | 4197 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); |
4198 req.SetReferrer("http://foo.com/test#fragment"); | 4198 req.SetReferrer("http://foo.com/test#fragment"); |
4199 req.SetReferrer(""); | 4199 req.SetReferrer(""); |
4200 req.Start(); | 4200 req.Start(); |
4201 base::RunLoop().Run(); | 4201 base::RunLoop().Run(); |
4202 | 4202 |
4203 EXPECT_EQ(std::string("None"), d.data_received()); | 4203 EXPECT_EQ(std::string("None"), d.data_received()); |
4204 } | 4204 } |
4205 | 4205 |
4206 | |
mmenke
2013/09/16 20:41:08
nit: Remove extra blank line.
davidben
2013/09/16 22:00:00
Done.
| |
4207 TEST_F(URLRequestTestHTTP, CachedRedirect) { | |
mmenke
2013/09/16 20:41:08
Maybe a second test where the redirect has a non-e
davidben
2013/09/16 22:00:00
Are you sure it doesn't already have a non-empty b
mmenke
2013/09/16 22:08:59
Looks like you're right. I saw the mock-headers,
| |
4208 ASSERT_TRUE(test_server_.Start()); | |
4209 | |
4210 // Write to the cache. | |
4211 { | |
4212 TestDelegate d; | |
4213 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | |
4214 URLRequest req(test_url, &d, &default_context_); | |
4215 | |
4216 req.Start(); | |
4217 base::RunLoop().Run(); | |
4218 | |
4219 EXPECT_EQ(1, d.received_redirect_count()); | |
4220 EXPECT_EQ(1, d.response_started_count()); | |
4221 EXPECT_FALSE(d.received_data_before_response()); | |
4222 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | |
4223 } | |
4224 | |
4225 // Stop at the redirect and make sure it was read from cache. | |
4226 { | |
4227 TestDelegate d; | |
4228 d.set_quit_on_redirect(true); | |
4229 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | |
4230 URLRequest req(test_url, &d, &default_context_); | |
4231 | |
4232 req.Start(); | |
4233 base::RunLoop().Run(); | |
4234 | |
4235 EXPECT_EQ(1, d.received_redirect_count()); | |
4236 EXPECT_TRUE(req.was_cached()); | |
4237 } | |
4238 } | |
4239 | |
4206 TEST_F(URLRequestTestHTTP, CancelRedirect) { | 4240 TEST_F(URLRequestTestHTTP, CancelRedirect) { |
4207 ASSERT_TRUE(test_server_.Start()); | 4241 ASSERT_TRUE(test_server_.Start()); |
4208 | 4242 |
4209 TestDelegate d; | 4243 TestDelegate d; |
4210 { | 4244 { |
4211 d.set_cancel_in_received_redirect(true); | 4245 d.set_cancel_in_received_redirect(true); |
4212 URLRequest req( | 4246 URLRequest req( |
4213 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); | 4247 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); |
4214 req.Start(); | 4248 req.Start(); |
4215 base::RunLoop().Run(); | 4249 base::RunLoop().Run(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4290 path = path.Append(FILE_PATH_LITERAL("data")); | 4324 path = path.Append(FILE_PATH_LITERAL("data")); |
4291 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 4325 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
4292 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 4326 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
4293 | 4327 |
4294 std::string contents; | 4328 std::string contents; |
4295 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 4329 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
4296 EXPECT_EQ(contents, d.data_received()); | 4330 EXPECT_EQ(contents, d.data_received()); |
4297 } | 4331 } |
4298 } | 4332 } |
4299 | 4333 |
4334 // Tests that a deferred redirect releases its lock on the cache. | |
4335 TEST_F(URLRequestTestHTTP, DeferredRedirect_ReleaseCacheEntry) { | |
4336 ASSERT_TRUE(test_server_.Start()); | |
4337 | |
4338 // First test the cold cache case. | |
4339 { | |
4340 TestDelegate d_defer, d; | |
mmenke
2013/09/16 20:41:08
nit: Define one variable per line.
mmenke
2013/09/16 20:41:08
nit: While this file name TestDelegates "d" a lot
davidben
2013/09/16 22:00:00
Done.
davidben
2013/09/16 22:00:00
Done.
| |
4341 | |
4342 // First, fire a request that defers its redirect. | |
4343 d_defer.set_quit_on_redirect(true); | |
4344 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | |
4345 URLRequest req_defer(test_url, &d_defer, &default_context_); | |
mmenke
2013/09/16 20:41:08
optional: Suggest "deferred_req" and "deferring_d
davidben
2013/09/16 22:00:00
Done.
| |
4346 req_defer.Start(); | |
4347 base::RunLoop().Run(); | |
4348 EXPECT_EQ(1, d_defer.received_redirect_count()); | |
4349 | |
4350 // This should test the cold cache case. | |
4351 EXPECT_FALSE(req_defer.was_cached()); | |
4352 | |
4353 // Now, fire a second at the same. It should not get stuck. | |
4354 URLRequest req(test_url, &d, &default_context_); | |
4355 req.Start(); | |
4356 base::RunLoop().Run(); | |
4357 EXPECT_EQ(1, d.response_started_count()); | |
4358 EXPECT_FALSE(d.received_data_before_response()); | |
4359 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | |
mmenke
2013/09/16 20:41:08
May want to mention something about the "deferred"
davidben
2013/09/16 22:00:00
Went with paused.
| |
4360 } | |
4361 | |
4362 // Repeat, now with the cache warmed from the last run. | |
4363 { | |
4364 TestDelegate d_defer, d; | |
4365 | |
4366 // First, fire a request that defers its redirect. | |
4367 d_defer.set_quit_on_redirect(true); | |
4368 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | |
4369 URLRequest req_defer(test_url, &d_defer, &default_context_); | |
4370 req_defer.Start(); | |
4371 base::RunLoop().Run(); | |
4372 EXPECT_EQ(1, d_defer.received_redirect_count()); | |
4373 | |
4374 // This should test the warm cache case. | |
4375 EXPECT_TRUE(req_defer.was_cached()); | |
4376 | |
4377 // Now, fire a second at the same. It should not get stuck. | |
4378 URLRequest req(test_url, &d, &default_context_); | |
4379 req.Start(); | |
4380 base::RunLoop().Run(); | |
4381 EXPECT_EQ(1, d.response_started_count()); | |
4382 EXPECT_FALSE(d.received_data_before_response()); | |
4383 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | |
4384 } | |
4385 } | |
4386 | |
4300 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { | 4387 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { |
4301 ASSERT_TRUE(test_server_.Start()); | 4388 ASSERT_TRUE(test_server_.Start()); |
4302 | 4389 |
4303 TestDelegate d; | 4390 TestDelegate d; |
4304 { | 4391 { |
4305 d.set_quit_on_redirect(true); | 4392 d.set_quit_on_redirect(true); |
4306 URLRequest req( | 4393 URLRequest req( |
4307 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); | 4394 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); |
4308 req.Start(); | 4395 req.Start(); |
4309 base::RunLoop().Run(); | 4396 base::RunLoop().Run(); |
(...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6286 | 6373 |
6287 EXPECT_FALSE(r.is_pending()); | 6374 EXPECT_FALSE(r.is_pending()); |
6288 EXPECT_EQ(1, d->response_started_count()); | 6375 EXPECT_EQ(1, d->response_started_count()); |
6289 EXPECT_FALSE(d->received_data_before_response()); | 6376 EXPECT_FALSE(d->received_data_before_response()); |
6290 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 6377 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
6291 } | 6378 } |
6292 } | 6379 } |
6293 #endif // !defined(DISABLE_FTP_SUPPORT) | 6380 #endif // !defined(DISABLE_FTP_SUPPORT) |
6294 | 6381 |
6295 } // namespace net | 6382 } // namespace net |
OLD | NEW |