зеркало из https://github.com/electron/electron.git
test: worker should be able to load asar files (#28858)
This commit is contained in:
Родитель
72092c2312
Коммит
b97b973306
|
@ -1,5 +1,6 @@
|
|||
import { expect } from 'chai';
|
||||
import * as path from 'path';
|
||||
import * as url from 'url';
|
||||
import { BrowserWindow, ipcMain } from 'electron/main';
|
||||
import { closeAllWindows } from './window-helpers';
|
||||
import { emittedOnce } from './events-helpers';
|
||||
|
@ -79,4 +80,32 @@ describe('asar package', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('worker', () => {
|
||||
it('Worker can load asar file', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixtures, 'workers', 'load_worker.html'));
|
||||
|
||||
const workerUrl = url.format({
|
||||
pathname: path.resolve(fixtures, 'workers', 'workers.asar', 'worker.js').replace(/\\/g, '/'),
|
||||
protocol: 'file',
|
||||
slashes: true
|
||||
});
|
||||
const result = await w.webContents.executeJavaScript(`loadWorker('${workerUrl}')`);
|
||||
expect(result).to.equal('success');
|
||||
});
|
||||
|
||||
it('SharedWorker can load asar file', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixtures, 'workers', 'load_shared_worker.html'));
|
||||
|
||||
const workerUrl = url.format({
|
||||
pathname: path.resolve(fixtures, 'workers', 'workers.asar', 'shared_worker.js').replace(/\\/g, '/'),
|
||||
protocol: 'file',
|
||||
slashes: true
|
||||
});
|
||||
const result = await w.webContents.executeJavaScript(`loadSharedWorker('${workerUrl}')`);
|
||||
expect(result).to.equal('success');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<script>
|
||||
function loadSharedWorker(url) {
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
const w = new SharedWorker(url);
|
||||
w.onerror = () => resolve('failed');
|
||||
w.port.onmessage = (m) => resolve(m.data);
|
||||
w.port.postMessage('success');
|
||||
} catch {
|
||||
resolve('failed');
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<script>
|
||||
function loadWorker(url) {
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
const w = new Worker(url);
|
||||
w.onerror = () => resolve('failed');
|
||||
w.onmessage = (m) => resolve(m.data);
|
||||
w.postMessage('success');
|
||||
} catch {
|
||||
resolve('failed');
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
Двоичный файл не отображается.
Загрузка…
Ссылка в новой задаче