Add pinning test for setting localResourceRoots

This commit is contained in:
Matt Bierner 2018-10-08 10:08:34 -07:00
parent d01d178b3b
commit 5b03dcd69d
2 changed files with 30 additions and 0 deletions

View file

@ -277,6 +277,36 @@ suite('Webview tests', () => {
assert.strictEqual((await response).value, false);
}
});
test('webviews should allow overriding allowed resource paths using localResourceRoots', async () => {
const webview = _register(vscode.window.createWebviewPanel(webviewId, 'title', { viewColumn: vscode.ViewColumn.One }, {
enableScripts: true,
localResourceRoots: [vscode.Uri.file(join(vscode.workspace.rootPath!, 'sub'))]
}));
webview.webview.html = createHtmlDocumentWithBody(/*html*/`
<script>
const vscode = acquireVsCodeApi();
window.addEventListener('message', (message) => {
const img = document.createElement('img');
img.addEventListener('load', () => { vscode.postMessage({ value: true }); });
img.addEventListener('error', () => { vscode.postMessage({ value: false }); });
img.src = message.data.src;
document.body.appendChild(img);
});
</script>`);
const workspaceRootUri = vscode.Uri.file(vscode.workspace.rootPath!).with({ scheme: 'vscode-resource' });
{
const response = sendRecieveMessage(webview, { src: workspaceRootUri.toString() + '/sub/image.png' });
assert.strictEqual((await response).value, true);
}
{
const response = sendRecieveMessage(webview, { src: workspaceRootUri.toString() + '/image.png' });
assert.strictEqual((await response).value, false);
}
});
});
function createHtmlDocumentWithBody(body: string): string {

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB