OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.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_disk_cache.h" | 10 #include "content/browser/service_worker/service_worker_disk_cache.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 was_called = false; | 224 was_called = false; |
225 | 225 |
226 // Store something. | 226 // Store something. |
227 scoped_refptr<ServiceWorkerRegistration> live_registration = | 227 scoped_refptr<ServiceWorkerRegistration> live_registration = |
228 new ServiceWorkerRegistration( | 228 new ServiceWorkerRegistration( |
229 kScope, kScript, kRegistrationId, context_ptr_); | 229 kScope, kScript, kRegistrationId, context_ptr_); |
230 scoped_refptr<ServiceWorkerVersion> live_version = | 230 scoped_refptr<ServiceWorkerVersion> live_version = |
231 new ServiceWorkerVersion( | 231 new ServiceWorkerVersion( |
232 live_registration, kVersionId, context_ptr_); | 232 live_registration, kVersionId, context_ptr_); |
233 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); | 233 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); |
234 live_registration->set_pending_version(live_version); | 234 live_registration->set_waiting_version(live_version); |
235 storage()->StoreRegistration(live_registration, live_version, | 235 storage()->StoreRegistration(live_registration, live_version, |
236 MakeStatusCallback(&was_called, &result)); | 236 MakeStatusCallback(&was_called, &result)); |
237 EXPECT_FALSE(was_called); // always async | 237 EXPECT_FALSE(was_called); // always async |
238 base::RunLoop().RunUntilIdle(); | 238 base::RunLoop().RunUntilIdle(); |
239 ASSERT_TRUE(was_called); | 239 ASSERT_TRUE(was_called); |
240 EXPECT_EQ(SERVICE_WORKER_OK, result); | 240 EXPECT_EQ(SERVICE_WORKER_OK, result); |
241 was_called = false; | 241 was_called = false; |
242 | 242 |
243 // Now we should find it and get the live ptr back immediately. | 243 // Now we should find it and get the live ptr back immediately. |
244 storage()->FindRegistrationForDocument( | 244 storage()->FindRegistrationForDocument( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 kDocumentUrl, | 285 kDocumentUrl, |
286 MakeFindCallback(&was_called, &result, &found_registration)); | 286 MakeFindCallback(&was_called, &result, &found_registration)); |
287 EXPECT_FALSE(was_called); | 287 EXPECT_FALSE(was_called); |
288 base::RunLoop().RunUntilIdle(); | 288 base::RunLoop().RunUntilIdle(); |
289 ASSERT_TRUE(was_called); | 289 ASSERT_TRUE(was_called); |
290 EXPECT_EQ(SERVICE_WORKER_OK, result); | 290 EXPECT_EQ(SERVICE_WORKER_OK, result); |
291 ASSERT_TRUE(found_registration); | 291 ASSERT_TRUE(found_registration); |
292 EXPECT_EQ(kRegistrationId, found_registration->id()); | 292 EXPECT_EQ(kRegistrationId, found_registration->id()); |
293 EXPECT_TRUE(found_registration->HasOneRef()); | 293 EXPECT_TRUE(found_registration->HasOneRef()); |
294 EXPECT_EQ(live_version, | 294 EXPECT_EQ(live_version, |
295 found_registration->pending_version()); | 295 found_registration->waiting_version()); |
296 was_called = false; | 296 was_called = false; |
297 found_registration = NULL; | 297 found_registration = NULL; |
298 | 298 |
299 // Drop the live version too. | 299 // Drop the live version too. |
300 live_version = NULL; | 300 live_version = NULL; |
301 | 301 |
302 // And FindRegistrationForPattern is always async. | 302 // And FindRegistrationForPattern is always async. |
303 storage()->FindRegistrationForPattern( | 303 storage()->FindRegistrationForPattern( |
304 kScope, | 304 kScope, |
305 MakeFindCallback(&was_called, &result, &found_registration)); | 305 MakeFindCallback(&was_called, &result, &found_registration)); |
306 EXPECT_FALSE(was_called); | 306 EXPECT_FALSE(was_called); |
307 base::RunLoop().RunUntilIdle(); | 307 base::RunLoop().RunUntilIdle(); |
308 ASSERT_TRUE(was_called); | 308 ASSERT_TRUE(was_called); |
309 EXPECT_EQ(SERVICE_WORKER_OK, result); | 309 EXPECT_EQ(SERVICE_WORKER_OK, result); |
310 ASSERT_TRUE(found_registration); | 310 ASSERT_TRUE(found_registration); |
311 EXPECT_EQ(kRegistrationId, found_registration->id()); | 311 EXPECT_EQ(kRegistrationId, found_registration->id()); |
312 EXPECT_TRUE(found_registration->HasOneRef()); | 312 EXPECT_TRUE(found_registration->HasOneRef()); |
313 EXPECT_FALSE(found_registration->active_version()); | 313 EXPECT_FALSE(found_registration->active_version()); |
314 ASSERT_TRUE(found_registration->pending_version()); | 314 ASSERT_TRUE(found_registration->waiting_version()); |
315 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, | 315 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, |
316 found_registration->pending_version()->status()); | 316 found_registration->waiting_version()->status()); |
317 was_called = false; | 317 was_called = false; |
318 | 318 |
319 // Update to active. | 319 // Update to active. |
320 scoped_refptr<ServiceWorkerVersion> temp_version = | 320 scoped_refptr<ServiceWorkerVersion> temp_version = |
321 found_registration->pending_version(); | 321 found_registration->waiting_version(); |
322 found_registration->set_pending_version(NULL); | 322 found_registration->set_waiting_version(NULL); |
323 temp_version->SetStatus(ServiceWorkerVersion::ACTIVE); | 323 temp_version->SetStatus(ServiceWorkerVersion::ACTIVE); |
324 found_registration->set_active_version(temp_version); | 324 found_registration->set_active_version(temp_version); |
325 temp_version = NULL; | 325 temp_version = NULL; |
326 storage()->UpdateToActiveState( | 326 storage()->UpdateToActiveState( |
327 found_registration, | 327 found_registration, |
328 MakeStatusCallback(&was_called, &result)); | 328 MakeStatusCallback(&was_called, &result)); |
329 EXPECT_FALSE(was_called); | 329 EXPECT_FALSE(was_called); |
330 base::RunLoop().RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
331 ASSERT_TRUE(was_called); | 331 ASSERT_TRUE(was_called); |
332 EXPECT_EQ(SERVICE_WORKER_OK, result); | 332 EXPECT_EQ(SERVICE_WORKER_OK, result); |
(...skipping 18 matching lines...) Expand all Loading... |
351 storage()->FindRegistrationForDocument( | 351 storage()->FindRegistrationForDocument( |
352 kDocumentUrl, | 352 kDocumentUrl, |
353 MakeFindCallback(&was_called, &result, &found_registration)); | 353 MakeFindCallback(&was_called, &result, &found_registration)); |
354 EXPECT_FALSE(was_called); | 354 EXPECT_FALSE(was_called); |
355 base::RunLoop().RunUntilIdle(); | 355 base::RunLoop().RunUntilIdle(); |
356 ASSERT_TRUE(was_called); | 356 ASSERT_TRUE(was_called); |
357 EXPECT_EQ(SERVICE_WORKER_OK, result); | 357 EXPECT_EQ(SERVICE_WORKER_OK, result); |
358 ASSERT_TRUE(found_registration); | 358 ASSERT_TRUE(found_registration); |
359 EXPECT_EQ(kRegistrationId, found_registration->id()); | 359 EXPECT_EQ(kRegistrationId, found_registration->id()); |
360 EXPECT_TRUE(found_registration->HasOneRef()); | 360 EXPECT_TRUE(found_registration->HasOneRef()); |
361 EXPECT_FALSE(found_registration->pending_version()); | 361 EXPECT_FALSE(found_registration->waiting_version()); |
362 ASSERT_TRUE(found_registration->active_version()); | 362 ASSERT_TRUE(found_registration->active_version()); |
363 EXPECT_EQ(ServiceWorkerVersion::ACTIVE, | 363 EXPECT_EQ(ServiceWorkerVersion::ACTIVE, |
364 found_registration->active_version()->status()); | 364 found_registration->active_version()->status()); |
365 was_called = false; | 365 was_called = false; |
366 | 366 |
367 // Delete from storage but with a instance still live. | 367 // Delete from storage but with a instance still live. |
368 EXPECT_TRUE(context_->GetLiveVersion(kRegistrationId)); | 368 EXPECT_TRUE(context_->GetLiveVersion(kRegistrationId)); |
369 storage()->DeleteRegistration( | 369 storage()->DeleteRegistration( |
370 kRegistrationId, | 370 kRegistrationId, |
371 kScope.GetOrigin(), | 371 kScope.GetOrigin(), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 scoped_refptr<ServiceWorkerRegistration> found_registration; | 412 scoped_refptr<ServiceWorkerRegistration> found_registration; |
413 | 413 |
414 // Create an unstored registration. | 414 // Create an unstored registration. |
415 scoped_refptr<ServiceWorkerRegistration> live_registration = | 415 scoped_refptr<ServiceWorkerRegistration> live_registration = |
416 new ServiceWorkerRegistration( | 416 new ServiceWorkerRegistration( |
417 kScope, kScript, kRegistrationId, context_ptr_); | 417 kScope, kScript, kRegistrationId, context_ptr_); |
418 scoped_refptr<ServiceWorkerVersion> live_version = | 418 scoped_refptr<ServiceWorkerVersion> live_version = |
419 new ServiceWorkerVersion( | 419 new ServiceWorkerVersion( |
420 live_registration, kVersionId, context_ptr_); | 420 live_registration, kVersionId, context_ptr_); |
421 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); | 421 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); |
422 live_registration->set_pending_version(live_version); | 422 live_registration->set_waiting_version(live_version); |
423 | 423 |
424 // Should not be findable, including by GetAllRegistrations. | 424 // Should not be findable, including by GetAllRegistrations. |
425 storage()->FindRegistrationForId( | 425 storage()->FindRegistrationForId( |
426 kRegistrationId, | 426 kRegistrationId, |
427 kScope.GetOrigin(), | 427 kScope.GetOrigin(), |
428 MakeFindCallback(&was_called, &result, &found_registration)); | 428 MakeFindCallback(&was_called, &result, &found_registration)); |
429 base::RunLoop().RunUntilIdle(); | 429 base::RunLoop().RunUntilIdle(); |
430 ASSERT_TRUE(was_called); | 430 ASSERT_TRUE(was_called); |
431 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, result); | 431 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, result); |
432 EXPECT_FALSE(found_registration); | 432 EXPECT_FALSE(found_registration); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 data.registration_id = kRegistrationId; | 551 data.registration_id = kRegistrationId; |
552 data.scope = kScope; | 552 data.scope = kScope; |
553 data.script = kScript; | 553 data.script = kScript; |
554 data.version_id = kVersionId; | 554 data.version_id = kVersionId; |
555 data.is_active = false; | 555 data.is_active = false; |
556 std::vector<ResourceRecord> resources; | 556 std::vector<ResourceRecord> resources; |
557 resources.push_back(ResourceRecord(kResourceId1, kScript)); | 557 resources.push_back(ResourceRecord(kResourceId1, kScript)); |
558 resources.push_back(ResourceRecord(kResourceId2, kImport)); | 558 resources.push_back(ResourceRecord(kResourceId2, kImport)); |
559 scoped_refptr<ServiceWorkerRegistration> registration = | 559 scoped_refptr<ServiceWorkerRegistration> registration = |
560 storage()->GetOrCreateRegistration(data, resources); | 560 storage()->GetOrCreateRegistration(data, resources); |
561 registration->pending_version()->SetStatus(ServiceWorkerVersion::NEW); | 561 registration->waiting_version()->SetStatus(ServiceWorkerVersion::NEW); |
562 | 562 |
563 // Add the resources ids to the uncommitted list. | 563 // Add the resources ids to the uncommitted list. |
564 std::set<int64> resource_ids; | 564 std::set<int64> resource_ids; |
565 resource_ids.insert(kResourceId1); | 565 resource_ids.insert(kResourceId1); |
566 resource_ids.insert(kResourceId2); | 566 resource_ids.insert(kResourceId2); |
567 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 567 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
568 storage()->database_->WriteUncommittedResourceIds(resource_ids)); | 568 storage()->database_->WriteUncommittedResourceIds(resource_ids)); |
569 | 569 |
570 // And dump something in the disk cache for them. | 570 // And dump something in the disk cache for them. |
571 WriteBasicResponse(storage(), kResourceId1); | 571 WriteBasicResponse(storage(), kResourceId1); |
572 WriteBasicResponse(storage(), kResourceId2); | 572 WriteBasicResponse(storage(), kResourceId2); |
573 EXPECT_TRUE(VerifyBasicResponse(storage(), kResourceId1, true)); | 573 EXPECT_TRUE(VerifyBasicResponse(storage(), kResourceId1, true)); |
574 EXPECT_TRUE(VerifyBasicResponse(storage(), kResourceId2, true)); | 574 EXPECT_TRUE(VerifyBasicResponse(storage(), kResourceId2, true)); |
575 | 575 |
576 // Storing the registration/version should take the resources ids out | 576 // Storing the registration/version should take the resources ids out |
577 // of the uncommitted list. | 577 // of the uncommitted list. |
578 bool was_called = false; | 578 bool was_called = false; |
579 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; | 579 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; |
580 storage()->StoreRegistration(registration, registration->pending_version(), | 580 storage()->StoreRegistration(registration, registration->waiting_version(), |
581 MakeStatusCallback(&was_called, &result)); | 581 MakeStatusCallback(&was_called, &result)); |
582 base::RunLoop().RunUntilIdle(); | 582 base::RunLoop().RunUntilIdle(); |
583 ASSERT_TRUE(was_called); | 583 ASSERT_TRUE(was_called); |
584 EXPECT_EQ(SERVICE_WORKER_OK, result); | 584 EXPECT_EQ(SERVICE_WORKER_OK, result); |
585 std::set<int64> verify_ids; | 585 std::set<int64> verify_ids; |
586 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 586 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
587 storage()->database_->GetUncommittedResourceIds(&verify_ids)); | 587 storage()->database_->GetUncommittedResourceIds(&verify_ids)); |
588 EXPECT_TRUE(verify_ids.empty()); | 588 EXPECT_TRUE(verify_ids.empty()); |
589 | 589 |
590 // Deleting it should result in the resources being added to the | 590 // Deleting it should result in the resources being added to the |
(...skipping 13 matching lines...) Expand all Loading... |
604 verify_ids.clear(); | 604 verify_ids.clear(); |
605 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 605 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
606 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 606 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
607 EXPECT_TRUE(verify_ids.empty()); | 607 EXPECT_TRUE(verify_ids.empty()); |
608 | 608 |
609 EXPECT_FALSE(VerifyBasicResponse(storage(), kResourceId1, false)); | 609 EXPECT_FALSE(VerifyBasicResponse(storage(), kResourceId1, false)); |
610 EXPECT_FALSE(VerifyBasicResponse(storage(), kResourceId2, false)); | 610 EXPECT_FALSE(VerifyBasicResponse(storage(), kResourceId2, false)); |
611 } | 611 } |
612 | 612 |
613 } // namespace content | 613 } // namespace content |
OLD | NEW |