| 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/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
| 9 #include "content/browser/service_worker/service_worker_provider_host.h" | 9 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 10 #include "content/browser/service_worker/service_worker_register_job.h" | 10 #include "content/browser/service_worker/service_worker_register_job.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 base::ThreadTaskRunnerHandle::Get(), | 29 base::ThreadTaskRunnerHandle::Get(), |
| 30 base::ThreadTaskRunnerHandle::Get(), | 30 base::ThreadTaskRunnerHandle::Get(), |
| 31 base::ThreadTaskRunnerHandle::Get(), | 31 base::ThreadTaskRunnerHandle::Get(), |
| 32 NULL, | 32 NULL, |
| 33 NULL, | 33 NULL, |
| 34 NULL)); | 34 NULL)); |
| 35 | 35 |
| 36 scope_ = GURL("http://www.example.com/"); | 36 scope_ = GURL("http://www.example.com/"); |
| 37 script_url_ = GURL("http://www.example.com/service_worker.js"); | 37 script_url_ = GURL("http://www.example.com/service_worker.js"); |
| 38 registration_ = new ServiceWorkerRegistration( | 38 registration_ = new ServiceWorkerRegistration( |
| 39 scope_, script_url_, 1L, context_->AsWeakPtr()); | 39 scope_, 1L, context_->AsWeakPtr()); |
| 40 version_ = new ServiceWorkerVersion( | 40 version_ = new ServiceWorkerVersion( |
| 41 registration_.get(), 1L, context_->AsWeakPtr()); | 41 registration_.get(), script_url_, 1L, context_->AsWeakPtr()); |
| 42 | 42 |
| 43 // Prepare provider hosts (for the same process). | 43 // Prepare provider hosts (for the same process). |
| 44 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( | 44 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( |
| 45 kRenderProcessId, 1 /* provider_id */, | 45 kRenderProcessId, 1 /* provider_id */, |
| 46 context_->AsWeakPtr(), NULL)); | 46 context_->AsWeakPtr(), NULL)); |
| 47 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost( | 47 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost( |
| 48 kRenderProcessId, 2 /* provider_id */, | 48 kRenderProcessId, 2 /* provider_id */, |
| 49 context_->AsWeakPtr(), NULL)); | 49 context_->AsWeakPtr(), NULL)); |
| 50 provider_host1_ = host1->AsWeakPtr(); | 50 provider_host1_ = host1->AsWeakPtr(); |
| 51 provider_host2_ = host2->AsWeakPtr(); | 51 provider_host2_ = host2->AsWeakPtr(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); | 187 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); |
| 188 } | 188 } |
| 189 | 189 |
| 190 TEST_F(ServiceWorkerProviderHostTest, | 190 TEST_F(ServiceWorkerProviderHostTest, |
| 191 ObserveVersionAttributesChanged_MultipleVersions) { | 191 ObserveVersionAttributesChanged_MultipleVersions) { |
| 192 provider_host1_->AssociateRegistration(registration_.get()); | 192 provider_host1_->AssociateRegistration(registration_.get()); |
| 193 provider_host2_->AssociateRegistration(registration_.get()); | 193 provider_host2_->AssociateRegistration(registration_.get()); |
| 194 VerifyVersionAttributes(provider_host1_, NULL, NULL, NULL); | 194 VerifyVersionAttributes(provider_host1_, NULL, NULL, NULL); |
| 195 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); | 195 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); |
| 196 | 196 |
| 197 scoped_refptr<ServiceWorkerVersion> version1 = | 197 scoped_refptr<ServiceWorkerVersion> version1 = new ServiceWorkerVersion( |
| 198 new ServiceWorkerVersion(registration_.get(), 10L, context_->AsWeakPtr()); | 198 registration_.get(), script_url_, 10L, context_->AsWeakPtr()); |
| 199 scoped_refptr<ServiceWorkerVersion> version2 = | 199 scoped_refptr<ServiceWorkerVersion> version2 = new ServiceWorkerVersion( |
| 200 new ServiceWorkerVersion(registration_.get(), 20L, context_->AsWeakPtr()); | 200 registration_.get(), script_url_, 20L, context_->AsWeakPtr()); |
| 201 | 201 |
| 202 registration_->SetInstallingVersion(version1.get()); | 202 registration_->SetInstallingVersion(version1.get()); |
| 203 VerifyVersionAttributes(provider_host1_, version1.get(), NULL, NULL); | 203 VerifyVersionAttributes(provider_host1_, version1.get(), NULL, NULL); |
| 204 VerifyVersionAttributes(provider_host2_, version1.get(), NULL, NULL); | 204 VerifyVersionAttributes(provider_host2_, version1.get(), NULL, NULL); |
| 205 | 205 |
| 206 registration_->SetWaitingVersion(version1.get()); | 206 registration_->SetWaitingVersion(version1.get()); |
| 207 VerifyVersionAttributes(provider_host1_, NULL, version1.get(), NULL); | 207 VerifyVersionAttributes(provider_host1_, NULL, version1.get(), NULL); |
| 208 VerifyVersionAttributes(provider_host2_, NULL, version1.get(), NULL); | 208 VerifyVersionAttributes(provider_host2_, NULL, version1.get(), NULL); |
| 209 | 209 |
| 210 registration_->SetInstallingVersion(version2.get()); | 210 registration_->SetInstallingVersion(version2.get()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 224 VerifyVersionAttributes( | 224 VerifyVersionAttributes( |
| 225 provider_host1_, version2.get(), NULL, version1.get()); | 225 provider_host1_, version2.get(), NULL, version1.get()); |
| 226 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); | 226 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); |
| 227 | 227 |
| 228 registration_->SetActiveVersion(version2.get()); | 228 registration_->SetActiveVersion(version2.get()); |
| 229 VerifyVersionAttributes(provider_host1_, NULL, NULL, version2.get()); | 229 VerifyVersionAttributes(provider_host1_, NULL, NULL, version2.get()); |
| 230 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); | 230 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); |
| 231 } | 231 } |
| 232 | 232 |
| 233 } // namespace content | 233 } // namespace content |
| OLD | NEW |