Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 23710059: Release the cache entry on deferred redirect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable new tests on Chrome Frame Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 TEST_F(URLRequestTestHTTP, CachedRedirect) {
rvargas (doing something else) 2013/09/17 19:53:25 I would have gone for an URLRequestJob unit test..
davidben 2013/09/17 22:16:04 Done.
4207 ASSERT_TRUE(test_server_.Start());
4208
4209 // Write to the cache.
4210 {
4211 TestDelegate d;
4212 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
4213 URLRequest req(test_url, &d, &default_context_);
4214
4215 req.Start();
4216 base::RunLoop().Run();
4217
4218 EXPECT_EQ(1, d.received_redirect_count());
4219 EXPECT_EQ(1, d.response_started_count());
4220 EXPECT_FALSE(d.received_data_before_response());
4221 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status());
4222 }
4223
4224 // Stop at the redirect and make sure it was read from cache.
4225 {
4226 TestDelegate d;
4227 d.set_quit_on_redirect(true);
4228 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
4229 URLRequest req(test_url, &d, &default_context_);
4230
4231 req.Start();
4232 base::RunLoop().Run();
4233
4234 EXPECT_EQ(1, d.received_redirect_count());
4235 EXPECT_TRUE(req.was_cached());
4236 }
4237 }
4238
4206 TEST_F(URLRequestTestHTTP, CancelRedirect) { 4239 TEST_F(URLRequestTestHTTP, CancelRedirect) {
4207 ASSERT_TRUE(test_server_.Start()); 4240 ASSERT_TRUE(test_server_.Start());
4208 4241
4209 TestDelegate d; 4242 TestDelegate d;
4210 { 4243 {
4211 d.set_cancel_in_received_redirect(true); 4244 d.set_cancel_in_received_redirect(true);
4212 URLRequest req( 4245 URLRequest req(
4213 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); 4246 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_);
4214 req.Start(); 4247 req.Start();
4215 base::RunLoop().Run(); 4248 base::RunLoop().Run();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
4290 path = path.Append(FILE_PATH_LITERAL("data")); 4323 path = path.Append(FILE_PATH_LITERAL("data"));
4291 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 4324 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
4292 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); 4325 path = path.Append(FILE_PATH_LITERAL("with-headers.html"));
4293 4326
4294 std::string contents; 4327 std::string contents;
4295 EXPECT_TRUE(base::ReadFileToString(path, &contents)); 4328 EXPECT_TRUE(base::ReadFileToString(path, &contents));
4296 EXPECT_EQ(contents, d.data_received()); 4329 EXPECT_EQ(contents, d.data_received());
4297 } 4330 }
4298 } 4331 }
4299 4332
4333 // Tests that a deferred redirect releases its lock on the cache.
4334 TEST_F(URLRequestTestHTTP, DeferredRedirect_ReleaseCacheEntry) {
4335 ASSERT_TRUE(test_server_.Start());
4336
4337 // First test the cold cache case.
4338 {
4339 // First, fire a request and (indefinitely) pause its redirect.
4340 TestDelegate pausing_delegate;
4341 pausing_delegate.set_quit_on_redirect(true);
4342 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
4343 URLRequest paused_req(test_url, &pausing_delegate, &default_context_);
4344 paused_req.Start();
4345 base::RunLoop().Run();
4346 EXPECT_EQ(1, pausing_delegate.received_redirect_count());
4347
4348 // This should test the cold cache case.
4349 EXPECT_FALSE(paused_req.was_cached());
4350
4351 // Now, fire a second at the same. It should not get stuck.
4352 TestDelegate delegate;
4353 URLRequest req(test_url, &delegate, &default_context_);
4354 req.Start();
4355 base::RunLoop().Run();
4356 EXPECT_EQ(1, delegate.response_started_count());
4357 EXPECT_FALSE(delegate.received_data_before_response());
4358 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status());
4359 }
4360
4361 // Repeat, now with the cache warmed from the last run.
4362 {
4363 // First, fire a request and (indefinitely) pause its redirect.
4364 TestDelegate pausing_delegate;
4365 pausing_delegate.set_quit_on_redirect(true);
4366 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
4367 URLRequest paused_req(test_url, &pausing_delegate, &default_context_);
4368 paused_req.Start();
4369 base::RunLoop().Run();
4370 EXPECT_EQ(1, pausing_delegate.received_redirect_count());
4371
4372 // This should test the cold cache case.
4373 EXPECT_TRUE(paused_req.was_cached());
4374
4375 // Now, fire a second at the same. It should not get stuck.
4376 TestDelegate delegate;
4377 URLRequest req(test_url, &delegate, &default_context_);
4378 req.Start();
4379 base::RunLoop().Run();
4380 EXPECT_EQ(1, delegate.response_started_count());
4381 EXPECT_FALSE(delegate.received_data_before_response());
4382 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status());
4383 }
4384 }
4385
4300 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { 4386 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) {
4301 ASSERT_TRUE(test_server_.Start()); 4387 ASSERT_TRUE(test_server_.Start());
4302 4388
4303 TestDelegate d; 4389 TestDelegate d;
4304 { 4390 {
4305 d.set_quit_on_redirect(true); 4391 d.set_quit_on_redirect(true);
4306 URLRequest req( 4392 URLRequest req(
4307 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); 4393 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_);
4308 req.Start(); 4394 req.Start();
4309 base::RunLoop().Run(); 4395 base::RunLoop().Run();
(...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after
6286 6372
6287 EXPECT_FALSE(r.is_pending()); 6373 EXPECT_FALSE(r.is_pending());
6288 EXPECT_EQ(1, d->response_started_count()); 6374 EXPECT_EQ(1, d->response_started_count());
6289 EXPECT_FALSE(d->received_data_before_response()); 6375 EXPECT_FALSE(d->received_data_before_response());
6290 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 6376 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
6291 } 6377 }
6292 } 6378 }
6293 #endif // !defined(DISABLE_FTP_SUPPORT) 6379 #endif // !defined(DISABLE_FTP_SUPPORT)
6294 6380
6295 } // namespace net 6381 } // namespace net
OLDNEW
« net/url_request/url_request_job.cc ('K') | « net/url_request/url_request_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698