mirror of
https://github.com/servo/servo.git
synced 2025-07-12 18:03:49 +01:00
78 lines
2.7 KiB
HTML
78 lines
2.7 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8">
|
|
<title>ClipboardItem tests</title>
|
|
<link rel="help" href="https://w3c.github.io/clipboard-apis/#async-clipboard-api">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script>
|
|
|
|
const blob = new Blob(['hello'], {type: 'text/plain'});
|
|
const blob2 = new Blob(['this should work'], {type: 'not a/real type'});
|
|
|
|
test(() => {
|
|
new ClipboardItem({'text/plain': blob});
|
|
new ClipboardItem({'text/plain': blob, 'not a/real type': blob2});
|
|
}, "ClipboardItem({string, Blob}) succeeds with different types");
|
|
|
|
test(() => {
|
|
new ClipboardItem({'text/plain': blob}, {});
|
|
}, "ClipboardItem() succeeds with empty options");
|
|
|
|
test(() => {
|
|
assert_throws(new TypeError(), () => {new ClipboardItem({});});
|
|
}, "ClipboardItem({}) fails with empty dictionary input");
|
|
|
|
test(() => {
|
|
assert_throws(new TypeError(), () => {new ClipboardItem(blob);});
|
|
}, "ClipboardItem(Blob) fails");
|
|
|
|
test(() => {
|
|
assert_throws(new TypeError(), () => {new ClipboardItem(null);});
|
|
}, "ClipboardItem() fails with null input");
|
|
|
|
test(() => {
|
|
assert_throws(new TypeError(), () => {new ClipboardItem();});
|
|
}, "ClipboardItem() fails with no input");
|
|
|
|
test(() => {
|
|
const item = new ClipboardItem({'text/plain': blob});
|
|
const types = item.types;
|
|
assert_equals(types.length, 1);
|
|
assert_equals(types[0], 'text/plain');
|
|
const item2 =
|
|
new ClipboardItem({'text/plain': blob, 'not a/real type': blob2});
|
|
const types2 = item2.types;
|
|
assert_equals(types2.length, 2);
|
|
assert_equals(types2[0], 'text/plain');
|
|
assert_equals(types2[1], 'not a/real type');
|
|
}, "types() returns correct values");
|
|
|
|
promise_test(async () => {
|
|
const item =
|
|
new ClipboardItem({'text/plain': blob, 'not a/real type': blob2});
|
|
|
|
const blobOutput = await item.getType('text/plain');
|
|
assert_true(blobOutput.type.includes('text/plain'));
|
|
const text = await (new Response(blobOutput)).text();
|
|
|
|
assert_equals('hello', text);
|
|
}, "getType(DOMString valid type) succeeds with correct output");
|
|
|
|
promise_test(async () => {
|
|
const item =
|
|
new ClipboardItem({'text/plain': blob, 'not a/real type': blob2});
|
|
|
|
const blobOutput = await item.getType('not a/real type');
|
|
assert_true(blobOutput.type.includes('not a/real type'));
|
|
const text = await (new Response(blobOutput)).text();
|
|
|
|
assert_equals('this should work', text);
|
|
}, "getType(DOMString invalid type) succeeds with correct output");
|
|
|
|
promise_test(async t => {
|
|
const item =
|
|
new ClipboardItem({'text/plain': blob, 'not a/real type': blob2});
|
|
promise_rejects(t, "NotFoundError", item.getType('type not in item'));
|
|
promise_rejects(t, "NotFoundError", item.getType('text/plain:subtype'));
|
|
}, "getType(DOMString type) rejects correctly when querying for missing type");
|
|
</script>
|