api-web-contents-view-spec.js 788 B

1234567891011121314151617181920212223242526
  1. 'use strict'
  2. const assert = require('assert')
  3. const {closeWindow} = require('./window-helpers')
  4. const {webContents, TopLevelWindow, WebContentsView} = require('electron').remote
  5. describe('WebContentsView', () => {
  6. let w = null
  7. afterEach(() => closeWindow(w).then(() => { w = null }))
  8. it('can be used as content view', () => {
  9. const web = webContents.create({})
  10. w = new TopLevelWindow({show: false})
  11. w.setContentView(new WebContentsView(web))
  12. })
  13. it('prevents adding same WebContents', () => {
  14. const web = webContents.create({})
  15. w = new TopLevelWindow({show: false})
  16. w.setContentView(new WebContentsView(web))
  17. assert.throws(() => {
  18. w.setContentView(new WebContentsView(web))
  19. }, /The WebContents has already been added to a View/)
  20. })
  21. })