Chromium Code Reviews| Index: content/browser/service_worker/service_worker_read_from_cache_job_unittest.cc |
| diff --git a/content/browser/service_worker/service_worker_read_from_cache_job_unittest.cc b/content/browser/service_worker/service_worker_read_from_cache_job_unittest.cc |
| index aa7508b7520af5f3aee65090be767c6e8e69906c..35889e69746eecff29ffa6b66d3ef3c2777f5f94 100644 |
| --- a/content/browser/service_worker/service_worker_read_from_cache_job_unittest.cc |
| +++ b/content/browser/service_worker/service_worker_read_from_cache_job_unittest.cc |
| @@ -7,6 +7,7 @@ |
| #include <stdint.h> |
| #include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "base/run_loop.h" |
| #include "content/browser/fileapi/mock_url_request_delegate.h" |
| #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| @@ -20,6 +21,7 @@ |
| #include "net/url_request/url_request_context.h" |
| #include "net/url_request/url_request_job_factory_impl.h" |
| #include "net/url_request/url_request_status.h" |
| +#include "net/url_request/url_request_test_util.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace content { |
| @@ -66,9 +68,15 @@ class ServiceWorkerReadFromCacheJobTest : public testing::Test { |
| helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
| InitializeStorage(); |
| - url_request_context_.reset(new net::URLRequestContext); |
| - url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
| - url_request_context_->set_job_factory(url_request_job_factory_.get()); |
| + url_request_context_.reset(new net::TestURLRequestContext(true)); |
| + |
| + // The |test_job_factory_| takes ownership of the interceptor. |
| + test_job_interceptor_ = new net::TestJobInterceptor(); |
| + EXPECT_TRUE(test_job_factory_.SetProtocolHandler( |
| + url::kHttpScheme, make_scoped_ptr(test_job_interceptor_))); |
| + url_request_context_->set_job_factory(&test_job_factory_); |
| + |
| + url_request_context_->Init(); |
| } |
| void InitializeStorage() { |
| @@ -145,9 +153,8 @@ class ServiceWorkerReadFromCacheJobTest : public testing::Test { |
| return status; |
| } |
| - void StartAndWaitForJob( |
| - const scoped_ptr<ServiceWorkerReadFromCacheJob>& job) { |
| - job->Start(); |
| + void StartAndWaitForRequest(net::URLRequest* request) { |
| + request->Start(); |
|
mmenke
2016/01/07 15:54:55
A lot of these test-only changes are because the n
Randy Smith (Not in Mondays)
2016/01/11 02:27:48
Acknowledged.
|
| // MockURLRequestDelegate quits the loop when the request is completed. |
| base::RunLoop().RunUntilIdle(); |
| } |
| @@ -168,8 +175,10 @@ class ServiceWorkerReadFromCacheJobTest : public testing::Test { |
| ServiceWorkerDatabase::ResourceRecord main_script_; |
| ServiceWorkerDatabase::ResourceRecord imported_script_; |
| - scoped_ptr<net::URLRequestContext> url_request_context_; |
| - scoped_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; |
| + net::TestJobInterceptor* test_job_interceptor_; |
|
Randy Smith (Not in Mondays)
2016/01/11 02:27:48
Willing to have a comment indicating ownership her
mmenke
2016/01/11 06:17:11
Done. Also added it to the initializer list.
|
| + net::URLRequestJobFactoryImpl test_job_factory_; |
| + |
| + scoped_ptr<net::TestURLRequestContext> url_request_context_; |
| MockURLRequestDelegate delegate_; |
| }; |
| @@ -177,12 +186,12 @@ TEST_F(ServiceWorkerReadFromCacheJobTest, ReadMainScript) { |
| // Read the main script from the diskcache. |
| scoped_ptr<net::URLRequest> request = url_request_context_->CreateRequest( |
| main_script_.url, net::DEFAULT_PRIORITY, &delegate_); |
| - scoped_ptr<ServiceWorkerReadFromCacheJob> job( |
| - new ServiceWorkerReadFromCacheJob( |
| + test_job_interceptor_->set_main_intercept_job( |
| + make_scoped_ptr(new ServiceWorkerReadFromCacheJob( |
| request.get(), nullptr /* NetworkDelegate */, |
| RESOURCE_TYPE_SERVICE_WORKER, context()->AsWeakPtr(), version_, |
| - main_script_.resource_id)); |
| - StartAndWaitForJob(job); |
| + main_script_.resource_id))); |
| + StartAndWaitForRequest(request.get()); |
| EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); |
| EXPECT_EQ(0, request->status().error()); |
| @@ -194,11 +203,11 @@ TEST_F(ServiceWorkerReadFromCacheJobTest, ReadImportedScript) { |
| // Read the imported script from the diskcache. |
| scoped_ptr<net::URLRequest> request = url_request_context_->CreateRequest( |
| imported_script_.url, net::DEFAULT_PRIORITY, &delegate_); |
| - scoped_ptr<ServiceWorkerReadFromCacheJob> job( |
| - new ServiceWorkerReadFromCacheJob( |
| + test_job_interceptor_->set_main_intercept_job( |
| + make_scoped_ptr(new ServiceWorkerReadFromCacheJob( |
| request.get(), nullptr /* NetworkDelegate */, RESOURCE_TYPE_SCRIPT, |
| - context()->AsWeakPtr(), version_, imported_script_.resource_id)); |
| - StartAndWaitForJob(job); |
| + context()->AsWeakPtr(), version_, imported_script_.resource_id))); |
| + StartAndWaitForRequest(request.get()); |
| EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); |
| EXPECT_EQ(0, request->status().error()); |
| @@ -214,12 +223,12 @@ TEST_F(ServiceWorkerReadFromCacheJobTest, ResourceNotFound) { |
| GURL("http://example.com/nonexistent"), net::DEFAULT_PRIORITY, |
| &delegate_); |
| const int64_t kNonexistentResourceId = 100; |
| - scoped_ptr<ServiceWorkerReadFromCacheJob> job( |
| - new ServiceWorkerReadFromCacheJob( |
| + test_job_interceptor_->set_main_intercept_job( |
| + make_scoped_ptr(new ServiceWorkerReadFromCacheJob( |
| request.get(), nullptr /* NetworkDelegate */, |
| RESOURCE_TYPE_SERVICE_WORKER, context()->AsWeakPtr(), version_, |
| - kNonexistentResourceId)); |
| - StartAndWaitForJob(job); |
| + kNonexistentResourceId))); |
| + StartAndWaitForRequest(request.get()); |
| EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); |
| EXPECT_EQ(net::ERR_CACHE_MISS, request->status().error()); |