no-proprietary-codecs.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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('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. }
  17. });
  18. window.webContents.on('crashed', (event, killed) => {
  19. console.log(`WebContents crashed (killed=${killed})`);
  20. app.exit(1);
  21. });
  22. window.loadFile(path.resolve(__dirname, 'test.asar', 'video.asar', 'index.html'));
  23. ipcMain.on('asar-video', (event, message, error) => {
  24. if (message === 'ended') {
  25. console.log('Video played, proprietary codecs are included');
  26. app.exit(1);
  27. return;
  28. }
  29. if (message === 'error' && error === MEDIA_ERR_SRC_NOT_SUPPORTED) {
  30. app.exit(0);
  31. return;
  32. }
  33. console.log(`Unexpected response from page: ${message} ${error}`);
  34. app.exit(1);
  35. });
  36. setTimeout(() => {
  37. console.log('No IPC message after 5 minutes');
  38. app.exit(1);
  39. }, FIVE_MINUTES);
  40. });