提交 c03b5818 编写于 作者: M Matt Bierner

Add test for copying text from webview

上级 f2ca025a
...@@ -7,7 +7,7 @@ import 'mocha'; ...@@ -7,7 +7,7 @@ import 'mocha';
import * as assert from 'assert'; import * as assert from 'assert';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { join } from 'path'; import { join } from 'path';
import { closeAllEditors, disposeAll, conditionalTest } from '../utils'; import { closeAllEditors, disposeAll, conditionalTest, delay } from '../utils';
const webviewId = 'myWebview'; const webviewId = 'myWebview';
...@@ -332,7 +332,27 @@ suite('Webview tests', () => { ...@@ -332,7 +332,27 @@ suite('Webview tests', () => {
webview.webview.postMessage({ value: 1 }); webview.webview.postMessage({ value: 1 });
await firstResponse; await firstResponse;
assert.strictEqual(webview.viewColumn, vscode.ViewColumn.One); assert.strictEqual(webview.viewColumn, vscode.ViewColumn.One);
});
test('webview can copy text from webview', async () => {
const expectedText = `webview text from: ${Date.now()}!`;
const webview = _register(vscode.window.createWebviewPanel(webviewId, 'title', { viewColumn: vscode.ViewColumn.One }, { enableScripts: true, retainContextWhenHidden: true }));
const ready = getMesssage(webview);
webview.webview.html = createHtmlDocumentWithBody(/*html*/`
<b>${expectedText}</b>
<script>
const vscode = acquireVsCodeApi();
document.execCommand('selectAll');
vscode.postMessage({ type: 'ready' });
</script>`);
await ready;
await vscode.commands.executeCommand('editor.action.webvieweditor.copy');
await delay(200); // Make sure copy has time to reach webview
assert.strictEqual(await vscode.env.clipboard.readText(), expectedText);
}); });
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册