123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- // Copyright (c) Jupyter Development Team.
- // Distributed under the terms of the Modified BSD License.
- import { IFrame } from '@jupyterlab/apputils';
- describe('@jupyterlab/apputils', () => {
- describe('IFrame', () => {
- describe('#constructor()', () => {
- it('should create a new iframe widget', () => {
- const iframe = new IFrame();
- expect(iframe).toBeInstanceOf(IFrame);
- expect(iframe.hasClass('jp-IFrame')).toBe(true);
- expect(iframe.node.querySelector('iframe')).toBeTruthy();
- });
- it('should be sandboxed by default', () => {
- const iframe = new IFrame();
- const node = iframe.node.querySelector('iframe')!;
- expect(node.getAttribute('sandbox') !== null).toBe(true);
- });
- it('should be have a no-referrer policy by default', () => {
- const iframe = new IFrame();
- const node = iframe.node.querySelector('iframe')!;
- expect(node.getAttribute('referrerpolicy')).toBe('no-referrer');
- });
- it('should allow sandboxing exceptions to be specified in the options', () => {
- const iframe = new IFrame({
- sandbox: ['allow-scripts', 'allow-same-origin']
- });
- const node = iframe.node.querySelector('iframe')!;
- expect(node.getAttribute('sandbox')).toBe(
- 'allow-scripts allow-same-origin'
- );
- });
- it('should allow the referrer policy to be specified in the options', () => {
- const iframe = new IFrame({ referrerPolicy: 'unsafe-url' });
- const node = iframe.node.querySelector('iframe')!;
- expect(node.getAttribute('referrerpolicy')).toBe('unsafe-url');
- });
- });
- describe('#url', () => {
- it('should be the url of the iframe', () => {
- const iframe = new IFrame();
- expect(iframe.url).toBe('');
- iframe.url = 'foo';
- expect(iframe.url).toBe('foo');
- });
- });
- describe('#referrerPolicy', () => {
- it('should set the referrer policy for the iframe.', () => {
- const iframe = new IFrame({ referrerPolicy: 'unsafe-url' });
- const node = iframe.node.querySelector('iframe')!;
- expect(iframe.referrerPolicy).toBe('unsafe-url');
- iframe.referrerPolicy = 'origin';
- expect(iframe.referrerPolicy).toBe('origin');
- expect(node.getAttribute('referrerpolicy')).toBe('origin');
- });
- });
- describe('#sandbox', () => {
- it('should set the exceptions for the sandbox attribute.', () => {
- const iframe = new IFrame({
- sandbox: ['allow-scripts', 'allow-same-origin']
- });
- const node = iframe.node.querySelector('iframe')!;
- expect(iframe.sandbox).toEqual(['allow-scripts', 'allow-same-origin']);
- iframe.sandbox = ['allow-pointer-lock'];
- expect(iframe.sandbox).toEqual(['allow-pointer-lock']);
- expect(node.getAttribute('sandbox')).toBe('allow-pointer-lock');
- });
- });
- });
- });
|