mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1866402 - Add nsIQuotaManagerService::PersistentOriginInitialized and nsIQuotaManagerService::TemporaryOriginInitialized methods; r=dom-storage-reviewers,jari
This additional testing infrastructure is needed for verifying origin initialization status. Differential Revision: https://phabricator.services.mozilla.com/D195526
This commit is contained in:
parent
14d1cca216
commit
3d5864cea5
@ -5413,6 +5413,28 @@ RefPtr<BoolPromise> QuotaManager::InitializePersistentOrigin(
|
||||
return initializePersistentOriginOp->OnResults();
|
||||
}
|
||||
|
||||
RefPtr<BoolPromise> QuotaManager::PersistentOriginInitialized(
|
||||
const PrincipalInfo& aPrincipalInfo) {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
auto persistentOriginInitializedOp = CreatePersistentOriginInitializedOp(
|
||||
WrapMovingNotNullUnchecked(this), aPrincipalInfo);
|
||||
|
||||
RegisterNormalOriginOp(*persistentOriginInitializedOp);
|
||||
|
||||
persistentOriginInitializedOp->RunImmediately();
|
||||
|
||||
return persistentOriginInitializedOp->OnResults();
|
||||
}
|
||||
|
||||
bool QuotaManager::IsPersistentOriginInitializedInternal(
|
||||
const OriginMetadata& aOriginMetadata) const {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aOriginMetadata.mPersistenceType == PERSISTENCE_TYPE_PERSISTENT);
|
||||
|
||||
return mInitializedOriginsInternal.Contains(aOriginMetadata.mOrigin);
|
||||
}
|
||||
|
||||
Result<std::pair<nsCOMPtr<nsIFile>, bool>, nsresult>
|
||||
QuotaManager::EnsurePersistentOriginIsInitializedInternal(
|
||||
const OriginMetadata& aOriginMetadata) {
|
||||
@ -5522,6 +5544,20 @@ RefPtr<BoolPromise> QuotaManager::InitializeTemporaryOrigin(
|
||||
return initializeTemporaryOriginOp->OnResults();
|
||||
}
|
||||
|
||||
RefPtr<BoolPromise> QuotaManager::TemporaryOriginInitialized(
|
||||
PersistenceType aPersistenceType, const PrincipalInfo& aPrincipalInfo) {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
auto temporaryOriginInitializedOp = CreateTemporaryOriginInitializedOp(
|
||||
WrapMovingNotNullUnchecked(this), aPersistenceType, aPrincipalInfo);
|
||||
|
||||
RegisterNormalOriginOp(*temporaryOriginInitializedOp);
|
||||
|
||||
temporaryOriginInitializedOp->RunImmediately();
|
||||
|
||||
return temporaryOriginInitializedOp->OnResults();
|
||||
}
|
||||
|
||||
bool QuotaManager::IsTemporaryOriginInitializedInternal(
|
||||
const OriginMetadata& aOriginMetadata) const {
|
||||
AssertIsOnIOThread();
|
||||
|
@ -352,6 +352,55 @@ class TemporaryStorageInitializedOp final : public InitializedRequestBase {
|
||||
bool GetResolveValue() override;
|
||||
};
|
||||
|
||||
class InitializedOriginRequestBase : public ResolvableNormalOriginOp<bool> {
|
||||
protected:
|
||||
const PrincipalInfo mPrincipalInfo;
|
||||
PrincipalMetadata mPrincipalMetadata;
|
||||
bool mInitialized;
|
||||
|
||||
InitializedOriginRequestBase(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager, const char* aName,
|
||||
const PrincipalInfo& aPrincipalInfo);
|
||||
|
||||
private:
|
||||
nsresult DoInit(QuotaManager& aQuotaManager) override;
|
||||
|
||||
RefPtr<BoolPromise> OpenDirectory() override;
|
||||
|
||||
void CloseDirectory() override;
|
||||
};
|
||||
|
||||
class PersistentOriginInitializedOp final
|
||||
: public InitializedOriginRequestBase {
|
||||
public:
|
||||
explicit PersistentOriginInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
const PrincipalInfo& aPrincipalInfo);
|
||||
|
||||
private:
|
||||
~PersistentOriginInitializedOp() = default;
|
||||
|
||||
nsresult DoDirectoryWork(QuotaManager& aQuotaManager) override;
|
||||
|
||||
bool GetResolveValue() override;
|
||||
};
|
||||
|
||||
class TemporaryOriginInitializedOp final : public InitializedOriginRequestBase {
|
||||
const PersistenceType mPersistenceType;
|
||||
|
||||
public:
|
||||
explicit TemporaryOriginInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
PersistenceType aPersistenceType, const PrincipalInfo& aPrincipalInfo);
|
||||
|
||||
private:
|
||||
~TemporaryOriginInitializedOp() = default;
|
||||
|
||||
nsresult DoDirectoryWork(QuotaManager& aQuotaManager) override;
|
||||
|
||||
bool GetResolveValue() override;
|
||||
};
|
||||
|
||||
class InitOp final : public ResolvableNormalOriginOp<bool> {
|
||||
RefPtr<UniversalDirectoryLock> mDirectoryLock;
|
||||
|
||||
@ -895,6 +944,21 @@ RefPtr<ResolvableNormalOriginOp<bool>> CreateTemporaryStorageInitializedOp(
|
||||
return MakeRefPtr<TemporaryStorageInitializedOp>(std::move(aQuotaManager));
|
||||
}
|
||||
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreatePersistentOriginInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
const mozilla::ipc::PrincipalInfo& aPrincipalInfo) {
|
||||
return MakeRefPtr<PersistentOriginInitializedOp>(std::move(aQuotaManager),
|
||||
aPrincipalInfo);
|
||||
}
|
||||
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateTemporaryOriginInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
const PersistenceType aPersistenceType,
|
||||
const mozilla::ipc::PrincipalInfo& aPrincipalInfo) {
|
||||
return MakeRefPtr<TemporaryOriginInitializedOp>(
|
||||
std::move(aQuotaManager), aPersistenceType, aPrincipalInfo);
|
||||
}
|
||||
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateInitOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
RefPtr<UniversalDirectoryLock> aDirectoryLock) {
|
||||
@ -1675,6 +1739,92 @@ bool TemporaryStorageInitializedOp::GetResolveValue() {
|
||||
return mInitialized;
|
||||
}
|
||||
|
||||
InitializedOriginRequestBase::InitializedOriginRequestBase(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager, const char* aName,
|
||||
const PrincipalInfo& aPrincipalInfo)
|
||||
: ResolvableNormalOriginOp(std::move(aQuotaManager), aName),
|
||||
mPrincipalInfo(aPrincipalInfo),
|
||||
mInitialized(false) {
|
||||
AssertIsOnOwningThread();
|
||||
}
|
||||
|
||||
nsresult InitializedOriginRequestBase::DoInit(QuotaManager& aQuotaManager) {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
QM_TRY_UNWRAP(
|
||||
mPrincipalMetadata,
|
||||
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mPrincipalInfo));
|
||||
|
||||
mPrincipalMetadata.AssertInvariants();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<BoolPromise> InitializedOriginRequestBase::OpenDirectory() {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
return BoolPromise::CreateAndResolve(true, __func__);
|
||||
}
|
||||
|
||||
void InitializedOriginRequestBase::CloseDirectory() {
|
||||
AssertIsOnOwningThread();
|
||||
}
|
||||
|
||||
PersistentOriginInitializedOp::PersistentOriginInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
const PrincipalInfo& aPrincipalInfo)
|
||||
: InitializedOriginRequestBase(std::move(aQuotaManager),
|
||||
"dom::quota::PersistentOriginInitializedOp",
|
||||
aPrincipalInfo) {
|
||||
AssertIsOnOwningThread();
|
||||
}
|
||||
|
||||
nsresult PersistentOriginInitializedOp::DoDirectoryWork(
|
||||
QuotaManager& aQuotaManager) {
|
||||
AssertIsOnIOThread();
|
||||
|
||||
AUTO_PROFILER_LABEL("PersistentOriginInitializedOp::DoDirectoryWork", OTHER);
|
||||
|
||||
mInitialized = aQuotaManager.IsPersistentOriginInitializedInternal(
|
||||
OriginMetadata{mPrincipalMetadata, PERSISTENCE_TYPE_PERSISTENT});
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool PersistentOriginInitializedOp::GetResolveValue() {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
return mInitialized;
|
||||
}
|
||||
|
||||
TemporaryOriginInitializedOp::TemporaryOriginInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
PersistenceType aPersistenceType, const PrincipalInfo& aPrincipalInfo)
|
||||
: InitializedOriginRequestBase(std::move(aQuotaManager),
|
||||
"dom::quota::TemporaryOriginInitializedOp",
|
||||
aPrincipalInfo),
|
||||
mPersistenceType(aPersistenceType) {
|
||||
AssertIsOnOwningThread();
|
||||
}
|
||||
|
||||
nsresult TemporaryOriginInitializedOp::DoDirectoryWork(
|
||||
QuotaManager& aQuotaManager) {
|
||||
AssertIsOnIOThread();
|
||||
|
||||
AUTO_PROFILER_LABEL("TemporaryOriginInitializedOp::DoDirectoryWork", OTHER);
|
||||
|
||||
mInitialized = aQuotaManager.IsTemporaryOriginInitializedInternal(
|
||||
OriginMetadata{mPrincipalMetadata, mPersistenceType});
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool TemporaryOriginInitializedOp::GetResolveValue() {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
return mInitialized;
|
||||
}
|
||||
|
||||
InitOp::InitOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
RefPtr<UniversalDirectoryLock> aDirectoryLock)
|
||||
: ResolvableNormalOriginOp(std::move(aQuotaManager), "dom::quota::InitOp"),
|
||||
|
@ -72,6 +72,15 @@ RefPtr<ResolvableNormalOriginOp<bool>> CreateStorageInitializedOp(
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateTemporaryStorageInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager);
|
||||
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreatePersistentOriginInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
|
||||
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateTemporaryOriginInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
const PersistenceType aPersistenceType,
|
||||
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
|
||||
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateInitOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
RefPtr<UniversalDirectoryLock> aDirectoryLock);
|
||||
|
@ -128,6 +128,13 @@ parent:
|
||||
async TemporaryStorageInitialized()
|
||||
returns(BoolResponse response);
|
||||
|
||||
async PersistentOriginInitialized(PrincipalInfo principalInfo)
|
||||
returns(BoolResponse response);
|
||||
|
||||
async TemporaryOriginInitialized(PersistenceType persistenceType,
|
||||
PrincipalInfo principalInfo)
|
||||
returns(BoolResponse response);
|
||||
|
||||
async InitializeStorage()
|
||||
returns(BoolResponse response);
|
||||
|
||||
|
@ -372,6 +372,12 @@ class QuotaManager final : public BackgroundThreadObject {
|
||||
const PrincipalInfo& aPrincipalInfo,
|
||||
RefPtr<UniversalDirectoryLock> aDirectoryLock);
|
||||
|
||||
RefPtr<BoolPromise> PersistentOriginInitialized(
|
||||
const PrincipalInfo& aPrincipalInfo);
|
||||
|
||||
bool IsPersistentOriginInitializedInternal(
|
||||
const OriginMetadata& aOriginMetadata) const;
|
||||
|
||||
// Returns a pair of an nsIFile object referring to the directory, and a bool
|
||||
// indicating whether the directory was newly created.
|
||||
Result<std::pair<nsCOMPtr<nsIFile>, bool>, nsresult>
|
||||
@ -385,6 +391,9 @@ class QuotaManager final : public BackgroundThreadObject {
|
||||
PersistenceType aPersistenceType, const PrincipalInfo& aPrincipalInfo,
|
||||
RefPtr<UniversalDirectoryLock> aDirectoryLock);
|
||||
|
||||
RefPtr<BoolPromise> TemporaryOriginInitialized(
|
||||
PersistenceType aPersistenceType, const PrincipalInfo& aPrincipalInfo);
|
||||
|
||||
bool IsTemporaryOriginInitializedInternal(
|
||||
const OriginMetadata& aOriginMetadata) const;
|
||||
|
||||
|
@ -544,6 +544,93 @@ QuotaManagerService::TemporaryStorageInitialized(nsIQuotaRequest** _retval) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
QuotaManagerService::PersistentOriginInitialized(nsIPrincipal* aPrincipal,
|
||||
nsIQuotaRequest** _retval) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aPrincipal);
|
||||
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(StaticPrefs::dom_quotaManager_testing()),
|
||||
NS_ERROR_UNEXPECTED);
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(EnsureBackgroundActor()));
|
||||
|
||||
QM_TRY_INSPECT(
|
||||
const auto& principalInfo,
|
||||
([&aPrincipal]() -> Result<PrincipalInfo, nsresult> {
|
||||
PrincipalInfo principalInfo;
|
||||
QM_TRY(MOZ_TO_RESULT(
|
||||
PrincipalToPrincipalInfo(aPrincipal, &principalInfo)));
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(QuotaManager::IsPrincipalInfoValid(principalInfo)),
|
||||
Err(NS_ERROR_INVALID_ARG));
|
||||
|
||||
return principalInfo;
|
||||
}()));
|
||||
|
||||
RefPtr<Request> request = new Request();
|
||||
|
||||
mBackgroundActor->SendPersistentOriginInitialized(principalInfo)
|
||||
->Then(GetCurrentSerialEventTarget(), __func__,
|
||||
BoolResponsePromiseResolveOrRejectCallback(request));
|
||||
|
||||
request.forget(_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
QuotaManagerService::TemporaryOriginInitialized(
|
||||
const nsACString& aPersistenceType, nsIPrincipal* aPrincipal,
|
||||
nsIQuotaRequest** _retval) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aPrincipal);
|
||||
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(StaticPrefs::dom_quotaManager_testing()),
|
||||
NS_ERROR_UNEXPECTED);
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(EnsureBackgroundActor()));
|
||||
|
||||
QM_TRY_INSPECT(
|
||||
const auto& persistenceType,
|
||||
([&aPersistenceType]() -> Result<PersistenceType, nsresult> {
|
||||
const auto persistenceType =
|
||||
PersistenceTypeFromString(aPersistenceType, fallible);
|
||||
QM_TRY(MOZ_TO_RESULT(persistenceType.isSome()),
|
||||
Err(NS_ERROR_INVALID_ARG));
|
||||
|
||||
QM_TRY(
|
||||
MOZ_TO_RESULT(IsBestEffortPersistenceType(persistenceType.ref())),
|
||||
Err(NS_ERROR_INVALID_ARG));
|
||||
|
||||
return persistenceType.ref();
|
||||
}()));
|
||||
|
||||
QM_TRY_INSPECT(
|
||||
const auto& principalInfo,
|
||||
([&aPrincipal]() -> Result<PrincipalInfo, nsresult> {
|
||||
PrincipalInfo principalInfo;
|
||||
QM_TRY(MOZ_TO_RESULT(
|
||||
PrincipalToPrincipalInfo(aPrincipal, &principalInfo)));
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(QuotaManager::IsPrincipalInfoValid(principalInfo)),
|
||||
Err(NS_ERROR_INVALID_ARG));
|
||||
|
||||
return principalInfo;
|
||||
}()));
|
||||
|
||||
RefPtr<Request> request = new Request();
|
||||
|
||||
mBackgroundActor
|
||||
->SendTemporaryOriginInitialized(persistenceType, principalInfo)
|
||||
->Then(GetCurrentSerialEventTarget(), __func__,
|
||||
BoolResponsePromiseResolveOrRejectCallback(request));
|
||||
|
||||
request.forget(_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
QuotaManagerService::Init(nsIQuotaRequest** _retval) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
@ -344,6 +344,58 @@ mozilla::ipc::IPCResult Quota::RecvTemporaryStorageInitialized(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult Quota::RecvPersistentOriginInitialized(
|
||||
const PrincipalInfo& aPrincipalInfo,
|
||||
PersistentOriginInitializedResolver&& aResolve) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(!QuotaManager::IsShuttingDown()),
|
||||
ResolveBoolResponseAndReturn(aResolve));
|
||||
|
||||
if (!TrustParams()) {
|
||||
QM_TRY(MOZ_TO_RESULT(QuotaManager::IsPrincipalInfoValid(aPrincipalInfo)),
|
||||
QM_CUF_AND_IPC_FAIL(this));
|
||||
}
|
||||
|
||||
QM_TRY_UNWRAP(const NotNull<RefPtr<QuotaManager>> quotaManager,
|
||||
QuotaManager::GetOrCreate(),
|
||||
ResolveBoolResponseAndReturn(aResolve));
|
||||
|
||||
quotaManager->PersistentOriginInitialized(aPrincipalInfo)
|
||||
->Then(GetCurrentSerialEventTarget(), __func__,
|
||||
BoolPromiseResolveOrRejectCallback(this, std::move(aResolve)));
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult Quota::RecvTemporaryOriginInitialized(
|
||||
const PersistenceType& aPersistenceType,
|
||||
const PrincipalInfo& aPrincipalInfo,
|
||||
TemporaryOriginInitializedResolver&& aResolve) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(!QuotaManager::IsShuttingDown()),
|
||||
ResolveBoolResponseAndReturn(aResolve));
|
||||
|
||||
if (!TrustParams()) {
|
||||
QM_TRY(MOZ_TO_RESULT(IsValidPersistenceType(aPersistenceType)),
|
||||
QM_CUF_AND_IPC_FAIL(this));
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(QuotaManager::IsPrincipalInfoValid(aPrincipalInfo)),
|
||||
QM_CUF_AND_IPC_FAIL(this));
|
||||
}
|
||||
|
||||
QM_TRY_UNWRAP(const NotNull<RefPtr<QuotaManager>> quotaManager,
|
||||
QuotaManager::GetOrCreate(),
|
||||
ResolveBoolResponseAndReturn(aResolve));
|
||||
|
||||
quotaManager->TemporaryOriginInitialized(aPersistenceType, aPrincipalInfo)
|
||||
->Then(GetCurrentSerialEventTarget(), __func__,
|
||||
BoolPromiseResolveOrRejectCallback(this, std::move(aResolve)));
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult Quota::RecvInitializeStorage(
|
||||
InitializeStorageResolver&& aResolver) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
@ -46,6 +46,15 @@ class Quota final : public PQuotaParent {
|
||||
virtual mozilla::ipc::IPCResult RecvTemporaryStorageInitialized(
|
||||
TemporaryStorageInitializedResolver&& aResolver) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvPersistentOriginInitialized(
|
||||
const PrincipalInfo& aPrincipalInfo,
|
||||
PersistentOriginInitializedResolver&& aResolve) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvTemporaryOriginInitialized(
|
||||
const PersistenceType& aPersistenceType,
|
||||
const PrincipalInfo& aPrincipalInfo,
|
||||
TemporaryOriginInitializedResolver&& aResolve) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvInitializeStorage(
|
||||
InitializeStorageResolver&& aResolver) override;
|
||||
|
||||
|
@ -42,6 +42,34 @@ interface nsIQuotaManagerService : nsISupports
|
||||
[must_use] nsIQuotaRequest
|
||||
temporaryStorageInitialized();
|
||||
|
||||
/**
|
||||
* Check if persistent origin is initialized.
|
||||
*
|
||||
* If the dom.quotaManager.testing preference is not true the call will be
|
||||
* a no-op.
|
||||
*
|
||||
* @param aPrincipal
|
||||
* A principal for the persistent origin whose state is to be checked.
|
||||
*/
|
||||
[must_use] nsIQuotaRequest
|
||||
persistentOriginInitialized(in nsIPrincipal aPrincipal);
|
||||
|
||||
/**
|
||||
* Check if temporary origin is initialized.
|
||||
*
|
||||
* If the dom.quotaManager.testing preference is not true the call will be
|
||||
* a no-op.
|
||||
*
|
||||
* @param aPersistenceType
|
||||
* A string that tells what persistence type will be checked (either
|
||||
* "temporary" or "default").
|
||||
* @param aPrincipal
|
||||
* A principal for the temporary origin whose state is to be checked.
|
||||
*/
|
||||
[must_use] nsIQuotaRequest
|
||||
temporaryOriginInitialized(in ACString aPersistenceType,
|
||||
in nsIPrincipal aPrincipal);
|
||||
|
||||
/**
|
||||
* Initializes storage directory. This can be used in tests to verify
|
||||
* upgrade methods.
|
||||
|
@ -236,6 +236,47 @@ void QuotaManagerDependencyFixture::InitializeTemporaryOrigin(
|
||||
});
|
||||
}
|
||||
|
||||
// static
|
||||
void QuotaManagerDependencyFixture::TemporaryOriginInitialized(
|
||||
const OriginMetadata& aOriginMetadata, bool* aResult) {
|
||||
ASSERT_TRUE(aResult);
|
||||
|
||||
mozilla::ipc::PrincipalInfo principalInfo;
|
||||
ASSERT_NO_FATAL_FAILURE(
|
||||
CreateContentPrincipalInfo(aOriginMetadata.mOrigin, principalInfo));
|
||||
|
||||
PerformOnBackgroundThread([persistenceType = aOriginMetadata.mPersistenceType,
|
||||
principalInfo = std::move(principalInfo),
|
||||
aResult]() {
|
||||
QuotaManager* quotaManager = QuotaManager::Get();
|
||||
ASSERT_TRUE(quotaManager);
|
||||
|
||||
auto value = Await(quotaManager->TemporaryOriginInitialized(persistenceType,
|
||||
principalInfo));
|
||||
if (value.IsResolve()) {
|
||||
*aResult = value.ResolveValue();
|
||||
} else {
|
||||
*aResult = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// static
|
||||
void QuotaManagerDependencyFixture::AssertTemporaryOriginInitialized(
|
||||
const OriginMetadata& aOriginMetadata) {
|
||||
bool result;
|
||||
ASSERT_NO_FATAL_FAILURE(TemporaryOriginInitialized(aOriginMetadata, &result));
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
// static
|
||||
void QuotaManagerDependencyFixture::AssertTemporaryOriginNotInitialized(
|
||||
const OriginMetadata& aOriginMetadata) {
|
||||
bool result;
|
||||
ASSERT_NO_FATAL_FAILURE(TemporaryOriginInitialized(aOriginMetadata, &result));
|
||||
ASSERT_FALSE(result);
|
||||
}
|
||||
|
||||
// static
|
||||
void QuotaManagerDependencyFixture::GetOriginUsage(
|
||||
const OriginMetadata& aOriginMetadata, UsageInfo* aResult) {
|
||||
|
@ -46,6 +46,12 @@ class QuotaManagerDependencyFixture : public testing::Test {
|
||||
static void ShutdownTemporaryStorage();
|
||||
|
||||
static void InitializeTemporaryOrigin(const OriginMetadata& aOriginMetadata);
|
||||
static void TemporaryOriginInitialized(const OriginMetadata& aOriginMetadata,
|
||||
bool* aResult);
|
||||
static void AssertTemporaryOriginInitialized(
|
||||
const OriginMetadata& aOriginMetadata);
|
||||
static void AssertTemporaryOriginNotInitialized(
|
||||
const OriginMetadata& aOriginMetadata);
|
||||
static void GetOriginUsage(const OriginMetadata& aOriginMetadata,
|
||||
UsageInfo* aResult);
|
||||
static void GetCachedOriginUsage(const OriginMetadata& aOriginMetadata,
|
||||
|
@ -138,6 +138,24 @@ function temporaryStorageInitialized(callback) {
|
||||
return request;
|
||||
}
|
||||
|
||||
function persistentOriginInitialized(principal, callback) {
|
||||
let request =
|
||||
SpecialPowers._getQuotaManager().persistentOriginInitialized(principal);
|
||||
request.callback = callback;
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
function temporaryOriginInitialized(persistence, principal, callback) {
|
||||
let request = SpecialPowers._getQuotaManager().temporaryOriginInitialized(
|
||||
persistence,
|
||||
principal
|
||||
);
|
||||
request.callback = callback;
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
function init(callback) {
|
||||
let request = SpecialPowers._getQuotaManager().init();
|
||||
request.callback = callback;
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
async function testSteps() {
|
||||
const clientMetadata = {
|
||||
persistence: "default",
|
||||
principal: getPrincipal("https://foo.example.com"),
|
||||
client: "sdb",
|
||||
file: getRelativeFile("storage/permanent/https+++foo.example.com/sdb"),
|
||||
|
43
dom/quota/test/xpcshell/test_initializePersistentOrigin.js
Normal file
43
dom/quota/test/xpcshell/test_initializePersistentOrigin.js
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
/**
|
||||
* This test is mainly to verify that initializePersistentOrigin() does call
|
||||
* QuotaManager::EnsurePersistentOriginIsInitialized() which ensures origin
|
||||
* directory existence.
|
||||
*/
|
||||
|
||||
async function testSteps() {
|
||||
const originMetadata = {
|
||||
principal: getPrincipal("https://foo.example.com"),
|
||||
file: getRelativeFile("storage/permanent/https+++foo.example.com"),
|
||||
};
|
||||
|
||||
info("Clearing");
|
||||
|
||||
let request = clear();
|
||||
await requestFinished(request);
|
||||
|
||||
info("Initializing");
|
||||
|
||||
request = init();
|
||||
await requestFinished(request);
|
||||
|
||||
info("Initializing persistent origin");
|
||||
|
||||
ok(!originMetadata.file.exists(), "Origin directory does not exist");
|
||||
|
||||
request = initPersistentOrigin(originMetadata.principal);
|
||||
await requestFinished(request);
|
||||
|
||||
ok(originMetadata.file.exists(), "Origin directory does exist");
|
||||
|
||||
info("Verifying persistent origin initialization status");
|
||||
|
||||
request = persistentOriginInitialized(originMetadata.principal);
|
||||
await requestFinished(request);
|
||||
|
||||
ok(request.result, "Persistent origin is initialized");
|
||||
}
|
55
dom/quota/test/xpcshell/test_initializeTemporaryOrigin.js
Normal file
55
dom/quota/test/xpcshell/test_initializeTemporaryOrigin.js
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
/**
|
||||
* This test is mainly to verify that initializeTemporaryOrigin() does call
|
||||
* QuotaManager::EnsureTemporaryOriginIsInitialized() which ensures origin
|
||||
* directory existence.
|
||||
*/
|
||||
|
||||
async function testSteps() {
|
||||
const originMetadata = {
|
||||
persistence: "default",
|
||||
principal: getPrincipal("https://foo.example.com"),
|
||||
file: getRelativeFile("storage/default/https+++foo.example.com"),
|
||||
};
|
||||
|
||||
info("Clearing");
|
||||
|
||||
let request = clear();
|
||||
await requestFinished(request);
|
||||
|
||||
info("Initializing");
|
||||
|
||||
request = init();
|
||||
await requestFinished(request);
|
||||
|
||||
info("Initializing temporary storage");
|
||||
|
||||
request = initTemporaryStorage();
|
||||
await requestFinished(request);
|
||||
|
||||
info("Initializing temporary origin");
|
||||
|
||||
ok(!originMetadata.file.exists(), "Origin directory does not exist");
|
||||
|
||||
request = initTemporaryOrigin(
|
||||
originMetadata.persistence,
|
||||
originMetadata.principal
|
||||
);
|
||||
await requestFinished(request);
|
||||
|
||||
ok(originMetadata.file.exists(), "Origin directory does exist");
|
||||
|
||||
info("Verifying temporary origin initialization status");
|
||||
|
||||
request = temporaryOriginInitialized(
|
||||
originMetadata.persistence,
|
||||
originMetadata.principal
|
||||
);
|
||||
await requestFinished(request);
|
||||
|
||||
ok(request.result, "Temporary origin is initialized");
|
||||
}
|
@ -79,8 +79,12 @@ skip-if = ["condprof"] # frequent perma fail, then goes away.
|
||||
|
||||
["test_initializePersistentClient.js"]
|
||||
|
||||
["test_initializePersistentOrigin.js"]
|
||||
|
||||
["test_initializeTemporaryClient.js"]
|
||||
|
||||
["test_initializeTemporaryOrigin.js"]
|
||||
|
||||
["test_listOrigins.js"]
|
||||
|
||||
["test_originEndsWithDot.js"]
|
||||
|
Loading…
Reference in New Issue
Block a user