iframe.spec.ts 2.9 KB

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