Add spec for app.enableMixedSandbox()
This commit is contained in:
parent
1258240067
commit
7fcc00f137
4 changed files with 58 additions and 38 deletions
|
@ -1034,23 +1034,21 @@ void App::EnableMixedSandbox(mate::Arguments* args) {
|
|||
"before app is ready");
|
||||
return;
|
||||
}
|
||||
|
||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||
if (command_line->HasSwitch(::switches::kNoSandbox)) {
|
||||
// Remove the --no-sandbox switch
|
||||
using StringType = base::CommandLine::StringType;
|
||||
using StringVector = base::CommandLine::StringVector;
|
||||
using CharType = base::CommandLine::CharType;
|
||||
auto argv = command_line->argv();
|
||||
StringVector modified_command_line;
|
||||
#if defined(OS_WIN)
|
||||
const CharType* kNoSandboxArg = L"--no-sandbox";
|
||||
#else
|
||||
const CharType* kNoSandboxArg = "--no-sandbox";
|
||||
#endif
|
||||
#if defined(OS_WIN)
|
||||
const base::CommandLine::CharType* noSandboxArg = L"--no-sandbox";
|
||||
#else
|
||||
const base::CommandLine::CharType* noSandboxArg = "--no-sandbox";
|
||||
#endif
|
||||
|
||||
for (const StringType& arg : argv) {
|
||||
if (arg.compare(kNoSandboxArg) != 0)
|
||||
modified_command_line.push_back(arg);
|
||||
// Remove the --no-sandbox switch
|
||||
base::CommandLine::StringVector modified_command_line;
|
||||
for (auto& arg : command_line->argv()) {
|
||||
if (arg.compare(noSandboxArg) != 0) {
|
||||
modified_command_line.push_back(arg);
|
||||
}
|
||||
}
|
||||
command_line->InitFromArgv(modified_command_line);
|
||||
}
|
||||
|
|
|
@ -566,4 +566,46 @@ describe('app module', function () {
|
|||
assert.equal(typeof features.gpu_compositing, 'string')
|
||||
})
|
||||
})
|
||||
|
||||
describe('mixed sandbox option', function () {
|
||||
let appProcess
|
||||
|
||||
afterEach(function () {
|
||||
if (appProcess != null) {
|
||||
appProcess.kill()
|
||||
}
|
||||
})
|
||||
|
||||
describe('when app.enableMixedSandbox() is called', () => {
|
||||
it('adds --enable-sandbox to render processes created with sandbox: true', (done) => {
|
||||
const appPath = path.join(__dirname, 'fixtures', 'api', 'mixed-sandbox-app')
|
||||
appProcess = ChildProcess.spawn(remote.process.execPath, [appPath], {stdio: ['ignore', 'ipc', 'ignore']})
|
||||
appProcess.once('message', (argv) => {
|
||||
assert.equal(argv.sandbox.includes('--enable-sandbox'), true)
|
||||
assert.equal(argv.sandbox.includes('--no-sandbox'), false)
|
||||
|
||||
assert.equal(argv.noSandbox.includes('--enable-sandbox'), false)
|
||||
assert.equal(argv.noSandbox.includes('--no-sandbox'), true)
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the app is launched with --enable-mixed-sandbox', () => {
|
||||
it('adds --enable-sandbox to render processes created with sandbox: true', (done) => {
|
||||
const appPath = path.join(__dirname, 'fixtures', 'api', 'mixed-sandbox-app')
|
||||
appProcess = ChildProcess.spawn(remote.process.execPath, [appPath, '--enable-mixed-sandbox'], {stdio: ['ignore', 'ipc', 'ignore']})
|
||||
appProcess.once('message', (argv) => {
|
||||
assert.equal(argv.sandbox.includes('--enable-sandbox'), true)
|
||||
assert.equal(argv.sandbox.includes('--no-sandbox'), false)
|
||||
|
||||
assert.equal(argv.noSandbox.includes('--enable-sandbox'), false)
|
||||
assert.equal(argv.noSandbox.includes('--no-sandbox'), true)
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1260,30 +1260,6 @@ describe('BrowserWindow module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('mixed sandbox option', function () {
|
||||
let appProcess
|
||||
|
||||
afterEach(function () {
|
||||
if (appProcess != null) {
|
||||
appProcess.kill()
|
||||
}
|
||||
})
|
||||
|
||||
it('adds --enable-sandbox to render processes created with sandbox: true', (done) => {
|
||||
const appPath = path.join(__dirname, 'fixtures', 'api', 'mixed-sandbox-app')
|
||||
appProcess = ChildProcess.spawn(remote.process.execPath, [appPath, '--enable-mixed-sandbox'], {stdio: ['ignore', 'ipc', 'ignore']})
|
||||
appProcess.once('message', (argv) => {
|
||||
assert.equal(argv.sandbox.includes('--enable-sandbox'), true)
|
||||
assert.equal(argv.sandbox.includes('--no-sandbox'), false)
|
||||
|
||||
assert.equal(argv.noSandbox.includes('--enable-sandbox'), false)
|
||||
assert.equal(argv.noSandbox.includes('--no-sandbox'), true)
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('nativeWindowOpen option', () => {
|
||||
beforeEach(() => {
|
||||
w.destroy()
|
||||
|
|
4
spec/fixtures/api/mixed-sandbox-app/main.js
vendored
4
spec/fixtures/api/mixed-sandbox-app/main.js
vendored
|
@ -5,6 +5,10 @@ process.on('uncaughtException', () => {
|
|||
app.exit(1)
|
||||
})
|
||||
|
||||
if (!process.argv.includes('--enable-mixed-sandbox')) {
|
||||
app.enableMixedSandbox()
|
||||
}
|
||||
|
||||
let sandboxWindow
|
||||
let noSandboxWindow
|
||||
|
||||
|
|
Loading…
Reference in a new issue