| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
| 7 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 8 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_provider_host.h" | 10 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 11 #include "content/browser/service_worker/service_worker_register_job.h" | 11 #include "content/browser/service_worker/service_worker_register_job.h" |
| 12 #include "content/browser/service_worker/service_worker_registration.h" | 12 #include "content/browser/service_worker/service_worker_registration.h" |
| 13 #include "content/browser/service_worker/service_worker_version.h" | 13 #include "content/browser/service_worker/service_worker_version.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 static const int kRenderProcessId = 33; // Dummy process ID for testing. | 19 static const int kRenderProcessId = 33; // Dummy process ID for testing. |
| 20 | 20 |
| 21 class ServiceWorkerProviderHostTest : public testing::Test { | 21 class ServiceWorkerProviderHostTest : public testing::Test { |
| 22 protected: | 22 protected: |
| 23 ServiceWorkerProviderHostTest() | 23 ServiceWorkerProviderHostTest() |
| 24 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 24 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 25 virtual ~ServiceWorkerProviderHostTest() {} | 25 virtual ~ServiceWorkerProviderHostTest() {} |
| 26 | 26 |
| 27 virtual void SetUp() OVERRIDE { | 27 virtual void SetUp() override { |
| 28 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); | 28 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); |
| 29 context_ = helper_->context(); | 29 context_ = helper_->context(); |
| 30 pattern_ = GURL("http://www.example.com/"); | 30 pattern_ = GURL("http://www.example.com/"); |
| 31 script_url_ = GURL("http://www.example.com/service_worker.js"); | 31 script_url_ = GURL("http://www.example.com/service_worker.js"); |
| 32 registration_ = new ServiceWorkerRegistration( | 32 registration_ = new ServiceWorkerRegistration( |
| 33 pattern_, 1L, context_->AsWeakPtr()); | 33 pattern_, 1L, context_->AsWeakPtr()); |
| 34 version_ = new ServiceWorkerVersion( | 34 version_ = new ServiceWorkerVersion( |
| 35 registration_.get(), script_url_, 1L, context_->AsWeakPtr()); | 35 registration_.get(), script_url_, 1L, context_->AsWeakPtr()); |
| 36 | 36 |
| 37 // Prepare provider hosts (for the same process). | 37 // Prepare provider hosts (for the same process). |
| 38 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( | 38 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( |
| 39 kRenderProcessId, 1 /* provider_id */, | 39 kRenderProcessId, 1 /* provider_id */, |
| 40 context_->AsWeakPtr(), NULL)); | 40 context_->AsWeakPtr(), NULL)); |
| 41 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost( | 41 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost( |
| 42 kRenderProcessId, 2 /* provider_id */, | 42 kRenderProcessId, 2 /* provider_id */, |
| 43 context_->AsWeakPtr(), NULL)); | 43 context_->AsWeakPtr(), NULL)); |
| 44 provider_host1_ = host1->AsWeakPtr(); | 44 provider_host1_ = host1->AsWeakPtr(); |
| 45 provider_host2_ = host2->AsWeakPtr(); | 45 provider_host2_ = host2->AsWeakPtr(); |
| 46 context_->AddProviderHost(make_scoped_ptr(host1.release())); | 46 context_->AddProviderHost(make_scoped_ptr(host1.release())); |
| 47 context_->AddProviderHost(make_scoped_ptr(host2.release())); | 47 context_->AddProviderHost(make_scoped_ptr(host2.release())); |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual void TearDown() OVERRIDE { | 50 virtual void TearDown() override { |
| 51 version_ = 0; | 51 version_ = 0; |
| 52 registration_ = 0; | 52 registration_ = 0; |
| 53 helper_.reset(); | 53 helper_.reset(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool HasProcessToRun() const { | 56 bool HasProcessToRun() const { |
| 57 return context_->process_manager()->PatternHasProcessToRun(pattern_); | 57 return context_->process_manager()->PatternHasProcessToRun(pattern_); |
| 58 } | 58 } |
| 59 | 59 |
| 60 content::TestBrowserThreadBundle thread_bundle_; | 60 content::TestBrowserThreadBundle thread_bundle_; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // from the version yet. | 143 // from the version yet. |
| 144 provider_host1_->DisassociateRegistration(); | 144 provider_host1_->DisassociateRegistration(); |
| 145 ASSERT_TRUE(HasProcessToRun()); | 145 ASSERT_TRUE(HasProcessToRun()); |
| 146 | 146 |
| 147 // Disassociating the other provider_host will remove all process refs. | 147 // Disassociating the other provider_host will remove all process refs. |
| 148 provider_host2_->DisassociateRegistration(); | 148 provider_host2_->DisassociateRegistration(); |
| 149 ASSERT_FALSE(HasProcessToRun()); | 149 ASSERT_FALSE(HasProcessToRun()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 } // namespace content | 152 } // namespace content |
| OLD | NEW |