Files
vscode-codeql/extensions/ql-vscode/src/vscode-tests/no-workspace/webview-uri.test.ts
Aditya Sharad d9a1dce7fa
Some checks failed
Build Extension / Build (ubuntu-latest) (push) Has been cancelled
Build Extension / Build (windows-latest) (push) Has been cancelled
Build Extension / Test (ubuntu-latest) (push) Has been cancelled
Build Extension / Test (windows-latest) (push) Has been cancelled
Release / Release (push) Has been cancelled
CodeQL for VS Code: Initial commit.
2019-11-13 12:23:53 -08:00

35 lines
1.2 KiB
TypeScript

import { expect } from "chai";
import * as tmp from "tmp";
import { window, ViewColumn, Uri } from "vscode";
import { fileUriToWebviewUri, webviewUriToFileUri } from '../../interface';
describe('webview uri conversion', function () {
it('should correctly round trip from filesystem to webview and back', function () {
const tmpFile = tmp.fileSync({ prefix: 'uri_test_', postfix: '.bqrs', keep: false });
const fileUriOnDisk = Uri.file(tmpFile.name);
const panel = window.createWebviewPanel(
'test panel',
'test panel',
ViewColumn.Beside,
{
enableScripts: false,
localResourceRoots: [
fileUriOnDisk
]
}
);
after(function () {
panel.dispose();
tmpFile.removeCallback();
});
// CSP allowing nothing, to prevent warnings.
const html = `<html><head><meta http-equiv="Content-Security-Policy" content="default-src 'none';"></head></html>`;
panel.webview.html = html;
const webviewUri = fileUriToWebviewUri(panel, fileUriOnDisk);
const reconstructedFileUri = webviewUriToFileUri(webviewUri);
expect(reconstructedFileUri.toString(true)).to.equal(fileUriOnDisk.toString(true));
});
});