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/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 506 |
507 TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) { | 507 TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) { |
508 const GURL kScope("http://www.test.not/scope/"); | 508 const GURL kScope("http://www.test.not/scope/"); |
509 const GURL kScript("http://www.test.not/script.js"); | 509 const GURL kScript("http://www.test.not/script.js"); |
510 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); | 510 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); |
511 const GURL kResource1("http://www.test.not/scope/resource1.js"); | 511 const GURL kResource1("http://www.test.not/scope/resource1.js"); |
512 const int64 kResource1Size = 1591234; | 512 const int64 kResource1Size = 1591234; |
513 const GURL kResource2("http://www.test.not/scope/resource2.js"); | 513 const GURL kResource2("http://www.test.not/scope/resource2.js"); |
514 const int64 kResource2Size = 51; | 514 const int64 kResource2Size = 51; |
515 const int64 kRegistrationId = 0; | 515 const int64 kRegistrationId = 0; |
516 const int64 kVersionId = 0; | 516 const std::string kVersionId = "ba78579f-c923-45a0-95e7-bcc86b8ebb97"; |
517 const base::Time kToday = base::Time::Now(); | 517 const base::Time kToday = base::Time::Now(); |
518 const base::Time kYesterday = kToday - base::TimeDelta::FromDays(1); | 518 const base::Time kYesterday = kToday - base::TimeDelta::FromDays(1); |
519 | 519 |
520 scoped_refptr<ServiceWorkerRegistration> found_registration; | 520 scoped_refptr<ServiceWorkerRegistration> found_registration; |
521 | 521 |
522 // We shouldn't find anything without having stored anything. | 522 // We shouldn't find anything without having stored anything. |
523 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 523 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
524 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 524 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
525 EXPECT_FALSE(found_registration.get()); | 525 EXPECT_FALSE(found_registration.get()); |
526 | 526 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 ASSERT_TRUE(found_registration.get()); | 662 ASSERT_TRUE(found_registration.get()); |
663 EXPECT_EQ(kRegistrationId, found_registration->id()); | 663 EXPECT_EQ(kRegistrationId, found_registration->id()); |
664 EXPECT_TRUE(found_registration->HasOneRef()); | 664 EXPECT_TRUE(found_registration->HasOneRef()); |
665 EXPECT_FALSE(found_registration->waiting_version()); | 665 EXPECT_FALSE(found_registration->waiting_version()); |
666 ASSERT_TRUE(found_registration->active_version()); | 666 ASSERT_TRUE(found_registration->active_version()); |
667 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, | 667 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, |
668 found_registration->active_version()->status()); | 668 found_registration->active_version()->status()); |
669 EXPECT_EQ(kToday, found_registration->last_update_check()); | 669 EXPECT_EQ(kToday, found_registration->last_update_check()); |
670 | 670 |
671 // Delete from storage but with a instance still live. | 671 // Delete from storage but with a instance still live. |
672 EXPECT_TRUE(context_->GetLiveVersion(kRegistrationId)); | 672 EXPECT_TRUE(context_->GetLiveVersion(kVersionId)); |
673 EXPECT_EQ(SERVICE_WORKER_OK, | 673 EXPECT_EQ(SERVICE_WORKER_OK, |
674 DeleteRegistration(kRegistrationId, kScope.GetOrigin())); | 674 DeleteRegistration(kRegistrationId, kScope.GetOrigin())); |
675 EXPECT_TRUE(context_->GetLiveVersion(kRegistrationId)); | 675 EXPECT_TRUE(context_->GetLiveVersion(kVersionId)); |
676 | 676 |
677 // Should no longer be found. | 677 // Should no longer be found. |
678 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 678 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
679 FindRegistrationForId( | 679 FindRegistrationForId( |
680 kRegistrationId, kScope.GetOrigin(), &found_registration)); | 680 kRegistrationId, kScope.GetOrigin(), &found_registration)); |
681 EXPECT_FALSE(found_registration.get()); | 681 EXPECT_FALSE(found_registration.get()); |
682 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 682 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
683 FindRegistrationForIdOnly(kRegistrationId, &found_registration)); | 683 FindRegistrationForIdOnly(kRegistrationId, &found_registration)); |
684 EXPECT_FALSE(found_registration.get()); | 684 EXPECT_FALSE(found_registration.get()); |
685 | 685 |
686 // Deleting an unstored registration should succeed. | 686 // Deleting an unstored registration should succeed. |
687 EXPECT_EQ(SERVICE_WORKER_OK, | 687 EXPECT_EQ(SERVICE_WORKER_OK, |
688 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin())); | 688 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin())); |
689 } | 689 } |
690 | 690 |
691 TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) { | 691 TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) { |
692 const GURL kScope("http://www.test.not/scope/"); | 692 const GURL kScope("http://www.test.not/scope/"); |
693 const GURL kScript("http://www.test.not/script.js"); | 693 const GURL kScript("http://www.test.not/script.js"); |
694 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); | 694 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); |
695 const int64 kRegistrationId = 0; | 695 const int64 kRegistrationId = 0; |
696 const int64 kVersionId = 0; | 696 const std::string kVersionId = "152a5cb0-79d5-47b5-a196-5b94963e612b"; |
697 | 697 |
698 scoped_refptr<ServiceWorkerRegistration> found_registration; | 698 scoped_refptr<ServiceWorkerRegistration> found_registration; |
699 | 699 |
700 // Create an unstored registration. | 700 // Create an unstored registration. |
701 scoped_refptr<ServiceWorkerRegistration> live_registration = | 701 scoped_refptr<ServiceWorkerRegistration> live_registration = |
702 new ServiceWorkerRegistration( | 702 new ServiceWorkerRegistration( |
703 kScope, kRegistrationId, context_ptr_); | 703 kScope, kRegistrationId, context_ptr_); |
704 scoped_refptr<ServiceWorkerVersion> live_version = | 704 scoped_refptr<ServiceWorkerVersion> live_version = |
705 new ServiceWorkerVersion( | 705 new ServiceWorkerVersion( |
706 live_registration.get(), kScript, kVersionId, context_ptr_); | 706 live_registration.get(), kScript, kVersionId, context_ptr_); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 | 806 |
807 GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(), | 807 GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(), |
808 ®istrations_for_origin); | 808 ®istrations_for_origin); |
809 EXPECT_TRUE(registrations_for_origin.empty()); | 809 EXPECT_TRUE(registrations_for_origin.empty()); |
810 } | 810 } |
811 | 811 |
812 TEST_F(ServiceWorkerStorageTest, StoreUserData) { | 812 TEST_F(ServiceWorkerStorageTest, StoreUserData) { |
813 const GURL kScope("http://www.test.not/scope/"); | 813 const GURL kScope("http://www.test.not/scope/"); |
814 const GURL kScript("http://www.test.not/script.js"); | 814 const GURL kScript("http://www.test.not/script.js"); |
815 const int64 kRegistrationId = 0; | 815 const int64 kRegistrationId = 0; |
816 const int64 kVersionId = 0; | 816 const std::string kVersionId = "152a5cb0-79d5-47b5-a196-5b94963e612b"; |
817 | 817 |
818 LazyInitialize(); | 818 LazyInitialize(); |
819 | 819 |
820 // Store a registration. | 820 // Store a registration. |
821 scoped_refptr<ServiceWorkerRegistration> live_registration = | 821 scoped_refptr<ServiceWorkerRegistration> live_registration = |
822 new ServiceWorkerRegistration( | 822 new ServiceWorkerRegistration( |
823 kScope, kRegistrationId, context_ptr_); | 823 kScope, kRegistrationId, context_ptr_); |
824 scoped_refptr<ServiceWorkerVersion> live_version = | 824 scoped_refptr<ServiceWorkerVersion> live_version = |
825 new ServiceWorkerVersion( | 825 new ServiceWorkerVersion( |
826 live_registration.get(), kScript, kVersionId, context_ptr_); | 826 live_registration.get(), kScript, kVersionId, context_ptr_); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 void SetUp() override { | 898 void SetUp() override { |
899 ServiceWorkerStorageTest::SetUp(); | 899 ServiceWorkerStorageTest::SetUp(); |
900 | 900 |
901 storage()->LazyInitialize(base::Bind(&base::DoNothing)); | 901 storage()->LazyInitialize(base::Bind(&base::DoNothing)); |
902 base::RunLoop().RunUntilIdle(); | 902 base::RunLoop().RunUntilIdle(); |
903 scope_ = GURL("http://www.test.not/scope/"); | 903 scope_ = GURL("http://www.test.not/scope/"); |
904 script_ = GURL("http://www.test.not/script.js"); | 904 script_ = GURL("http://www.test.not/script.js"); |
905 import_ = GURL("http://www.test.not/import.js"); | 905 import_ = GURL("http://www.test.not/import.js"); |
906 document_url_ = GURL("http://www.test.not/scope/document.html"); | 906 document_url_ = GURL("http://www.test.not/scope/document.html"); |
907 registration_id_ = storage()->NewRegistrationId(); | 907 registration_id_ = storage()->NewRegistrationId(); |
908 version_id_ = storage()->NewVersionId(); | 908 version_uuid_ = "2df145e9-00d2-4200-a6c5-cffd60320022"; |
909 resource_id1_ = storage()->NewResourceId(); | 909 resource_id1_ = storage()->NewResourceId(); |
910 resource_id2_ = storage()->NewResourceId(); | 910 resource_id2_ = storage()->NewResourceId(); |
911 resource_id1_size_ = 239193; | 911 resource_id1_size_ = 239193; |
912 resource_id2_size_ = 59923; | 912 resource_id2_size_ = 59923; |
913 | 913 |
914 // Cons up a new registration+version with two script resources. | 914 // Cons up a new registration+version with two script resources. |
915 RegistrationData data; | 915 RegistrationData data; |
916 data.registration_id = registration_id_; | 916 data.registration_id = registration_id_; |
917 data.scope = scope_; | 917 data.scope = scope_; |
918 data.script = script_; | 918 data.script = script_; |
919 data.version_id = version_id_; | 919 data.version_uuid = version_uuid_; |
920 data.is_active = false; | 920 data.is_active = false; |
921 std::vector<ResourceRecord> resources; | 921 std::vector<ResourceRecord> resources; |
922 resources.push_back( | 922 resources.push_back( |
923 ResourceRecord(resource_id1_, script_, resource_id1_size_)); | 923 ResourceRecord(resource_id1_, script_, resource_id1_size_)); |
924 resources.push_back( | 924 resources.push_back( |
925 ResourceRecord(resource_id2_, import_, resource_id2_size_)); | 925 ResourceRecord(resource_id2_, import_, resource_id2_size_)); |
926 registration_ = storage()->GetOrCreateRegistration(data, resources); | 926 registration_ = storage()->GetOrCreateRegistration(data, resources); |
927 registration_->waiting_version()->SetStatus(ServiceWorkerVersion::NEW); | 927 registration_->waiting_version()->SetStatus(ServiceWorkerVersion::NEW); |
928 | 928 |
929 // Add the resources ids to the uncommitted list. | 929 // Add the resources ids to the uncommitted list. |
(...skipping 21 matching lines...) Expand all Loading... |
951 storage()->database_->GetUncommittedResourceIds(&verify_ids)); | 951 storage()->database_->GetUncommittedResourceIds(&verify_ids)); |
952 EXPECT_TRUE(verify_ids.empty()); | 952 EXPECT_TRUE(verify_ids.empty()); |
953 } | 953 } |
954 | 954 |
955 protected: | 955 protected: |
956 GURL scope_; | 956 GURL scope_; |
957 GURL script_; | 957 GURL script_; |
958 GURL import_; | 958 GURL import_; |
959 GURL document_url_; | 959 GURL document_url_; |
960 int64 registration_id_; | 960 int64 registration_id_; |
961 int64 version_id_; | 961 std::string version_uuid_; |
962 int64 resource_id1_; | 962 int64 resource_id1_; |
963 uint64 resource_id1_size_; | 963 uint64 resource_id1_size_; |
964 int64 resource_id2_; | 964 int64 resource_id2_; |
965 uint64 resource_id2_size_; | 965 uint64 resource_id2_size_; |
966 scoped_refptr<ServiceWorkerRegistration> registration_; | 966 scoped_refptr<ServiceWorkerRegistration> registration_; |
967 }; | 967 }; |
968 | 968 |
969 class ServiceWorkerResourceStorageDiskTest | 969 class ServiceWorkerResourceStorageDiskTest |
970 : public ServiceWorkerResourceStorageTest { | 970 : public ServiceWorkerResourceStorageTest { |
971 public: | 971 public: |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 } | 1399 } |
1400 | 1400 |
1401 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { | 1401 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { |
1402 const GURL kDocumentUrl("http://www.example.com/scope/foo"); | 1402 const GURL kDocumentUrl("http://www.example.com/scope/foo"); |
1403 scoped_refptr<ServiceWorkerRegistration> found_registration; | 1403 scoped_refptr<ServiceWorkerRegistration> found_registration; |
1404 | 1404 |
1405 // Registration for "/scope/". | 1405 // Registration for "/scope/". |
1406 const GURL kScope1("http://www.example.com/scope/"); | 1406 const GURL kScope1("http://www.example.com/scope/"); |
1407 const GURL kScript1("http://www.example.com/script1.js"); | 1407 const GURL kScript1("http://www.example.com/script1.js"); |
1408 const int64 kRegistrationId1 = 1; | 1408 const int64 kRegistrationId1 = 1; |
1409 const int64 kVersionId1 = 1; | 1409 const std::string kVersionId1 = "96097827-4b07-4f1e-8d63-1cbae771ee00"; |
1410 scoped_refptr<ServiceWorkerRegistration> live_registration1 = | 1410 scoped_refptr<ServiceWorkerRegistration> live_registration1 = |
1411 new ServiceWorkerRegistration( | 1411 new ServiceWorkerRegistration( |
1412 kScope1, kRegistrationId1, context_ptr_); | 1412 kScope1, kRegistrationId1, context_ptr_); |
1413 scoped_refptr<ServiceWorkerVersion> live_version1 = | 1413 scoped_refptr<ServiceWorkerVersion> live_version1 = |
1414 new ServiceWorkerVersion( | 1414 new ServiceWorkerVersion( |
1415 live_registration1.get(), kScript1, kVersionId1, context_ptr_); | 1415 live_registration1.get(), kScript1, kVersionId1, context_ptr_); |
1416 std::vector<ServiceWorkerDatabase::ResourceRecord> records1; | 1416 std::vector<ServiceWorkerDatabase::ResourceRecord> records1; |
1417 records1.push_back(ServiceWorkerDatabase::ResourceRecord( | 1417 records1.push_back(ServiceWorkerDatabase::ResourceRecord( |
1418 1, live_version1->script_url(), 100)); | 1418 1, live_version1->script_url(), 100)); |
1419 live_version1->script_cache_map()->SetResources(records1); | 1419 live_version1->script_cache_map()->SetResources(records1); |
1420 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); | 1420 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); |
1421 live_registration1->SetWaitingVersion(live_version1); | 1421 live_registration1->SetWaitingVersion(live_version1); |
1422 | 1422 |
1423 // Registration for "/scope/foo". | 1423 // Registration for "/scope/foo". |
1424 const GURL kScope2("http://www.example.com/scope/foo"); | 1424 const GURL kScope2("http://www.example.com/scope/foo"); |
1425 const GURL kScript2("http://www.example.com/script2.js"); | 1425 const GURL kScript2("http://www.example.com/script2.js"); |
1426 const int64 kRegistrationId2 = 2; | 1426 const int64 kRegistrationId2 = 2; |
1427 const int64 kVersionId2 = 2; | 1427 const std::string kVersionId2 = "721a870b-f0e6-4740-88e4-3055a7662ac0"; |
1428 scoped_refptr<ServiceWorkerRegistration> live_registration2 = | 1428 scoped_refptr<ServiceWorkerRegistration> live_registration2 = |
1429 new ServiceWorkerRegistration( | 1429 new ServiceWorkerRegistration( |
1430 kScope2, kRegistrationId2, context_ptr_); | 1430 kScope2, kRegistrationId2, context_ptr_); |
1431 scoped_refptr<ServiceWorkerVersion> live_version2 = | 1431 scoped_refptr<ServiceWorkerVersion> live_version2 = |
1432 new ServiceWorkerVersion( | 1432 new ServiceWorkerVersion( |
1433 live_registration2.get(), kScript2, kVersionId2, context_ptr_); | 1433 live_registration2.get(), kScript2, kVersionId2, context_ptr_); |
1434 std::vector<ServiceWorkerDatabase::ResourceRecord> records2; | 1434 std::vector<ServiceWorkerDatabase::ResourceRecord> records2; |
1435 records2.push_back(ServiceWorkerDatabase::ResourceRecord( | 1435 records2.push_back(ServiceWorkerDatabase::ResourceRecord( |
1436 2, live_version2->script_url(), 100)); | 1436 2, live_version2->script_url(), 100)); |
1437 live_version2->script_cache_map()->SetResources(records2); | 1437 live_version2->script_cache_map()->SetResources(records2); |
1438 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); | 1438 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); |
1439 live_registration2->SetWaitingVersion(live_version2); | 1439 live_registration2->SetWaitingVersion(live_version2); |
1440 | 1440 |
1441 // Registration for "/scope/foobar". | 1441 // Registration for "/scope/foobar". |
1442 const GURL kScope3("http://www.example.com/scope/foobar"); | 1442 const GURL kScope3("http://www.example.com/scope/foobar"); |
1443 const GURL kScript3("http://www.example.com/script3.js"); | 1443 const GURL kScript3("http://www.example.com/script3.js"); |
1444 const int64 kRegistrationId3 = 3; | 1444 const int64 kRegistrationId3 = 3; |
1445 const int64 kVersionId3 = 3; | 1445 const std::string kVersionId3 = "4ac0d6cf-8369-4d1b-8961-ba5a0fb01d2d"; |
1446 scoped_refptr<ServiceWorkerRegistration> live_registration3 = | 1446 scoped_refptr<ServiceWorkerRegistration> live_registration3 = |
1447 new ServiceWorkerRegistration( | 1447 new ServiceWorkerRegistration( |
1448 kScope3, kRegistrationId3, context_ptr_); | 1448 kScope3, kRegistrationId3, context_ptr_); |
1449 scoped_refptr<ServiceWorkerVersion> live_version3 = | 1449 scoped_refptr<ServiceWorkerVersion> live_version3 = |
1450 new ServiceWorkerVersion( | 1450 new ServiceWorkerVersion( |
1451 live_registration3.get(), kScript3, kVersionId3, context_ptr_); | 1451 live_registration3.get(), kScript3, kVersionId3, context_ptr_); |
1452 std::vector<ServiceWorkerDatabase::ResourceRecord> records3; | 1452 std::vector<ServiceWorkerDatabase::ResourceRecord> records3; |
1453 records3.push_back(ServiceWorkerDatabase::ResourceRecord( | 1453 records3.push_back(ServiceWorkerDatabase::ResourceRecord( |
1454 3, live_version3->script_url(), 100)); | 1454 3, live_version3->script_url(), 100)); |
1455 live_version3->script_cache_map()->SetResources(records3); | 1455 live_version3->script_cache_map()->SetResources(records3); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 are_equal = true; | 1547 are_equal = true; |
1548 storage()->CompareScriptResources( | 1548 storage()->CompareScriptResources( |
1549 5, 6, | 1549 5, 6, |
1550 base::Bind(&OnCompareComplete, &status, &are_equal)); | 1550 base::Bind(&OnCompareComplete, &status, &are_equal)); |
1551 base::RunLoop().RunUntilIdle(); | 1551 base::RunLoop().RunUntilIdle(); |
1552 EXPECT_EQ(SERVICE_WORKER_OK, status); | 1552 EXPECT_EQ(SERVICE_WORKER_OK, status); |
1553 EXPECT_FALSE(are_equal); | 1553 EXPECT_FALSE(are_equal); |
1554 } | 1554 } |
1555 | 1555 |
1556 } // namespace content | 1556 } // namespace content |
OLD | NEW |