api-browser-view-spec.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. 'use strict'
  2. const assert = require('assert')
  3. const {closeWindow} = require('./window-helpers')
  4. const {remote} = require('electron')
  5. const {BrowserView, BrowserWindow} = remote
  6. describe('View module', function () {
  7. var w = null
  8. var view = null
  9. beforeEach(function () {
  10. w = new BrowserWindow({
  11. show: false,
  12. width: 400,
  13. height: 400,
  14. webPreferences: {
  15. backgroundThrottling: false
  16. }
  17. })
  18. })
  19. afterEach(function () {
  20. if (view) {
  21. view.destroy()
  22. view = null
  23. }
  24. return closeWindow(w).then(function () { w = null })
  25. })
  26. describe('BrowserView.setBackgroundColor()', function () {
  27. it('does not throw for valid args', function () {
  28. view = new BrowserView()
  29. view.setBackgroundColor('#000')
  30. })
  31. it('throws for invalid args', function () {
  32. view = new BrowserView()
  33. assert.throws(function () {
  34. view.setBackgroundColor(null)
  35. }, /conversion failure/)
  36. })
  37. })
  38. describe('BrowserView.setAutoResize()', function () {
  39. it('does not throw for valid args', function () {
  40. view = new BrowserView()
  41. view.setAutoResize({})
  42. view.setAutoResize({ width: true, height: false })
  43. })
  44. it('throws for invalid args', function () {
  45. view = new BrowserView()
  46. assert.throws(function () {
  47. view.setAutoResize(null)
  48. }, /conversion failure/)
  49. })
  50. })
  51. describe('BrowserView.setBounds()', function () {
  52. it('does not throw for valid args', function () {
  53. view = new BrowserView()
  54. view.setBounds({ x: 0, y: 0, width: 1, height: 1 })
  55. })
  56. it('throws for invalid args', function () {
  57. view = new BrowserView()
  58. assert.throws(function () {
  59. view.setBounds(null)
  60. }, /conversion failure/)
  61. assert.throws(function () {
  62. view.setBounds({})
  63. }, /conversion failure/)
  64. })
  65. })
  66. describe('BrowserWindow.setBrowserView()', function () {
  67. it('does not throw for valid args', function () {
  68. view = new BrowserView()
  69. w.setBrowserView(view)
  70. })
  71. it('does not throw if called multiple times with same view', function () {
  72. view = new BrowserView()
  73. w.setBrowserView(view)
  74. w.setBrowserView(view)
  75. w.setBrowserView(view)
  76. })
  77. })
  78. })