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

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

Issue 2251633002: Use tri-state enum for the existence of Fetch Handler in ServiceWorkerVersion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 ServiceWorkerDatabase::ResourceRecord(1, kResource1, kResource1Size)); 621 ServiceWorkerDatabase::ResourceRecord(1, kResource1, kResource1Size));
622 resources.push_back( 622 resources.push_back(
623 ServiceWorkerDatabase::ResourceRecord(2, kResource2, kResource2Size)); 623 ServiceWorkerDatabase::ResourceRecord(2, kResource2, kResource2Size));
624 624
625 // Store something. 625 // Store something.
626 scoped_refptr<ServiceWorkerRegistration> live_registration = 626 scoped_refptr<ServiceWorkerRegistration> live_registration =
627 new ServiceWorkerRegistration(kScope, kRegistrationId, 627 new ServiceWorkerRegistration(kScope, kRegistrationId,
628 context()->AsWeakPtr()); 628 context()->AsWeakPtr());
629 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( 629 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
630 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 630 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr());
631 live_version->set_has_fetch_handler(true);
631 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); 632 live_version->SetStatus(ServiceWorkerVersion::INSTALLED);
632 live_version->script_cache_map()->SetResources(resources); 633 live_version->script_cache_map()->SetResources(resources);
633 live_version->set_foreign_fetch_scopes( 634 live_version->set_foreign_fetch_scopes(
634 std::vector<GURL>(1, kForeignFetchScope)); 635 std::vector<GURL>(1, kForeignFetchScope));
635 live_version->set_foreign_fetch_origins( 636 live_version->set_foreign_fetch_origins(
636 std::vector<url::Origin>(1, kForeignFetchOrigin)); 637 std::vector<url::Origin>(1, kForeignFetchOrigin));
637 live_registration->SetWaitingVersion(live_version); 638 live_registration->SetWaitingVersion(live_version);
638 live_registration->set_last_update_check(kYesterday); 639 live_registration->set_last_update_check(kYesterday);
639 EXPECT_EQ(SERVICE_WORKER_OK, 640 EXPECT_EQ(SERVICE_WORKER_OK,
640 StoreRegistration(live_registration, live_version)); 641 StoreRegistration(live_registration, live_version));
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 // Store a registration. 927 // Store a registration.
927 scoped_refptr<ServiceWorkerRegistration> live_registration = 928 scoped_refptr<ServiceWorkerRegistration> live_registration =
928 new ServiceWorkerRegistration(kScope, kRegistrationId, 929 new ServiceWorkerRegistration(kScope, kRegistrationId,
929 context()->AsWeakPtr()); 930 context()->AsWeakPtr());
930 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( 931 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
931 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 932 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr());
932 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 933 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
933 records.push_back(ServiceWorkerDatabase::ResourceRecord( 934 records.push_back(ServiceWorkerDatabase::ResourceRecord(
934 1, live_version->script_url(), 100)); 935 1, live_version->script_url(), 100));
935 live_version->script_cache_map()->SetResources(records); 936 live_version->script_cache_map()->SetResources(records);
937 live_version->set_has_fetch_handler(true);
936 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); 938 live_version->SetStatus(ServiceWorkerVersion::INSTALLED);
937 live_registration->SetWaitingVersion(live_version); 939 live_registration->SetWaitingVersion(live_version);
938 EXPECT_EQ(SERVICE_WORKER_OK, 940 EXPECT_EQ(SERVICE_WORKER_OK,
939 StoreRegistration(live_registration, live_version)); 941 StoreRegistration(live_registration, live_version));
940 942
941 // Store user data associated with the registration. 943 // Store user data associated with the registration.
942 std::vector<std::string> data_out; 944 std::vector<std::string> data_out;
943 EXPECT_EQ( 945 EXPECT_EQ(
944 SERVICE_WORKER_OK, 946 SERVICE_WORKER_OK,
945 StoreUserData(kRegistrationId, kScope.GetOrigin(), {{"key", "data"}})); 947 StoreUserData(kRegistrationId, kScope.GetOrigin(), {{"key", "data"}}));
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 // Make an updated registration. 1500 // Make an updated registration.
1499 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( 1501 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
1500 registration_.get(), script_, storage()->NewVersionId(), 1502 registration_.get(), script_, storage()->NewVersionId(),
1501 context()->AsWeakPtr()); 1503 context()->AsWeakPtr());
1502 live_version->SetStatus(ServiceWorkerVersion::NEW); 1504 live_version->SetStatus(ServiceWorkerVersion::NEW);
1503 registration_->SetWaitingVersion(live_version); 1505 registration_->SetWaitingVersion(live_version);
1504 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 1506 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
1505 records.push_back(ServiceWorkerDatabase::ResourceRecord( 1507 records.push_back(ServiceWorkerDatabase::ResourceRecord(
1506 10, live_version->script_url(), 100)); 1508 10, live_version->script_url(), 100));
1507 live_version->script_cache_map()->SetResources(records); 1509 live_version->script_cache_map()->SetResources(records);
1510 live_version->set_has_fetch_handler(true);
1508 1511
1509 // Writing the registration should move the old version's resources to the 1512 // Writing the registration should move the old version's resources to the
1510 // purgeable list but keep them available. 1513 // purgeable list but keep them available.
1511 storage()->StoreRegistration( 1514 storage()->StoreRegistration(
1512 registration_.get(), 1515 registration_.get(),
1513 registration_->waiting_version(), 1516 registration_->waiting_version(),
1514 base::Bind(&VerifyPurgeableListStatusCallback, 1517 base::Bind(&VerifyPurgeableListStatusCallback,
1515 base::Unretained(storage()->database_.get()), 1518 base::Unretained(storage()->database_.get()),
1516 &verify_ids, 1519 &verify_ids,
1517 &was_called, 1520 &was_called,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 const int64_t kVersionId1 = 1; 1556 const int64_t kVersionId1 = 1;
1554 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1557 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1555 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1558 new ServiceWorkerRegistration(kScope1, kRegistrationId1,
1556 context()->AsWeakPtr()); 1559 context()->AsWeakPtr());
1557 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion( 1560 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion(
1558 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr()); 1561 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr());
1559 std::vector<ServiceWorkerDatabase::ResourceRecord> records1; 1562 std::vector<ServiceWorkerDatabase::ResourceRecord> records1;
1560 records1.push_back(ServiceWorkerDatabase::ResourceRecord( 1563 records1.push_back(ServiceWorkerDatabase::ResourceRecord(
1561 1, live_version1->script_url(), 100)); 1564 1, live_version1->script_url(), 100));
1562 live_version1->script_cache_map()->SetResources(records1); 1565 live_version1->script_cache_map()->SetResources(records1);
1566 live_version1->set_has_fetch_handler(true);
1563 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); 1567 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED);
1564 live_registration1->SetWaitingVersion(live_version1); 1568 live_registration1->SetWaitingVersion(live_version1);
1565 1569
1566 // Registration for "/scope/foo". 1570 // Registration for "/scope/foo".
1567 const GURL kScope2("http://www.example.com/scope/foo"); 1571 const GURL kScope2("http://www.example.com/scope/foo");
1568 const GURL kScript2("http://www.example.com/script2.js"); 1572 const GURL kScript2("http://www.example.com/script2.js");
1569 const int64_t kRegistrationId2 = 2; 1573 const int64_t kRegistrationId2 = 2;
1570 const int64_t kVersionId2 = 2; 1574 const int64_t kVersionId2 = 2;
1571 scoped_refptr<ServiceWorkerRegistration> live_registration2 = 1575 scoped_refptr<ServiceWorkerRegistration> live_registration2 =
1572 new ServiceWorkerRegistration(kScope2, kRegistrationId2, 1576 new ServiceWorkerRegistration(kScope2, kRegistrationId2,
1573 context()->AsWeakPtr()); 1577 context()->AsWeakPtr());
1574 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion( 1578 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion(
1575 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr()); 1579 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr());
1576 std::vector<ServiceWorkerDatabase::ResourceRecord> records2; 1580 std::vector<ServiceWorkerDatabase::ResourceRecord> records2;
1577 records2.push_back(ServiceWorkerDatabase::ResourceRecord( 1581 records2.push_back(ServiceWorkerDatabase::ResourceRecord(
1578 2, live_version2->script_url(), 100)); 1582 2, live_version2->script_url(), 100));
1579 live_version2->script_cache_map()->SetResources(records2); 1583 live_version2->script_cache_map()->SetResources(records2);
1584 live_version2->set_has_fetch_handler(true);
1580 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); 1585 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED);
1581 live_registration2->SetWaitingVersion(live_version2); 1586 live_registration2->SetWaitingVersion(live_version2);
1582 1587
1583 // Registration for "/scope/foobar". 1588 // Registration for "/scope/foobar".
1584 const GURL kScope3("http://www.example.com/scope/foobar"); 1589 const GURL kScope3("http://www.example.com/scope/foobar");
1585 const GURL kScript3("http://www.example.com/script3.js"); 1590 const GURL kScript3("http://www.example.com/script3.js");
1586 const int64_t kRegistrationId3 = 3; 1591 const int64_t kRegistrationId3 = 3;
1587 const int64_t kVersionId3 = 3; 1592 const int64_t kVersionId3 = 3;
1588 scoped_refptr<ServiceWorkerRegistration> live_registration3 = 1593 scoped_refptr<ServiceWorkerRegistration> live_registration3 =
1589 new ServiceWorkerRegistration(kScope3, kRegistrationId3, 1594 new ServiceWorkerRegistration(kScope3, kRegistrationId3,
1590 context()->AsWeakPtr()); 1595 context()->AsWeakPtr());
1591 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion( 1596 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion(
1592 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr()); 1597 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr());
1593 std::vector<ServiceWorkerDatabase::ResourceRecord> records3; 1598 std::vector<ServiceWorkerDatabase::ResourceRecord> records3;
1594 records3.push_back(ServiceWorkerDatabase::ResourceRecord( 1599 records3.push_back(ServiceWorkerDatabase::ResourceRecord(
1595 3, live_version3->script_url(), 100)); 1600 3, live_version3->script_url(), 100));
1596 live_version3->script_cache_map()->SetResources(records3); 1601 live_version3->script_cache_map()->SetResources(records3);
1602 live_version3->set_has_fetch_handler(true);
1597 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); 1603 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED);
1598 live_registration3->SetWaitingVersion(live_version3); 1604 live_registration3->SetWaitingVersion(live_version3);
1599 1605
1600 // Notify storage of they being installed. 1606 // Notify storage of they being installed.
1601 storage()->NotifyInstallingRegistration(live_registration1.get()); 1607 storage()->NotifyInstallingRegistration(live_registration1.get());
1602 storage()->NotifyInstallingRegistration(live_registration2.get()); 1608 storage()->NotifyInstallingRegistration(live_registration2.get());
1603 storage()->NotifyInstallingRegistration(live_registration3.get()); 1609 storage()->NotifyInstallingRegistration(live_registration3.get());
1604 1610
1605 // Find a registration among installing ones. 1611 // Find a registration among installing ones.
1606 EXPECT_EQ(SERVICE_WORKER_OK, 1612 EXPECT_EQ(SERVICE_WORKER_OK,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 const int64_t kVersionId1 = 1; 1654 const int64_t kVersionId1 = 1;
1649 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1655 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1650 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1656 new ServiceWorkerRegistration(kScope1, kRegistrationId1,
1651 context()->AsWeakPtr()); 1657 context()->AsWeakPtr());
1652 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion( 1658 scoped_refptr<ServiceWorkerVersion> live_version1 = new ServiceWorkerVersion(
1653 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr()); 1659 live_registration1.get(), kScript1, kVersionId1, context()->AsWeakPtr());
1654 std::vector<ServiceWorkerDatabase::ResourceRecord> records1; 1660 std::vector<ServiceWorkerDatabase::ResourceRecord> records1;
1655 records1.push_back(ServiceWorkerDatabase::ResourceRecord( 1661 records1.push_back(ServiceWorkerDatabase::ResourceRecord(
1656 1, live_version1->script_url(), 100)); 1662 1, live_version1->script_url(), 100));
1657 live_version1->script_cache_map()->SetResources(records1); 1663 live_version1->script_cache_map()->SetResources(records1);
1664 live_version1->set_has_fetch_handler(true);
1658 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); 1665 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED);
1659 live_version1->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope1)); 1666 live_version1->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope1));
1660 live_registration1->SetWaitingVersion(live_version1); 1667 live_registration1->SetWaitingVersion(live_version1);
1661 1668
1662 // Registration 2 for http://www.example.com 1669 // Registration 2 for http://www.example.com
1663 const GURL kScope2("http://www.example.com/scope/foo"); 1670 const GURL kScope2("http://www.example.com/scope/foo");
1664 const GURL kScript2("http://www.example.com/script2.js"); 1671 const GURL kScript2("http://www.example.com/script2.js");
1665 const int64_t kRegistrationId2 = 2; 1672 const int64_t kRegistrationId2 = 2;
1666 const int64_t kVersionId2 = 2; 1673 const int64_t kVersionId2 = 2;
1667 scoped_refptr<ServiceWorkerRegistration> live_registration2 = 1674 scoped_refptr<ServiceWorkerRegistration> live_registration2 =
1668 new ServiceWorkerRegistration(kScope2, kRegistrationId2, 1675 new ServiceWorkerRegistration(kScope2, kRegistrationId2,
1669 context()->AsWeakPtr()); 1676 context()->AsWeakPtr());
1670 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion( 1677 scoped_refptr<ServiceWorkerVersion> live_version2 = new ServiceWorkerVersion(
1671 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr()); 1678 live_registration2.get(), kScript2, kVersionId2, context()->AsWeakPtr());
1672 std::vector<ServiceWorkerDatabase::ResourceRecord> records2; 1679 std::vector<ServiceWorkerDatabase::ResourceRecord> records2;
1673 records2.push_back(ServiceWorkerDatabase::ResourceRecord( 1680 records2.push_back(ServiceWorkerDatabase::ResourceRecord(
1674 2, live_version2->script_url(), 100)); 1681 2, live_version2->script_url(), 100));
1675 live_version2->script_cache_map()->SetResources(records2); 1682 live_version2->script_cache_map()->SetResources(records2);
1683 live_version2->set_has_fetch_handler(true);
1676 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); 1684 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED);
1677 live_version2->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope2)); 1685 live_version2->set_foreign_fetch_scopes(std::vector<GURL>(1, kScope2));
1678 live_registration2->SetWaitingVersion(live_version2); 1686 live_registration2->SetWaitingVersion(live_version2);
1679 1687
1680 // Registration for http://www.test.com 1688 // Registration for http://www.test.com
1681 const GURL kScope3("http://www.test.com/scope/foobar"); 1689 const GURL kScope3("http://www.test.com/scope/foobar");
1682 const GURL kScript3("http://www.test.com/script3.js"); 1690 const GURL kScript3("http://www.test.com/script3.js");
1683 const int64_t kRegistrationId3 = 3; 1691 const int64_t kRegistrationId3 = 3;
1684 const int64_t kVersionId3 = 3; 1692 const int64_t kVersionId3 = 3;
1685 scoped_refptr<ServiceWorkerRegistration> live_registration3 = 1693 scoped_refptr<ServiceWorkerRegistration> live_registration3 =
1686 new ServiceWorkerRegistration(kScope3, kRegistrationId3, 1694 new ServiceWorkerRegistration(kScope3, kRegistrationId3,
1687 context()->AsWeakPtr()); 1695 context()->AsWeakPtr());
1688 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion( 1696 scoped_refptr<ServiceWorkerVersion> live_version3 = new ServiceWorkerVersion(
1689 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr()); 1697 live_registration3.get(), kScript3, kVersionId3, context()->AsWeakPtr());
1690 std::vector<ServiceWorkerDatabase::ResourceRecord> records3; 1698 std::vector<ServiceWorkerDatabase::ResourceRecord> records3;
1691 records3.push_back(ServiceWorkerDatabase::ResourceRecord( 1699 records3.push_back(ServiceWorkerDatabase::ResourceRecord(
1692 3, live_version3->script_url(), 100)); 1700 3, live_version3->script_url(), 100));
1693 live_version3->script_cache_map()->SetResources(records3); 1701 live_version3->script_cache_map()->SetResources(records3);
1702 live_version3->set_has_fetch_handler(true);
1694 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); 1703 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED);
1695 live_registration3->SetWaitingVersion(live_version3); 1704 live_registration3->SetWaitingVersion(live_version3);
1696 1705
1697 // Neither origin should have registrations before they are stored. 1706 // Neither origin should have registrations before they are stored.
1698 const GURL kOrigin1 = kScope1.GetOrigin(); 1707 const GURL kOrigin1 = kScope1.GetOrigin();
1699 const GURL kOrigin2 = kScope3.GetOrigin(); 1708 const GURL kOrigin2 = kScope3.GetOrigin();
1700 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1)); 1709 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1));
1701 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2)); 1710 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2));
1702 1711
1703 // Store all registrations. 1712 // Store all registrations.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 // Remove other registration at first origin. 1746 // Remove other registration at first origin.
1738 EXPECT_EQ(SERVICE_WORKER_OK, 1747 EXPECT_EQ(SERVICE_WORKER_OK,
1739 DeleteRegistration(kRegistrationId2, kScope2.GetOrigin())); 1748 DeleteRegistration(kRegistrationId2, kScope2.GetOrigin()));
1740 1749
1741 // No foreign fetch registrations remain. 1750 // No foreign fetch registrations remain.
1742 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1)); 1751 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1));
1743 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2)); 1752 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2));
1744 } 1753 }
1745 1754
1746 } // namespace content 1755 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698