api-web-contents-view-spec.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. const chai = require('chai');
  3. const ChildProcess = require('child_process');
  4. const dirtyChai = require('dirty-chai');
  5. const path = require('path');
  6. const { emittedOnce } = require('./events-helpers');
  7. const { closeWindow } = require('./window-helpers');
  8. const { remote } = require('electron');
  9. const { webContents, TopLevelWindow, WebContentsView } = remote;
  10. const { expect } = chai;
  11. chai.use(dirtyChai);
  12. describe('WebContentsView', () => {
  13. let w = null;
  14. afterEach(() => closeWindow(w).then(() => { w = null; }));
  15. it('can be used as content view', () => {
  16. const web = webContents.create({});
  17. w = new TopLevelWindow({ show: false });
  18. w.setContentView(new WebContentsView(web));
  19. });
  20. it('prevents adding same WebContents', () => {
  21. const web = webContents.create({});
  22. w = new TopLevelWindow({ show: false });
  23. w.setContentView(new WebContentsView(web));
  24. expect(() => {
  25. w.setContentView(new WebContentsView(web));
  26. }).to.throw('The WebContents has already been added to a View');
  27. });
  28. describe('new WebContentsView()', () => {
  29. it('does not crash on exit', async () => {
  30. const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontentsview.js');
  31. const electronPath = remote.getGlobal('process').execPath;
  32. const appProcess = ChildProcess.spawn(electronPath, [appPath]);
  33. const [code] = await emittedOnce(appProcess, 'close');
  34. expect(code).to.equal(0);
  35. });
  36. });
  37. });