2020-03-20 20:28:31 +00:00
|
|
|
const { expect } = require('chai');
|
|
|
|
const fs = require('fs');
|
|
|
|
const http = require('http');
|
|
|
|
const path = require('path');
|
|
|
|
const ws = require('ws');
|
|
|
|
const url = require('url');
|
|
|
|
const ChildProcess = require('child_process');
|
|
|
|
const { ipcRenderer } = require('electron');
|
|
|
|
const { emittedOnce } = require('./events-helpers');
|
|
|
|
const { resolveGetters } = require('./expect-helpers');
|
2020-06-23 03:32:45 +00:00
|
|
|
const features = process._linkedBinding('electron_common_features');
|
2016-03-04 20:38:39 +00:00
|
|
|
|
2017-11-23 22:22:43 +00:00
|
|
|
/* Most of the APIs here don't use standard callbacks */
|
|
|
|
/* eslint-disable standard/no-callback-literal */
|
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('chromium feature', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const fixtures = path.resolve(__dirname, 'fixtures');
|
|
|
|
let listener = null;
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
afterEach(() => {
|
2016-01-12 02:40:23 +00:00
|
|
|
if (listener != null) {
|
2020-03-20 20:28:31 +00:00
|
|
|
window.removeEventListener('message', listener);
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
listener = null;
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('heap snapshot', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
it('does not crash', function () {
|
2020-06-23 03:32:45 +00:00
|
|
|
process._linkedBinding('electron_common_v8_util').takeHeapSnapshot();
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('navigator.webkitGetUserMedia', () => {
|
|
|
|
it('calls its callbacks', (done) => {
|
2016-02-17 01:39:11 +00:00
|
|
|
navigator.webkitGetUserMedia({
|
2016-01-12 02:40:23 +00:00
|
|
|
audio: true,
|
|
|
|
video: false
|
2017-11-13 20:13:19 +00:00
|
|
|
}, () => done(),
|
2020-03-20 20:28:31 +00:00
|
|
|
() => done());
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('navigator.language', () => {
|
|
|
|
it('should not be empty', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(navigator.language).to.not.equal('');
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2018-08-23 15:51:46 +00:00
|
|
|
describe('navigator.geolocation', () => {
|
|
|
|
before(function () {
|
|
|
|
if (!features.isFakeLocationProviderEnabled()) {
|
2020-03-20 20:28:31 +00:00
|
|
|
return this.skip();
|
2018-08-23 15:51:46 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2018-08-23 15:51:46 +00:00
|
|
|
|
|
|
|
it('returns position when permission is granted', (done) => {
|
|
|
|
navigator.geolocation.getCurrentPosition((position) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(position).to.have.a.property('coords');
|
|
|
|
expect(position).to.have.a.property('timestamp');
|
|
|
|
done();
|
2018-08-23 15:51:46 +00:00
|
|
|
}, (error) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
done(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-08-23 15:51:46 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('window.open', () => {
|
|
|
|
it('accepts "nodeIntegration" as feature', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let b = null;
|
2017-11-13 20:13:19 +00:00
|
|
|
listener = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(event.data.isProcessGlobalUndefined).to.be.true();
|
|
|
|
b.close();
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
window.addEventListener('message', listener);
|
|
|
|
b = window.open(`file://${fixtures}/pages/window-opener-node.html`, '', 'nodeIntegration=no,show=no');
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('inherit options of parent window', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let b = null;
|
2017-11-13 20:13:19 +00:00
|
|
|
listener = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const width = outerWidth;
|
|
|
|
const height = outerHeight;
|
|
|
|
expect(event.data).to.equal(`size: ${width} ${height}`);
|
|
|
|
b.close();
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
window.addEventListener('message', listener);
|
|
|
|
b = window.open(`file://${fixtures}/pages/window-open-size.html`, '', 'show=no');
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('disables node integration when it is disabled on the parent window', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let b = null;
|
2017-11-13 20:13:19 +00:00
|
|
|
listener = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(event.data.isProcessGlobalUndefined).to.be.true();
|
|
|
|
b.close();
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
window.addEventListener('message', listener);
|
2016-03-23 23:53:20 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
const windowUrl = require('url').format({
|
2016-03-24 00:40:25 +00:00
|
|
|
pathname: `${fixtures}/pages/window-opener-no-node-integration.html`,
|
2016-03-23 23:53:20 +00:00
|
|
|
protocol: 'file',
|
|
|
|
query: {
|
2016-03-24 00:40:25 +00:00
|
|
|
p: `${fixtures}/pages/window-opener-node.html`
|
2016-03-23 23:53:20 +00:00
|
|
|
},
|
|
|
|
slashes: true
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
b = window.open(windowUrl, '', 'nodeIntegration=no,show=no');
|
|
|
|
});
|
2016-03-23 23:53:20 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('disables the <webview> tag when it is disabled on the parent window', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let b = null;
|
2017-11-13 20:13:19 +00:00
|
|
|
listener = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(event.data.isWebViewGlobalUndefined).to.be.true();
|
|
|
|
b.close();
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
window.addEventListener('message', listener);
|
2017-05-17 20:27:28 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
const windowUrl = require('url').format({
|
2017-05-17 20:27:28 +00:00
|
|
|
pathname: `${fixtures}/pages/window-opener-no-webview-tag.html`,
|
|
|
|
protocol: 'file',
|
|
|
|
query: {
|
|
|
|
p: `${fixtures}/pages/window-opener-webview.html`
|
|
|
|
},
|
|
|
|
slashes: true
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
b = window.open(windowUrl, '', 'webviewTag=no,nodeIntegration=yes,show=no');
|
|
|
|
});
|
2017-05-17 20:27:28 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('does not override child options', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let b = null;
|
2017-11-13 20:13:19 +00:00
|
|
|
const size = {
|
2016-01-12 02:40:23 +00:00
|
|
|
width: 350,
|
|
|
|
height: 450
|
2020-03-20 20:28:31 +00:00
|
|
|
};
|
2017-11-13 20:13:19 +00:00
|
|
|
listener = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(event.data).to.equal(`size: ${size.width} ${size.height}`);
|
|
|
|
b.close();
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
window.addEventListener('message', listener);
|
|
|
|
b = window.open(`file://${fixtures}/pages/window-open-size.html`, '', 'show=no,width=' + size.width + ',height=' + size.height);
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('throws an exception when the arguments cannot be converted to strings', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
window.open('', { toString: null });
|
|
|
|
}).to.throw('Cannot convert object to primitive value');
|
2017-04-25 20:16:07 +00:00
|
|
|
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
window.open('', '', { toString: 3 });
|
|
|
|
}).to.throw('Cannot convert object to primitive value');
|
|
|
|
});
|
2017-04-25 20:52:56 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('does not throw an exception when the features include webPreferences', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let b = null;
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
b = window.open('', '', 'webPreferences=');
|
|
|
|
}).to.not.throw();
|
|
|
|
b.close();
|
|
|
|
});
|
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('window.opener', () => {
|
|
|
|
it('is not null for window opened by window.open', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let b = null;
|
2017-11-13 20:13:19 +00:00
|
|
|
listener = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(event.data).to.equal('object');
|
|
|
|
b.close();
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
window.addEventListener('message', listener);
|
|
|
|
b = window.open(`file://${fixtures}/pages/window-opener.html`, '', 'show=no');
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('window.postMessage', () => {
|
|
|
|
it('throws an exception when the targetOrigin cannot be converted to a string', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const b = window.open('');
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
b.postMessage('test', { toString: null });
|
|
|
|
}).to.throw('Cannot convert object to primitive value');
|
|
|
|
b.close();
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('window.opener.postMessage', () => {
|
|
|
|
it('sets source and origin correctly', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let b = null;
|
2017-11-13 20:13:19 +00:00
|
|
|
listener = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
window.removeEventListener('message', listener);
|
2020-04-27 19:46:04 +00:00
|
|
|
expect(event.source).to.deep.equal(b);
|
2020-03-20 20:28:31 +00:00
|
|
|
b.close();
|
|
|
|
expect(event.origin).to.equal('file://');
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
window.addEventListener('message', listener);
|
|
|
|
b = window.open(`file://${fixtures}/pages/window-opener-postMessage.html`, '', 'show=no');
|
|
|
|
});
|
2016-06-09 19:02:01 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('supports windows opened from a <webview>', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const webview = new WebView();
|
2017-11-13 20:13:19 +00:00
|
|
|
webview.addEventListener('console-message', (e) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
webview.remove();
|
|
|
|
expect(e.message).to.equal('message');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
webview.allowpopups = true;
|
2016-06-09 19:02:01 +00:00
|
|
|
webview.src = url.format({
|
|
|
|
pathname: `${fixtures}/pages/webview-opener-postMessage.html`,
|
|
|
|
protocol: 'file',
|
|
|
|
query: {
|
|
|
|
p: `${fixtures}/pages/window-opener-postMessage.html`
|
|
|
|
},
|
|
|
|
slashes: true
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
document.body.appendChild(webview);
|
|
|
|
});
|
2017-04-26 17:44:16 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('targetOrigin argument', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let serverURL;
|
|
|
|
let server;
|
2017-04-26 17:44:16 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
beforeEach((done) => {
|
|
|
|
server = http.createServer((req, res) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
res.writeHead(200);
|
|
|
|
const filePath = path.join(fixtures, 'pages', 'window-opener-targetOrigin.html');
|
|
|
|
res.end(fs.readFileSync(filePath, 'utf8'));
|
|
|
|
});
|
2017-11-13 20:13:19 +00:00
|
|
|
server.listen(0, '127.0.0.1', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
serverURL = `http://127.0.0.1:${server.address().port}`;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-04-26 17:44:16 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
afterEach(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
server.close();
|
|
|
|
});
|
2017-04-26 17:44:16 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('delivers messages that match the origin', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let b = null;
|
2017-11-13 20:13:19 +00:00
|
|
|
listener = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
window.removeEventListener('message', listener);
|
|
|
|
b.close();
|
|
|
|
expect(event.data).to.equal('deliver');
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
window.addEventListener('message', listener);
|
|
|
|
b = window.open(serverURL, '', 'show=no');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('webgl', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
2019-10-11 20:55:50 +00:00
|
|
|
if (process.platform === 'win32') {
|
2020-03-20 20:28:31 +00:00
|
|
|
this.skip();
|
2017-11-15 21:05:46 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-04-30 09:21:18 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('can be get as context in canvas', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
if (process.platform === 'linux') {
|
|
|
|
// FIXME(alexeykuzmin): Skip the test.
|
|
|
|
// this.skip()
|
2020-03-20 20:28:31 +00:00
|
|
|
return;
|
2017-11-15 21:05:46 +00:00
|
|
|
}
|
2016-03-28 23:11:00 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const webgl = document.createElement('canvas').getContext('webgl');
|
|
|
|
expect(webgl).to.not.be.null();
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('web workers', () => {
|
|
|
|
it('Worker can work', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const worker = new Worker('../fixtures/workers/worker.js');
|
|
|
|
const message = 'ping';
|
2017-11-13 20:13:19 +00:00
|
|
|
worker.onmessage = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(event.data).to.equal(message);
|
|
|
|
worker.terminate();
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
worker.postMessage(message);
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('Worker has no node integration by default', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const worker = new Worker('../fixtures/workers/worker_node.js');
|
2017-11-13 20:13:19 +00:00
|
|
|
worker.onmessage = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(event.data).to.equal('undefined undefined undefined undefined');
|
|
|
|
worker.terminate();
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
});
|
2017-03-15 11:07:28 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('Worker has node integration with nodeIntegrationInWorker', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const webview = new WebView();
|
2017-11-13 20:13:19 +00:00
|
|
|
webview.addEventListener('ipc-message', (e) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(e.channel).to.equal('object function object function');
|
|
|
|
webview.remove();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
webview.src = `file://${fixtures}/pages/worker.html`;
|
|
|
|
webview.setAttribute('webpreferences', 'nodeIntegration, nodeIntegrationInWorker');
|
|
|
|
document.body.appendChild(webview);
|
|
|
|
});
|
2017-03-15 11:07:28 +00:00
|
|
|
|
2019-07-03 01:22:09 +00:00
|
|
|
// FIXME: disabled during chromium update due to crash in content::WorkerScriptFetchInitiator::CreateScriptLoaderOnIO
|
|
|
|
xdescribe('SharedWorker', () => {
|
|
|
|
it('can work', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const worker = new SharedWorker('../fixtures/workers/shared_worker.js');
|
|
|
|
const message = 'ping';
|
2019-07-03 01:22:09 +00:00
|
|
|
worker.port.onmessage = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(event.data).to.equal(message);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
worker.port.postMessage(message);
|
|
|
|
});
|
2017-03-15 11:07:28 +00:00
|
|
|
|
2019-07-03 01:22:09 +00:00
|
|
|
it('has no node integration by default', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const worker = new SharedWorker('../fixtures/workers/shared_worker_node.js');
|
2019-07-03 01:22:09 +00:00
|
|
|
worker.port.onmessage = (event) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(event.data).to.equal('undefined undefined undefined undefined');
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
});
|
2019-07-03 01:22:09 +00:00
|
|
|
|
|
|
|
it('has node integration with nodeIntegrationInWorker', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const webview = new WebView();
|
2019-07-03 01:22:09 +00:00
|
|
|
webview.addEventListener('console-message', (e) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(e);
|
|
|
|
});
|
2019-07-03 01:22:09 +00:00
|
|
|
webview.addEventListener('ipc-message', (e) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(e.channel).to.equal('object function object function');
|
|
|
|
webview.remove();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
webview.src = `file://${fixtures}/pages/shared_worker.html`;
|
|
|
|
webview.setAttribute('webpreferences', 'nodeIntegration, nodeIntegrationInWorker');
|
|
|
|
document.body.appendChild(webview);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('iframe', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let iframe = null;
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
beforeEach(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
iframe = document.createElement('iframe');
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
afterEach(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
document.body.removeChild(iframe);
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('does not have node integration', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
iframe.src = `file://${fixtures}/pages/set-global.html`;
|
|
|
|
document.body.appendChild(iframe);
|
2017-11-13 20:13:19 +00:00
|
|
|
iframe.onload = () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(iframe.contentWindow.test).to.equal('undefined undefined undefined');
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('storage', () => {
|
2019-11-22 19:35:54 +00:00
|
|
|
describe('DOM storage quota increase', () => {
|
2018-11-12 17:19:01 +00:00
|
|
|
['localStorage', 'sessionStorage'].forEach((storageName) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const storage = window[storageName];
|
2019-11-22 19:35:54 +00:00
|
|
|
it(`allows saving at least 40MiB in ${storageName}`, (done) => {
|
|
|
|
// Although JavaScript strings use UTF-16, the underlying
|
|
|
|
// storage provider may encode strings differently, muddling the
|
|
|
|
// translation between character and byte counts. However,
|
|
|
|
// a string of 40 * 2^20 characters will require at least 40MiB
|
|
|
|
// and presumably no more than 80MiB, a size guaranteed to
|
|
|
|
// to exceed the original 10MiB quota yet stay within the
|
|
|
|
// new 100MiB quota.
|
|
|
|
// Note that both the key name and value affect the total size.
|
2020-03-20 20:28:31 +00:00
|
|
|
const testKeyName = '_electronDOMStorageQuotaIncreasedTest';
|
|
|
|
const length = 40 * Math.pow(2, 20) - testKeyName.length;
|
|
|
|
storage.setItem(testKeyName, 'X'.repeat(length));
|
2019-11-22 19:35:54 +00:00
|
|
|
// Wait at least one turn of the event loop to help avoid false positives
|
|
|
|
// Although not entirely necessary, the previous version of this test case
|
|
|
|
// failed to detect a real problem (perhaps related to DOM storage data caching)
|
|
|
|
// wherein calling `getItem` immediately after `setItem` would appear to work
|
|
|
|
// but then later (e.g. next tick) it would not.
|
|
|
|
setTimeout(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(storage.getItem(testKeyName)).to.have.lengthOf(length);
|
|
|
|
storage.removeItem(testKeyName);
|
|
|
|
done();
|
|
|
|
}, 1);
|
|
|
|
});
|
2019-11-22 19:35:54 +00:00
|
|
|
it(`throws when attempting to use more than 128MiB in ${storageName}`, () => {
|
|
|
|
expect(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const testKeyName = '_electronDOMStorageQuotaStillEnforcedTest';
|
|
|
|
const length = 128 * Math.pow(2, 20) - testKeyName.length;
|
2019-11-22 19:35:54 +00:00
|
|
|
try {
|
2020-03-20 20:28:31 +00:00
|
|
|
storage.setItem(testKeyName, 'X'.repeat(length));
|
2019-11-22 19:35:54 +00:00
|
|
|
} finally {
|
2020-03-20 20:28:31 +00:00
|
|
|
storage.removeItem(testKeyName);
|
2019-11-22 19:35:54 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
}).to.throw();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-11-12 17:19:01 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('requesting persitent quota works', (done) => {
|
|
|
|
navigator.webkitPersistentStorage.requestQuota(1024 * 1024, (grantedBytes) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(grantedBytes).to.equal(1048576);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('websockets', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let wss = null;
|
|
|
|
let server = null;
|
|
|
|
const WebSocketServer = ws.Server;
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
afterEach(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
wss.close();
|
|
|
|
server.close();
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('has user agent', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
server = http.createServer();
|
2017-11-13 20:13:19 +00:00
|
|
|
server.listen(0, '127.0.0.1', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const port = server.address().port;
|
|
|
|
wss = new WebSocketServer({ server: server });
|
|
|
|
wss.on('error', done);
|
2018-06-20 07:18:24 +00:00
|
|
|
wss.on('connection', (ws, upgradeReq) => {
|
|
|
|
if (upgradeReq.headers['user-agent']) {
|
2020-03-20 20:28:31 +00:00
|
|
|
done();
|
2016-01-12 02:40:23 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
done('user agent is empty');
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
const socket = new WebSocket(`ws://127.0.0.1:${port}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('Promise', () => {
|
|
|
|
it('resolves correctly in Node.js calls', (done) => {
|
2019-10-28 22:12:35 +00:00
|
|
|
class XElement extends HTMLElement {}
|
2020-03-20 20:28:31 +00:00
|
|
|
customElements.define('x-element', XElement);
|
2017-11-13 20:13:19 +00:00
|
|
|
setImmediate(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let called = false;
|
2017-11-13 20:13:19 +00:00
|
|
|
Promise.resolve().then(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
done(called ? undefined : new Error('wrong sequence'));
|
|
|
|
});
|
|
|
|
document.createElement('x-element');
|
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
it('resolves correctly in Electron calls', (done) => {
|
2019-10-28 22:12:35 +00:00
|
|
|
class YElement extends HTMLElement {}
|
2020-03-20 20:28:31 +00:00
|
|
|
customElements.define('y-element', YElement);
|
2019-10-16 15:12:31 +00:00
|
|
|
ipcRenderer.invoke('ping').then(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let called = false;
|
2017-11-13 20:13:19 +00:00
|
|
|
Promise.resolve().then(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
done(called ? undefined : new Error('wrong sequence'));
|
|
|
|
});
|
|
|
|
document.createElement('y-element');
|
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-08-22 10:26:07 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('fetch', () => {
|
|
|
|
it('does not crash', (done) => {
|
|
|
|
const server = http.createServer((req, res) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
res.end('test');
|
|
|
|
server.close();
|
|
|
|
});
|
2017-11-13 20:13:19 +00:00
|
|
|
server.listen(0, '127.0.0.1', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const port = server.address().port;
|
2017-11-13 20:13:19 +00:00
|
|
|
fetch(`http://127.0.0.1:${port}`).then((res) => res.body.getReader())
|
|
|
|
.then((reader) => {
|
|
|
|
reader.read().then((r) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
reader.cancel();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}).catch((e) => done(e));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-02-04 14:48:16 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('window.alert(message, title)', () => {
|
|
|
|
it('throws an exception when the arguments cannot be converted to strings', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
window.alert({ toString: null });
|
|
|
|
}).to.throw('Cannot convert object to primitive value');
|
|
|
|
});
|
|
|
|
});
|
2017-04-21 19:19:37 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('window.confirm(message, title)', () => {
|
|
|
|
it('throws an exception when the arguments cannot be converted to strings', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
window.confirm({ toString: null }, 'title');
|
|
|
|
}).to.throw('Cannot convert object to primitive value');
|
|
|
|
});
|
|
|
|
});
|
2017-04-25 21:48:01 +00:00
|
|
|
|
2017-11-13 20:13:19 +00:00
|
|
|
describe('window.history', () => {
|
|
|
|
describe('window.history.go(offset)', () => {
|
|
|
|
it('throws an exception when the argumnet cannot be converted to a string', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
window.history.go({ toString: null });
|
|
|
|
}).to.throw('Cannot convert object to primitive value');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-11 13:52:12 +00:00
|
|
|
|
2019-10-11 20:55:50 +00:00
|
|
|
// TODO(nornagon): this is broken on CI, it triggers:
|
|
|
|
// [FATAL:speech_synthesis.mojom-shared.h(237)] The outgoing message will
|
|
|
|
// trigger VALIDATION_ERROR_UNEXPECTED_NULL_POINTER at the receiving side
|
|
|
|
// (null text in SpeechSynthesisUtterance struct).
|
|
|
|
describe.skip('SpeechSynthesis', () => {
|
2018-10-11 13:52:12 +00:00
|
|
|
before(function () {
|
2019-10-11 20:55:50 +00:00
|
|
|
if (!features.isTtsEnabled()) {
|
2020-03-20 20:28:31 +00:00
|
|
|
this.skip();
|
2018-10-11 13:52:12 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2018-10-11 13:52:12 +00:00
|
|
|
|
|
|
|
it('should emit lifecycle events', async () => {
|
|
|
|
const sentence = `long sentence which will take at least a few seconds to
|
2020-03-20 20:28:31 +00:00
|
|
|
utter so that it's possible to pause and resume before the end`;
|
|
|
|
const utter = new SpeechSynthesisUtterance(sentence);
|
2018-10-11 13:52:12 +00:00
|
|
|
// Create a dummy utterence so that speech synthesis state
|
|
|
|
// is initialized for later calls.
|
2020-03-20 20:28:31 +00:00
|
|
|
speechSynthesis.speak(new SpeechSynthesisUtterance());
|
|
|
|
speechSynthesis.cancel();
|
|
|
|
speechSynthesis.speak(utter);
|
2018-10-11 13:52:12 +00:00
|
|
|
// paused state after speak()
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(speechSynthesis.paused).to.be.false();
|
|
|
|
await new Promise((resolve) => { utter.onstart = resolve; });
|
2018-10-11 13:52:12 +00:00
|
|
|
// paused state after start event
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(speechSynthesis.paused).to.be.false();
|
2018-10-11 13:52:12 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
speechSynthesis.pause();
|
2018-10-11 13:52:12 +00:00
|
|
|
// paused state changes async, right before the pause event
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(speechSynthesis.paused).to.be.false();
|
|
|
|
await new Promise((resolve) => { utter.onpause = resolve; });
|
|
|
|
expect(speechSynthesis.paused).to.be.true();
|
2018-10-11 13:52:12 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
speechSynthesis.resume();
|
|
|
|
await new Promise((resolve) => { utter.onresume = resolve; });
|
2018-10-11 13:52:12 +00:00
|
|
|
// paused state after resume event
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(speechSynthesis.paused).to.be.false();
|
2018-10-11 13:52:12 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
await new Promise((resolve) => { utter.onend = resolve; });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-11-08 14:51:51 +00:00
|
|
|
|
2019-06-13 22:56:58 +00:00
|
|
|
describe('console functions', () => {
|
|
|
|
it('should exist', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(console.log, 'log').to.be.a('function');
|
|
|
|
expect(console.error, 'error').to.be.a('function');
|
|
|
|
expect(console.warn, 'warn').to.be.a('function');
|
|
|
|
expect(console.info, 'info').to.be.a('function');
|
|
|
|
expect(console.debug, 'debug').to.be.a('function');
|
|
|
|
expect(console.trace, 'trace').to.be.a('function');
|
|
|
|
expect(console.time, 'time').to.be.a('function');
|
|
|
|
expect(console.timeEnd, 'timeEnd').to.be.a('function');
|
|
|
|
});
|
|
|
|
});
|