| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 EXPECT_FALSE(found_registration.get()); | 344 EXPECT_FALSE(found_registration.get()); |
| 345 | 345 |
| 346 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 346 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
| 347 FindRegistrationForId( | 347 FindRegistrationForId( |
| 348 kRegistrationId, kScope.GetOrigin(), &found_registration)); | 348 kRegistrationId, kScope.GetOrigin(), &found_registration)); |
| 349 EXPECT_FALSE(found_registration.get()); | 349 EXPECT_FALSE(found_registration.get()); |
| 350 | 350 |
| 351 // Store something. | 351 // Store something. |
| 352 scoped_refptr<ServiceWorkerRegistration> live_registration = | 352 scoped_refptr<ServiceWorkerRegistration> live_registration = |
| 353 new ServiceWorkerRegistration( | 353 new ServiceWorkerRegistration( |
| 354 kScope, kScript, kRegistrationId, context_ptr_); | 354 kScope, kRegistrationId, context_ptr_); |
| 355 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( | 355 scoped_refptr<ServiceWorkerVersion> live_version = |
| 356 live_registration.get(), kVersionId, context_ptr_); | 356 new ServiceWorkerVersion( |
| 357 live_registration.get(), kScript, kVersionId, context_ptr_); |
| 357 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); | 358 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 358 live_registration->SetWaitingVersion(live_version.get()); | 359 live_registration->SetWaitingVersion(live_version.get()); |
| 359 live_registration->set_last_update_check(kYesterday); | 360 live_registration->set_last_update_check(kYesterday); |
| 360 EXPECT_EQ(SERVICE_WORKER_OK, | 361 EXPECT_EQ(SERVICE_WORKER_OK, |
| 361 StoreRegistration(live_registration, live_version)); | 362 StoreRegistration(live_registration, live_version)); |
| 362 | 363 |
| 363 // Now we should find it and get the live ptr back immediately. | 364 // Now we should find it and get the live ptr back immediately. |
| 364 EXPECT_EQ(SERVICE_WORKER_OK, | 365 EXPECT_EQ(SERVICE_WORKER_OK, |
| 365 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 366 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
| 366 EXPECT_EQ(live_registration, found_registration); | 367 EXPECT_EQ(live_registration, found_registration); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 temp_version = NULL; | 417 temp_version = NULL; |
| 417 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration)); | 418 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration)); |
| 418 found_registration->set_last_update_check(kToday); | 419 found_registration->set_last_update_check(kToday); |
| 419 UpdateLastUpdateCheckTime(found_registration.get()); | 420 UpdateLastUpdateCheckTime(found_registration.get()); |
| 420 | 421 |
| 421 found_registration = NULL; | 422 found_registration = NULL; |
| 422 | 423 |
| 423 // Trying to update a unstored registration to active should fail. | 424 // Trying to update a unstored registration to active should fail. |
| 424 scoped_refptr<ServiceWorkerRegistration> unstored_registration = | 425 scoped_refptr<ServiceWorkerRegistration> unstored_registration = |
| 425 new ServiceWorkerRegistration( | 426 new ServiceWorkerRegistration( |
| 426 kScope, kScript, kRegistrationId + 1, context_ptr_); | 427 kScope, kRegistrationId + 1, context_ptr_); |
| 427 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 428 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
| 428 UpdateToActiveState(unstored_registration)); | 429 UpdateToActiveState(unstored_registration)); |
| 429 unstored_registration = NULL; | 430 unstored_registration = NULL; |
| 430 | 431 |
| 431 // The Find methods should return a registration with an active version | 432 // The Find methods should return a registration with an active version |
| 432 // and the expected update time. | 433 // and the expected update time. |
| 433 EXPECT_EQ(SERVICE_WORKER_OK, | 434 EXPECT_EQ(SERVICE_WORKER_OK, |
| 434 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 435 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
| 435 ASSERT_TRUE(found_registration.get()); | 436 ASSERT_TRUE(found_registration.get()); |
| 436 EXPECT_EQ(kRegistrationId, found_registration->id()); | 437 EXPECT_EQ(kRegistrationId, found_registration->id()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 463 const GURL kScript("http://www.test.not/script.js"); | 464 const GURL kScript("http://www.test.not/script.js"); |
| 464 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); | 465 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); |
| 465 const int64 kRegistrationId = 0; | 466 const int64 kRegistrationId = 0; |
| 466 const int64 kVersionId = 0; | 467 const int64 kVersionId = 0; |
| 467 | 468 |
| 468 scoped_refptr<ServiceWorkerRegistration> found_registration; | 469 scoped_refptr<ServiceWorkerRegistration> found_registration; |
| 469 | 470 |
| 470 // Create an unstored registration. | 471 // Create an unstored registration. |
| 471 scoped_refptr<ServiceWorkerRegistration> live_registration = | 472 scoped_refptr<ServiceWorkerRegistration> live_registration = |
| 472 new ServiceWorkerRegistration( | 473 new ServiceWorkerRegistration( |
| 473 kScope, kScript, kRegistrationId, context_ptr_); | 474 kScope, kRegistrationId, context_ptr_); |
| 474 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( | 475 scoped_refptr<ServiceWorkerVersion> live_version = |
| 475 live_registration.get(), kVersionId, context_ptr_); | 476 new ServiceWorkerVersion( |
| 477 live_registration.get(), kScript, kVersionId, context_ptr_); |
| 476 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); | 478 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); |
| 477 live_registration->SetWaitingVersion(live_version.get()); | 479 live_registration->SetWaitingVersion(live_version.get()); |
| 478 | 480 |
| 479 // Should not be findable, including by GetAllRegistrations. | 481 // Should not be findable, including by GetAllRegistrations. |
| 480 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 482 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
| 481 FindRegistrationForId( | 483 FindRegistrationForId( |
| 482 kRegistrationId, kScope.GetOrigin(), &found_registration)); | 484 kRegistrationId, kScope.GetOrigin(), &found_registration)); |
| 483 EXPECT_FALSE(found_registration.get()); | 485 EXPECT_FALSE(found_registration.get()); |
| 484 | 486 |
| 485 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 487 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 context_->AsWeakPtr(), | 856 context_->AsWeakPtr(), |
| 855 NULL)); | 857 NULL)); |
| 856 registration_->active_version()->AddControllee(host.get()); | 858 registration_->active_version()->AddControllee(host.get()); |
| 857 | 859 |
| 858 bool was_called = false; | 860 bool was_called = false; |
| 859 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; | 861 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; |
| 860 std::set<int64> verify_ids; | 862 std::set<int64> verify_ids; |
| 861 | 863 |
| 862 // Make an updated registration. | 864 // Make an updated registration. |
| 863 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( | 865 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( |
| 864 registration_.get(), storage()->NewVersionId(), context_ptr_); | 866 registration_.get(), script_, storage()->NewVersionId(), context_ptr_); |
| 865 live_version->SetStatus(ServiceWorkerVersion::NEW); | 867 live_version->SetStatus(ServiceWorkerVersion::NEW); |
| 866 registration_->SetWaitingVersion(live_version.get()); | 868 registration_->SetWaitingVersion(live_version.get()); |
| 867 | 869 |
| 868 // Writing the registration should move the old version's resources to the | 870 // Writing the registration should move the old version's resources to the |
| 869 // purgeable list but keep them available. | 871 // purgeable list but keep them available. |
| 870 storage()->StoreRegistration( | 872 storage()->StoreRegistration( |
| 871 registration_.get(), | 873 registration_.get(), |
| 872 registration_->waiting_version(), | 874 registration_->waiting_version(), |
| 873 base::Bind(&VerifyPurgeableListStatusCallback, | 875 base::Bind(&VerifyPurgeableListStatusCallback, |
| 874 base::Unretained(storage()->database_.get()), | 876 base::Unretained(storage()->database_.get()), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 905 const GURL kDocumentUrl("http://www.example.com/scope/foo"); | 907 const GURL kDocumentUrl("http://www.example.com/scope/foo"); |
| 906 scoped_refptr<ServiceWorkerRegistration> found_registration; | 908 scoped_refptr<ServiceWorkerRegistration> found_registration; |
| 907 | 909 |
| 908 // Registration for "/scope/". | 910 // Registration for "/scope/". |
| 909 const GURL kScope1("http://www.example.com/scope/"); | 911 const GURL kScope1("http://www.example.com/scope/"); |
| 910 const GURL kScript1("http://www.example.com/script1.js"); | 912 const GURL kScript1("http://www.example.com/script1.js"); |
| 911 const int64 kRegistrationId1 = 1; | 913 const int64 kRegistrationId1 = 1; |
| 912 const int64 kVersionId1 = 1; | 914 const int64 kVersionId1 = 1; |
| 913 scoped_refptr<ServiceWorkerRegistration> live_registration1 = | 915 scoped_refptr<ServiceWorkerRegistration> live_registration1 = |
| 914 new ServiceWorkerRegistration( | 916 new ServiceWorkerRegistration( |
| 915 kScope1, kScript1, kRegistrationId1, context_ptr_); | 917 kScope1, kRegistrationId1, context_ptr_); |
| 916 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion( | 918 scoped_refptr<ServiceWorkerVersion> live_version1 = |
| 917 live_registration1.get(), kVersionId1, context_ptr_); | 919 new ServiceWorkerVersion( |
| 920 live_registration1.get(), kScript1, kVersionId1, context_ptr_); |
| 918 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); | 921 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 919 live_registration1->SetWaitingVersion(live_version1.get()); | 922 live_registration1->SetWaitingVersion(live_version1.get()); |
| 920 | 923 |
| 921 // Registration for "/scope/foo". | 924 // Registration for "/scope/foo". |
| 922 const GURL kScope2("http://www.example.com/scope/foo"); | 925 const GURL kScope2("http://www.example.com/scope/foo"); |
| 923 const GURL kScript2("http://www.example.com/script2.js"); | 926 const GURL kScript2("http://www.example.com/script2.js"); |
| 924 const int64 kRegistrationId2 = 2; | 927 const int64 kRegistrationId2 = 2; |
| 925 const int64 kVersionId2 = 2; | 928 const int64 kVersionId2 = 2; |
| 926 scoped_refptr<ServiceWorkerRegistration> live_registration2 = | 929 scoped_refptr<ServiceWorkerRegistration> live_registration2 = |
| 927 new ServiceWorkerRegistration( | 930 new ServiceWorkerRegistration( |
| 928 kScope2, kScript2, kRegistrationId2, context_ptr_); | 931 kScope2, kRegistrationId2, context_ptr_); |
| 929 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion( | 932 scoped_refptr<ServiceWorkerVersion> live_version2 = |
| 930 live_registration2.get(), kVersionId2, context_ptr_); | 933 new ServiceWorkerVersion( |
| 934 live_registration2.get(), kScript2, kVersionId2, context_ptr_); |
| 931 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); | 935 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 932 live_registration2->SetWaitingVersion(live_version2.get()); | 936 live_registration2->SetWaitingVersion(live_version2.get()); |
| 933 | 937 |
| 934 // Registration for "/scope/foobar". | 938 // Registration for "/scope/foobar". |
| 935 const GURL kScope3("http://www.example.com/scope/foobar"); | 939 const GURL kScope3("http://www.example.com/scope/foobar"); |
| 936 const GURL kScript3("http://www.example.com/script3.js"); | 940 const GURL kScript3("http://www.example.com/script3.js"); |
| 937 const int64 kRegistrationId3 = 3; | 941 const int64 kRegistrationId3 = 3; |
| 938 const int64 kVersionId3 = 3; | 942 const int64 kVersionId3 = 3; |
| 939 scoped_refptr<ServiceWorkerRegistration> live_registration3 = | 943 scoped_refptr<ServiceWorkerRegistration> live_registration3 = |
| 940 new ServiceWorkerRegistration( | 944 new ServiceWorkerRegistration( |
| 941 kScope3, kScript3, kRegistrationId3, context_ptr_); | 945 kScope3, kRegistrationId3, context_ptr_); |
| 942 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion( | 946 scoped_refptr<ServiceWorkerVersion> live_version3 = |
| 943 live_registration3.get(), kVersionId3, context_ptr_); | 947 new ServiceWorkerVersion( |
| 948 live_registration3.get(), kScript3, kVersionId3, context_ptr_); |
| 944 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); | 949 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 945 live_registration3->SetWaitingVersion(live_version3.get()); | 950 live_registration3->SetWaitingVersion(live_version3.get()); |
| 946 | 951 |
| 947 // Notify storage of they being installed. | 952 // Notify storage of they being installed. |
| 948 storage()->NotifyInstallingRegistration(live_registration1.get()); | 953 storage()->NotifyInstallingRegistration(live_registration1.get()); |
| 949 storage()->NotifyInstallingRegistration(live_registration2.get()); | 954 storage()->NotifyInstallingRegistration(live_registration2.get()); |
| 950 storage()->NotifyInstallingRegistration(live_registration3.get()); | 955 storage()->NotifyInstallingRegistration(live_registration3.get()); |
| 951 | 956 |
| 952 // Find a registration among installing ones. | 957 // Find a registration among installing ones. |
| 953 EXPECT_EQ(SERVICE_WORKER_OK, | 958 EXPECT_EQ(SERVICE_WORKER_OK, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 are_equal = true; | 1038 are_equal = true; |
| 1034 storage()->CompareScriptResources( | 1039 storage()->CompareScriptResources( |
| 1035 5, 6, | 1040 5, 6, |
| 1036 base::Bind(&OnCompareComplete, &status, &are_equal)); | 1041 base::Bind(&OnCompareComplete, &status, &are_equal)); |
| 1037 base::RunLoop().RunUntilIdle(); | 1042 base::RunLoop().RunUntilIdle(); |
| 1038 EXPECT_EQ(SERVICE_WORKER_OK, status); | 1043 EXPECT_EQ(SERVICE_WORKER_OK, status); |
| 1039 EXPECT_FALSE(are_equal); | 1044 EXPECT_FALSE(are_equal); |
| 1040 } | 1045 } |
| 1041 | 1046 |
| 1042 } // namespace content | 1047 } // namespace content |
| OLD | NEW |