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

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

Powered by Google App Engine
This is Rietveld 408576698