| 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/embedded_worker_test_helper.h" | 5 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 273 |
| 274 ServiceWorkerContextCore* EmbeddedWorkerTestHelper::context() { | 274 ServiceWorkerContextCore* EmbeddedWorkerTestHelper::context() { |
| 275 return wrapper_->context(); | 275 return wrapper_->context(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void EmbeddedWorkerTestHelper::ShutdownContext() { | 278 void EmbeddedWorkerTestHelper::ShutdownContext() { |
| 279 wrapper_->Shutdown(); | 279 wrapper_->Shutdown(); |
| 280 wrapper_ = NULL; | 280 wrapper_ = NULL; |
| 281 } | 281 } |
| 282 | 282 |
| 283 // static |
| 284 net::HttpResponseInfo EmbeddedWorkerTestHelper::CreateHttpResponseInfo() { |
| 285 net::HttpResponseInfo info; |
| 286 const char data[] = |
| 287 "HTTP/1.1 200 OK\0" |
| 288 "Content-Type: application/javascript\0" |
| 289 "\0"; |
| 290 info.headers = |
| 291 new net::HttpResponseHeaders(std::string(data, arraysize(data))); |
| 292 return info; |
| 293 } |
| 294 |
| 283 void EmbeddedWorkerTestHelper::OnStartWorker(int embedded_worker_id, | 295 void EmbeddedWorkerTestHelper::OnStartWorker(int embedded_worker_id, |
| 284 int64_t service_worker_version_id, | 296 int64_t service_worker_version_id, |
| 285 const GURL& scope, | 297 const GURL& scope, |
| 286 const GURL& script_url, | 298 const GURL& script_url, |
| 287 bool pause_after_download) { | 299 bool pause_after_download) { |
| 288 embedded_worker_id_service_worker_version_id_map_[embedded_worker_id] = | 300 embedded_worker_id_service_worker_version_id_map_[embedded_worker_id] = |
| 289 service_worker_version_id; | 301 service_worker_version_id; |
| 290 SimulateWorkerReadyForInspection(embedded_worker_id); | 302 SimulateWorkerReadyForInspection(embedded_worker_id); |
| 291 SimulateWorkerScriptCached(embedded_worker_id); | 303 SimulateWorkerScriptCached(embedded_worker_id); |
| 292 SimulateWorkerScriptLoaded(embedded_worker_id); | 304 SimulateWorkerScriptLoaded(embedded_worker_id); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); | 409 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); |
| 398 if (!version || version->script_cache_map()->size()) | 410 if (!version || version->script_cache_map()->size()) |
| 399 return; | 411 return; |
| 400 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 412 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
| 401 // Add a dummy ResourceRecord for the main script to the script cache map of | 413 // Add a dummy ResourceRecord for the main script to the script cache map of |
| 402 // the ServiceWorkerVersion. We use embedded_worker_id for resource_id to | 414 // the ServiceWorkerVersion. We use embedded_worker_id for resource_id to |
| 403 // avoid ID collision. | 415 // avoid ID collision. |
| 404 records.push_back(ServiceWorkerDatabase::ResourceRecord( | 416 records.push_back(ServiceWorkerDatabase::ResourceRecord( |
| 405 embedded_worker_id, version->script_url(), 100)); | 417 embedded_worker_id, version->script_url(), 100)); |
| 406 version->script_cache_map()->SetResources(records); | 418 version->script_cache_map()->SetResources(records); |
| 419 version->SetMainScriptHttpResponseInfo(CreateHttpResponseInfo()); |
| 407 } | 420 } |
| 408 | 421 |
| 409 void EmbeddedWorkerTestHelper::SimulateWorkerScriptLoaded( | 422 void EmbeddedWorkerTestHelper::SimulateWorkerScriptLoaded( |
| 410 int embedded_worker_id) { | 423 int embedded_worker_id) { |
| 411 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 424 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
| 412 ASSERT_TRUE(worker != NULL); | 425 ASSERT_TRUE(worker != NULL); |
| 413 registry()->OnWorkerScriptLoaded(worker->process_id(), embedded_worker_id); | 426 registry()->OnWorkerScriptLoaded(worker->process_id(), embedded_worker_id); |
| 414 } | 427 } |
| 415 | 428 |
| 416 void EmbeddedWorkerTestHelper::SimulateWorkerThreadStarted( | 429 void EmbeddedWorkerTestHelper::SimulateWorkerThreadStarted( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 service_manager::InterfaceProviderSpec()); | 579 service_manager::InterfaceProviderSpec()); |
| 567 | 580 |
| 568 std::unique_ptr<service_manager::InterfaceProvider> remote_interfaces( | 581 std::unique_ptr<service_manager::InterfaceProvider> remote_interfaces( |
| 569 new service_manager::InterfaceProvider); | 582 new service_manager::InterfaceProvider); |
| 570 remote_interfaces->Bind(std::move(interfaces)); | 583 remote_interfaces->Bind(std::move(interfaces)); |
| 571 rph->SetRemoteInterfaces(std::move(remote_interfaces)); | 584 rph->SetRemoteInterfaces(std::move(remote_interfaces)); |
| 572 return registry; | 585 return registry; |
| 573 } | 586 } |
| 574 | 587 |
| 575 } // namespace content | 588 } // namespace content |
| OLD | NEW |