no-proprietary-codecs.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Verifies that Electron cannot play a video that uses proprietary codecs
  2. //
  3. // This application should be run with the ffmpeg that does not include
  4. // proprietary codecs to ensure Electron uses it instead of the version
  5. // that does include proprietary codecs.
  6. const { app, BrowserWindow, ipcMain } = require('electron');
  7. const path = require('node:path');
  8. const MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
  9. const FIVE_MINUTES = 5 * 60 * 1000;
  10. let window;
  11. app.whenReady().then(() => {
  12. window = new BrowserWindow({
  13. show: false,
  14. webPreferences: {
  15. nodeIntegration: true,
  16. contextIsolation: false
  17. }
  18. });
  19. window.webContents.on('render-process-gone', (event, details) => {
  20. console.log(`WebContents crashed ${JSON.stringify(details)}`);
  21. app.exit(1);
  22. });
  23. window.loadFile(path.resolve(__dirname, 'test.asar', 'video.asar', 'index.html'));
  24. ipcMain.on('asar-video', (event, message, error) => {
  25. if (message === 'ended') {
  26. console.log('Video played, proprietary codecs are included');
  27. app.exit(1);
  28. return;
  29. }
  30. if (message === 'error' && error === MEDIA_ERR_SRC_NOT_SUPPORTED) {
  31. app.exit(0);
  32. return;
  33. }
  34. console.log(`Unexpected response from page: ${message} ${error}`);
  35. app.exit(1);
  36. });
  37. setTimeout(() => {
  38. console.log('No IPC message after 5 minutes');
  39. app.exit(1);
  40. }, FIVE_MINUTES);
  41. });