test: migrate more chromium specs to main (#35081)
This commit is contained in:
parent
62001dc6cb
commit
7c2ed98214
4 changed files with 187 additions and 201 deletions
|
@ -2,7 +2,6 @@ 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');
|
||||
|
@ -16,51 +15,6 @@ const features = process._linkedBinding('electron_common_features');
|
|||
describe('chromium feature', () => {
|
||||
const fixtures = path.resolve(__dirname, 'fixtures');
|
||||
|
||||
describe('Badging API', () => {
|
||||
it('does not crash', () => {
|
||||
expect(() => {
|
||||
navigator.setAppBadge(42);
|
||||
}).to.not.throw();
|
||||
expect(() => {
|
||||
// setAppBadge with no argument should show dot
|
||||
navigator.setAppBadge();
|
||||
}).to.not.throw();
|
||||
expect(() => {
|
||||
navigator.clearAppBadge();
|
||||
}).to.not.throw();
|
||||
});
|
||||
});
|
||||
|
||||
describe('heap snapshot', () => {
|
||||
it('does not crash', function () {
|
||||
process._linkedBinding('electron_common_v8_util').takeHeapSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigator.webkitGetUserMedia', () => {
|
||||
it('calls its callbacks', (done) => {
|
||||
navigator.webkitGetUserMedia({
|
||||
audio: true,
|
||||
video: false
|
||||
}, () => done(),
|
||||
() => done());
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigator.language', () => {
|
||||
it('should not be empty', () => {
|
||||
expect(navigator.language).to.not.equal('');
|
||||
});
|
||||
});
|
||||
|
||||
ifdescribe(features.isFakeLocationProviderEnabled())('navigator.geolocation', () => {
|
||||
it('returns position when permission is granted', async () => {
|
||||
const position = await new Promise((resolve, reject) => navigator.geolocation.getCurrentPosition(resolve, reject));
|
||||
expect(position).to.have.a.property('coords');
|
||||
expect(position).to.have.a.property('timestamp');
|
||||
});
|
||||
});
|
||||
|
||||
describe('window.open', () => {
|
||||
it('inherit options of parent window', async () => {
|
||||
const message = waitForEvent(window, 'message');
|
||||
|
@ -208,105 +162,6 @@ describe('chromium feature', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('webgl', () => {
|
||||
before(function () {
|
||||
if (process.platform === 'win32') {
|
||||
this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
it('can be get as context in canvas', () => {
|
||||
if (process.platform === 'linux') {
|
||||
// FIXME(alexeykuzmin): Skip the test.
|
||||
// this.skip()
|
||||
return;
|
||||
}
|
||||
|
||||
const webgl = document.createElement('canvas').getContext('webgl');
|
||||
expect(webgl).to.not.be.null();
|
||||
});
|
||||
});
|
||||
|
||||
describe('web workers', () => {
|
||||
it('Worker can work', async () => {
|
||||
const worker = new Worker('../fixtures/workers/worker.js');
|
||||
const message = 'ping';
|
||||
const eventPromise = new Promise((resolve) => { worker.onmessage = resolve; });
|
||||
worker.postMessage(message);
|
||||
const event = await eventPromise;
|
||||
worker.terminate();
|
||||
expect(event.data).to.equal(message);
|
||||
});
|
||||
|
||||
it('Worker has no node integration by default', async () => {
|
||||
const worker = new Worker('../fixtures/workers/worker_node.js');
|
||||
const event = await new Promise((resolve) => { worker.onmessage = resolve; });
|
||||
worker.terminate();
|
||||
expect(event.data).to.equal('undefined undefined undefined undefined');
|
||||
});
|
||||
|
||||
it('Worker has node integration with nodeIntegrationInWorker', async () => {
|
||||
const webview = new WebView();
|
||||
const eventPromise = waitForEvent(webview, 'ipc-message');
|
||||
webview.src = `file://${fixtures}/pages/worker.html`;
|
||||
webview.setAttribute('webpreferences', 'nodeIntegration, nodeIntegrationInWorker, contextIsolation=no');
|
||||
document.body.appendChild(webview);
|
||||
const event = await eventPromise;
|
||||
webview.remove();
|
||||
expect(event.channel).to.equal('object function object function');
|
||||
});
|
||||
|
||||
describe('SharedWorker', () => {
|
||||
it('can work', async () => {
|
||||
const worker = new SharedWorker('../fixtures/workers/shared_worker.js');
|
||||
const message = 'ping';
|
||||
const eventPromise = new Promise((resolve) => { worker.port.onmessage = resolve; });
|
||||
worker.port.postMessage(message);
|
||||
const event = await eventPromise;
|
||||
expect(event.data).to.equal(message);
|
||||
});
|
||||
|
||||
it('has no node integration by default', async () => {
|
||||
const worker = new SharedWorker('../fixtures/workers/shared_worker_node.js');
|
||||
const event = await new Promise((resolve) => { worker.port.onmessage = resolve; });
|
||||
expect(event.data).to.equal('undefined undefined undefined undefined');
|
||||
});
|
||||
|
||||
it('has node integration with nodeIntegrationInWorker', async () => {
|
||||
const webview = new WebView();
|
||||
webview.addEventListener('console-message', (e) => {
|
||||
console.log(e);
|
||||
});
|
||||
const eventPromise = waitForEvent(webview, 'ipc-message');
|
||||
webview.src = `file://${fixtures}/pages/shared_worker.html`;
|
||||
webview.setAttribute('webpreferences', 'nodeIntegration, nodeIntegrationInWorker, contextIsolation=no');
|
||||
document.body.appendChild(webview);
|
||||
const event = await eventPromise;
|
||||
webview.remove();
|
||||
expect(event.channel).to.equal('object function object function');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('iframe', () => {
|
||||
let iframe = null;
|
||||
|
||||
beforeEach(() => {
|
||||
iframe = document.createElement('iframe');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(iframe);
|
||||
});
|
||||
|
||||
it('does not have node integration', async () => {
|
||||
iframe.src = `file://${fixtures}/pages/set-global.html`;
|
||||
document.body.appendChild(iframe);
|
||||
await waitForEvent(iframe, 'load');
|
||||
expect(iframe.contentWindow.test).to.equal('undefined undefined undefined');
|
||||
});
|
||||
});
|
||||
|
||||
describe('storage', () => {
|
||||
describe('DOM storage quota increase', () => {
|
||||
['localStorage', 'sessionStorage'].forEach((storageName) => {
|
||||
|
@ -357,34 +212,6 @@ describe('chromium feature', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('websockets', () => {
|
||||
let wss = null;
|
||||
let server = null;
|
||||
const WebSocketServer = ws.Server;
|
||||
|
||||
afterEach(() => {
|
||||
wss.close();
|
||||
server.close();
|
||||
});
|
||||
|
||||
it('has user agent', (done) => {
|
||||
server = http.createServer();
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
const port = server.address().port;
|
||||
wss = new WebSocketServer({ server: server });
|
||||
wss.on('error', done);
|
||||
wss.on('connection', (ws, upgradeReq) => {
|
||||
if (upgradeReq.headers['user-agent']) {
|
||||
done();
|
||||
} else {
|
||||
done('user agent is empty');
|
||||
}
|
||||
});
|
||||
const socket = new WebSocket(`ws://127.0.0.1:${port}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Promise', () => {
|
||||
it('resolves correctly in Node.js calls', (done) => {
|
||||
class XElement extends HTMLElement {}
|
||||
|
@ -413,25 +240,6 @@ describe('chromium feature', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('fetch', () => {
|
||||
it('does not crash', (done) => {
|
||||
const server = http.createServer((req, res) => {
|
||||
res.end('test');
|
||||
server.close();
|
||||
});
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
const port = server.address().port;
|
||||
fetch(`http://127.0.0.1:${port}`).then((res) => res.body.getReader())
|
||||
.then((reader) => {
|
||||
reader.read().then((r) => {
|
||||
reader.cancel();
|
||||
done();
|
||||
});
|
||||
}).catch((e) => done(e));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('window.alert(message, title)', () => {
|
||||
it('throws an exception when the arguments cannot be converted to strings', () => {
|
||||
expect(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue