| 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_request_handler.h" | 5 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "content/browser/fileapi/mock_url_request_delegate.h" | 8 #include "content/browser/fileapi/mock_url_request_delegate.h" |
| 9 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 9 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 void EmptyCallback() { | 30 void EmptyCallback() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 } | 33 } |
| 34 | 34 |
| 35 class ServiceWorkerRequestHandlerTest : public testing::Test { | 35 class ServiceWorkerRequestHandlerTest : public testing::Test { |
| 36 public: | 36 public: |
| 37 ServiceWorkerRequestHandlerTest() | 37 ServiceWorkerRequestHandlerTest() |
| 38 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 38 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 39 | 39 |
| 40 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() override { |
| 41 helper_.reset(new EmbeddedWorkerTestHelper(kMockRenderProcessId)); | 41 helper_.reset(new EmbeddedWorkerTestHelper(kMockRenderProcessId)); |
| 42 | 42 |
| 43 // A new unstored registration/version. | 43 // A new unstored registration/version. |
| 44 registration_ = new ServiceWorkerRegistration( | 44 registration_ = new ServiceWorkerRegistration( |
| 45 GURL("http://host/scope/"), 1L, context()->AsWeakPtr()); | 45 GURL("http://host/scope/"), 1L, context()->AsWeakPtr()); |
| 46 version_ = new ServiceWorkerVersion(registration_.get(), | 46 version_ = new ServiceWorkerVersion(registration_.get(), |
| 47 GURL("http://host/script.js"), | 47 GURL("http://host/script.js"), |
| 48 1L, | 48 1L, |
| 49 context()->AsWeakPtr()); | 49 context()->AsWeakPtr()); |
| 50 | 50 |
| 51 // An empty host. | 51 // An empty host. |
| 52 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 52 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 53 kMockRenderProcessId, kMockProviderId, context()->AsWeakPtr(), NULL)); | 53 kMockRenderProcessId, kMockProviderId, context()->AsWeakPtr(), NULL)); |
| 54 provider_host_ = host->AsWeakPtr(); | 54 provider_host_ = host->AsWeakPtr(); |
| 55 context()->AddProviderHost(host.Pass()); | 55 context()->AddProviderHost(host.Pass()); |
| 56 | 56 |
| 57 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); | 57 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); |
| 58 base::RunLoop().RunUntilIdle(); | 58 base::RunLoop().RunUntilIdle(); |
| 59 | 59 |
| 60 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 60 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 61 registration_->SetActiveVersion(version_.get()); | 61 registration_->SetActiveVersion(version_.get()); |
| 62 context()->storage()->StoreRegistration( | 62 context()->storage()->StoreRegistration( |
| 63 registration_.get(), | 63 registration_.get(), |
| 64 version_.get(), | 64 version_.get(), |
| 65 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 65 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 66 provider_host_->AssociateRegistration(registration_.get()); | 66 provider_host_->AssociateRegistration(registration_.get()); |
| 67 base::RunLoop().RunUntilIdle(); | 67 base::RunLoop().RunUntilIdle(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void TearDown() OVERRIDE { | 70 virtual void TearDown() override { |
| 71 version_ = NULL; | 71 version_ = NULL; |
| 72 registration_ = NULL; | 72 registration_ = NULL; |
| 73 helper_.reset(); | 73 helper_.reset(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 ServiceWorkerContextCore* context() const { return helper_->context(); } | 76 ServiceWorkerContextCore* context() const { return helper_->context(); } |
| 77 ServiceWorkerContextWrapper* context_wrapper() const { | 77 ServiceWorkerContextWrapper* context_wrapper() const { |
| 78 return helper_->context_wrapper(); | 78 return helper_->context_wrapper(); |
| 79 } | 79 } |
| 80 | 80 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 provider_host_->SetDocumentUrl(GURL("")); | 149 provider_host_->SetDocumentUrl(GURL("")); |
| 150 EXPECT_FALSE(InitializeHandlerCheck( | 150 EXPECT_FALSE(InitializeHandlerCheck( |
| 151 "http://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); | 151 "http://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); |
| 152 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); | 152 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); |
| 153 EXPECT_FALSE(InitializeHandlerCheck( | 153 EXPECT_FALSE(InitializeHandlerCheck( |
| 154 "https://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); | 154 "https://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); |
| 155 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); | 155 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace content | 158 } // namespace content |
| OLD | NEW |