Chromium Code Reviews| 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 "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
| 8 #include "content/browser/service_worker/service_worker_provider_host.h" | 8 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 9 #include "content/browser/service_worker/service_worker_register_job.h" | 9 #include "content/browser/service_worker/service_worker_register_job.h" |
| 10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 // Disassociating one provider_host shouldn't remove all process refs | 144 // Disassociating one provider_host shouldn't remove all process refs |
| 145 // from the version yet. | 145 // from the version yet. |
| 146 provider_host1_->SetWaitingVersion(NULL); | 146 provider_host1_->SetWaitingVersion(NULL); |
| 147 ASSERT_TRUE(version_->HasProcessToRun()); | 147 ASSERT_TRUE(version_->HasProcessToRun()); |
| 148 | 148 |
| 149 // Disassociating the other provider_host will remove all process refs. | 149 // Disassociating the other provider_host will remove all process refs. |
| 150 provider_host2_->SetWaitingVersion(NULL); | 150 provider_host2_->SetWaitingVersion(NULL); |
| 151 ASSERT_FALSE(version_->HasProcessToRun()); | 151 ASSERT_FALSE(version_->HasProcessToRun()); |
| 152 } | 152 } |
| 153 | 153 |
| 154 class ServiceWorkerProviderHostWaitingVersionTest : public testing::Test { | 154 class ServiceWorkerProviderHostWaitingVersionTest : public testing::Test { |
|
falken
2014/07/02 05:42:11
Maybe this should now be called ServiceWorkerProvi
| |
| 155 protected: | 155 protected: |
| 156 ServiceWorkerProviderHostWaitingVersionTest() | 156 ServiceWorkerProviderHostWaitingVersionTest() |
| 157 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 157 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
| 158 next_provider_id_(1L) {} | 158 next_provider_id_(1L) {} |
| 159 virtual ~ServiceWorkerProviderHostWaitingVersionTest() {} | 159 virtual ~ServiceWorkerProviderHostWaitingVersionTest() {} |
| 160 | 160 |
| 161 virtual void SetUp() OVERRIDE { | 161 virtual void SetUp() OVERRIDE { |
| 162 context_.reset( | 162 context_.reset( |
| 163 new ServiceWorkerContextCore(base::FilePath(), | 163 new ServiceWorkerContextCore(base::FilePath(), |
| 164 base::MessageLoopProxy::current(), | 164 base::MessageLoopProxy::current(), |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 193 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_; | 193 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_; |
| 194 base::WeakPtr<ServiceWorkerProviderHost> provider_host3_; | 194 base::WeakPtr<ServiceWorkerProviderHost> provider_host3_; |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 int64 next_provider_id_; | 197 int64 next_provider_id_; |
| 198 | 198 |
| 199 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostWaitingVersionTest); | 199 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostWaitingVersionTest); |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 TEST_F(ServiceWorkerProviderHostWaitingVersionTest, | 202 TEST_F(ServiceWorkerProviderHostWaitingVersionTest, |
| 203 AssociateWaitingVersionToDocuments) { | 203 AssociateInstallingVersionToDocuments) { |
| 204 const GURL scope1("http://www.example.com/*"); | 204 const GURL scope1("http://www.example.com/*"); |
| 205 const GURL script_url1("http://www.example.com/service_worker1.js"); | 205 const GURL script_url1("http://www.example.com/service_worker1.js"); |
| 206 scoped_refptr<ServiceWorkerRegistration> registration1( | 206 scoped_refptr<ServiceWorkerRegistration> registration1( |
| 207 new ServiceWorkerRegistration( | 207 new ServiceWorkerRegistration( |
| 208 scope1, script_url1, 1L, context_->AsWeakPtr())); | 208 scope1, script_url1, 1L, context_->AsWeakPtr())); |
| 209 scoped_refptr<ServiceWorkerVersion> version1( | 209 scoped_refptr<ServiceWorkerVersion> version1( |
| 210 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); | 210 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); |
| 211 | 211 |
| 212 ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments( | 212 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
| 213 context_->AsWeakPtr(), version1.get()); | 213 context_->AsWeakPtr(), version1); |
| 214 EXPECT_EQ(version1.get(), provider_host1_->waiting_version()); | 214 EXPECT_EQ(version1.get(), provider_host1_->installing_version()); |
| 215 EXPECT_EQ(version1.get(), provider_host2_->waiting_version()); | 215 EXPECT_EQ(version1.get(), provider_host2_->installing_version()); |
| 216 EXPECT_EQ(NULL, provider_host3_->waiting_version()); | 216 EXPECT_EQ(NULL, provider_host3_->installing_version()); |
| 217 | 217 |
| 218 // Version2 is associated with the same registration as version1, so the | 218 // Version2 is associated with the same registration as version1, so the |
| 219 // waiting version of host1 and host2 should be replaced. | 219 // waiting version of host1 and host2 should be replaced. |
| 220 scoped_refptr<ServiceWorkerVersion> version2( | 220 scoped_refptr<ServiceWorkerVersion> version2( |
| 221 new ServiceWorkerVersion(registration1, 2L, context_->AsWeakPtr())); | 221 new ServiceWorkerVersion(registration1, 2L, context_->AsWeakPtr())); |
| 222 ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments( | 222 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
| 223 context_->AsWeakPtr(), version2.get()); | 223 context_->AsWeakPtr(), version2); |
| 224 EXPECT_EQ(version2.get(), provider_host1_->waiting_version()); | 224 EXPECT_EQ(version2.get(), provider_host1_->installing_version()); |
| 225 EXPECT_EQ(version2.get(), provider_host2_->waiting_version()); | 225 EXPECT_EQ(version2.get(), provider_host2_->installing_version()); |
| 226 EXPECT_EQ(NULL, provider_host3_->waiting_version()); | 226 EXPECT_EQ(NULL, provider_host3_->installing_version()); |
| 227 | 227 |
| 228 const GURL scope3(provider_host1_->document_url()); | 228 const GURL scope3(provider_host1_->document_url()); |
| 229 const GURL script_url3("http://www.example.com/service_worker3.js"); | 229 const GURL script_url3("http://www.example.com/service_worker3.js"); |
| 230 scoped_refptr<ServiceWorkerRegistration> registration3( | 230 scoped_refptr<ServiceWorkerRegistration> registration3( |
| 231 new ServiceWorkerRegistration( | 231 new ServiceWorkerRegistration( |
| 232 scope3, script_url3, 3L, context_->AsWeakPtr())); | 232 scope3, script_url3, 3L, context_->AsWeakPtr())); |
| 233 scoped_refptr<ServiceWorkerVersion> version3( | 233 scoped_refptr<ServiceWorkerVersion> version3( |
| 234 new ServiceWorkerVersion(registration3, 3L, context_->AsWeakPtr())); | 234 new ServiceWorkerVersion(registration3, 3L, context_->AsWeakPtr())); |
| 235 | 235 |
| 236 // Although version3 can match longer than version2 for host1, it should be | 236 // Although version3 can match longer than version2 for host1, it should be |
| 237 // ignored because version3 is associated with a different registration from | 237 // ignored because version3 is associated with a different registration from |
| 238 // version2. | 238 // version2. |
| 239 ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments( | 239 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
| 240 context_->AsWeakPtr(), version3.get()); | 240 context_->AsWeakPtr(), version3); |
| 241 EXPECT_EQ(version2.get(), provider_host1_->waiting_version()); | 241 EXPECT_EQ(version2.get(), provider_host1_->installing_version()); |
| 242 EXPECT_EQ(version2.get(), provider_host2_->waiting_version()); | 242 EXPECT_EQ(version2.get(), provider_host2_->installing_version()); |
| 243 EXPECT_EQ(NULL, provider_host3_->waiting_version()); | 243 EXPECT_EQ(NULL, provider_host3_->installing_version()); |
| 244 } | 244 } |
| 245 | 245 |
| 246 TEST_F(ServiceWorkerProviderHostWaitingVersionTest, | 246 TEST_F(ServiceWorkerProviderHostWaitingVersionTest, |
| 247 DisassociateWaitingVersionFromDocuments) { | 247 DisassociateVersionFromDocuments) { |
| 248 const GURL scope1("http://www.example.com/*"); | 248 const GURL scope1("http://www.example.com/*"); |
| 249 const GURL script_url1("http://www.example.com/service_worker.js"); | 249 const GURL script_url1("http://www.example.com/service_worker.js"); |
| 250 scoped_refptr<ServiceWorkerRegistration> registration1( | 250 scoped_refptr<ServiceWorkerRegistration> registration1( |
| 251 new ServiceWorkerRegistration( | 251 new ServiceWorkerRegistration( |
| 252 scope1, script_url1, 1L, context_->AsWeakPtr())); | 252 scope1, script_url1, 1L, context_->AsWeakPtr())); |
| 253 scoped_refptr<ServiceWorkerVersion> version1( | 253 scoped_refptr<ServiceWorkerVersion> version1( |
| 254 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); | 254 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); |
| 255 | 255 |
| 256 const GURL scope2("http://www.example.ca/*"); | 256 const GURL scope2("http://www.example.ca/*"); |
| 257 const GURL script_url2("http://www.example.ca/service_worker.js"); | 257 const GURL script_url2("http://www.example.ca/service_worker.js"); |
| 258 scoped_refptr<ServiceWorkerRegistration> registration2( | 258 scoped_refptr<ServiceWorkerRegistration> registration2( |
| 259 new ServiceWorkerRegistration( | 259 new ServiceWorkerRegistration( |
| 260 scope2, script_url2, 2L, context_->AsWeakPtr())); | 260 scope2, script_url2, 2L, context_->AsWeakPtr())); |
| 261 scoped_refptr<ServiceWorkerVersion> version2( | 261 scoped_refptr<ServiceWorkerVersion> version2( |
| 262 new ServiceWorkerVersion(registration2, 2L, context_->AsWeakPtr())); | 262 new ServiceWorkerVersion(registration2, 2L, context_->AsWeakPtr())); |
| 263 | 263 |
| 264 ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments( | 264 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
| 265 context_->AsWeakPtr(), version1.get()); | 265 context_->AsWeakPtr(), version1); |
| 266 ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments( | 266 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
| 267 context_->AsWeakPtr(), version2.get()); | 267 context_->AsWeakPtr(), version2); |
| 268 | 268 |
| 269 // Host1 and host2 are associated with version1 as a waiting version, whereas | 269 // Host1 and host2 are associated with version1 as a waiting version, whereas |
| 270 // host3 is associated with version2. | 270 // host3 is associated with version2. |
| 271 EXPECT_EQ(version1.get(), provider_host1_->waiting_version()); | 271 EXPECT_EQ(version1.get(), provider_host1_->installing_version()); |
| 272 EXPECT_EQ(version1.get(), provider_host2_->waiting_version()); | 272 EXPECT_EQ(version1.get(), provider_host2_->installing_version()); |
| 273 EXPECT_EQ(version2.get(), provider_host3_->waiting_version()); | 273 EXPECT_EQ(version2.get(), provider_host3_->installing_version()); |
| 274 | 274 |
| 275 // Disassociate version1 from host1 and host2. | 275 // Disassociate version1 from host1 and host2. |
| 276 ServiceWorkerRegisterJob::DisassociateWaitingVersionFromDocuments( | 276 ServiceWorkerRegisterJob::DisassociateVersionFromDocuments( |
| 277 context_->AsWeakPtr(), version1->version_id()); | 277 context_->AsWeakPtr(), version1); |
| 278 EXPECT_EQ(NULL, provider_host1_->waiting_version()); | 278 EXPECT_EQ(NULL, provider_host1_->installing_version()); |
| 279 EXPECT_EQ(NULL, provider_host2_->waiting_version()); | 279 EXPECT_EQ(NULL, provider_host2_->installing_version()); |
| 280 EXPECT_EQ(version2.get(), provider_host3_->waiting_version()); | 280 EXPECT_EQ(version2.get(), provider_host3_->installing_version()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 } // namespace content | 283 } // namespace content |
| OLD | NEW |