electron/spec/node-spec.js

645 lines
21 KiB
JavaScript
Raw Normal View History

2016-06-29 16:37:10 +00:00
const ChildProcess = require('child_process')
const chai = require('chai')
const { expect } = chai
const dirtyChai = require('dirty-chai')
2016-03-25 20:03:49 +00:00
const fs = require('fs')
const path = require('path')
const os = require('os')
2018-09-13 16:10:51 +00:00
const { ipcRenderer, remote } = require('electron')
const features = process.electronBinding('features')
2016-03-25 20:03:49 +00:00
const { emittedOnce } = require('./events-helpers')
2016-06-20 02:16:17 +00:00
const isCI = remote.getGlobal('isCi')
chai.use(dirtyChai)
2016-06-20 02:16:17 +00:00
describe('node feature', () => {
const fixtures = path.join(__dirname, 'fixtures')
describe('child_process', () => {
beforeEach(function () {
if (!features.isRunAsNodeEnabled()) {
this.skip()
}
})
2018-06-18 03:09:51 +00:00
describe('child_process.fork', () => {
it('works in current process', (done) => {
const child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js'))
child.on('message', msg => {
expect(msg).to.equal('message')
2016-03-25 20:03:49 +00:00
done()
})
child.send('message')
})
it('preserves args', (done) => {
const args = ['--expose_gc', '-test', '1']
const child = ChildProcess.fork(path.join(fixtures, 'module', 'process_args.js'), args)
child.on('message', (msg) => {
expect(args).to.deep.equal(msg.slice(2))
2016-03-25 20:03:49 +00:00
done()
})
child.send('message')
})
it('works in forked process', (done) => {
const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'))
child.on('message', (msg) => {
expect(msg).to.equal('message')
2016-03-25 20:03:49 +00:00
done()
})
child.send('message')
})
it('works in forked process when options.env is specifed', (done) => {
const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
2016-01-12 02:40:23 +00:00
path: process.env['PATH']
2016-03-25 20:03:49 +00:00
})
child.on('message', (msg) => {
expect(msg).to.equal('message')
2016-03-25 20:03:49 +00:00
done()
})
child.send('message')
})
it('works in browser process', (done) => {
const fork = remote.require('child_process').fork
const child = fork(path.join(fixtures, 'module', 'ping.js'))
child.on('message', (msg) => {
expect(msg).to.equal('message')
2016-03-25 20:03:49 +00:00
done()
})
child.send('message')
})
it('has String::localeCompare working in script', (done) => {
const child = ChildProcess.fork(path.join(fixtures, 'module', 'locale-compare.js'))
child.on('message', (msg) => {
expect(msg).to.deep.equal([0, -1, 1])
2016-03-25 20:03:49 +00:00
done()
})
child.send('message')
})
it('has setImmediate working in script', (done) => {
const child = ChildProcess.fork(path.join(fixtures, 'module', 'set-immediate.js'))
child.on('message', (msg) => {
expect(msg).to.equal('ok')
2016-03-25 20:03:49 +00:00
done()
})
child.send('message')
})
it('pipes stdio', (done) => {
2018-09-13 16:10:51 +00:00
const child = ChildProcess.fork(path.join(fixtures, 'module', 'process-stdout.js'), { silent: true })
let data = ''
child.stdout.on('data', (chunk) => {
data += String(chunk)
})
child.on('close', (code) => {
expect(code).to.equal(0)
expect(data).to.equal('pipes stdio')
done()
})
})
it('works when sending a message to a process forked with the --eval argument', (done) => {
2017-04-06 16:52:52 +00:00
const source = "process.on('message', (message) => { process.send(message) })"
const forked = ChildProcess.fork('--eval', [source])
2017-04-06 16:52:52 +00:00
forked.once('message', (message) => {
expect(message).to.equal('hello')
done()
})
forked.send('hello')
})
it('has the electron version in process.versions', (done) => {
const source = 'process.send(process.versions)'
const forked = ChildProcess.fork('--eval', [source])
forked.on('message', (message) => {
expect(message)
.to.have.own.property('electron')
.that.is.a('string')
.and.matches(/^\d+\.\d+\.\d+(\S*)?$/)
done()
})
})
2016-03-25 20:03:49 +00:00
})
describe('child_process.spawn', () => {
let child
afterEach(() => {
if (child != null) child.kill()
})
it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', (done) => {
child = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
env: {
ELECTRON_RUN_AS_NODE: true
}
})
let output = ''
child.stdout.on('data', data => {
output += data
})
child.stdout.on('close', () => {
expect(JSON.parse(output)).to.deep.equal({
processLog: process.platform === 'win32' ? 'function' : 'undefined',
processType: 'undefined',
window: 'undefined'
})
done()
})
})
})
describe('child_process.exec', () => {
(process.platform === 'linux' ? it : it.skip)('allows executing a setuid binary from non-sandboxed renderer', () => {
// Chrome uses prctl(2) to set the NO_NEW_PRIVILEGES flag on Linux (see
// https://github.com/torvalds/linux/blob/40fde647cc/Documentation/userspace-api/no_new_privs.rst).
// We disable this for unsandboxed processes, which the remote tests
// are running in. If this test fails with an error like 'effective uid
// is not 0', then it's likely that our patch to prevent the flag from
// being set has become ineffective.
const stdout = ChildProcess.execSync('sudo --help')
expect(stdout).to.not.be.empty()
})
})
2016-03-25 20:03:49 +00:00
})
describe('contexts', () => {
describe('setTimeout in fs callback', () => {
it('does not crash', (done) => {
fs.readFile(__filename, () => {
2016-03-25 20:03:49 +00:00
setTimeout(done, 0)
})
})
})
describe('error thrown in renderer process node context', () => {
it('gets emitted as a process uncaughtException event', (done) => {
const error = new Error('boo!')
const listeners = process.listeners('uncaughtException')
2016-03-25 20:03:49 +00:00
process.removeAllListeners('uncaughtException')
process.on('uncaughtException', (thrown) => {
try {
expect(thrown).to.equal(error)
done()
} catch (e) {
done(e)
} finally {
process.removeAllListeners('uncaughtException')
listeners.forEach((listener) => process.on('uncaughtException', listener))
}
2016-03-25 20:03:49 +00:00
})
fs.readFile(__filename, () => {
2016-03-25 20:03:49 +00:00
throw error
})
})
})
describe('error thrown in main process node context', () => {
it('gets emitted as a process uncaughtException event', () => {
const error = ipcRenderer.sendSync('handle-uncaught-exception', 'hello')
expect(error).to.equal('hello')
})
})
describe('promise rejection in main process node context', () => {
it('gets emitted as a process unhandledRejection event', () => {
const error = ipcRenderer.sendSync('handle-unhandled-rejection', 'hello')
expect(error).to.equal('hello')
})
})
describe('setTimeout called under Chromium event loop in browser process', () => {
it('can be scheduled in time', (done) => {
2016-03-25 20:03:49 +00:00
remote.getGlobal('setTimeout')(done, 0)
})
it('can be promisified', (done) => {
remote.getGlobal('setTimeoutPromisified')(0).then(done)
})
2016-03-25 20:03:49 +00:00
})
describe('setTimeout called under blink env in renderer process', () => {
it('can be scheduled in time', (done) => {
setTimeout(done, 10)
})
it('works from the timers module', (done) => {
require('timers').setTimeout(done, 10)
})
})
describe('setInterval called under Chromium event loop in browser process', () => {
it('can be scheduled in time', (done) => {
Fix some flaky tests in CI (#12153) * Guard whole InitPrefs with ScopedAllowIO Saw a crash: 0 0x7f8d2f7d918d base::debug::StackTrace::StackTrace() 1 0x7f8d2f7d755c base::debug::StackTrace::StackTrace() 2 0x7f8d2f867caa logging::LogMessage::~LogMessage() 3 0x7f8d2fa157c7 base::ThreadRestrictions::AssertIOAllowed() 4 0x7f8d2f83453a base::OpenFile() 5 0x7f8d2f82a967 base::ReadFileToStringWithMaxSize() 6 0x7f8d2f82ad44 base::ReadFileToString() 7 0x7f8d2f846f73 JSONFileValueDeserializer::ReadFileToString() 8 0x7f8d2f84738c JSONFileValueDeserializer::Deserialize() 9 0x7f8d35a5d1f6 <unknown> 10 0x7f8d35a5c217 JsonPrefStore::ReadPrefs() 11 0x7f8d35a87d3e PrefService::InitFromStorage() 12 0x7f8d35a87c60 PrefService::PrefService() 13 0x7f8d35a91a10 PrefServiceFactory::Create() 14 0x000000e86e1b brightray::BrowserContext::InitPrefs() 15 0x000000c2bd64 atom::AtomBrowserContext::AtomBrowserContext() 16 0x000000c320db atom::AtomBrowserContext::From() 17 0x000000b4b8b5 atom::api::Session::FromPartition() * Fix done being called twice in setInterval test The callback passed to browser process is called asyncly, so it is possible that multiple callbacks has already been scheduled before we can clearInternval. * Fix failing test when dir name has special chars The pdfSource is not escaped while parsedURL.search is. * Call done with Error instead of string * Fix crash caused by not removing input observer Solve crash: 0 libcontent.dylib content::RenderWidgetHostImpl::DispatchInputEventWithLatencyInfo(blink::WebInputEvent const&, ui::LatencyInfo*) + 214 1 libcontent.dylib content::RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo(blink::WebMouseEvent const&, ui::LatencyInfo const&) + 1350 2 libcontent.dylib content::RenderWidgetHostViewMac::ProcessMouseEvent(blink::WebMouseEvent const&, ui::LatencyInfo const&) + 44 3 libcontent.dylib content::RenderWidgetHostInputEventRouter::RouteMouseEvent(content::RenderWidgetHostViewBase*, blink::WebMouseEvent*, ui::LatencyInfo const&) + 1817 * Print detailed error * Run tests after server is ready
2018-03-07 05:40:27 +00:00
let interval = null
2018-03-14 05:51:47 +00:00
let clearing = false
Fix some flaky tests in CI (#12153) * Guard whole InitPrefs with ScopedAllowIO Saw a crash: 0 0x7f8d2f7d918d base::debug::StackTrace::StackTrace() 1 0x7f8d2f7d755c base::debug::StackTrace::StackTrace() 2 0x7f8d2f867caa logging::LogMessage::~LogMessage() 3 0x7f8d2fa157c7 base::ThreadRestrictions::AssertIOAllowed() 4 0x7f8d2f83453a base::OpenFile() 5 0x7f8d2f82a967 base::ReadFileToStringWithMaxSize() 6 0x7f8d2f82ad44 base::ReadFileToString() 7 0x7f8d2f846f73 JSONFileValueDeserializer::ReadFileToString() 8 0x7f8d2f84738c JSONFileValueDeserializer::Deserialize() 9 0x7f8d35a5d1f6 <unknown> 10 0x7f8d35a5c217 JsonPrefStore::ReadPrefs() 11 0x7f8d35a87d3e PrefService::InitFromStorage() 12 0x7f8d35a87c60 PrefService::PrefService() 13 0x7f8d35a91a10 PrefServiceFactory::Create() 14 0x000000e86e1b brightray::BrowserContext::InitPrefs() 15 0x000000c2bd64 atom::AtomBrowserContext::AtomBrowserContext() 16 0x000000c320db atom::AtomBrowserContext::From() 17 0x000000b4b8b5 atom::api::Session::FromPartition() * Fix done being called twice in setInterval test The callback passed to browser process is called asyncly, so it is possible that multiple callbacks has already been scheduled before we can clearInternval. * Fix failing test when dir name has special chars The pdfSource is not escaped while parsedURL.search is. * Call done with Error instead of string * Fix crash caused by not removing input observer Solve crash: 0 libcontent.dylib content::RenderWidgetHostImpl::DispatchInputEventWithLatencyInfo(blink::WebInputEvent const&, ui::LatencyInfo*) + 214 1 libcontent.dylib content::RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo(blink::WebMouseEvent const&, ui::LatencyInfo const&) + 1350 2 libcontent.dylib content::RenderWidgetHostViewMac::ProcessMouseEvent(blink::WebMouseEvent const&, ui::LatencyInfo const&) + 44 3 libcontent.dylib content::RenderWidgetHostInputEventRouter::RouteMouseEvent(content::RenderWidgetHostViewBase*, blink::WebMouseEvent*, ui::LatencyInfo const&) + 1817 * Print detailed error * Run tests after server is ready
2018-03-07 05:40:27 +00:00
const clear = () => {
if (interval === null || clearing) return
2018-03-14 05:51:47 +00:00
// interval might trigger while clearing (remote is slow sometimes)
clearing = true
2016-03-25 20:03:49 +00:00
remote.getGlobal('clearInterval')(interval)
2018-03-14 05:51:47 +00:00
clearing = false
Fix some flaky tests in CI (#12153) * Guard whole InitPrefs with ScopedAllowIO Saw a crash: 0 0x7f8d2f7d918d base::debug::StackTrace::StackTrace() 1 0x7f8d2f7d755c base::debug::StackTrace::StackTrace() 2 0x7f8d2f867caa logging::LogMessage::~LogMessage() 3 0x7f8d2fa157c7 base::ThreadRestrictions::AssertIOAllowed() 4 0x7f8d2f83453a base::OpenFile() 5 0x7f8d2f82a967 base::ReadFileToStringWithMaxSize() 6 0x7f8d2f82ad44 base::ReadFileToString() 7 0x7f8d2f846f73 JSONFileValueDeserializer::ReadFileToString() 8 0x7f8d2f84738c JSONFileValueDeserializer::Deserialize() 9 0x7f8d35a5d1f6 <unknown> 10 0x7f8d35a5c217 JsonPrefStore::ReadPrefs() 11 0x7f8d35a87d3e PrefService::InitFromStorage() 12 0x7f8d35a87c60 PrefService::PrefService() 13 0x7f8d35a91a10 PrefServiceFactory::Create() 14 0x000000e86e1b brightray::BrowserContext::InitPrefs() 15 0x000000c2bd64 atom::AtomBrowserContext::AtomBrowserContext() 16 0x000000c320db atom::AtomBrowserContext::From() 17 0x000000b4b8b5 atom::api::Session::FromPartition() * Fix done being called twice in setInterval test The callback passed to browser process is called asyncly, so it is possible that multiple callbacks has already been scheduled before we can clearInternval. * Fix failing test when dir name has special chars The pdfSource is not escaped while parsedURL.search is. * Call done with Error instead of string * Fix crash caused by not removing input observer Solve crash: 0 libcontent.dylib content::RenderWidgetHostImpl::DispatchInputEventWithLatencyInfo(blink::WebInputEvent const&, ui::LatencyInfo*) + 214 1 libcontent.dylib content::RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo(blink::WebMouseEvent const&, ui::LatencyInfo const&) + 1350 2 libcontent.dylib content::RenderWidgetHostViewMac::ProcessMouseEvent(blink::WebMouseEvent const&, ui::LatencyInfo const&) + 44 3 libcontent.dylib content::RenderWidgetHostInputEventRouter::RouteMouseEvent(content::RenderWidgetHostViewBase*, blink::WebMouseEvent*, ui::LatencyInfo const&) + 1817 * Print detailed error * Run tests after server is ready
2018-03-07 05:40:27 +00:00
interval = null
2016-03-25 20:03:49 +00:00
done()
}
interval = remote.getGlobal('setInterval')(clear, 10)
})
})
describe('setInterval called under blink env in renderer process', () => {
it('can be scheduled in time', (done) => {
let interval = null
let clearing = false
const clear = () => {
if (interval === null || clearing) return
// interval might trigger while clearing (remote is slow sometimes)
clearing = true
clearInterval(interval)
clearing = false
interval = null
done()
}
interval = setInterval(clear, 10)
})
it('can be scheduled in time from timers module', (done) => {
let interval = null
let clearing = false
const clear = () => {
if (interval === null || clearing) return
// interval might trigger while clearing (remote is slow sometimes)
clearing = true
require('timers').clearInterval(interval)
clearing = false
interval = null
done()
}
interval = require('timers').setInterval(clear, 10)
})
})
2016-03-25 20:03:49 +00:00
})
describe('inspector', () => {
let child = null
let exitPromise = null
2017-11-06 14:25:48 +00:00
beforeEach(function () {
if (!features.isRunAsNodeEnabled()) {
this.skip()
}
})
afterEach(async () => {
if (child && exitPromise) {
const [code, signal] = await exitPromise
expect(signal).to.equal(null)
expect(code).to.equal(0)
} else if (child) {
child.kill()
}
2017-11-06 14:25:48 +00:00
})
it('supports starting the v8 inspector with --inspect/--inspect-brk', (done) => {
child = ChildProcess.spawn(process.execPath, ['--inspect-brk', path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
env: {
ELECTRON_RUN_AS_NODE: true
}
})
let output = ''
function cleanup () {
child.stderr.removeListener('data', errorDataListener)
child.stdout.removeListener('data', outDataHandler)
}
function errorDataListener (data) {
2017-11-06 14:25:48 +00:00
output += data
if (output.trim().startsWith('Debugger listening on ws://')) {
cleanup()
done()
}
}
function outDataHandler (data) {
cleanup()
2017-11-06 14:25:48 +00:00
done(new Error(`Unexpected output: ${data.toString()}`))
}
child.stderr.on('data', errorDataListener)
child.stdout.on('data', outDataHandler)
2017-11-06 14:25:48 +00:00
})
it('supports starting the v8 inspector with --inspect and a provided port', (done) => {
child = ChildProcess.spawn(process.execPath, ['--inspect=17364', path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
env: {
ELECTRON_RUN_AS_NODE: true
}
})
exitPromise = emittedOnce(child, 'exit')
let output = ''
function cleanup () {
child.stderr.removeListener('data', errorDataListener)
child.stdout.removeListener('data', outDataHandler)
}
function errorDataListener (data) {
output += data
if (output.trim().startsWith('Debugger listening on ws://')) {
expect(output.trim()).to.contain(':17364', 'should be listening on port 17364')
cleanup()
done()
}
}
function outDataHandler (data) {
cleanup()
done(new Error(`Unexpected output: ${data.toString()}`))
}
child.stderr.on('data', errorDataListener)
child.stdout.on('data', outDataHandler)
})
it('does not start the v8 inspector when --inspect is after a -- argument', (done) => {
child = ChildProcess.spawn(remote.process.execPath, [path.join(__dirname, 'fixtures', 'module', 'noop.js'), '--', '--inspect'])
exitPromise = emittedOnce(child, 'exit')
let output = ''
function dataListener (data) {
output += data
}
child.stderr.on('data', dataListener)
child.stdout.on('data', dataListener)
child.on('exit', () => {
if (output.trim().startsWith('Debugger listening on ws://')) {
done(new Error('Inspector was started when it should not have been'))
} else {
done()
}
})
})
it('does does not crash when quitting with the inspector connected', function (done) {
// IPC Electron child process not supported on Windows
if (process.platform === 'win32') return this.skip()
child = ChildProcess.spawn(remote.process.execPath, [path.join(__dirname, 'fixtures', 'module', 'delay-exit'), '--inspect=0'], {
stdio: ['ipc']
})
exitPromise = emittedOnce(child, 'exit')
let output = ''
function dataListener (data) {
output += data
chore: bump chromium to f1d9522c04ca8fa0a906f88ababe9 (master) (#18648) * chore: bump chromium in DEPS to 675d7dc9f3334b15c3ec28c27db3dc19b26bd12e * chore: update patches * chore: bump chromium in DEPS to dce3562696f165a324273fcb6893f0e1fef42ab1 * chore: const interfaces are being removed from //content Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1631749 Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=908139 * chore: update patches * chore: blink::MediaStreamType is now consistent and deduplicated * chore: update patches and printing code for ref -> uniq * chore: bridge_impl() --> GetInProcessNSWindowBridge Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1642988 * fixme: TotalMarkedObjectSize has been removed * chore: fix linting * chore: bump chromium in DEPS to 9503e1a2fcbf17db08094d8caae3e1407e918af3 * chore: fix slightly broken printing patch * chore: update patches for SiteInstanceImpl changes Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1612025 * chore: update patches for SiteInstanceImpl changes * chore: bump chromium in DEPS to 6801e6c1ddd1b7b73e594e97157ddd539ca335d7 * chore: update patches * chore: bump chromium in DEPS to 27e198912d7c1767052ec785c22e2e88b2cb4d8b * chore: remove system_request_context Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1647172 * chore: creation of FtpProtocolHandler needs an auth cache Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639683 * fixme: disable marked spec * chore: bump chromium in DEPS to 3dcd7fe453ad13a22b114b95f05590eba74c5471 * chore: bump chromium in DEPS to bdc24128b75008743d819e298557a53205706e7c * chore: bump chromium in DEPS to 7da330b58fbe0ba94b9b94abbb8085bead220228 * update patches * remove TotalMarkedObjectSize https://chromium-review.googlesource.com/c/chromium/src/+/1631708 * add libvulkan.so to dist zip manifest on linux * chore: bump chromium in DEPS to 1e85d0f45b52649efd0010cc9dab6d2804f24443 * update patches * add angle features to gpuinfo https://chromium-review.googlesource.com/c/chromium/src/+/1638658 * mark 'marked' property as deprecated * disable webview resize test * FIXME: disable vulkan on 32-bit arm * chore: bump chromium in DEPS to cd0297c6a83fdd2b1f6bc312e7d5acca736a3c56 * Revert "FIXME: disable vulkan on 32-bit arm" This reverts commit 5c1e0ef302a6db1e72231d4e823f91bb08e281af. * backport from upstream: fix swiftshader build on arm https://swiftshader-review.googlesource.com/c/SwiftShader/+/32768/ * update patches * viz: update OutputDeviceWin to new shared memory api https://chromium-review.googlesource.com/c/chromium/src/+/1649574 * base::Contains{Key,Value} => base::Contains https://chromium-review.googlesource.com/c/chromium/src/+/1649478 * fixup! viz: update OutputDeviceWin to new shared memory api * stub out StatusIconLinuxDbus-related delegate methods https://chromium-review.googlesource.com/c/chromium/src/+/1638180 * chore: bump chromium in DEPS to 964ea3fd4bdc006d62533f5755043076220181f1 * Remove the BrowserContext methods to create URLRequestContexts for main/media partitions when a partition_domain is specified https://chromium-review.googlesource.com/c/chromium/src/+/1655087 * fixup! stub out StatusIconLinuxDbus-related delegate methods * add remote_cocoa to chromium_src deps https://chromium-review.googlesource.com/c/chromium/src/+/1657068 * fixup! stub out StatusIconLinuxDbus-related delegate methods * attempt at fix linux-debug build * add swiftshader/libvulkan.so to arm manifest * chore: bump chromium in DEPS to 28688f76afef27c36631aa274691e333ddecdc22 * update patches * chore: bump chromium in DEPS to fe7450e1578a9584189f87d59d0d1a8548bf6b90 * chore: bump chromium in DEPS to f304dfd682dc86a755a6c49a16ee6876e0db45fb * chore: bump chromium in DEPS to f0fd4d6c365aad9edd83bdfff9954c47d271b75c * Update patches * Remove no longer needed WOA patch * Put back IOThread in BrowserProcess We need this until we enable the network service. * move atom.ico to inputs * Update to latest LKGR to fix no template named 'bitset' in namespace 'std' * fixup! Put back IOThread in BrowserProcess * chore: bump chromium in DEPS to dcf9662dc9a896a175d791001350324167b1cad3 * Update patches content_allow_embedder_to_prevent_locking_scheme_registry.patch is no longer necessary as it was upstreamed via https://chromium-review.googlesource.com/c/chromium/src/+/1637040 * Fix renamed enum * Use newer docker container Contains updated dependencies * Try to track down arm test failures * Fix arm tests * chore: bump chromium in DEPS to 8cbceef57b37ee14b9c4c3405a3f7663922c5b5d * Update patches * Add needed dependencies for testing 32-bit linux * Remove arm debugging. * Remove additional debugging * Fix compiler errors * Handle new macOS helper * Fix compile error on Linux * chore: bump chromium in DEPS to 66a93991ddaff6a9f1b13d110959947cb03a1860 * Add new helper files to manifests * fix BUILD.gn for macOS * Fix compile errors * Add patch to put back colors needed for autofill/datalist * chore: bump chromium in DEPS to e89617079f11e33f33cdb3924f719a579c73704b * Updated patches * Remove no longer needed patch * Remove no longer needed patch * Fix compile error with patch * Really fix the patch * chore: bump chromium in DEPS to c70f12476a45840408f1d5ff5968e7f7ceaad9d4 * chore: bump chromium in DEPS to 06d2dd7a8933b41545a7c26349c802f570563fd5 * chore: bump chromium in DEPS to b0b9ff8f727deb519ccbec7cf1c8d9ed543d88ab * Update patches * Fix compiler errors * Fix removed ChromeNetLog * Revert "Fix removed ChromeNetLog" This reverts commit 426dfd90b5ab0a9c1df415d71c88e8aed2bd5bbe. * Remove ChromeNetLog. https://chromium-review.googlesource.com/c/chromium/src/+/1663846 * chore: bump chromium in DEPS to fefcc4926d58dccd59ac95be65eab3a4ebfe2f29 * Update patches * Update v8 patches * Fix lint error * Fix compile errors * chore: bump chromium in DEPS to 4de815ef92ef2eef515506fe09bdc466526a8fd9 * Use custom protocol to test baseURLForDataURL * Use newer SDK (10.0.18362) for Windows * Update patches * Update arm manifest since swiftshader reenabled. * Don't delete dir that isn't ever there. * Fix compile errors. * Need src dir created * Update for removed InspectorFrontendAPI.addExtensions * Revert "Use newer SDK (10.0.18362) for Windows" This reverts commit 68763a0c88cdc44b971462e49662aecc167d3d99. * Revert "Need src dir created" This reverts commit 7daedc29d0844316d4097648dde7f40f1a3848fb. * Revert "Don't delete dir that isn't ever there." This reverts commit bf424bc30ffcb23b1d9a634d4df410342536640e. * chore: bump chromium in DEPS to 97dab6b0124ea53244caf123921b5d14893bcca7 * chore: bump chromium in DEPS to c87d16d49a85dc7122781f6c979d354c20f7f78b * chore: bump chromium in DEPS to 004bcee2ea336687cedfda8f8a151806ac757d15 * chore: bump chromium in DEPS to 24428b26a9d15a013b2a253e1084ec3cb54b660b * chore: bump chromium in DEPS to fd25914e875237df88035a6abf89a70bf1360b57 * Update patches * Update node to fix build error * Fix compile errors * chore: bump chromium in DEPS to 3062b7cf090f1d9522c04ca8fa0a906f88ababe9 * chore: update node ref for pushed tags * chore: update patches for new chromium * chore: fix printing patches * Use new (10.0.18362) Windows SDK * roll node to fix v8 build issues in debug build * Add support for plugin helper * fix: add patch to fix gpu info enumeration Can be removed once CL lands upstream. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1685993 * spec: navigator.requestMIDIAccess now requires a secure origin This test requires a secure origin so we fake one. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1657952 * FIXME: temporarily disable SharedWorker tests * use released version of node-abstractsocket * fix abstract-socket
2019-07-03 01:22:09 +00:00
if (output.trim().indexOf('Debugger listening on ws://') > -1 && output.indexOf('\n') > -1) {
const socketMatch = output.trim().match(/(ws:\/\/.+:[0-9]+\/.+?)\n/gm)
if (socketMatch && socketMatch[0]) {
child.stderr.removeListener('data', dataListener)
child.stdout.removeListener('data', dataListener)
const connection = new WebSocket(socketMatch[0])
connection.onopen = () => {
child.send('plz-quit')
connection.close()
done()
}
}
}
}
child.stderr.on('data', dataListener)
child.stdout.on('data', dataListener)
})
2017-11-06 14:25:48 +00:00
it('supports js binding', (done) => {
child = ChildProcess.spawn(process.execPath, ['--inspect', path.join(__dirname, 'fixtures', 'module', 'inspector-binding.js')], {
env: {
ELECTRON_RUN_AS_NODE: true
},
stdio: ['ipc']
})
exitPromise = emittedOnce(child, 'exit')
2017-11-06 14:25:48 +00:00
child.on('message', ({ cmd, debuggerEnabled, success }) => {
2017-11-06 14:25:48 +00:00
if (cmd === 'assert') {
expect(debuggerEnabled).to.be.true()
expect(success).to.be.true()
2017-11-06 14:25:48 +00:00
done()
}
})
})
})
describe('message loop', () => {
describe('process.nextTick', () => {
it('emits the callback', (done) => process.nextTick(done))
2016-03-25 20:03:49 +00:00
it('works in nested calls', (done) => {
process.nextTick(() => {
process.nextTick(() => process.nextTick(done))
2016-03-25 20:03:49 +00:00
})
})
})
describe('setImmediate', () => {
it('emits the callback', (done) => setImmediate(done))
2016-03-25 20:03:49 +00:00
it('works in nested calls', (done) => {
setImmediate(() => {
setImmediate(() => setImmediate(done))
2016-03-25 20:03:49 +00:00
})
})
})
})
describe('net.connect', () => {
before(function () {
if (!features.isRunAsNodeEnabled() || process.platform !== 'darwin') {
this.skip()
}
})
2018-06-18 14:24:26 +00:00
it('emit error when connect to a socket path without listeners', (done) => {
const socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock')
const script = path.join(fixtures, 'module', 'create_socket.js')
const child = ChildProcess.fork(script, [socketPath])
child.on('exit', (code) => {
expect(code).to.equal(0)
const client = require('net').connect(socketPath)
client.on('error', (error) => {
expect(error.code).to.equal('ECONNREFUSED')
2016-03-25 20:03:49 +00:00
done()
})
})
})
})
describe('Buffer', () => {
it('can be created from WebKit external string', () => {
const p = document.createElement('p')
2016-03-25 20:03:49 +00:00
p.innerText = '闲云潭影日悠悠,物换星移几度秋'
const b = Buffer.from(p.innerText)
expect(b.toString()).to.equal('闲云潭影日悠悠,物换星移几度秋')
expect(Buffer.byteLength(p.innerText)).to.equal(45)
2016-03-25 20:03:49 +00:00
})
it('correctly parses external one-byte UTF8 string', () => {
const p = document.createElement('p')
2016-03-25 20:03:49 +00:00
p.innerText = 'Jøhänñéß'
const b = Buffer.from(p.innerText)
expect(b.toString()).to.equal('Jøhänñéß')
expect(Buffer.byteLength(p.innerText)).to.equal(13)
2016-03-25 20:03:49 +00:00
})
2016-04-05 08:08:27 +00:00
it('does not crash when creating large Buffers', () => {
let buffer = Buffer.from(new Array(4096).join(' '))
expect(buffer.length).to.equal(4095)
buffer = Buffer.from(new Array(4097).join(' '))
expect(buffer.length).to.equal(4096)
2016-04-05 08:08:27 +00:00
})
2017-12-27 11:14:41 +00:00
it('does not crash for crypto operations', () => {
const crypto = require('crypto')
const data = 'lG9E+/g4JmRmedDAnihtBD4Dfaha/GFOjd+xUOQI05UtfVX3DjUXvrS98p7kZQwY3LNhdiFo7MY5rGft8yBuDhKuNNag9vRx/44IuClDhdQ='
const key = 'q90K9yBqhWZnAMCMTOJfPQ=='
const cipherText = '{"error_code":114,"error_message":"Tham số không hợp lệ","data":null}'
for (let i = 0; i < 10000; ++i) {
const iv = Buffer.from('0'.repeat(32), 'hex')
const input = Buffer.from(data, 'base64')
const decipher = crypto.createDecipheriv('aes-128-cbc', Buffer.from(key, 'base64'), iv)
const result = Buffer.concat([decipher.update(input), decipher.final()]).toString('utf8')
expect(cipherText).to.equal(result)
2017-12-27 11:14:41 +00:00
}
})
2016-03-25 20:03:49 +00:00
})
describe('process.stdout', () => {
it('does not throw an exception when accessed', () => {
expect(() => process.stdout).to.not.throw()
2016-03-25 20:03:49 +00:00
})
it('does not throw an exception when calling write()', () => {
expect(() => {
2016-09-07 21:40:18 +00:00
process.stdout.write('test')
}).to.not.throw()
2016-03-25 20:03:49 +00:00
})
it('should have isTTY defined on Mac and Linux', function () {
if (isCI || process.platform === 'win32') {
this.skip()
return
}
expect(process.stdout.isTTY).to.be.a('boolean')
})
2016-06-20 02:16:17 +00:00
it('should have isTTY undefined on Windows', function () {
if (isCI || process.platform !== 'win32') {
this.skip()
return
2016-09-08 20:12:00 +00:00
}
expect(process.stdout.isTTY).to.be.undefined()
2016-03-25 20:03:49 +00:00
})
})
describe('process.stdin', () => {
it('does not throw an exception when accessed', () => {
expect(() => process.stdin).to.not.throw()
2016-09-07 21:40:18 +00:00
})
it('returns null when read from', () => {
expect(process.stdin.read()).to.be.null()
2016-09-07 21:40:18 +00:00
})
})
describe('process.version', () => {
it('should not have -pre', () => {
expect(process.version.endsWith('-pre')).to.be.false()
})
})
describe('vm.runInNewContext', () => {
it('should not crash', () => {
2016-03-25 20:03:49 +00:00
require('vm').runInNewContext('')
})
})
describe('crypto', () => {
it('should list the ripemd160 hash in getHashes', () => {
expect(require('crypto').getHashes()).to.include('ripemd160')
})
it('should be able to create a ripemd160 hash and use it', () => {
const hash = require('crypto').createHash('ripemd160')
hash.update('electron-ripemd160')
expect(hash.digest('hex')).to.equal('fa7fec13c624009ab126ebb99eda6525583395fe')
})
it('should list aes-{128,256}-cfb in getCiphers', () => {
expect(require('crypto').getCiphers()).to.include.members(['aes-128-cfb', 'aes-256-cfb'])
})
it('should be able to create an aes-128-cfb cipher', () => {
require('crypto').createCipheriv('aes-128-cfb', '0123456789abcdef', '0123456789abcdef')
})
it('should be able to create an aes-256-cfb cipher', () => {
require('crypto').createCipheriv('aes-256-cfb', '0123456789abcdef0123456789abcdef', '0123456789abcdef')
})
it('should list des-ede-cbc in getCiphers', () => {
expect(require('crypto').getCiphers()).to.include('des-ede-cbc')
})
it('should be able to create an des-ede-cbc cipher', () => {
const key = Buffer.from('0123456789abcdeff1e0d3c2b5a49786', 'hex')
const iv = Buffer.from('fedcba9876543210', 'hex')
require('crypto').createCipheriv('des-ede-cbc', key, iv)
})
it('should not crash when getting an ECDH key', () => {
const ecdh = require('crypto').createECDH('prime256v1')
expect(ecdh.generateKeys()).to.be.an.instanceof(Buffer)
expect(ecdh.getPrivateKey()).to.be.an.instanceof(Buffer)
})
it('should not crash when generating DH keys or fetching DH fields', () => {
const dh = require('crypto').createDiffieHellman('modp15')
expect(dh.generateKeys()).to.be.an.instanceof(Buffer)
expect(dh.getPublicKey()).to.be.an.instanceof(Buffer)
expect(dh.getPrivateKey()).to.be.an.instanceof(Buffer)
expect(dh.getPrime()).to.be.an.instanceof(Buffer)
expect(dh.getGenerator()).to.be.an.instanceof(Buffer)
})
it('should not crash when creating an ECDH cipher', () => {
const crypto = require('crypto')
const dh = crypto.createECDH('prime256v1')
dh.generateKeys()
dh.setPrivateKey(dh.getPrivateKey())
})
})
it('includes the electron version in process.versions', () => {
expect(process.versions)
.to.have.own.property('electron')
.that.is.a('string')
.and.matches(/^\d+\.\d+\.\d+(\S*)?$/)
})
it('includes the chrome version in process.versions', () => {
expect(process.versions)
.to.have.own.property('chrome')
.that.is.a('string')
.and.matches(/^\d+\.\d+\.\d+\.\d+$/)
})
it('can find a module using a package.json main field', () => {
const result = ChildProcess.spawnSync(remote.process.execPath, [path.resolve(fixtures, 'api', 'electron-main-module', 'app.asar')])
expect(result.status).to.equal(0)
})
2016-03-25 20:03:49 +00:00
})