test: clean up some stale code in renderer spec runner (#21384)

* test: clean up some stale code in renderer spec runner

* remove jquery from spec

* remove extraneous close tag

* Revert "remove jquery from spec"

This reverts commit 7b885c8ca807e15bad3b7bf94691eee3c53d0a8d.

* re-clean-up html

* don't highlight tags

* update session docs; clear cache on boot

* clear user-data-dir before running tests
This commit is contained in:
Jeremy Apthorp 2019-12-16 18:15:12 -08:00 committed by Cheng Zhao
parent b57d218466
commit 53957d47d6
5 changed files with 17 additions and 73 deletions

View file

@ -126,9 +126,10 @@ Clears the sessions HTTP cache.
`scheme://host:port`.
* `storages` String[] (optional) - The types of storages to clear, can contain:
`appcache`, `cookies`, `filesystem`, `indexdb`, `localstorage`,
`shadercache`, `websql`, `serviceworkers`, `cachestorage`.
`shadercache`, `websql`, `serviceworkers`, `cachestorage`. If not
specified, clear all storage types.
* `quotas` String[] (optional) - The types of quotas to clear, can contain:
`temporary`, `persistent`, `syncable`.
`temporary`, `persistent`, `syncable`. If not specified, clear all quotas.
Returns `Promise<void>` - resolves when the storage data has been cleared.

View file

@ -146,7 +146,7 @@ describe('node feature', () => {
(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
// We disable this for unsandboxed processes, which the renderer 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.

View file

@ -1,13 +1,5 @@
<html>
<head>
<meta name="referrer" content="always">
<link href="../node_modules/mocha/mocha.css" rel="stylesheet">
<script src="jquery-2.0.3.min.js"></script>
</head>
<body>
<div id="mocha"></div>
<script src="jquery-2.0.3.min.js"></script>
<script type="text/javascript" charset="utf-8">
(function() {
// Deprecated APIs are still supported and should be tested.
@ -93,7 +85,6 @@
const runner = mocha.run(() => {
// Ensure the callback is called after runner is defined
setTimeout(() => {
Mocha.utils.highlightTags('code')
ipcRenderer.send('process.exit', runner.failures)
}, 0)
})
@ -101,4 +92,3 @@
})()
</script>
</body>
</html>

View file

@ -2,7 +2,13 @@
process.throwDeprecation = false
const electron = require('electron')
const { app, BrowserWindow, crashReporter, dialog, ipcMain, protocol, webContents } = electron
const { app, BrowserWindow, crashReporter, dialog, ipcMain, protocol, webContents, session } = electron
try {
require('fs').rmdirSync(app.getPath('userData'), { recursive: true })
} catch (e) {
console.warn(`Warning: couldn't clear user data directory:`, e)
}
const fs = require('fs')
const path = require('path')
@ -18,9 +24,6 @@ const argv = require('yargs')
let window = null
// will be used by crash-reporter spec.
process.port = 0
v8.setFlagsFromString('--expose_gc')
app.commandLine.appendSwitch('js-flags', '--expose_gc')
app.commandLine.appendSwitch('ignore-certificate-errors')
@ -47,11 +50,6 @@ ipcMain.handle('get-modules', () => Object.keys(electron))
ipcMain.handle('get-temp-dir', () => app.getPath('temp'))
ipcMain.handle('ping', () => null)
// Set productName so getUploadedReports() uses the right directory in specs
if (process.platform !== 'darwin') {
crashReporter.productName = 'Zombies'
}
// Write output to file if OUTPUT_TO_FILE is defined.
const outputToFile = process.env.OUTPUT_TO_FILE
const print = function (_, method, args) {
@ -76,8 +74,6 @@ ipcMain.on('echo', function (event, msg) {
event.returnValue = msg
})
global.setTimeoutPromisified = util.promisify(setTimeout)
process.removeAllListeners('uncaughtException')
process.on('uncaughtException', function (error) {
console.error(error, error.stack)
@ -86,18 +82,6 @@ process.on('uncaughtException', function (error) {
global.nativeModulesEnabled = !process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS
// Register app as standard scheme.
global.standardScheme = 'app'
global.zoomScheme = 'zoom'
protocol.registerSchemesAsPrivileged([
{ scheme: global.standardScheme, privileges: { standard: true, secure: true } },
{ scheme: global.zoomScheme, privileges: { standard: true, secure: true } },
{ scheme: 'cors', privileges: { corsEnabled: true, supportFetchAPI: true } },
{ scheme: 'cors-blob', privileges: { corsEnabled: true, supportFetchAPI: true } },
{ scheme: 'no-cors', privileges: { supportFetchAPI: true } },
{ scheme: 'no-fetch', privileges: { corsEnabled: true } }
])
app.on('window-all-closed', function () {
app.quit()
})
@ -110,15 +94,12 @@ app.on('renderer-process-crashed', (event, contents, killed) => {
console.log(`webContents ${contents.id} crashed: ${contents.getURL()} (killed=${killed})`)
})
app.on('ready', function () {
app.on('ready', async function () {
await session.defaultSession.clearCache()
await session.defaultSession.clearStorageData()
// Test if using protocol module would crash.
electron.protocol.registerStringProtocol('test-if-crashes', function () {})
// Send auto updater errors to window to be verified in specs
electron.autoUpdater.on('error', function (error) {
window.send('auto-updater-error', error.message)
})
window = new BrowserWindow({
title: 'Electron Tests',
show: false,
@ -153,35 +134,6 @@ app.on('ready', function () {
})
})
for (const eventName of [
'remote-get-guest-web-contents'
]) {
ipcMain.on(`handle-next-${eventName}`, function (event, returnValue) {
event.sender.once(eventName, (event) => {
if (returnValue) {
event.returnValue = returnValue
} else {
event.preventDefault()
}
})
})
}
ipcMain.on('set-client-certificate-option', function (event, skip) {
app.once('select-client-certificate', function (event, webContents, url, list, callback) {
event.preventDefault()
if (skip) {
callback()
} else {
ipcMain.on('client-certificate-response', function (event, certificate) {
callback(certificate)
})
window.webContents.send('select-client-certificate', webContents.id, list)
}
})
event.returnValue = 'done'
})
ipcMain.on('prevent-next-will-attach-webview', (event) => {
event.sender.once('will-attach-webview', event => event.preventDefault())
})

View file

@ -4,6 +4,7 @@ const http = require('http')
const url = require('url')
const { ipcRenderer } = require('electron')
const { emittedOnce, waitForEvent } = require('./events-helpers')
const { ifdescribe, ifit } = require('./spec-helpers')
const features = process.electronBinding('features')
const nativeModulesEnabled = process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS
@ -469,7 +470,7 @@ describe('<webview> tag', function () {
})
})
it('can disable the remote module', async () => {
ifit(features.isRemoteModuleEnabled())('can disable the remote module', async () => {
const message = await startLoadingWebViewAndWaitForMessage(webview, {
preload: `${fixtures}/module/preload-disable-remote.js`,
src: `file://${fixtures}/api/blank.html`,