Add spec for app.enableMixedSandbox()
This commit is contained in:
parent
1258240067
commit
7fcc00f137
4 changed files with 58 additions and 38 deletions
|
@ -1034,24 +1034,22 @@ void App::EnableMixedSandbox(mate::Arguments* args) {
|
||||||
"before app is ready");
|
"before app is ready");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||||
if (command_line->HasSwitch(::switches::kNoSandbox)) {
|
if (command_line->HasSwitch(::switches::kNoSandbox)) {
|
||||||
// Remove the --no-sandbox switch
|
#if defined(OS_WIN)
|
||||||
using StringType = base::CommandLine::StringType;
|
const base::CommandLine::CharType* noSandboxArg = L"--no-sandbox";
|
||||||
using StringVector = base::CommandLine::StringVector;
|
#else
|
||||||
using CharType = base::CommandLine::CharType;
|
const base::CommandLine::CharType* noSandboxArg = "--no-sandbox";
|
||||||
auto argv = command_line->argv();
|
#endif
|
||||||
StringVector modified_command_line;
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
const CharType* kNoSandboxArg = L"--no-sandbox";
|
|
||||||
#else
|
|
||||||
const CharType* kNoSandboxArg = "--no-sandbox";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (const StringType& arg : argv) {
|
// Remove the --no-sandbox switch
|
||||||
if (arg.compare(kNoSandboxArg) != 0)
|
base::CommandLine::StringVector modified_command_line;
|
||||||
|
for (auto& arg : command_line->argv()) {
|
||||||
|
if (arg.compare(noSandboxArg) != 0) {
|
||||||
modified_command_line.push_back(arg);
|
modified_command_line.push_back(arg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
command_line->InitFromArgv(modified_command_line);
|
command_line->InitFromArgv(modified_command_line);
|
||||||
}
|
}
|
||||||
command_line->AppendSwitch(switches::kEnableMixedSandbox);
|
command_line->AppendSwitch(switches::kEnableMixedSandbox);
|
||||||
|
|
|
@ -566,4 +566,46 @@ describe('app module', function () {
|
||||||
assert.equal(typeof features.gpu_compositing, 'string')
|
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', () => {
|
describe('nativeWindowOpen option', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
w.destroy()
|
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)
|
app.exit(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!process.argv.includes('--enable-mixed-sandbox')) {
|
||||||
|
app.enableMixedSandbox()
|
||||||
|
}
|
||||||
|
|
||||||
let sandboxWindow
|
let sandboxWindow
|
||||||
let noSandboxWindow
|
let noSandboxWindow
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue