зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1495687 - Introduce initTemporaryStorage to nsIQuotaManagerService for testing; r=janv
--HG-- extra : rebase_source : c38521eaf9f9c204971049b959efc5113ae86baa
This commit is contained in:
Родитель
7d4004ada1
Коммит
8e0aa26fa8
|
@ -316,6 +316,7 @@ QuotaRequestChild::Recv__delete__(const RequestResponse& aResponse)
|
|||
break;
|
||||
|
||||
case RequestResponse::TInitResponse:
|
||||
case RequestResponse::TInitTemporaryStorageResponse:
|
||||
case RequestResponse::TClearOriginResponse:
|
||||
case RequestResponse::TClearDataResponse:
|
||||
case RequestResponse::TClearAllResponse:
|
||||
|
|
|
@ -1229,6 +1229,27 @@ private:
|
|||
GetResponse(RequestResponse& aResponse) override;
|
||||
};
|
||||
|
||||
class InitTemporaryStorageOp final
|
||||
: public QuotaRequestBase
|
||||
{
|
||||
public:
|
||||
InitTemporaryStorageOp()
|
||||
: QuotaRequestBase(/* aExclusive */ false)
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
}
|
||||
|
||||
private:
|
||||
~InitTemporaryStorageOp()
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
DoDirectoryWork(QuotaManager* aQuotaManager) override;
|
||||
|
||||
void
|
||||
GetResponse(RequestResponse& aResponse) override;
|
||||
};
|
||||
|
||||
class InitOriginOp final
|
||||
: public QuotaRequestBase
|
||||
{
|
||||
|
@ -6765,6 +6786,10 @@ Quota::AllocPQuotaRequestParent(const RequestParams& aParams)
|
|||
actor = new InitOp();
|
||||
break;
|
||||
|
||||
case RequestParams::TInitTemporaryStorageParams:
|
||||
actor = new InitTemporaryStorageOp();
|
||||
break;
|
||||
|
||||
case RequestParams::TInitOriginParams:
|
||||
actor = new InitOriginOp(aParams);
|
||||
break;
|
||||
|
@ -7407,6 +7432,31 @@ InitOp::GetResponse(RequestResponse& aResponse)
|
|||
aResponse = InitResponse();
|
||||
}
|
||||
|
||||
nsresult
|
||||
InitTemporaryStorageOp::DoDirectoryWork(QuotaManager* aQuotaManager)
|
||||
{
|
||||
AssertIsOnIOThread();
|
||||
|
||||
AUTO_PROFILER_LABEL("InitTemporaryStorageOp::DoDirectoryWork", OTHER);
|
||||
|
||||
aQuotaManager->AssertStorageIsInitialized();
|
||||
|
||||
nsresult rv = aQuotaManager->EnsureTemporaryStorageIsInitialized();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
InitTemporaryStorageOp::GetResponse(RequestResponse& aResponse)
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
aResponse = InitTemporaryStorageResponse();
|
||||
}
|
||||
|
||||
InitOriginOp::InitOriginOp(const RequestParams& aParams)
|
||||
: QuotaRequestBase(/* aExclusive */ false)
|
||||
, mParams(aParams.get_InitOriginParams())
|
||||
|
|
|
@ -21,6 +21,10 @@ struct InitParams
|
|||
{
|
||||
};
|
||||
|
||||
struct InitTemporaryStorageParams
|
||||
{
|
||||
};
|
||||
|
||||
struct InitOriginParams
|
||||
{
|
||||
PrincipalInfo principalInfo;
|
||||
|
@ -78,6 +82,7 @@ struct PersistParams
|
|||
union RequestParams
|
||||
{
|
||||
InitParams;
|
||||
InitTemporaryStorageParams;
|
||||
InitOriginParams;
|
||||
ClearOriginParams;
|
||||
ClearDataParams;
|
||||
|
|
|
@ -12,6 +12,10 @@ struct InitResponse
|
|||
{
|
||||
};
|
||||
|
||||
struct InitTemporaryStorageResponse
|
||||
{
|
||||
};
|
||||
|
||||
struct InitOriginResponse
|
||||
{
|
||||
bool created;
|
||||
|
@ -46,6 +50,7 @@ union RequestResponse
|
|||
{
|
||||
nsresult;
|
||||
InitResponse;
|
||||
InitTemporaryStorageResponse;
|
||||
InitOriginResponse;
|
||||
ClearOriginResponse;
|
||||
ClearDataResponse;
|
||||
|
|
|
@ -458,6 +458,31 @@ QuotaManagerService::Init(nsIQuotaRequest** _retval)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
QuotaManagerService::InitTemporaryStorage(nsIQuotaRequest** _retval)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
|
||||
|
||||
if (NS_WARN_IF(!gTestingMode)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
RefPtr<Request> request = new Request();
|
||||
|
||||
InitTemporaryStorageParams params;
|
||||
|
||||
nsAutoPtr<PendingRequestInfo> info(new RequestInfo(request, params));
|
||||
|
||||
nsresult rv = InitiateRequest(info);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
request.forget(_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
QuotaManagerService::InitStoragesForPrincipal(
|
||||
nsIPrincipal* aPrincipal,
|
||||
|
|
|
@ -24,6 +24,16 @@ interface nsIQuotaManagerService : nsISupports
|
|||
[must_use] nsIQuotaRequest
|
||||
init();
|
||||
|
||||
/**
|
||||
* Initializes temporary storage. This can be used in tests to verify
|
||||
* temporary storage initialization.
|
||||
*
|
||||
* If the dom.quotaManager.testing preference is not true the call will be
|
||||
* a no-op.
|
||||
*/
|
||||
[must_use] nsIQuotaRequest
|
||||
initTemporaryStorage();
|
||||
|
||||
/**
|
||||
* Initializes storages for the given principal. This can be used in tests to
|
||||
* verify origin initialization.
|
||||
|
|
|
@ -116,6 +116,14 @@ function init(callback)
|
|||
return request;
|
||||
}
|
||||
|
||||
function initTemporaryStorage(callback)
|
||||
{
|
||||
let request = SpecialPowers._getQuotaManager().initTemporaryStorage();
|
||||
request.callback = callback;
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
function initOrigin(principal, persistence, callback)
|
||||
{
|
||||
let request =
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
/**
|
||||
* This test is mainly to verify initTemporaryStorage() does call
|
||||
* QuotaManager::EnsureTemporaryStorageIsInitialized() which does various
|
||||
* things, for example, it restores the directory metadata if it's broken or
|
||||
* missing.
|
||||
*/
|
||||
|
||||
async function testSteps()
|
||||
{
|
||||
const originDirPath = "storage/default/https+++foo.example.com";
|
||||
const metadataFileName = ".metadata-v2";
|
||||
|
||||
info("Creating an empty directory");
|
||||
|
||||
let originDir = getRelativeFile(originDirPath);
|
||||
originDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
|
||||
|
||||
info("Initializing the temporary storage");
|
||||
|
||||
let request = initTemporaryStorage();
|
||||
await requestFinished(request);
|
||||
|
||||
info("Verifying directory metadata was restored after calling " +
|
||||
"initTemporaryStorage()");
|
||||
|
||||
let metadataFile = originDir.clone();
|
||||
metadataFile.append(metadataFileName);
|
||||
|
||||
ok(metadataFile.exists(), "Directory metadata file does exist");
|
||||
}
|
|
@ -25,6 +25,7 @@ support-files =
|
|||
[test_defaultStorageUpgrade.js]
|
||||
[test_getUsage.js]
|
||||
[test_idbSubdirUpgrade.js]
|
||||
[test_initTemporaryStorage.js]
|
||||
[test_morgueCleanup.js]
|
||||
[test_obsoleteOriginAttributesUpgrade.js]
|
||||
[test_originAttributesUpgrade.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче