api-web-contents-view-spec.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { closeWindow } from './lib/window-helpers';
  2. import { BaseWindow, WebContentsView } from 'electron/main';
  3. describe('WebContentsView', () => {
  4. let w: BaseWindow;
  5. afterEach(async () => {
  6. await closeWindow(w as any);
  7. w = null as unknown as BaseWindow;
  8. });
  9. it('can be used as content view', () => {
  10. w = new BaseWindow({ show: false });
  11. w.setContentView(new WebContentsView({}));
  12. });
  13. function triggerGCByAllocation () {
  14. const arr = [];
  15. for (let i = 0; i < 1000000; i++) {
  16. arr.push([]);
  17. }
  18. return arr;
  19. }
  20. it('doesn\'t crash when GCed during allocation', (done) => {
  21. // eslint-disable-next-line no-new
  22. new WebContentsView({});
  23. setTimeout(() => {
  24. // NB. the crash we're testing for is the lack of a current `v8::Context`
  25. // when emitting an event in WebContents's destructor. V8 is inconsistent
  26. // about whether or not there's a current context during garbage
  27. // collection, and it seems that `v8Util.requestGarbageCollectionForTesting`
  28. // causes a GC in which there _is_ a current context, so the crash isn't
  29. // triggered. Thus, we force a GC by other means: namely, by allocating a
  30. // bunch of stuff.
  31. triggerGCByAllocation();
  32. done();
  33. });
  34. });
  35. });