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

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: change useCache to updateViaCache Created 3 years, 6 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(ServiceWorkerRegistrationOptions(kScope),
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(ServiceWorkerRegistrationOptions(kScope),
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(ServiceWorkerRegistrationOptions(kScope),
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(ServiceWorkerRegistrationOptions(kScope),
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(ServiceWorkerRegistrationOptions(kScope),
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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { 1622 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) {
1622 const GURL kDocumentUrl("http://www.example.com/scope/foo"); 1623 const GURL kDocumentUrl("http://www.example.com/scope/foo");
1623 scoped_refptr<ServiceWorkerRegistration> found_registration; 1624 scoped_refptr<ServiceWorkerRegistration> found_registration;
1624 1625
1625 // Registration for "/scope/". 1626 // Registration for "/scope/".
1626 const GURL kScope1("http://www.example.com/scope/"); 1627 const GURL kScope1("http://www.example.com/scope/");
1627 const GURL kScript1("http://www.example.com/script1.js"); 1628 const GURL kScript1("http://www.example.com/script1.js");
1628 const int64_t kRegistrationId1 = 1; 1629 const int64_t kRegistrationId1 = 1;
1629 const int64_t kVersionId1 = 1; 1630 const int64_t kVersionId1 = 1;
1630 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1631 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1631 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1632 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope1),
1632 context()->AsWeakPtr()); 1633 kRegistrationId1, context()->AsWeakPtr());
1633 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion( 1634 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion(
1634 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr()); 1635 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr());
1635 std::vector<ServiceWorkerDatabase::ResourceRecord> records1; 1636 std::vector<ServiceWorkerDatabase::ResourceRecord> records1;
1636 records1.push_back(ServiceWorkerDatabase::ResourceRecord( 1637 records1.push_back(ServiceWorkerDatabase::ResourceRecord(
1637 1, live_version1->script_url(), 100)); 1638 1, live_version1->script_url(), 100));
1638 live_version1->script_cache_map()->SetResources(records1); 1639 live_version1->script_cache_map()->SetResources(records1);
1639 live_version1->set_fetch_handler_existence( 1640 live_version1->set_fetch_handler_existence(
1640 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1641 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1641 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); 1642 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED);
1642 live_registration1->SetWaitingVersion(live_version1); 1643 live_registration1->SetWaitingVersion(live_version1);
1643 1644
1644 // Registration for "/scope/foo". 1645 // Registration for "/scope/foo".
1645 const GURL kScope2("http://www.example.com/scope/foo"); 1646 const GURL kScope2("http://www.example.com/scope/foo");
1646 const GURL kScript2("http://www.example.com/script2.js"); 1647 const GURL kScript2("http://www.example.com/script2.js");
1647 const int64_t kRegistrationId2 = 2; 1648 const int64_t kRegistrationId2 = 2;
1648 const int64_t kVersionId2 = 2; 1649 const int64_t kVersionId2 = 2;
1649 scoped_refptr<ServiceWorkerRegistration> live_registration2 = 1650 scoped_refptr<ServiceWorkerRegistration> live_registration2 =
1650 new ServiceWorkerRegistration(kScope2, kRegistrationId2, 1651 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope2),
1651 context()->AsWeakPtr()); 1652 kRegistrationId2, context()->AsWeakPtr());
1652 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion( 1653 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion(
1653 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr()); 1654 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr());
1654 std::vector<ServiceWorkerDatabase::ResourceRecord> records2; 1655 std::vector<ServiceWorkerDatabase::ResourceRecord> records2;
1655 records2.push_back(ServiceWorkerDatabase::ResourceRecord( 1656 records2.push_back(ServiceWorkerDatabase::ResourceRecord(
1656 2, live_version2->script_url(), 100)); 1657 2, live_version2->script_url(), 100));
1657 live_version2->script_cache_map()->SetResources(records2); 1658 live_version2->script_cache_map()->SetResources(records2);
1658 live_version2->set_fetch_handler_existence( 1659 live_version2->set_fetch_handler_existence(
1659 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1660 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1660 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); 1661 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED);
1661 live_registration2->SetWaitingVersion(live_version2); 1662 live_registration2->SetWaitingVersion(live_version2);
1662 1663
1663 // Registration for "/scope/foobar". 1664 // Registration for "/scope/foobar".
1664 const GURL kScope3("http://www.example.com/scope/foobar"); 1665 const GURL kScope3("http://www.example.com/scope/foobar");
1665 const GURL kScript3("http://www.example.com/script3.js"); 1666 const GURL kScript3("http://www.example.com/script3.js");
1666 const int64_t kRegistrationId3 = 3; 1667 const int64_t kRegistrationId3 = 3;
1667 const int64_t kVersionId3 = 3; 1668 const int64_t kVersionId3 = 3;
1668 scoped_refptr<ServiceWorkerRegistration> live_registration3 = 1669 scoped_refptr<ServiceWorkerRegistration> live_registration3 =
1669 new ServiceWorkerRegistration(kScope3, kRegistrationId3, 1670 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope3),
1670 context()->AsWeakPtr()); 1671 kRegistrationId3, context()->AsWeakPtr());
1671 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion( 1672 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion(
1672 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr()); 1673 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr());
1673 std::vector<ServiceWorkerDatabase::ResourceRecord> records3; 1674 std::vector<ServiceWorkerDatabase::ResourceRecord> records3;
1674 records3.push_back(ServiceWorkerDatabase::ResourceRecord( 1675 records3.push_back(ServiceWorkerDatabase::ResourceRecord(
1675 3, live_version3->script_url(), 100)); 1676 3, live_version3->script_url(), 100));
1676 live_version3->script_cache_map()->SetResources(records3); 1677 live_version3->script_cache_map()->SetResources(records3);
1677 live_version3->set_fetch_handler_existence( 1678 live_version3->set_fetch_handler_existence(
1678 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1679 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1679 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); 1680 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED);
1680 live_registration3->SetWaitingVersion(live_version3); 1681 live_registration3->SetWaitingVersion(live_version3);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 1725
1725 TEST_F(ServiceWorkerStorageDiskTest, OriginHasForeignFetchRegistrations) { 1726 TEST_F(ServiceWorkerStorageDiskTest, OriginHasForeignFetchRegistrations) {
1726 LazyInitialize(); 1727 LazyInitialize();
1727 1728
1728 // Registration 1 for http://www.example.com 1729 // Registration 1 for http://www.example.com
1729 const GURL kScope1("http://www.example.com/scope/"); 1730 const GURL kScope1("http://www.example.com/scope/");
1730 const GURL kScript1("http://www.example.com/script1.js"); 1731 const GURL kScript1("http://www.example.com/script1.js");
1731 const int64_t kRegistrationId1 = 1; 1732 const int64_t kRegistrationId1 = 1;
1732 const int64_t kVersionId1 = 1; 1733 const int64_t kVersionId1 = 1;
1733 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1734 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1734 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1735 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope1),
1735 context()->AsWeakPtr()); 1736 kRegistrationId1, context()->AsWeakPtr());
1736 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion( 1737 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion(
1737 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr()); 1738 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr());
1738 std::vector<ServiceWorkerDatabase::ResourceRecord> records1; 1739 std::vector<ServiceWorkerDatabase::ResourceRecord> records1;
1739 records1.push_back(ServiceWorkerDatabase::ResourceRecord( 1740 records1.push_back(ServiceWorkerDatabase::ResourceRecord(
1740 1, live_version1->script_url(), 100)); 1741 1, live_version1->script_url(), 100));
1741 live_version1->script_cache_map()->SetResources(records1); 1742 live_version1->script_cache_map()->SetResources(records1);
1742 live_version1->set_fetch_handler_existence( 1743 live_version1->set_fetch_handler_existence(
1743 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1744 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1744 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); 1745 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED);
1745 live_version1->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope1)); 1746 live_version1->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope1));
1746 live_registration1->SetWaitingVersion(live_version1); 1747 live_registration1->SetWaitingVersion(live_version1);
1747 1748
1748 // Registration 2 for http://www.example.com 1749 // Registration 2 for http://www.example.com
1749 const GURL kScope2("http://www.example.com/scope/foo"); 1750 const GURL kScope2("http://www.example.com/scope/foo");
1750 const GURL kScript2("http://www.example.com/script2.js"); 1751 const GURL kScript2("http://www.example.com/script2.js");
1751 const int64_t kRegistrationId2 = 2; 1752 const int64_t kRegistrationId2 = 2;
1752 const int64_t kVersionId2 = 2; 1753 const int64_t kVersionId2 = 2;
1753 scoped_refptr<ServiceWorkerRegistration> live_registration2 = 1754 scoped_refptr<ServiceWorkerRegistration> live_registration2 =
1754 new ServiceWorkerRegistration(kScope2, kRegistrationId2, 1755 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope2),
1755 context()->AsWeakPtr()); 1756 kRegistrationId2, context()->AsWeakPtr());
1756 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion( 1757 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion(
1757 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr()); 1758 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr());
1758 std::vector<ServiceWorkerDatabase::ResourceRecord> records2; 1759 std::vector<ServiceWorkerDatabase::ResourceRecord> records2;
1759 records2.push_back(ServiceWorkerDatabase::ResourceRecord( 1760 records2.push_back(ServiceWorkerDatabase::ResourceRecord(
1760 2, live_version2->script_url(), 100)); 1761 2, live_version2->script_url(), 100));
1761 live_version2->script_cache_map()->SetResources(records2); 1762 live_version2->script_cache_map()->SetResources(records2);
1762 live_version2->set_fetch_handler_existence( 1763 live_version2->set_fetch_handler_existence(
1763 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1764 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1764 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); 1765 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED);
1765 live_version2->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope2)); 1766 live_version2->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope2));
1766 live_registration2->SetWaitingVersion(live_version2); 1767 live_registration2->SetWaitingVersion(live_version2);
1767 1768
1768 // Registration for http://www.test.com 1769 // Registration for http://www.test.com
1769 const GURL kScope3("http://www.test.com/scope/foobar"); 1770 const GURL kScope3("http://www.test.com/scope/foobar");
1770 const GURL kScript3("http://www.test.com/script3.js"); 1771 const GURL kScript3("http://www.test.com/script3.js");
1771 const int64_t kRegistrationId3 = 3; 1772 const int64_t kRegistrationId3 = 3;
1772 const int64_t kVersionId3 = 3; 1773 const int64_t kVersionId3 = 3;
1773 scoped_refptr<ServiceWorkerRegistration> live_registration3 = 1774 scoped_refptr<ServiceWorkerRegistration> live_registration3 =
1774 new ServiceWorkerRegistration(kScope3, kRegistrationId3, 1775 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope3),
1775 context()->AsWeakPtr()); 1776 kRegistrationId3, context()->AsWeakPtr());
1776 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion( 1777 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion(
1777 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr()); 1778 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr());
1778 std::vector<ServiceWorkerDatabase::ResourceRecord> records3; 1779 std::vector<ServiceWorkerDatabase::ResourceRecord> records3;
1779 records3.push_back(ServiceWorkerDatabase::ResourceRecord( 1780 records3.push_back(ServiceWorkerDatabase::ResourceRecord(
1780 3, live_version3->script_url(), 100)); 1781 3, live_version3->script_url(), 100));
1781 live_version3->script_cache_map()->SetResources(records3); 1782 live_version3->script_cache_map()->SetResources(records3);
1782 live_version3->set_fetch_handler_existence( 1783 live_version3->set_fetch_handler_existence(
1783 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1784 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1784 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); 1785 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED);
1785 live_registration3->SetWaitingVersion(live_version3); 1786 live_registration3->SetWaitingVersion(live_version3);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 TestContentClient test_content_client_; 1918 TestContentClient test_content_client_;
1918 }; 1919 };
1919 1920
1920 TEST_F(ServiceWorkerStorageOriginTrialsDiskTest, FromMainScript) { 1921 TEST_F(ServiceWorkerStorageOriginTrialsDiskTest, FromMainScript) {
1921 LazyInitialize(); 1922 LazyInitialize();
1922 const GURL kScope("https://valid.example.com/scope"); 1923 const GURL kScope("https://valid.example.com/scope");
1923 const GURL kScript("https://valid.example.com/script.js"); 1924 const GURL kScript("https://valid.example.com/script.js");
1924 const int64_t kRegistrationId = 1; 1925 const int64_t kRegistrationId = 1;
1925 const int64_t kVersionId = 1; 1926 const int64_t kVersionId = 1;
1926 scoped_refptr<ServiceWorkerRegistration> registration = 1927 scoped_refptr<ServiceWorkerRegistration> registration =
1927 new ServiceWorkerRegistration(kScope, kRegistrationId, 1928 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope),
1928 context()->AsWeakPtr()); 1929 kRegistrationId, context()->AsWeakPtr());
1929 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 1930 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
1930 registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 1931 registration.get(), kScript, kVersionId, context()->AsWeakPtr());
1931 1932
1932 net::HttpResponseInfo http_info; 1933 net::HttpResponseInfo http_info;
1933 http_info.ssl_info.cert = 1934 http_info.ssl_info.cert =
1934 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 1935 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
1935 EXPECT_TRUE(http_info.ssl_info.is_valid()); 1936 EXPECT_TRUE(http_info.ssl_info.is_valid());
1936 http_info.ssl_info.security_bits = 0x100; 1937 http_info.ssl_info.security_bits = 0x100;
1937 // SSL3 TLS_DHE_RSA_WITH_AES_256_CBC_SHA 1938 // SSL3 TLS_DHE_RSA_WITH_AES_256_CBC_SHA
1938 http_info.ssl_info.connection_status = 0x300039; 1939 http_info.ssl_info.connection_status = 0x300039;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 2046
2046 // Tests loading a registration with a disabled navigation preload 2047 // Tests loading a registration with a disabled navigation preload
2047 // state. 2048 // state.
2048 TEST_F(ServiceWorkerStorageDiskTest, DisabledNavigationPreloadState) { 2049 TEST_F(ServiceWorkerStorageDiskTest, DisabledNavigationPreloadState) {
2049 LazyInitialize(); 2050 LazyInitialize();
2050 const GURL kScope("https://valid.example.com/scope"); 2051 const GURL kScope("https://valid.example.com/scope");
2051 const GURL kScript("https://valid.example.com/script.js"); 2052 const GURL kScript("https://valid.example.com/script.js");
2052 const int64_t kRegistrationId = 1; 2053 const int64_t kRegistrationId = 1;
2053 const int64_t kVersionId = 1; 2054 const int64_t kVersionId = 1;
2054 scoped_refptr<ServiceWorkerRegistration> registration = 2055 scoped_refptr<ServiceWorkerRegistration> registration =
2055 new ServiceWorkerRegistration(kScope, kRegistrationId, 2056 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope),
2056 context()->AsWeakPtr()); 2057 kRegistrationId, context()->AsWeakPtr());
2057 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 2058 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
2058 registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 2059 registration.get(), kScript, kVersionId, context()->AsWeakPtr());
2059 2060
2060 std::vector<ServiceWorkerDatabase::ResourceRecord> record; 2061 std::vector<ServiceWorkerDatabase::ResourceRecord> record;
2061 record.push_back(ServiceWorkerDatabase::ResourceRecord(1, kScript, 100)); 2062 record.push_back(ServiceWorkerDatabase::ResourceRecord(1, kScript, 100));
2062 version->script_cache_map()->SetResources(record); 2063 version->script_cache_map()->SetResources(record);
2063 version->set_fetch_handler_existence( 2064 version->set_fetch_handler_existence(
2064 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 2065 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
2065 version->SetStatus(ServiceWorkerVersion::ACTIVATED); 2066 version->SetStatus(ServiceWorkerVersion::ACTIVATED);
2066 registration->SetActiveVersion(version); 2067 registration->SetActiveVersion(version);
(...skipping 24 matching lines...) Expand all
2091 // Tests loading a registration with an enabled navigation preload state, as 2092 // Tests loading a registration with an enabled navigation preload state, as
2092 // well as a custom header value. 2093 // well as a custom header value.
2093 TEST_F(ServiceWorkerStorageDiskTest, EnabledNavigationPreloadState) { 2094 TEST_F(ServiceWorkerStorageDiskTest, EnabledNavigationPreloadState) {
2094 LazyInitialize(); 2095 LazyInitialize();
2095 const GURL kScope("https://valid.example.com/scope"); 2096 const GURL kScope("https://valid.example.com/scope");
2096 const GURL kScript("https://valid.example.com/script.js"); 2097 const GURL kScript("https://valid.example.com/script.js");
2097 const std::string kHeaderValue("custom header value"); 2098 const std::string kHeaderValue("custom header value");
2098 const int64_t kRegistrationId = 1; 2099 const int64_t kRegistrationId = 1;
2099 const int64_t kVersionId = 1; 2100 const int64_t kVersionId = 1;
2100 scoped_refptr<ServiceWorkerRegistration> registration = 2101 scoped_refptr<ServiceWorkerRegistration> registration =
2101 new ServiceWorkerRegistration(kScope, kRegistrationId, 2102 new ServiceWorkerRegistration(ServiceWorkerRegistrationOptions(kScope),
2102 context()->AsWeakPtr()); 2103 kRegistrationId, context()->AsWeakPtr());
2103 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 2104 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
2104 registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 2105 registration.get(), kScript, kVersionId, context()->AsWeakPtr());
2105 2106
2106 std::vector<ServiceWorkerDatabase::ResourceRecord> record; 2107 std::vector<ServiceWorkerDatabase::ResourceRecord> record;
2107 record.push_back(ServiceWorkerDatabase::ResourceRecord(1, kScript, 100)); 2108 record.push_back(ServiceWorkerDatabase::ResourceRecord(1, kScript, 100));
2108 version->script_cache_map()->SetResources(record); 2109 version->script_cache_map()->SetResources(record);
2109 version->set_fetch_handler_existence( 2110 version->set_fetch_handler_existence(
2110 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 2111 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
2111 version->SetStatus(ServiceWorkerVersion::ACTIVATED); 2112 version->SetStatus(ServiceWorkerVersion::ACTIVATED);
2112 registration->SetActiveVersion(version); 2113 registration->SetActiveVersion(version);
(...skipping 16 matching lines...) Expand all
2129 EXPECT_TRUE(registration_state.enabled); 2130 EXPECT_TRUE(registration_state.enabled);
2130 EXPECT_EQ(kHeaderValue, registration_state.header); 2131 EXPECT_EQ(kHeaderValue, registration_state.header);
2131 ASSERT_TRUE(found_registration->active_version()); 2132 ASSERT_TRUE(found_registration->active_version());
2132 const NavigationPreloadState& state = 2133 const NavigationPreloadState& state =
2133 found_registration->active_version()->navigation_preload_state(); 2134 found_registration->active_version()->navigation_preload_state();
2134 EXPECT_TRUE(state.enabled); 2135 EXPECT_TRUE(state.enabled);
2135 EXPECT_EQ(kHeaderValue, state.header); 2136 EXPECT_EQ(kHeaderValue, state.header);
2136 } 2137 }
2137 2138
2138 } // namespace content 2139 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698