Bug 1753424 - Update SandboxTest code with sandboxingKind r=jld

Differential Revision: https://phabricator.services.mozilla.com/D140744
This commit is contained in:
Alexandre Lissy 2022-03-26 09:53:46 +00:00
Родитель d8a614f619
Коммит 4885ddade7
5 изменённых файлов: 50 добавлений и 12 удалений

Просмотреть файл

@ -107,9 +107,41 @@ SandboxTest::StartTests(const nsTArray<nsCString>& aProcessesList) {
#endif
for (const auto& processTypeName : aProcessesList) {
GeckoProcessType type = GeckoProcessStringToType(processTypeName);
if (type == GeckoProcessType::GeckoProcessType_Invalid) {
return NS_ERROR_ILLEGAL_VALUE;
SandboxingKind sandboxingKind = SandboxingKind::COUNT;
GeckoProcessType type = GeckoProcessType::GeckoProcessType_Invalid;
if (processTypeName.Find(":") != kNotFound) {
int32_t pos = processTypeName.Find(":");
nsCString processType = nsCString(Substring(processTypeName, 0, pos));
nsCString sandboxKindStr = nsCString(
Substring(processTypeName, pos + 1, processTypeName.Length()));
nsresult err;
uint64_t sbVal = (uint64_t)(sandboxKindStr.ToDouble(&err));
if (NS_FAILED(err)) {
NS_WARNING("Unable to get SandboxingKind");
return NS_ERROR_ILLEGAL_VALUE;
}
if (sbVal >= SandboxingKind::COUNT || sbVal < GENERIC_UTILITY) {
NS_WARNING("Invalid sandboxing kind");
return NS_ERROR_ILLEGAL_VALUE;
}
if (!processType.Equals(
XRE_GeckoProcessTypeToString(GeckoProcessType_Utility))) {
NS_WARNING("Expected utility process type");
return NS_ERROR_ILLEGAL_VALUE;
}
sandboxingKind = (SandboxingKind)sbVal;
type = GeckoProcessType_Utility;
} else {
type = GeckoProcessStringToType(processTypeName);
if (type == GeckoProcessType::GeckoProcessType_Invalid) {
NS_WARNING("Invalid process type");
return NS_ERROR_ILLEGAL_VALUE;
}
}
RefPtr<ProcessPromise::Private> processPromise =
@ -223,7 +255,7 @@ SandboxTest::StartTests(const nsTArray<nsCString>& aProcessesList) {
case GeckoProcessType_Utility: {
RefPtr<UtilityProcessManager> utilityProc =
UtilityProcessManager::GetSingleton();
utilityProc->LaunchProcess(SandboxingKind::GENERIC_UTILITY)
utilityProc->LaunchProcess(sandboxingKind)
->Then(
GetMainThreadSerialEventTarget(), __func__,
[processPromise, utilityProc]() {
@ -253,8 +285,8 @@ SandboxTest::StartTests(const nsTArray<nsCString>& aProcessesList) {
RefPtr<ProcessPromise> aPromise(processPromise);
aPromise->Then(
GetMainThreadSerialEventTarget(), __func__,
[self, type](SandboxTestingParent* aValue) {
self->mSandboxTestingParents[type] = std::move(aValue);
[self](SandboxTestingParent* aValue) {
self->mSandboxTestingParents.AppendElement(aValue);
return NS_OK;
},
[](nsresult aError) {
@ -299,6 +331,9 @@ SandboxTest::FinishTests() {
SandboxTestingParent::Destroy(stp);
}
// Make sure there is no leftover for test --verify to run without failure
mSandboxTestingParents.Clear();
#if defined(XP_WIN)
nsCOMPtr<nsIFile> testFile;
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(testFile));

Просмотреть файл

@ -11,6 +11,7 @@
#include "mozilla/GfxMessageUtils.h"
#include "mozilla/MozPromise.h"
#include "GMPService.h"
#include "nsTArray.h"
#if !defined(MOZ_DEBUG) || !defined(ENABLE_TESTS)
# error "This file should not be used outside of debug with tests"
@ -32,9 +33,7 @@ class SandboxTest : public mozISandboxTest {
private:
virtual ~SandboxTest() = default;
static constexpr size_t NumProcessTypes =
static_cast<size_t>(GeckoProcessType_End);
SandboxTestingParent* mSandboxTestingParents[NumProcessTypes];
nsTArray<SandboxTestingParent*> mSandboxTestingParents;
RefPtr<gmp::GMPContentParent::CloseBlocker> mGMPContentParentWrapper;
#if defined(XP_WIN)
bool mChromeDirExisted = false;

Просмотреть файл

@ -86,7 +86,7 @@ void SandboxTestingChild::Bind(Endpoint<PSandboxTestingChild>&& aEndpoint) {
MOZ_ASSERT(s, "Unable to grab a UtilityProcessChild");
switch (s->mSandbox) {
case ipc::SandboxingKind::GENERIC_UTILITY:
RunTestsUtility(this);
RunTestsGenericUtility(this);
break;
default:

Просмотреть файл

@ -580,7 +580,7 @@ void RunTestsGMPlugin(SandboxTestingChild* child) {
#endif
}
void RunTestsUtility(SandboxTestingChild* child) {
void RunTestsGenericUtility(SandboxTestingChild* child) {
MOZ_ASSERT(child, "No SandboxTestingChild*?");
#ifdef XP_UNIX

Просмотреть файл

@ -14,7 +14,11 @@ function test() {
// GPU process might not run depending on the platform, so we need it to be
// the last one of the list to allow the remainingTests logic below to work
// as expected.
var processTypes = ["tab", "socket", "rdd", "gmplugin", "utility", "gpu"];
//
// For UtilityProcess, allow constructing a string made of the process type
// and the sandbox variant we want to test, e.g.,
// utility:0 for GENERIC_UTILITY
var processTypes = ["tab", "socket", "rdd", "gmplugin", "utility:0", "gpu"];
// A callback called after each test-result.
let sandboxTestResult = (subject, topic, data) => {