OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_context_request_handler. h" | 5 #include "content/browser/service_worker/service_worker_context_request_handler. h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 | 114 |
115 // Associates a ServiceWorkerRequestHandler with a request. Use this instead | 115 // Associates a ServiceWorkerRequestHandler with a request. Use this instead |
116 // of CreateHandler if you want to actually start the request to test what the | 116 // of CreateHandler if you want to actually start the request to test what the |
117 // job created by the handler does. | 117 // job created by the handler does. |
118 void InitializeHandler(net::URLRequest* request) { | 118 void InitializeHandler(net::URLRequest* request) { |
119 ServiceWorkerRequestHandler::InitializeHandler( | 119 ServiceWorkerRequestHandler::InitializeHandler( |
120 request, helper_->context_wrapper(), &blob_storage_context_, | 120 request, helper_->context_wrapper(), &blob_storage_context_, |
121 helper_->mock_render_process_id(), provider_host_->provider_id(), | 121 helper_->mock_render_process_id(), provider_host_->provider_id(), |
122 false /* skip_service_worker */, FETCH_REQUEST_MODE_NO_CORS, | 122 false /* skip_service_worker */, FETCH_REQUEST_MODE_NO_CORS, |
123 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, | 123 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, |
124 RESOURCE_TYPE_SERVICE_WORKER, REQUEST_CONTEXT_TYPE_SERVICE_WORKER, | 124 "" /*integrity*/, RESOURCE_TYPE_SERVICE_WORKER, |
falken
2017/07/07 00:56:10
ditto
xiaofengzhang
2017/07/12 09:13:52
Done.
| |
125 REQUEST_CONTEXT_FRAME_TYPE_NONE, nullptr); | 125 REQUEST_CONTEXT_TYPE_SERVICE_WORKER, REQUEST_CONTEXT_FRAME_TYPE_NONE, |
126 nullptr); | |
126 } | 127 } |
127 | 128 |
128 protected: | 129 protected: |
129 TestBrowserThreadBundle browser_thread_bundle_; | 130 TestBrowserThreadBundle browser_thread_bundle_; |
130 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 131 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
131 scoped_refptr<ServiceWorkerRegistration> registration_; | 132 scoped_refptr<ServiceWorkerRegistration> registration_; |
132 scoped_refptr<ServiceWorkerVersion> version_; | 133 scoped_refptr<ServiceWorkerVersion> version_; |
133 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 134 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
134 net::URLRequestContext url_request_context_; | 135 net::URLRequestContext url_request_context_; |
135 net::TestDelegate url_request_delegate_; | 136 net::TestDelegate url_request_delegate_; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 TEST_F(ServiceWorkerContextRequestHandlerTest, | 247 TEST_F(ServiceWorkerContextRequestHandlerTest, |
247 SkipServiceWorkerForServiceWorkerRequest) { | 248 SkipServiceWorkerForServiceWorkerRequest) { |
248 // Conduct a resource fetch for the main script. | 249 // Conduct a resource fetch for the main script. |
249 version_->SetStatus(ServiceWorkerVersion::NEW); | 250 version_->SetStatus(ServiceWorkerVersion::NEW); |
250 std::unique_ptr<net::URLRequest> request(CreateRequest(script_url_)); | 251 std::unique_ptr<net::URLRequest> request(CreateRequest(script_url_)); |
251 ServiceWorkerRequestHandler::InitializeHandler( | 252 ServiceWorkerRequestHandler::InitializeHandler( |
252 request.get(), helper_->context_wrapper(), &blob_storage_context_, | 253 request.get(), helper_->context_wrapper(), &blob_storage_context_, |
253 helper_->mock_render_process_id(), provider_host_->provider_id(), | 254 helper_->mock_render_process_id(), provider_host_->provider_id(), |
254 true /* skip_service_worker */, FETCH_REQUEST_MODE_NO_CORS, | 255 true /* skip_service_worker */, FETCH_REQUEST_MODE_NO_CORS, |
255 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, | 256 FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, |
256 RESOURCE_TYPE_SERVICE_WORKER, REQUEST_CONTEXT_TYPE_SERVICE_WORKER, | 257 "" /*integrity*/, RESOURCE_TYPE_SERVICE_WORKER, |
falken
2017/07/07 00:56:10
ditto
xiaofengzhang
2017/07/12 09:13:52
Done.
| |
257 REQUEST_CONTEXT_FRAME_TYPE_NONE, nullptr); | 258 REQUEST_CONTEXT_TYPE_SERVICE_WORKER, REQUEST_CONTEXT_FRAME_TYPE_NONE, |
259 nullptr); | |
258 // Verify a ServiceWorkerRequestHandler was created. | 260 // Verify a ServiceWorkerRequestHandler was created. |
259 ServiceWorkerRequestHandler* handler = | 261 ServiceWorkerRequestHandler* handler = |
260 ServiceWorkerRequestHandler::GetHandler(request.get()); | 262 ServiceWorkerRequestHandler::GetHandler(request.get()); |
261 EXPECT_TRUE(handler); | 263 EXPECT_TRUE(handler); |
262 } | 264 } |
263 | 265 |
264 TEST_F(ServiceWorkerContextRequestHandlerTest, NewWorker) { | 266 TEST_F(ServiceWorkerContextRequestHandlerTest, NewWorker) { |
265 // Conduct a resource fetch for the main script. | 267 // Conduct a resource fetch for the main script. |
266 { | 268 { |
267 base::HistogramTester histograms; | 269 base::HistogramTester histograms; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 EXPECT_EQ(net::ERR_FAILED, url_request_delegate_.request_status()); | 435 EXPECT_EQ(net::ERR_FAILED, url_request_delegate_.request_status()); |
434 histograms.ExpectUniqueSample( | 436 histograms.ExpectUniqueSample( |
435 "ServiceWorker.ContextRequestHandlerStatus.NewWorker.MainScript", | 437 "ServiceWorker.ContextRequestHandlerStatus.NewWorker.MainScript", |
436 static_cast<int>(ServiceWorkerContextRequestHandler::CreateJobStatus:: | 438 static_cast<int>(ServiceWorkerContextRequestHandler::CreateJobStatus:: |
437 ERROR_NO_CONTEXT), | 439 ERROR_NO_CONTEXT), |
438 1); | 440 1); |
439 } | 441 } |
440 } | 442 } |
441 | 443 |
442 } // namespace content | 444 } // namespace content |
OLD | NEW |