iframe.spec.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import 'jest';
  4. import { IFrame } from '@jupyterlab/apputils';
  5. describe('@jupyterlab/apputils', () => {
  6. describe('IFrame', () => {
  7. describe('#constructor()', () => {
  8. it('should create a new iframe widget', () => {
  9. const iframe = new IFrame();
  10. expect(iframe).toBeInstanceOf(IFrame);
  11. expect(iframe.hasClass('jp-IFrame')).toBe(true);
  12. expect(iframe.node.querySelector('iframe')).toBeTruthy();
  13. });
  14. it('should be sandboxed by default', () => {
  15. const iframe = new IFrame();
  16. const node = iframe.node.querySelector('iframe')!;
  17. expect(node.getAttribute('sandbox') !== null).toBe(true);
  18. });
  19. it('should be have a no-referrer policy by default', () => {
  20. const iframe = new IFrame();
  21. const node = iframe.node.querySelector('iframe')!;
  22. expect(node.getAttribute('referrerpolicy')).toBe('no-referrer');
  23. });
  24. it('should allow sandboxing exceptions to be specified in the options', () => {
  25. const iframe = new IFrame({
  26. sandbox: ['allow-scripts', 'allow-same-origin']
  27. });
  28. const node = iframe.node.querySelector('iframe')!;
  29. expect(node.getAttribute('sandbox')).toBe(
  30. 'allow-scripts allow-same-origin'
  31. );
  32. });
  33. it('should allow the referrer policy to be specified in the options', () => {
  34. const iframe = new IFrame({ referrerPolicy: 'unsafe-url' });
  35. const node = iframe.node.querySelector('iframe')!;
  36. expect(node.getAttribute('referrerpolicy')).toBe('unsafe-url');
  37. });
  38. });
  39. describe('#url', () => {
  40. it('should be the url of the iframe', () => {
  41. const iframe = new IFrame();
  42. expect(iframe.url).toBe('');
  43. iframe.url = 'foo';
  44. expect(iframe.url).toBe('foo');
  45. });
  46. });
  47. describe('#referrerPolicy', () => {
  48. it('should set the referrer policy for the iframe.', () => {
  49. const iframe = new IFrame({ referrerPolicy: 'unsafe-url' });
  50. const node = iframe.node.querySelector('iframe')!;
  51. expect(iframe.referrerPolicy).toBe('unsafe-url');
  52. iframe.referrerPolicy = 'origin';
  53. expect(iframe.referrerPolicy).toBe('origin');
  54. expect(node.getAttribute('referrerpolicy')).toBe('origin');
  55. });
  56. });
  57. describe('#sandbox', () => {
  58. it('should set the exceptions for the sandbox attribute.', () => {
  59. const iframe = new IFrame({
  60. sandbox: ['allow-scripts', 'allow-same-origin']
  61. });
  62. const node = iframe.node.querySelector('iframe')!;
  63. expect(iframe.sandbox).toEqual(['allow-scripts', 'allow-same-origin']);
  64. iframe.sandbox = ['allow-pointer-lock'];
  65. expect(iframe.sandbox).toEqual(['allow-pointer-lock']);
  66. expect(node.getAttribute('sandbox')).toBe('allow-pointer-lock');
  67. });
  68. });
  69. });
  70. });