mirror of
https://github.com/servo/servo.git
synced 2025-07-16 11:53:39 +01:00
87 lines
2.7 KiB
HTML
87 lines
2.7 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8">
|
|
<title>Async Clipboard input type validation tests</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script>
|
|
|
|
test(() => {
|
|
assert_not_equals(navigator.clipboard, undefined);
|
|
assert_true(navigator.clipboard instanceof Clipboard);
|
|
assert_equals(navigator.clipboard, navigator.clipboard);
|
|
}, "navigator.clipboard exists");
|
|
|
|
/* clipboard.write() */
|
|
|
|
promise_test(async () => {
|
|
const dt = new DataTransfer();
|
|
dt.items.add("Howdy", "text/plain");
|
|
await navigator.clipboard.write(dt);
|
|
}, "navigator.clipboard.write(DataTransfer) succeeds");
|
|
|
|
promise_test(async t => {
|
|
await promise_rejects(t, new TypeError(),
|
|
navigator.clipboard.write());
|
|
}, "navigator.clipboard.write() fails (expect DataTransfer)");
|
|
|
|
promise_test(async t => {
|
|
await promise_rejects(t, new TypeError(),
|
|
navigator.clipboard.write(null));
|
|
}, "navigator.clipboard.write(null) fails (expect DataTransfer)");
|
|
|
|
promise_test(async t => {
|
|
await promise_rejects(t, new TypeError(),
|
|
navigator.clipboard.write("Bad string"));
|
|
}, "navigator.clipboard.write(DOMString) fails (expect DataTransfer)");
|
|
|
|
|
|
/* clipboard.writeText() */
|
|
|
|
promise_test(async () => {
|
|
await navigator.clipboard.writeText("New clipboard text");
|
|
}, "navigator.clipboard.writeText(DOMString) succeeds");
|
|
|
|
promise_test(async t => {
|
|
await promise_rejects(t, new TypeError(),
|
|
navigator.clipboard.writeText());
|
|
}, "navigator.clipboard.writeText() fails (expect DOMString)");
|
|
|
|
/* clipboard.writeImageExperimental() */
|
|
|
|
promise_test(async () => {
|
|
const fetched = await fetch(
|
|
'http://localhost:8001/clipboard-apis/resources/greenbox.png');
|
|
const image = await fetched.blob();
|
|
|
|
await navigator.clipboard.writeImageExperimental(image);
|
|
}, "navigator.clipboard.writeImageExperimental(Blob) succeeds");
|
|
|
|
promise_test(async t => {
|
|
await promise_rejects(t, new TypeError(),
|
|
navigator.clipboard.writeImageExperimental());
|
|
}, "navigator.clipboard.writeImageExperimental() fails (expect Blob)");
|
|
|
|
|
|
/* clipboard.read() */
|
|
|
|
promise_test(async () => {
|
|
const result = await navigator.clipboard.read();
|
|
assert_true(result instanceof DataTransfer);
|
|
}, "navigator.clipboard.read() succeeds");
|
|
|
|
|
|
/* clipboard.readText() */
|
|
|
|
promise_test(async () => {
|
|
const result = await navigator.clipboard.readText();
|
|
assert_equals(typeof result, "string");
|
|
}, "navigator.clipboard.readText() succeeds");
|
|
|
|
/* clipboard.readImageExperimental() */
|
|
|
|
promise_test(async () => {
|
|
const result = await navigator.clipboard.readImageExperimental();
|
|
assert_equals(typeof result, "object");
|
|
}, "navigator.clipboard.readImageExperimental() succeeds");
|
|
|
|
</script>
|