#include "components/services/storage/service_worker/service_worker_database.h"
#include <stddef.h>
#include <stdint.h>
#include <string>
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/unguessable_token.h"
#include "components/services/storage/service_worker/service_worker_database.pb.h"
#include "net/base/features.h"
#include "services/network/public/cpp/web_sandbox_flags.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "services/network/public/mojom/referrer_policy.mojom-shared.h"
#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/safe_url_pattern.h"
#include "third_party/blink/public/common/service_worker/service_worker_router_rule.h"
#include "third_party/blink/public/mojom/frame/policy_container.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom.h"
#include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
#include "url/origin.h"
namespace storage {
namespace {
ElementsAreArray;
IsEmpty;
RegistrationData;
RegistrationDataPtr;
ResourceRecordPtr;
struct AvailableIds { … };
GURL URL(const GURL& origin, const std::string& path) { … }
ResourceRecordPtr CreateResource(int64_t resource_id,
const GURL& url,
uint64_t size_bytes) { … }
ServiceWorkerDatabase* CreateDatabase(const base::FilePath& path) { … }
ServiceWorkerDatabase* CreateDatabaseInMemory() { … }
void VerifyRegistrationData(const RegistrationData& expected,
const RegistrationData& actual) { … }
void VerifyResourceRecords(const std::vector<ResourceRecordPtr>& expected,
const std::vector<ResourceRecordPtr>& actual) { … }
network::CrossOriginEmbedderPolicy CrossOriginEmbedderPolicyNone() { … }
network::CrossOriginEmbedderPolicy CrossOriginEmbedderPolicyRequireCorp() { … }
network::CrossOriginEmbedderPolicy CrossOriginEmbedderPolicyCredentialless() { … }
std::vector<mojom::ServiceWorkerUserDataPtr> CreateUserData(
int64_t registration_id,
const std::vector<std::pair<std::string, std::string>>& key_value_pairs) { … }
}
TEST(ServiceWorkerDatabaseTest, OpenDatabase) { … }
TEST(ServiceWorkerDatabaseTest, OpenDatabase_InMemory) { … }
TEST(ServiceWorkerDatabaseTest, DatabaseVersion_ValidSchemaVersion) { … }
TEST(ServiceWorkerDatabaseTest, DatabaseVersion_ObsoleteSchemaVersion) { … }
TEST(ServiceWorkerDatabaseTest, DatabaseVersion_CorruptedSchemaVersion) { … }
TEST(ServiceWorkerDatabaseTest, GetNextAvailableIds) { … }
TEST(ServiceWorkerDatabaseTest, GetStorageKeysWithRegistrations) { … }
TEST(ServiceWorkerDatabaseTest, GetRegistrationsForStorageKey) { … }
TEST(ServiceWorkerDatabaseTest, GetAllRegistrations) { … }
TEST(ServiceWorkerDatabaseTest, Registration_Basic) { … }
TEST(ServiceWorkerDatabaseTest, DeleteNonExistentRegistration) { … }
TEST(ServiceWorkerDatabaseTest, Registration_Overwrite) { … }
TEST(ServiceWorkerDatabaseTest, Registration_Multiple) { … }
TEST(ServiceWorkerDatabaseTest, Registration_UninitializedDatabase) { … }
TEST(ServiceWorkerDatabaseTest, Registration_ScriptType) { … }
TEST(ServiceWorkerDatabaseTest, UserData_Basic) { … }
TEST(ServiceWorkerDatabaseTest,
UserData_ReadUserDataForAllRegistrationsByKeyPrefix) { … }
TEST(ServiceWorkerDatabaseTest, ReadUserDataByKeyPrefix) { … }
TEST(ServiceWorkerDatabaseTest, ReadUserKeysAndDataByKeyPrefix) { … }
TEST(ServiceWorkerDatabaseTest, UserData_DeleteUserDataByKeyPrefixes) { … }
TEST(ServiceWorkerDatabaseTest,
UserData_DeleteUserDataForAllRegistrationsByKeyPrefix) { … }
TEST(ServiceWorkerDatabaseTest, UserData_DataIsolation) { … }
TEST(ServiceWorkerDatabaseTest, UserData_DeleteRegistration) { … }
TEST(ServiceWorkerDatabaseTest, UserData_UninitializedDatabase) { … }
TEST(ServiceWorkerDatabaseTest, UpdateVersionToActive) { … }
TEST(ServiceWorkerDatabaseTest, UpdateLastCheckTime) { … }
TEST(ServiceWorkerDatabaseTest, UpdateFetchHandlerType) { … }
TEST(ServiceWorkerDatabaseTest, UpdateResourceSha256Checksums) { … }
TEST(ServiceWorkerDatabaseTest, UncommittedAndPurgeableResourceIds) { … }
namespace {
class DeleteAllDataForStorageKeyTest { … };
void DeleteAllDataForStorageKeyTest::TestDeleteAllDataForStorageKey(
std::string registered_key_origin,
std::string registered_key_top_level_site,
blink::mojom::AncestorChainBit registered_key_ancestor_chain_bit,
std::string deleted_origin,
bool expect_key_deleted) { … }
void DeleteAllDataForStorageKeyTest::
TestDeleteAllDataForStorageKeyWithMultipleKeys() { … }
}
class DeleteAllDataForStorageKeyFirstPartyP
: public DeleteAllDataForStorageKeyTest,
public testing::TestWithParam<bool> { … };
class ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty
: public DeleteAllDataForStorageKeyTest,
public testing::Test { … };
TEST_P(DeleteAllDataForStorageKeyFirstPartyP, Matching) { … }
TEST_P(DeleteAllDataForStorageKeyFirstPartyP, NonMatching) { … }
TEST_P(DeleteAllDataForStorageKeyFirstPartyP, WithSubsiteOrigin) { … }
TEST_P(DeleteAllDataForStorageKeyFirstPartyP, WithSupersiteOfDeletedOrigin) { … }
TEST_P(DeleteAllDataForStorageKeyFirstPartyP,
WithSubsiteMatchingDeletedOrigin) { … }
TEST_P(DeleteAllDataForStorageKeyFirstPartyP, CallWithMultipleKeys) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
WithSubsiteMatchingDeletedOrigin) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
WithSubsiteMatchingDeletedOriginMatchingTopLevelSite) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
SupersiteOfDeletedOrigin) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
SupersiteOfDeletedOriginMatchingTopLevelSite) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
SubsiteOfDeletedOrigin) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
PerAncestorChainBitSubsiteOfDeletedOrigin) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
WithMatchingOrigin) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
PerAncestorChainBitWithMatchingOrigin) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
ForOtherOrigin) { … }
TEST_F(ServiceWorkerDatabaseTestDeleteAllDataForStorageKeyThirdParty,
WithMatchingTopLevelSite) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST(ServiceWorkerDatabaseTest, DestroyDatabase) { … }
TEST(ServiceWorkerDatabaseTest, Corruption_NoMainResource) { … }
TEST(ServiceWorkerDatabaseTest, Corruption_GetRegistrationsForStorageKey) { … }
TEST(ServiceWorkerDatabaseTest, InvalidWebFeature) { … }
TEST(ServiceWorkerDatabaseTest, CrossOriginEmbedderPolicyStoreRestore) { … }
TEST(ServiceWorkerDatabaseTest, NoCrossOriginEmbedderPolicyValue) { … }
const network::mojom::WebSandboxFlags kWebSandboxFlags[] = …;
static_assert …;
TEST(ServiceWorkerDatabaseTest, PolicyContainerPoliciesStoreRestore) { … }
TEST(ServiceWorkerDatabaseTest, StorageKeyImplCanReadPreviousOriginImplDB) { … }
TEST(ServiceWorkerDatabaseTest, NoFetchHandlerType) { … }
TEST(ServiceWorkerDatabaseTest, FetchHandlerType) { … }
TEST(ServiceWorkerDatabaseTest, FetchHandlerTypeStoreRestore) { … }
TEST(ServiceWorkerDatabaseTest, RouterRulesStoreRestore) { … }
TEST(ServiceWorkerDatabaseTest, RouterRulesLegacyPathname) { … }
}