1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { IFrame } from '@jupyterlab/ui-components';
describe('@jupyterlab/ui-components', () => {
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');
});
});
});
});
|