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 14 matching lines...) Expand all Loading... |
25 virtual void SetUp() OVERRIDE { | 25 virtual void SetUp() OVERRIDE { |
26 context_.reset( | 26 context_.reset( |
27 new ServiceWorkerContextCore(base::FilePath(), | 27 new ServiceWorkerContextCore(base::FilePath(), |
28 base::MessageLoopProxy::current(), | 28 base::MessageLoopProxy::current(), |
29 base::MessageLoopProxy::current(), | 29 base::MessageLoopProxy::current(), |
30 base::MessageLoopProxy::current(), | 30 base::MessageLoopProxy::current(), |
31 NULL, | 31 NULL, |
32 NULL, | 32 NULL, |
33 NULL)); | 33 NULL)); |
34 | 34 |
35 scope_ = GURL("http://www.example.com/*"); | 35 scope_ = GURL("http://www.example.com/"); |
36 script_url_ = GURL("http://www.example.com/service_worker.js"); | 36 script_url_ = GURL("http://www.example.com/service_worker.js"); |
37 registration_ = new ServiceWorkerRegistration( | 37 registration_ = new ServiceWorkerRegistration( |
38 scope_, script_url_, 1L, context_->AsWeakPtr()); | 38 scope_, script_url_, 1L, context_->AsWeakPtr()); |
39 version_ = new ServiceWorkerVersion( | 39 version_ = new ServiceWorkerVersion( |
40 registration_, | 40 registration_, |
41 1L, context_->AsWeakPtr()); | 41 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 */, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 base::WeakPtr<ServiceWorkerProviderHost> provider_host3_; | 196 base::WeakPtr<ServiceWorkerProviderHost> provider_host3_; |
197 | 197 |
198 private: | 198 private: |
199 int64 next_provider_id_; | 199 int64 next_provider_id_; |
200 | 200 |
201 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostWaitingVersionTest); | 201 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostWaitingVersionTest); |
202 }; | 202 }; |
203 | 203 |
204 TEST_F(ServiceWorkerProviderHostWaitingVersionTest, | 204 TEST_F(ServiceWorkerProviderHostWaitingVersionTest, |
205 AssociateInstallingVersionToDocuments) { | 205 AssociateInstallingVersionToDocuments) { |
206 const GURL scope1("http://www.example.com/*"); | 206 const GURL scope1("http://www.example.com/"); |
207 const GURL script_url1("http://www.example.com/service_worker1.js"); | 207 const GURL script_url1("http://www.example.com/service_worker1.js"); |
208 scoped_refptr<ServiceWorkerRegistration> registration1( | 208 scoped_refptr<ServiceWorkerRegistration> registration1( |
209 new ServiceWorkerRegistration( | 209 new ServiceWorkerRegistration( |
210 scope1, script_url1, 1L, context_->AsWeakPtr())); | 210 scope1, script_url1, 1L, context_->AsWeakPtr())); |
211 scoped_refptr<ServiceWorkerVersion> version1( | 211 scoped_refptr<ServiceWorkerVersion> version1( |
212 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); | 212 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); |
213 | 213 |
214 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( | 214 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
215 context_->AsWeakPtr(), version1); | 215 context_->AsWeakPtr(), version1); |
216 EXPECT_EQ(version1.get(), provider_host1_->installing_version()); | 216 EXPECT_EQ(version1.get(), provider_host1_->installing_version()); |
(...skipping 23 matching lines...) Expand all Loading... |
240 // version2. | 240 // version2. |
241 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( | 241 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
242 context_->AsWeakPtr(), version3); | 242 context_->AsWeakPtr(), version3); |
243 EXPECT_EQ(version2.get(), provider_host1_->installing_version()); | 243 EXPECT_EQ(version2.get(), provider_host1_->installing_version()); |
244 EXPECT_EQ(version2.get(), provider_host2_->installing_version()); | 244 EXPECT_EQ(version2.get(), provider_host2_->installing_version()); |
245 EXPECT_EQ(NULL, provider_host3_->installing_version()); | 245 EXPECT_EQ(NULL, provider_host3_->installing_version()); |
246 } | 246 } |
247 | 247 |
248 TEST_F(ServiceWorkerProviderHostWaitingVersionTest, | 248 TEST_F(ServiceWorkerProviderHostWaitingVersionTest, |
249 DisassociateVersionFromDocuments) { | 249 DisassociateVersionFromDocuments) { |
250 const GURL scope1("http://www.example.com/*"); | 250 const GURL scope1("http://www.example.com/"); |
251 const GURL script_url1("http://www.example.com/service_worker.js"); | 251 const GURL script_url1("http://www.example.com/service_worker.js"); |
252 scoped_refptr<ServiceWorkerRegistration> registration1( | 252 scoped_refptr<ServiceWorkerRegistration> registration1( |
253 new ServiceWorkerRegistration( | 253 new ServiceWorkerRegistration( |
254 scope1, script_url1, 1L, context_->AsWeakPtr())); | 254 scope1, script_url1, 1L, context_->AsWeakPtr())); |
255 scoped_refptr<ServiceWorkerVersion> version1( | 255 scoped_refptr<ServiceWorkerVersion> version1( |
256 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); | 256 new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); |
257 | 257 |
258 const GURL scope2("http://www.example.ca/*"); | 258 const GURL scope2("http://www.example.ca/"); |
259 const GURL script_url2("http://www.example.ca/service_worker.js"); | 259 const GURL script_url2("http://www.example.ca/service_worker.js"); |
260 scoped_refptr<ServiceWorkerRegistration> registration2( | 260 scoped_refptr<ServiceWorkerRegistration> registration2( |
261 new ServiceWorkerRegistration( | 261 new ServiceWorkerRegistration( |
262 scope2, script_url2, 2L, context_->AsWeakPtr())); | 262 scope2, script_url2, 2L, context_->AsWeakPtr())); |
263 scoped_refptr<ServiceWorkerVersion> version2( | 263 scoped_refptr<ServiceWorkerVersion> version2( |
264 new ServiceWorkerVersion(registration2, 2L, context_->AsWeakPtr())); | 264 new ServiceWorkerVersion(registration2, 2L, context_->AsWeakPtr())); |
265 | 265 |
266 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( | 266 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
267 context_->AsWeakPtr(), version1); | 267 context_->AsWeakPtr(), version1); |
268 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( | 268 ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments( |
269 context_->AsWeakPtr(), version2); | 269 context_->AsWeakPtr(), version2); |
270 | 270 |
271 // Host1 and host2 are associated with version1 as a waiting version, whereas | 271 // Host1 and host2 are associated with version1 as a waiting version, whereas |
272 // host3 is associated with version2. | 272 // host3 is associated with version2. |
273 EXPECT_EQ(version1.get(), provider_host1_->installing_version()); | 273 EXPECT_EQ(version1.get(), provider_host1_->installing_version()); |
274 EXPECT_EQ(version1.get(), provider_host2_->installing_version()); | 274 EXPECT_EQ(version1.get(), provider_host2_->installing_version()); |
275 EXPECT_EQ(version2.get(), provider_host3_->installing_version()); | 275 EXPECT_EQ(version2.get(), provider_host3_->installing_version()); |
276 | 276 |
277 // Disassociate version1 from host1 and host2. | 277 // Disassociate version1 from host1 and host2. |
278 ServiceWorkerRegisterJob::DisassociateVersionFromDocuments( | 278 ServiceWorkerRegisterJob::DisassociateVersionFromDocuments( |
279 context_->AsWeakPtr(), version1); | 279 context_->AsWeakPtr(), version1); |
280 EXPECT_EQ(NULL, provider_host1_->installing_version()); | 280 EXPECT_EQ(NULL, provider_host1_->installing_version()); |
281 EXPECT_EQ(NULL, provider_host2_->installing_version()); | 281 EXPECT_EQ(NULL, provider_host2_->installing_version()); |
282 EXPECT_EQ(version2.get(), provider_host3_->installing_version()); | 282 EXPECT_EQ(version2.get(), provider_host3_->installing_version()); |
283 } | 283 } |
284 | 284 |
285 } // namespace content | 285 } // namespace content |
OLD | NEW |