| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <utility> |
| 7 | 8 |
| 8 #include "base/bind.h" | 9 #include "base/bind.h" |
| 9 #include "base/callback.h" | 10 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 scoped_ptr<net::test_server::HttpResponse> VerifyServiceWorkerHeaderInRequest( | 214 scoped_ptr<net::test_server::HttpResponse> VerifyServiceWorkerHeaderInRequest( |
| 214 const net::test_server::HttpRequest& request) { | 215 const net::test_server::HttpRequest& request) { |
| 215 EXPECT_EQ(request.relative_url, "/service_worker/generated_sw.js"); | 216 EXPECT_EQ(request.relative_url, "/service_worker/generated_sw.js"); |
| 216 auto it = request.headers.find("Service-Worker"); | 217 auto it = request.headers.find("Service-Worker"); |
| 217 EXPECT_TRUE(it != request.headers.end()); | 218 EXPECT_TRUE(it != request.headers.end()); |
| 218 EXPECT_EQ("script", it->second); | 219 EXPECT_EQ("script", it->second); |
| 219 | 220 |
| 220 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 221 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
| 221 new net::test_server::BasicHttpResponse()); | 222 new net::test_server::BasicHttpResponse()); |
| 222 http_response->set_content_type("text/javascript"); | 223 http_response->set_content_type("text/javascript"); |
| 223 return http_response.Pass(); | 224 return std::move(http_response); |
| 224 } | 225 } |
| 225 | 226 |
| 226 // The ImportsBustMemcache test requires that the imported script | 227 // The ImportsBustMemcache test requires that the imported script |
| 227 // would naturally be cached in blink's memcache, but the embedded | 228 // would naturally be cached in blink's memcache, but the embedded |
| 228 // test server doesn't produce headers that allow the blink's memcache | 229 // test server doesn't produce headers that allow the blink's memcache |
| 229 // to do that. This interceptor injects headers that give the import | 230 // to do that. This interceptor injects headers that give the import |
| 230 // an experiration far in the future. | 231 // an experiration far in the future. |
| 231 class LongLivedResourceInterceptor : public net::URLRequestInterceptor { | 232 class LongLivedResourceInterceptor : public net::URLRequestInterceptor { |
| 232 public: | 233 public: |
| 233 LongLivedResourceInterceptor(const std::string& body) | 234 LongLivedResourceInterceptor(const std::string& body) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 254 }; | 255 }; |
| 255 | 256 |
| 256 void CreateLongLivedResourceInterceptors( | 257 void CreateLongLivedResourceInterceptors( |
| 257 const GURL& worker_url, const GURL& import_url) { | 258 const GURL& worker_url, const GURL& import_url) { |
| 258 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 259 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 259 scoped_ptr<net::URLRequestInterceptor> interceptor; | 260 scoped_ptr<net::URLRequestInterceptor> interceptor; |
| 260 | 261 |
| 261 interceptor.reset(new LongLivedResourceInterceptor( | 262 interceptor.reset(new LongLivedResourceInterceptor( |
| 262 "importScripts('long_lived_import.js');")); | 263 "importScripts('long_lived_import.js');")); |
| 263 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 264 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 264 worker_url, interceptor.Pass()); | 265 worker_url, std::move(interceptor)); |
| 265 | 266 |
| 266 interceptor.reset(new LongLivedResourceInterceptor( | 267 interceptor.reset(new LongLivedResourceInterceptor( |
| 267 "// the imported script does nothing")); | 268 "// the imported script does nothing")); |
| 268 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 269 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 269 import_url, interceptor.Pass()); | 270 import_url, std::move(interceptor)); |
| 270 } | 271 } |
| 271 | 272 |
| 272 void CountScriptResources( | 273 void CountScriptResources( |
| 273 ServiceWorkerContextWrapper* wrapper, | 274 ServiceWorkerContextWrapper* wrapper, |
| 274 const GURL& scope, | 275 const GURL& scope, |
| 275 int* num_resources) { | 276 int* num_resources) { |
| 276 *num_resources = -1; | 277 *num_resources = -1; |
| 277 | 278 |
| 278 std::vector<ServiceWorkerRegistrationInfo> infos = | 279 std::vector<ServiceWorkerRegistrationInfo> infos = |
| 279 wrapper->GetAllLiveRegistrationInfo(); | 280 wrapper->GetAllLiveRegistrationInfo(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 FROM_HERE, | 448 FROM_HERE, |
| 448 base::Bind(&self::FetchOnIOThread, | 449 base::Bind(&self::FetchOnIOThread, |
| 449 this, | 450 this, |
| 450 fetch_run_loop.QuitClosure(), | 451 fetch_run_loop.QuitClosure(), |
| 451 &prepare_result, | 452 &prepare_result, |
| 452 &fetch_result)); | 453 &fetch_result)); |
| 453 fetch_run_loop.Run(); | 454 fetch_run_loop.Run(); |
| 454 ASSERT_TRUE(prepare_result); | 455 ASSERT_TRUE(prepare_result); |
| 455 *result = fetch_result.result; | 456 *result = fetch_result.result; |
| 456 *response = fetch_result.response; | 457 *response = fetch_result.response; |
| 457 *blob_data_handle = fetch_result.blob_data_handle.Pass(); | 458 *blob_data_handle = std::move(fetch_result.blob_data_handle); |
| 458 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); | 459 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); |
| 459 } | 460 } |
| 460 | 461 |
| 461 void FetchTestHelper(const std::string& worker_url, | 462 void FetchTestHelper(const std::string& worker_url, |
| 462 ServiceWorkerFetchEventResult* result, | 463 ServiceWorkerFetchEventResult* result, |
| 463 ServiceWorkerResponse* response, | 464 ServiceWorkerResponse* response, |
| 464 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { | 465 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { |
| 465 RunOnIOThread( | 466 RunOnIOThread( |
| 466 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); | 467 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); |
| 467 FetchOnRegisteredWorker(result, response, blob_data_handle); | 468 FetchOnRegisteredWorker(result, response, blob_data_handle); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 501 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 501 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 502 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 502 33 /* dummy render process id */, | 503 33 /* dummy render process id */, |
| 503 MSG_ROUTING_NONE /* render_frame_id */, 1 /* dummy provider_id */, | 504 MSG_ROUTING_NONE /* render_frame_id */, 1 /* dummy provider_id */, |
| 504 SERVICE_WORKER_PROVIDER_FOR_WINDOW, wrapper()->context()->AsWeakPtr(), | 505 SERVICE_WORKER_PROVIDER_FOR_WINDOW, wrapper()->context()->AsWeakPtr(), |
| 505 NULL)); | 506 NULL)); |
| 506 host->SetDocumentUrl( | 507 host->SetDocumentUrl( |
| 507 embedded_test_server()->GetURL("/service_worker/host")); | 508 embedded_test_server()->GetURL("/service_worker/host")); |
| 508 host->AssociateRegistration(registration_.get(), | 509 host->AssociateRegistration(registration_.get(), |
| 509 false /* notify_controllerchange */); | 510 false /* notify_controllerchange */); |
| 510 wrapper()->context()->AddProviderHost(host.Pass()); | 511 wrapper()->context()->AddProviderHost(std::move(host)); |
| 511 } | 512 } |
| 512 | 513 |
| 513 void AddWaitingWorkerOnIOThread(const std::string& worker_url) { | 514 void AddWaitingWorkerOnIOThread(const std::string& worker_url) { |
| 514 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 515 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 515 scoped_refptr<ServiceWorkerVersion> waiting_version( | 516 scoped_refptr<ServiceWorkerVersion> waiting_version( |
| 516 new ServiceWorkerVersion( | 517 new ServiceWorkerVersion( |
| 517 registration_.get(), embedded_test_server()->GetURL(worker_url), | 518 registration_.get(), embedded_test_server()->GetURL(worker_url), |
| 518 wrapper()->context()->storage()->NewVersionId(), | 519 wrapper()->context()->storage()->NewVersionId(), |
| 519 wrapper()->context()->AsWeakPtr())); | 520 wrapper()->context()->AsWeakPtr())); |
| 520 waiting_version->SetStatus(ServiceWorkerVersion::INSTALLED); | 521 waiting_version->SetStatus(ServiceWorkerVersion::INSTALLED); |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1291 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 1291 // Stop the worker. | 1292 // Stop the worker. |
| 1292 StopWorker(SERVICE_WORKER_OK); | 1293 StopWorker(SERVICE_WORKER_OK); |
| 1293 // Restart the worker. | 1294 // Restart the worker. |
| 1294 StartWorker(SERVICE_WORKER_OK); | 1295 StartWorker(SERVICE_WORKER_OK); |
| 1295 // Stop the worker. | 1296 // Stop the worker. |
| 1296 StopWorker(SERVICE_WORKER_OK); | 1297 StopWorker(SERVICE_WORKER_OK); |
| 1297 } | 1298 } |
| 1298 | 1299 |
| 1299 } // namespace content | 1300 } // namespace content |
| OLD | NEW |