mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Automated downstream sync of changes from upstream as of 18-05-2025 [no-wpt-sync] Signed-off-by: WPT Sync Bot <ghbot+wpt-sync@servo.org>
112 lines
No EOL
4.1 KiB
HTML
Vendored
112 lines
No EOL
4.1 KiB
HTML
Vendored
<!doctype html>
|
|
<meta charset="utf-8">
|
|
<title>Async Clipboard input type validation tests - DOMString input in write API</title>
|
|
<link rel="help" href="https://w3c.github.io/clipboard-apis/#typedefdef-clipboarditemdata">
|
|
|
|
<body>Body needed for test_driver.click()</body>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/resources/testdriver.js"></script>
|
|
<script src="/resources/testdriver-vendor.js"></script>
|
|
<script src="resources/user-activation.js"></script>
|
|
<script>
|
|
|
|
// Permissions are required in order to invoke navigator.clipboard functions in
|
|
// an automated test.
|
|
async function getPermissions() {
|
|
await tryGrantReadPermission();
|
|
await tryGrantWritePermission();
|
|
await waitForUserActivation();
|
|
}
|
|
|
|
test(() => {
|
|
assert_not_equals(navigator.clipboard, undefined);
|
|
assert_true(navigator.clipboard instanceof Clipboard);
|
|
assert_equals(navigator.clipboard, navigator.clipboard);
|
|
}, 'navigator.clipboard exists');
|
|
|
|
promise_test(async t => {
|
|
await getPermissions();
|
|
const text_plain = "This text was copied using `Clipboard.prototype.write`.";
|
|
const html_text = "<p style='color: red; font-style: oblique;'>Test</p>";
|
|
await navigator.clipboard.write([
|
|
new ClipboardItem({
|
|
"text/plain": text_plain,
|
|
"text/html": html_text
|
|
}),
|
|
]);
|
|
}, 'navigator.clipboard.write(DOMString) succeeds');
|
|
|
|
promise_test(async () => {
|
|
await getPermissions();
|
|
const promise_text_string = Promise.resolve('hello');
|
|
const promise_html_string = Promise.resolve("<p style='color: red; font-style: oblique;'>hello</p>");
|
|
const item = new ClipboardItem({
|
|
'text/plain': promise_text_string,
|
|
'text/html': promise_html_string
|
|
});
|
|
await navigator.clipboard.write([item]);
|
|
}, 'navigator.clipboard.write(Promise<DOMString>) succeeds');
|
|
|
|
promise_test(async () => {
|
|
await getPermissions();
|
|
const promise_html_string = `
|
|
<table>
|
|
<tbody>
|
|
<tr>
|
|
<td>0,00€</td>
|
|
</tr>
|
|
<tr>
|
|
<td>0,00€</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
`;
|
|
const item = new ClipboardItem({
|
|
'text/html': promise_html_string
|
|
});
|
|
await navigator.clipboard.write([item]);
|
|
}, 'navigator.clipboard.write(Promise<DOMString>) with utf-16 string succeeds');
|
|
|
|
promise_test(async t => {
|
|
await getPermissions();
|
|
const text_plain = 'hello';
|
|
const html_text = "<p style='color: red; font-style: oblique;'>hello</p>";
|
|
const image = await fetch("/clipboard-apis/resources/greenbox.png");
|
|
const item = new ClipboardItem({
|
|
'text/plain': text_plain,
|
|
'text/html': new Blob([html_text], {type: 'text/html'}),
|
|
'image/png': image.blob(), // Promise<Blob>
|
|
'web text/csv': 'hello,world'
|
|
});
|
|
await navigator.clipboard.write([item]);
|
|
}, 'navigator.clipboard.write(web_custom_format) succeeds');
|
|
|
|
promise_test(async () => {
|
|
await getPermissions();
|
|
const html_text = "<p style='color: red; font-style: oblique;'>Test</p>";
|
|
const item = new ClipboardItem({
|
|
'text/plain': 'hello',
|
|
'text/html': new Blob([html_text], {type: 'text/html'})
|
|
});
|
|
const text = await item.getType('text/plain');
|
|
const blob = await item.getType('text/html');
|
|
assert_true(text instanceof Blob, "item.getType('text/plain') should return a Blob");
|
|
assert_true(blob instanceof Blob, "item.getType('text/html') should return a Blob");
|
|
}, 'validate GetType(type) on a constructed ClipboardItem returns Blob');
|
|
|
|
promise_test(async () => {
|
|
await getPermissions();
|
|
// Test string with various non-Latin characters: Chinese, Arabic, Cyrillic, emoji
|
|
const nonLatinText = "你好 مرحبا Привет 👋🌍";
|
|
const item = new ClipboardItem({
|
|
'text/plain': nonLatinText
|
|
});
|
|
await navigator.clipboard.write([item]);
|
|
|
|
// Read back the text and verify it matches
|
|
const readText = await navigator.clipboard.readText();
|
|
assert_equals(readText, nonLatinText,
|
|
"Text read from clipboard should match the non-Latin text that was written");
|
|
}, 'write non-Latin characters with DOMString and verify readText returns the same string');
|
|
</script> |