Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: content/browser/service_worker/service_worker_storage_unittest.cc

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/service_worker/service_worker_storage.h" 5 #include "content/browser/service_worker/service_worker_storage.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 std::vector<scoped_refptr<ServiceWorkerRegistration>> found_registrations; 571 std::vector<scoped_refptr<ServiceWorkerRegistration>> found_registrations;
572 EXPECT_EQ( 572 EXPECT_EQ(
573 SERVICE_WORKER_ERROR_ABORT, 573 SERVICE_WORKER_ERROR_ABORT,
574 GetRegistrationsForOrigin(kScope.GetOrigin(), &found_registrations)); 574 GetRegistrationsForOrigin(kScope.GetOrigin(), &found_registrations));
575 575
576 std::vector<ServiceWorkerRegistrationInfo> all_registrations; 576 std::vector<ServiceWorkerRegistrationInfo> all_registrations;
577 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, 577 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT,
578 GetAllRegistrationsInfos(&all_registrations)); 578 GetAllRegistrationsInfos(&all_registrations));
579 579
580 scoped_refptr<ServiceWorkerRegistration> live_registration = 580 scoped_refptr<ServiceWorkerRegistration> live_registration =
581 new ServiceWorkerRegistration(kScope, kRegistrationId, 581 new ServiceWorkerRegistration(kScope, false /* use_cache */,
582 context()->AsWeakPtr()); 582 kRegistrationId, context()->AsWeakPtr());
583 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( 583 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
584 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 584 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr());
585 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, 585 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT,
586 StoreRegistration(live_registration, live_version)); 586 StoreRegistration(live_registration, live_version));
587 587
588 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, UpdateToActiveState(live_registration)); 588 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, UpdateToActiveState(live_registration));
589 589
590 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, 590 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT,
591 DeleteRegistration(kRegistrationId, kScope.GetOrigin())); 591 DeleteRegistration(kRegistrationId, kScope.GetOrigin()));
592 592
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 EXPECT_FALSE(found_registration.get()); 655 EXPECT_FALSE(found_registration.get());
656 656
657 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; 657 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
658 resources.push_back( 658 resources.push_back(
659 ServiceWorkerDatabase::ResourceRecord(1, kResource1, kResource1Size)); 659 ServiceWorkerDatabase::ResourceRecord(1, kResource1, kResource1Size));
660 resources.push_back( 660 resources.push_back(
661 ServiceWorkerDatabase::ResourceRecord(2, kResource2, kResource2Size)); 661 ServiceWorkerDatabase::ResourceRecord(2, kResource2, kResource2Size));
662 662
663 // Store something. 663 // Store something.
664 scoped_refptr<ServiceWorkerRegistration> live_registration = 664 scoped_refptr<ServiceWorkerRegistration> live_registration =
665 new ServiceWorkerRegistration(kScope, kRegistrationId, 665 new ServiceWorkerRegistration(kScope, false /* use_cache */,
666 context()->AsWeakPtr()); 666 kRegistrationId, context()->AsWeakPtr());
667 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( 667 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
668 live_registration.get(), kResource1, kVersionId, context()->AsWeakPtr()); 668 live_registration.get(), kResource1, kVersionId, context()->AsWeakPtr());
669 live_version->set_fetch_handler_existence( 669 live_version->set_fetch_handler_existence(
670 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 670 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
671 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); 671 live_version->SetStatus(ServiceWorkerVersion::INSTALLED);
672 live_version->script_cache_map()->SetResources(resources); 672 live_version->script_cache_map()->SetResources(resources);
673 live_version->set_foreign_fetch_scopes( 673 live_version->set_foreign_fetch_scopes(
674 std::vector<GURL>(1, kForeignFetchScope)); 674 std::vector<GURL>(1, kForeignFetchScope));
675 live_version->set_foreign_fetch_origins( 675 live_version->set_foreign_fetch_origins(
676 std::vector<url::Origin>(1, kForeignFetchOrigin)); 676 std::vector<url::Origin>(1, kForeignFetchOrigin));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 found_registration->SetActiveVersion(temp_version); 783 found_registration->SetActiveVersion(temp_version);
784 temp_version = NULL; 784 temp_version = NULL;
785 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration)); 785 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration));
786 found_registration->set_last_update_check(kToday); 786 found_registration->set_last_update_check(kToday);
787 UpdateLastUpdateCheckTime(found_registration.get()); 787 UpdateLastUpdateCheckTime(found_registration.get());
788 788
789 found_registration = NULL; 789 found_registration = NULL;
790 790
791 // Trying to update a unstored registration to active should fail. 791 // Trying to update a unstored registration to active should fail.
792 scoped_refptr<ServiceWorkerRegistration> unstored_registration = 792 scoped_refptr<ServiceWorkerRegistration> unstored_registration =
793 new ServiceWorkerRegistration(kScope, kRegistrationId + 1, 793 new ServiceWorkerRegistration(kScope, false /* use_cache */,
794 kRegistrationId + 1,
794 context()->AsWeakPtr()); 795 context()->AsWeakPtr());
795 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 796 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
796 UpdateToActiveState(unstored_registration)); 797 UpdateToActiveState(unstored_registration));
797 unstored_registration = NULL; 798 unstored_registration = NULL;
798 799
799 // The Find methods should return a registration with an active version 800 // The Find methods should return a registration with an active version
800 // and the expected update time. 801 // and the expected update time.
801 EXPECT_EQ(SERVICE_WORKER_OK, 802 EXPECT_EQ(SERVICE_WORKER_OK,
802 FindRegistrationForDocument(kDocumentUrl, &found_registration)); 803 FindRegistrationForDocument(kDocumentUrl, &found_registration));
803 ASSERT_TRUE(found_registration.get()); 804 ASSERT_TRUE(found_registration.get());
(...skipping 29 matching lines...) Expand all
833 const GURL kScope("http://www.test.not/scope/"); 834 const GURL kScope("http://www.test.not/scope/");
834 const GURL kScript("http://www.test.not/script.js"); 835 const GURL kScript("http://www.test.not/script.js");
835 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); 836 const GURL kDocumentUrl("http://www.test.not/scope/document.html");
836 const int64_t kRegistrationId = 0; 837 const int64_t kRegistrationId = 0;
837 const int64_t kVersionId = 0; 838 const int64_t kVersionId = 0;
838 839
839 scoped_refptr<ServiceWorkerRegistration> found_registration; 840 scoped_refptr<ServiceWorkerRegistration> found_registration;
840 841
841 // Create an unstored registration. 842 // Create an unstored registration.
842 scoped_refptr<ServiceWorkerRegistration> live_registration = 843 scoped_refptr<ServiceWorkerRegistration> live_registration =
843 new ServiceWorkerRegistration(kScope, kRegistrationId, 844 new ServiceWorkerRegistration(kScope, false /* use_cache */,
844 context()->AsWeakPtr()); 845 kRegistrationId, context()->AsWeakPtr());
845 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( 846 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
846 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 847 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr());
847 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); 848 live_version->SetStatus(ServiceWorkerVersion::INSTALLING);
848 live_registration->SetWaitingVersion(live_version); 849 live_registration->SetWaitingVersion(live_version);
849 850
850 // Should not be findable, including by GetAllRegistrationsInfos. 851 // Should not be findable, including by GetAllRegistrationsInfos.
851 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 852 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
852 FindRegistrationForId( 853 FindRegistrationForId(
853 kRegistrationId, kScope.GetOrigin(), &found_registration)); 854 kRegistrationId, kScope.GetOrigin(), &found_registration));
854 EXPECT_FALSE(found_registration.get()); 855 EXPECT_FALSE(found_registration.get());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 TEST_F(ServiceWorkerStorageTest, StoreUserData) { 962 TEST_F(ServiceWorkerStorageTest, StoreUserData) {
962 const GURL kScope("http://www.test.not/scope/"); 963 const GURL kScope("http://www.test.not/scope/");
963 const GURL kScript("http://www.test.not/script.js"); 964 const GURL kScript("http://www.test.not/script.js");
964 const int64_t kRegistrationId = 0; 965 const int64_t kRegistrationId = 0;
965 const int64_t kVersionId = 0; 966 const int64_t kVersionId = 0;
966 967
967 LazyInitialize(); 968 LazyInitialize();
968 969
969 // Store a registration. 970 // Store a registration.
970 scoped_refptr<ServiceWorkerRegistration> live_registration = 971 scoped_refptr<ServiceWorkerRegistration> live_registration =
971 new ServiceWorkerRegistration(kScope, kRegistrationId, 972 new ServiceWorkerRegistration(kScope, false /* use_cache */,
972 context()->AsWeakPtr()); 973 kRegistrationId, context()->AsWeakPtr());
973 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( 974 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
974 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 975 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr());
975 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 976 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
976 records.push_back(ServiceWorkerDatabase::ResourceRecord( 977 records.push_back(ServiceWorkerDatabase::ResourceRecord(
977 1, live_version->script_url(), 100)); 978 1, live_version->script_url(), 100));
978 live_version->script_cache_map()->SetResources(records); 979 live_version->script_cache_map()->SetResources(records);
979 live_version->set_fetch_handler_existence( 980 live_version->set_fetch_handler_existence(
980 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 981 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
981 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); 982 live_version->SetStatus(ServiceWorkerVersion::INSTALLED);
982 live_registration->SetWaitingVersion(live_version); 983 live_registration->SetWaitingVersion(live_version);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 version_id_ = storage()->NewVersionId(); 1141 version_id_ = storage()->NewVersionId();
1141 resource_id1_ = storage()->NewResourceId(); 1142 resource_id1_ = storage()->NewResourceId();
1142 resource_id2_ = storage()->NewResourceId(); 1143 resource_id2_ = storage()->NewResourceId();
1143 resource_id1_size_ = 239193; 1144 resource_id1_size_ = 239193;
1144 resource_id2_size_ = 59923; 1145 resource_id2_size_ = 59923;
1145 1146
1146 // Cons up a new registration+version with two script resources. 1147 // Cons up a new registration+version with two script resources.
1147 RegistrationData data; 1148 RegistrationData data;
1148 data.registration_id = registration_id_; 1149 data.registration_id = registration_id_;
1149 data.scope = scope_; 1150 data.scope = scope_;
1151 data.use_cache = false;
1150 data.script = script_; 1152 data.script = script_;
1151 data.version_id = version_id_; 1153 data.version_id = version_id_;
1152 data.is_active = false; 1154 data.is_active = false;
1153 std::vector<ResourceRecord> resources; 1155 std::vector<ResourceRecord> resources;
1154 resources.push_back( 1156 resources.push_back(
1155 ResourceRecord(resource_id1_, script_, resource_id1_size_)); 1157 ResourceRecord(resource_id1_, script_, resource_id1_size_));
1156 resources.push_back( 1158 resources.push_back(
1157 ResourceRecord(resource_id2_, import_, resource_id2_size_)); 1159 ResourceRecord(resource_id2_, import_, resource_id2_size_));
1158 registration_ = storage()->GetOrCreateRegistration(data, resources); 1160 registration_ = storage()->GetOrCreateRegistration(data, resources);
1159 registration_->waiting_version()->SetStatus(ServiceWorkerVersion::NEW); 1161 registration_->waiting_version()->SetStatus(ServiceWorkerVersion::NEW);
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { 1617 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) {
1616 const GURL kDocumentUrl("http://www.example.com/scope/foo"); 1618 const GURL kDocumentUrl("http://www.example.com/scope/foo");
1617 scoped_refptr<ServiceWorkerRegistration> found_registration; 1619 scoped_refptr<ServiceWorkerRegistration> found_registration;
1618 1620
1619 // Registration for "/scope/". 1621 // Registration for "/scope/".
1620 const GURL kScope1("http://www.example.com/scope/"); 1622 const GURL kScope1("http://www.example.com/scope/");
1621 const GURL kScript1("http://www.example.com/script1.js"); 1623 const GURL kScript1("http://www.example.com/script1.js");
1622 const int64_t kRegistrationId1 = 1; 1624 const int64_t kRegistrationId1 = 1;
1623 const int64_t kVersionId1 = 1; 1625 const int64_t kVersionId1 = 1;
1624 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1626 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1625 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1627 new ServiceWorkerRegistration(kScope1, false /* use_cache */,
1626 context()->AsWeakPtr()); 1628 kRegistrationId1, context()->AsWeakPtr());
1627 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion( 1629 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion(
1628 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr()); 1630 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr());
1629 std::vector<ServiceWorkerDatabase::ResourceRecord> records1; 1631 std::vector<ServiceWorkerDatabase::ResourceRecord> records1;
1630 records1.push_back(ServiceWorkerDatabase::ResourceRecord( 1632 records1.push_back(ServiceWorkerDatabase::ResourceRecord(
1631 1, live_version1->script_url(), 100)); 1633 1, live_version1->script_url(), 100));
1632 live_version1->script_cache_map()->SetResources(records1); 1634 live_version1->script_cache_map()->SetResources(records1);
1633 live_version1->set_fetch_handler_existence( 1635 live_version1->set_fetch_handler_existence(
1634 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1636 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1635 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); 1637 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED);
1636 live_registration1->SetWaitingVersion(live_version1); 1638 live_registration1->SetWaitingVersion(live_version1);
1637 1639
1638 // Registration for "/scope/foo". 1640 // Registration for "/scope/foo".
1639 const GURL kScope2("http://www.example.com/scope/foo"); 1641 const GURL kScope2("http://www.example.com/scope/foo");
1640 const GURL kScript2("http://www.example.com/script2.js"); 1642 const GURL kScript2("http://www.example.com/script2.js");
1641 const int64_t kRegistrationId2 = 2; 1643 const int64_t kRegistrationId2 = 2;
1642 const int64_t kVersionId2 = 2; 1644 const int64_t kVersionId2 = 2;
1643 scoped_refptr<ServiceWorkerRegistration> live_registration2 = 1645 scoped_refptr<ServiceWorkerRegistration> live_registration2 =
1644 new ServiceWorkerRegistration(kScope2, kRegistrationId2, 1646 new ServiceWorkerRegistration(kScope2, false /* use_cache */,
1645 context()->AsWeakPtr()); 1647 kRegistrationId2, context()->AsWeakPtr());
1646 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion( 1648 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion(
1647 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr()); 1649 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr());
1648 std::vector<ServiceWorkerDatabase::ResourceRecord> records2; 1650 std::vector<ServiceWorkerDatabase::ResourceRecord> records2;
1649 records2.push_back(ServiceWorkerDatabase::ResourceRecord( 1651 records2.push_back(ServiceWorkerDatabase::ResourceRecord(
1650 2, live_version2->script_url(), 100)); 1652 2, live_version2->script_url(), 100));
1651 live_version2->script_cache_map()->SetResources(records2); 1653 live_version2->script_cache_map()->SetResources(records2);
1652 live_version2->set_fetch_handler_existence( 1654 live_version2->set_fetch_handler_existence(
1653 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1655 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1654 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); 1656 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED);
1655 live_registration2->SetWaitingVersion(live_version2); 1657 live_registration2->SetWaitingVersion(live_version2);
1656 1658
1657 // Registration for "/scope/foobar". 1659 // Registration for "/scope/foobar".
1658 const GURL kScope3("http://www.example.com/scope/foobar"); 1660 const GURL kScope3("http://www.example.com/scope/foobar");
1659 const GURL kScript3("http://www.example.com/script3.js"); 1661 const GURL kScript3("http://www.example.com/script3.js");
1660 const int64_t kRegistrationId3 = 3; 1662 const int64_t kRegistrationId3 = 3;
1661 const int64_t kVersionId3 = 3; 1663 const int64_t kVersionId3 = 3;
1662 scoped_refptr<ServiceWorkerRegistration> live_registration3 = 1664 scoped_refptr<ServiceWorkerRegistration> live_registration3 =
1663 new ServiceWorkerRegistration(kScope3, kRegistrationId3, 1665 new ServiceWorkerRegistration(kScope3, false /* use_cache */,
1664 context()->AsWeakPtr()); 1666 kRegistrationId3, context()->AsWeakPtr());
1665 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion( 1667 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion(
1666 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr()); 1668 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr());
1667 std::vector<ServiceWorkerDatabase::ResourceRecord> records3; 1669 std::vector<ServiceWorkerDatabase::ResourceRecord> records3;
1668 records3.push_back(ServiceWorkerDatabase::ResourceRecord( 1670 records3.push_back(ServiceWorkerDatabase::ResourceRecord(
1669 3, live_version3->script_url(), 100)); 1671 3, live_version3->script_url(), 100));
1670 live_version3->script_cache_map()->SetResources(records3); 1672 live_version3->script_cache_map()->SetResources(records3);
1671 live_version3->set_fetch_handler_existence( 1673 live_version3->set_fetch_handler_existence(
1672 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1674 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1673 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); 1675 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED);
1674 live_registration3->SetWaitingVersion(live_version3); 1676 live_registration3->SetWaitingVersion(live_version3);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 1720
1719 TEST_F(ServiceWorkerStorageDiskTest, OriginHasForeignFetchRegistrations) { 1721 TEST_F(ServiceWorkerStorageDiskTest, OriginHasForeignFetchRegistrations) {
1720 LazyInitialize(); 1722 LazyInitialize();
1721 1723
1722 // Registration 1 for http://www.example.com 1724 // Registration 1 for http://www.example.com
1723 const GURL kScope1("http://www.example.com/scope/"); 1725 const GURL kScope1("http://www.example.com/scope/");
1724 const GURL kScript1("http://www.example.com/script1.js"); 1726 const GURL kScript1("http://www.example.com/script1.js");
1725 const int64_t kRegistrationId1 = 1; 1727 const int64_t kRegistrationId1 = 1;
1726 const int64_t kVersionId1 = 1; 1728 const int64_t kVersionId1 = 1;
1727 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1729 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1728 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1730 new ServiceWorkerRegistration(kScope1, false /* use_cache */,
1729 context()->AsWeakPtr()); 1731 kRegistrationId1, context()->AsWeakPtr());
1730 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion( 1732 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion(
1731 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr()); 1733 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr());
1732 std::vector<ServiceWorkerDatabase::ResourceRecord> records1; 1734 std::vector<ServiceWorkerDatabase::ResourceRecord> records1;
1733 records1.push_back(ServiceWorkerDatabase::ResourceRecord( 1735 records1.push_back(ServiceWorkerDatabase::ResourceRecord(
1734 1, live_version1->script_url(), 100)); 1736 1, live_version1->script_url(), 100));
1735 live_version1->script_cache_map()->SetResources(records1); 1737 live_version1->script_cache_map()->SetResources(records1);
1736 live_version1->set_fetch_handler_existence( 1738 live_version1->set_fetch_handler_existence(
1737 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1739 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1738 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); 1740 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED);
1739 live_version1->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope1)); 1741 live_version1->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope1));
1740 live_registration1->SetWaitingVersion(live_version1); 1742 live_registration1->SetWaitingVersion(live_version1);
1741 1743
1742 // Registration 2 for http://www.example.com 1744 // Registration 2 for http://www.example.com
1743 const GURL kScope2("http://www.example.com/scope/foo"); 1745 const GURL kScope2("http://www.example.com/scope/foo");
1744 const GURL kScript2("http://www.example.com/script2.js"); 1746 const GURL kScript2("http://www.example.com/script2.js");
1745 const int64_t kRegistrationId2 = 2; 1747 const int64_t kRegistrationId2 = 2;
1746 const int64_t kVersionId2 = 2; 1748 const int64_t kVersionId2 = 2;
1747 scoped_refptr<ServiceWorkerRegistration> live_registration2 = 1749 scoped_refptr<ServiceWorkerRegistration> live_registration2 =
1748 new ServiceWorkerRegistration(kScope2, kRegistrationId2, 1750 new ServiceWorkerRegistration(kScope2, false /* use_cache */,
1749 context()->AsWeakPtr()); 1751 kRegistrationId2, context()->AsWeakPtr());
1750 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion( 1752 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion(
1751 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr()); 1753 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr());
1752 std::vector<ServiceWorkerDatabase::ResourceRecord> records2; 1754 std::vector<ServiceWorkerDatabase::ResourceRecord> records2;
1753 records2.push_back(ServiceWorkerDatabase::ResourceRecord( 1755 records2.push_back(ServiceWorkerDatabase::ResourceRecord(
1754 2, live_version2->script_url(), 100)); 1756 2, live_version2->script_url(), 100));
1755 live_version2->script_cache_map()->SetResources(records2); 1757 live_version2->script_cache_map()->SetResources(records2);
1756 live_version2->set_fetch_handler_existence( 1758 live_version2->set_fetch_handler_existence(
1757 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1759 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1758 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); 1760 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED);
1759 live_version2->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope2)); 1761 live_version2->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope2));
1760 live_registration2->SetWaitingVersion(live_version2); 1762 live_registration2->SetWaitingVersion(live_version2);
1761 1763
1762 // Registration for http://www.test.com 1764 // Registration for http://www.test.com
1763 const GURL kScope3("http://www.test.com/scope/foobar"); 1765 const GURL kScope3("http://www.test.com/scope/foobar");
1764 const GURL kScript3("http://www.test.com/script3.js"); 1766 const GURL kScript3("http://www.test.com/script3.js");
1765 const int64_t kRegistrationId3 = 3; 1767 const int64_t kRegistrationId3 = 3;
1766 const int64_t kVersionId3 = 3; 1768 const int64_t kVersionId3 = 3;
1767 scoped_refptr<ServiceWorkerRegistration> live_registration3 = 1769 scoped_refptr<ServiceWorkerRegistration> live_registration3 =
1768 new ServiceWorkerRegistration(kScope3, kRegistrationId3, 1770 new ServiceWorkerRegistration(kScope3, false /* use_cache */,
1769 context()->AsWeakPtr()); 1771 kRegistrationId3, context()->AsWeakPtr());
1770 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion( 1772 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion(
1771 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr()); 1773 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr());
1772 std::vector<ServiceWorkerDatabase::ResourceRecord> records3; 1774 std::vector<ServiceWorkerDatabase::ResourceRecord> records3;
1773 records3.push_back(ServiceWorkerDatabase::ResourceRecord( 1775 records3.push_back(ServiceWorkerDatabase::ResourceRecord(
1774 3, live_version3->script_url(), 100)); 1776 3, live_version3->script_url(), 100));
1775 live_version3->script_cache_map()->SetResources(records3); 1777 live_version3->script_cache_map()->SetResources(records3);
1776 live_version3->set_fetch_handler_existence( 1778 live_version3->set_fetch_handler_existence(
1777 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1779 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1778 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); 1780 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED);
1779 live_registration3->SetWaitingVersion(live_version3); 1781 live_registration3->SetWaitingVersion(live_version3);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 TestContentClient test_content_client_; 1913 TestContentClient test_content_client_;
1912 }; 1914 };
1913 1915
1914 TEST_F(ServiceWorkerStorageOriginTrialsDiskTest, FromMainScript) { 1916 TEST_F(ServiceWorkerStorageOriginTrialsDiskTest, FromMainScript) {
1915 LazyInitialize(); 1917 LazyInitialize();
1916 const GURL kScope("https://valid.example.com/scope"); 1918 const GURL kScope("https://valid.example.com/scope");
1917 const GURL kScript("https://valid.example.com/script.js"); 1919 const GURL kScript("https://valid.example.com/script.js");
1918 const int64_t kRegistrationId = 1; 1920 const int64_t kRegistrationId = 1;
1919 const int64_t kVersionId = 1; 1921 const int64_t kVersionId = 1;
1920 scoped_refptr<ServiceWorkerRegistration> registration = 1922 scoped_refptr<ServiceWorkerRegistration> registration =
1921 new ServiceWorkerRegistration(kScope, kRegistrationId, 1923 new ServiceWorkerRegistration(kScope, false /* use_cache */,
1922 context()->AsWeakPtr()); 1924 kRegistrationId, context()->AsWeakPtr());
1923 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 1925 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
1924 registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 1926 registration.get(), kScript, kVersionId, context()->AsWeakPtr());
1925 1927
1926 net::HttpResponseInfo http_info; 1928 net::HttpResponseInfo http_info;
1927 http_info.ssl_info.cert = 1929 http_info.ssl_info.cert =
1928 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 1930 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
1929 EXPECT_TRUE(http_info.ssl_info.is_valid()); 1931 EXPECT_TRUE(http_info.ssl_info.is_valid());
1930 http_info.ssl_info.security_bits = 0x100; 1932 http_info.ssl_info.security_bits = 0x100;
1931 // SSL3 TLS_DHE_RSA_WITH_AES_256_CBC_SHA 1933 // SSL3 TLS_DHE_RSA_WITH_AES_256_CBC_SHA
1932 http_info.ssl_info.connection_status = 0x300039; 1934 http_info.ssl_info.connection_status = 0x300039;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2039 2041
2040 // Tests loading a registration with a disabled navigation preload 2042 // Tests loading a registration with a disabled navigation preload
2041 // state. 2043 // state.
2042 TEST_F(ServiceWorkerStorageDiskTest, DisabledNavigationPreloadState) { 2044 TEST_F(ServiceWorkerStorageDiskTest, DisabledNavigationPreloadState) {
2043 LazyInitialize(); 2045 LazyInitialize();
2044 const GURL kScope("https://valid.example.com/scope"); 2046 const GURL kScope("https://valid.example.com/scope");
2045 const GURL kScript("https://valid.example.com/script.js"); 2047 const GURL kScript("https://valid.example.com/script.js");
2046 const int64_t kRegistrationId = 1; 2048 const int64_t kRegistrationId = 1;
2047 const int64_t kVersionId = 1; 2049 const int64_t kVersionId = 1;
2048 scoped_refptr<ServiceWorkerRegistration> registration = 2050 scoped_refptr<ServiceWorkerRegistration> registration =
2049 new ServiceWorkerRegistration(kScope, kRegistrationId, 2051 new ServiceWorkerRegistration(kScope, false /* use_cache */,
2050 context()->AsWeakPtr()); 2052 kRegistrationId, context()->AsWeakPtr());
2051 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 2053 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
2052 registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 2054 registration.get(), kScript, kVersionId, context()->AsWeakPtr());
2053 2055
2054 std::vector<ServiceWorkerDatabase::ResourceRecord> record; 2056 std::vector<ServiceWorkerDatabase::ResourceRecord> record;
2055 record.push_back(ServiceWorkerDatabase::ResourceRecord(1, kScript, 100)); 2057 record.push_back(ServiceWorkerDatabase::ResourceRecord(1, kScript, 100));
2056 version->script_cache_map()->SetResources(record); 2058 version->script_cache_map()->SetResources(record);
2057 version->set_fetch_handler_existence( 2059 version->set_fetch_handler_existence(
2058 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 2060 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
2059 version->SetStatus(ServiceWorkerVersion::ACTIVATED); 2061 version->SetStatus(ServiceWorkerVersion::ACTIVATED);
2060 registration->SetActiveVersion(version); 2062 registration->SetActiveVersion(version);
(...skipping 24 matching lines...) Expand all
2085 // Tests loading a registration with an enabled navigation preload state, as 2087 // Tests loading a registration with an enabled navigation preload state, as
2086 // well as a custom header value. 2088 // well as a custom header value.
2087 TEST_F(ServiceWorkerStorageDiskTest, EnabledNavigationPreloadState) { 2089 TEST_F(ServiceWorkerStorageDiskTest, EnabledNavigationPreloadState) {
2088 LazyInitialize(); 2090 LazyInitialize();
2089 const GURL kScope("https://valid.example.com/scope"); 2091 const GURL kScope("https://valid.example.com/scope");
2090 const GURL kScript("https://valid.example.com/script.js"); 2092 const GURL kScript("https://valid.example.com/script.js");
2091 const std::string kHeaderValue("custom header value"); 2093 const std::string kHeaderValue("custom header value");
2092 const int64_t kRegistrationId = 1; 2094 const int64_t kRegistrationId = 1;
2093 const int64_t kVersionId = 1; 2095 const int64_t kVersionId = 1;
2094 scoped_refptr<ServiceWorkerRegistration> registration = 2096 scoped_refptr<ServiceWorkerRegistration> registration =
2095 new ServiceWorkerRegistration(kScope, kRegistrationId, 2097 new ServiceWorkerRegistration(kScope, false /* use_cache */,
2096 context()->AsWeakPtr()); 2098 kRegistrationId, context()->AsWeakPtr());
2097 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 2099 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
2098 registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 2100 registration.get(), kScript, kVersionId, context()->AsWeakPtr());
2099 2101
2100 std::vector<ServiceWorkerDatabase::ResourceRecord> record; 2102 std::vector<ServiceWorkerDatabase::ResourceRecord> record;
2101 record.push_back(ServiceWorkerDatabase::ResourceRecord(1, kScript, 100)); 2103 record.push_back(ServiceWorkerDatabase::ResourceRecord(1, kScript, 100));
2102 version->script_cache_map()->SetResources(record); 2104 version->script_cache_map()->SetResources(record);
2103 version->set_fetch_handler_existence( 2105 version->set_fetch_handler_existence(
2104 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 2106 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
2105 version->SetStatus(ServiceWorkerVersion::ACTIVATED); 2107 version->SetStatus(ServiceWorkerVersion::ACTIVATED);
2106 registration->SetActiveVersion(version); 2108 registration->SetActiveVersion(version);
(...skipping 16 matching lines...) Expand all
2123 EXPECT_TRUE(registration_state.enabled); 2125 EXPECT_TRUE(registration_state.enabled);
2124 EXPECT_EQ(kHeaderValue, registration_state.header); 2126 EXPECT_EQ(kHeaderValue, registration_state.header);
2125 ASSERT_TRUE(found_registration->active_version()); 2127 ASSERT_TRUE(found_registration->active_version());
2126 const NavigationPreloadState& state = 2128 const NavigationPreloadState& state =
2127 found_registration->active_version()->navigation_preload_state(); 2129 found_registration->active_version()->navigation_preload_state();
2128 EXPECT_TRUE(state.enabled); 2130 EXPECT_TRUE(state.enabled);
2129 EXPECT_EQ(kHeaderValue, state.header); 2131 EXPECT_EQ(kHeaderValue, state.header);
2130 } 2132 }
2131 2133
2132 } // namespace content 2134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698