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 "base/guid.h" |
5 #include "base/location.h" | 6 #include "base/location.h" |
6 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
7 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
8 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
9 #include "content/browser/fileapi/mock_url_request_delegate.h" | 10 #include "content/browser/fileapi/mock_url_request_delegate.h" |
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 11 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
11 #include "content/browser/service_worker/service_worker_context_core.h" | 12 #include "content/browser/service_worker/service_worker_context_core.h" |
12 #include "content/browser/service_worker/service_worker_context_request_handler.
h" | 13 #include "content/browser/service_worker/service_worker_context_request_handler.
h" |
13 #include "content/browser/service_worker/service_worker_disk_cache.h" | 14 #include "content/browser/service_worker/service_worker_disk_cache.h" |
14 #include "content/browser/service_worker/service_worker_provider_host.h" | 15 #include "content/browser/service_worker/service_worker_provider_host.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 ServiceWorkerRequestHandler::InitializeHandler( | 290 ServiceWorkerRequestHandler::InitializeHandler( |
290 request_.get(), context_wrapper(), &blob_storage_context_, process_id, | 291 request_.get(), context_wrapper(), &blob_storage_context_, process_id, |
291 provider_id, false, FETCH_REQUEST_MODE_NO_CORS, | 292 provider_id, false, FETCH_REQUEST_MODE_NO_CORS, |
292 FETCH_CREDENTIALS_MODE_OMIT, RESOURCE_TYPE_SERVICE_WORKER, | 293 FETCH_CREDENTIALS_MODE_OMIT, RESOURCE_TYPE_SERVICE_WORKER, |
293 REQUEST_CONTEXT_TYPE_SERVICE_WORKER, REQUEST_CONTEXT_FRAME_TYPE_NONE, | 294 REQUEST_CONTEXT_TYPE_SERVICE_WORKER, REQUEST_CONTEXT_FRAME_TYPE_NONE, |
294 scoped_refptr<ResourceRequestBody>()); | 295 scoped_refptr<ResourceRequestBody>()); |
295 } | 296 } |
296 | 297 |
297 int NextRenderProcessId() { return next_render_process_id_++; } | 298 int NextRenderProcessId() { return next_render_process_id_++; } |
298 int NextProviderId() { return next_provider_id_++; } | 299 int NextProviderId() { return next_provider_id_++; } |
299 int NextVersionId() { return next_version_id_++; } | |
300 | 300 |
301 void SetUp() override { | 301 void SetUp() override { |
302 int render_process_id = NextRenderProcessId(); | 302 int render_process_id = NextRenderProcessId(); |
303 int provider_id = NextProviderId(); | 303 int provider_id = NextProviderId(); |
304 helper_.reset( | 304 helper_.reset( |
305 new EmbeddedWorkerTestHelper(base::FilePath(), render_process_id)); | 305 new EmbeddedWorkerTestHelper(base::FilePath(), render_process_id)); |
306 | 306 |
307 // A new unstored registration/version. | 307 // A new unstored registration/version. |
308 scope_ = GURL("https://host/scope/"); | 308 scope_ = GURL("https://host/scope/"); |
309 script_url_ = GURL("https://host/script.js"); | 309 script_url_ = GURL("https://host/script.js"); |
310 registration_ = | 310 registration_ = |
311 new ServiceWorkerRegistration(scope_, 1L, context()->AsWeakPtr()); | 311 new ServiceWorkerRegistration(scope_, 1L, context()->AsWeakPtr()); |
312 version_ = | 312 version_ = new ServiceWorkerVersion( |
313 new ServiceWorkerVersion(registration_.get(), script_url_, | 313 registration_.get(), script_url_, |
314 NextVersionId(), context()->AsWeakPtr()); | 314 std::string("8f8c6868-e838-4296-847a-6a8d6b552884"), |
| 315 context()->AsWeakPtr()); |
315 CreateHostForVersion(render_process_id, provider_id, version_); | 316 CreateHostForVersion(render_process_id, provider_id, version_); |
316 SetUpScriptRequest(render_process_id, provider_id); | 317 SetUpScriptRequest(render_process_id, provider_id); |
317 | 318 |
318 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); | 319 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); |
319 base::RunLoop().RunUntilIdle(); | 320 base::RunLoop().RunUntilIdle(); |
320 } | 321 } |
321 | 322 |
322 void TearDown() override { | 323 void TearDown() override { |
323 request_.reset(); | 324 request_.reset(); |
324 url_request_context_.reset(); | 325 url_request_context_.reset(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } | 359 } |
359 | 360 |
360 // Performs the net request for an update of |registration_|'s incumbent | 361 // Performs the net request for an update of |registration_|'s incumbent |
361 // to the script |response|. Returns the new version. | 362 // to the script |response|. Returns the new version. |
362 scoped_refptr<ServiceWorkerVersion> UpdateScript( | 363 scoped_refptr<ServiceWorkerVersion> UpdateScript( |
363 const std::string& response) { | 364 const std::string& response) { |
364 int render_process_id = NextRenderProcessId(); | 365 int render_process_id = NextRenderProcessId(); |
365 int provider_id = NextProviderId(); | 366 int provider_id = NextProviderId(); |
366 scoped_refptr<ServiceWorkerVersion> new_version = | 367 scoped_refptr<ServiceWorkerVersion> new_version = |
367 new ServiceWorkerVersion(registration_.get(), script_url_, | 368 new ServiceWorkerVersion(registration_.get(), script_url_, |
368 NextVersionId(), context()->AsWeakPtr()); | 369 base::GenerateGUID(), context()->AsWeakPtr()); |
369 CreateHostForVersion(render_process_id, provider_id, new_version); | 370 CreateHostForVersion(render_process_id, provider_id, new_version); |
370 | 371 |
371 SetUpScriptRequest(render_process_id, provider_id); | 372 SetUpScriptRequest(render_process_id, provider_id); |
372 mock_protocol_handler_->SetCreateJobCallback( | 373 mock_protocol_handler_->SetCreateJobCallback( |
373 base::Bind(&CreateResponseJob, response)); | 374 base::Bind(&CreateResponseJob, response)); |
374 request_->Start(); | 375 request_->Start(); |
375 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
376 return new_version; | 377 return new_version; |
377 } | 378 } |
378 | 379 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 version = UpdateScript(std::string()); | 568 version = UpdateScript(std::string()); |
568 VerifyResource(GetResourceId(version.get()), std::string()); | 569 VerifyResource(GetResourceId(version.get()), std::string()); |
569 registration_->SetWaitingVersion(version); | 570 registration_->SetWaitingVersion(version); |
570 | 571 |
571 // Update from empty to empty. | 572 // Update from empty to empty. |
572 version = UpdateScript(std::string()); | 573 version = UpdateScript(std::string()); |
573 EXPECT_EQ(kInvalidServiceWorkerResponseId, GetResourceId(version.get())); | 574 EXPECT_EQ(kInvalidServiceWorkerResponseId, GetResourceId(version.get())); |
574 } | 575 } |
575 | 576 |
576 } // namespace content | 577 } // namespace content |
OLD | NEW |