Chromium Code Reviews| Index: content/browser/renderer_host/resource_dispatcher_host_unittest.cc |
| diff --git a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc |
| index 178aca4c39635c4282b6dff2f2bfd13d5f4e63cd..b0638ec765d6d144f32ebbc944f7e7c2268bae34 100644 |
| --- a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc |
| +++ b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc |
| @@ -265,6 +265,28 @@ class URLRequestTestDelayedStartJob : public net::URLRequestTestJob { |
| URLRequestTestDelayedStartJob* |
| URLRequestTestDelayedStartJob::list_head_ = NULL; |
| +// This class is a variation on URLRequestTestJob in that it |
| +// returns IO_pending errors before every read, not just the first one. |
| +class URLRequestTestDelayedCompletionJob : public net::URLRequestTestJob { |
| + public: |
| + explicit URLRequestTestDelayedCompletionJob(net::URLRequest* request) |
| + : net::URLRequestTestJob(request) {} |
| + URLRequestTestDelayedCompletionJob(net::URLRequest* request, |
| + bool auto_advance) |
| + : net::URLRequestTestJob(request, auto_advance) {} |
| + URLRequestTestDelayedCompletionJob(net::URLRequest* request, |
| + const std::string& response_headers, |
|
rvargas (doing something else)
2012/05/30 00:49:03
nit: indent two more spaces
Randy Smith (Not in Mondays)
2012/05/30 19:36:43
Done.
|
| + const std::string& response_data, |
| + bool auto_advance) |
| + : net::URLRequestTestJob(request, response_headers, |
| + response_data, auto_advance) {} |
| + |
| + private: |
| + virtual bool NextReadAsync() OVERRIDE { return true; } |
| +}; |
| + |
| + |
| + |
| // Associated with an URLRequest to determine if the URLRequest gets deleted. |
| class TestUserData : public base::SupportsUserData::Data { |
| public: |
| @@ -378,6 +400,7 @@ class ResourceDispatcherHostTest : public testing::Test, |
| &ResourceDispatcherHostTest::Factory); |
| EnsureTestSchemeIsAllowed(); |
| delay_start_ = false; |
| + delay_complete_ = false; |
| } |
| virtual void TearDown() { |
| @@ -455,6 +478,8 @@ class ResourceDispatcherHostTest : public testing::Test, |
| if (test_fixture_->response_headers_.empty()) { |
| if (delay_start_) { |
| return new URLRequestTestDelayedStartJob(request); |
| + } else if (delay_complete_) { |
| + return new URLRequestTestDelayedCompletionJob(request); |
| } else { |
| return new net::URLRequestTestJob(request); |
| } |
| @@ -463,6 +488,10 @@ class ResourceDispatcherHostTest : public testing::Test, |
| return new URLRequestTestDelayedStartJob( |
| request, test_fixture_->response_headers_, |
| test_fixture_->response_data_, false); |
| + } else if (delay_complete_) { |
| + return new URLRequestTestDelayedCompletionJob( |
| + request, test_fixture_->response_headers_, |
| + test_fixture_->response_data_, false); |
| } else { |
| return new net::URLRequestTestJob(request, |
| test_fixture_->response_headers_, |
| @@ -476,6 +505,10 @@ class ResourceDispatcherHostTest : public testing::Test, |
| delay_start_ = delay_job_start; |
| } |
| + void SetDelayedCompleteJobGeneration(bool delay_job_complete) { |
| + delay_complete_ = delay_job_complete; |
| + } |
| + |
| MessageLoopForIO message_loop_; |
| BrowserThreadImpl ui_thread_; |
| BrowserThreadImpl file_thread_; |
| @@ -492,10 +525,12 @@ class ResourceDispatcherHostTest : public testing::Test, |
| ResourceType::Type resource_type_; |
| static ResourceDispatcherHostTest* test_fixture_; |
| static bool delay_start_; |
| + static bool delay_complete_; |
| }; |
| // Static. |
| ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; |
| bool ResourceDispatcherHostTest::delay_start_ = false; |
| +bool ResourceDispatcherHostTest::delay_complete_ = false; |
| void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, |
| int request_id, |
| @@ -1245,8 +1280,16 @@ TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { |
| response.size())); |
| std::string response_data("01234567890123456789\x01foobar"); |
| + // Get past sniffing metrics in the BufferedResourceHandler. Note that |
| + // if we don't get past the sniffing metrics, the result will be that |
| + // the BufferedResourceHandler won't have figured out that it's a download, |
| + // won't have constructed a DownloadResourceHandler, and and the request |
| + // will be successfully canceled below, failing the test. |
| + response_data.resize(1025, ' '); |
| + |
| SetResponse(raw_headers, response_data); |
| SetResourceType(ResourceType::MAIN_FRAME); |
| + SetDelayedCompleteJobGeneration(true); |
| HandleScheme("http"); |
| MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
| @@ -1279,9 +1322,12 @@ TEST_F(ResourceDispatcherHostTest, CancelRequestsForContext) { |
| std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
| response.size())); |
| std::string response_data("01234567890123456789\x01foobar"); |
| + // Get past sniffing metrics. |
| + response_data.resize(1025, ' '); |
| SetResponse(raw_headers, response_data); |
| SetResourceType(ResourceType::MAIN_FRAME); |
| + SetDelayedCompleteJobGeneration(true); |
| HandleScheme("http"); |
| MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |