| <!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(Blob/text) */ |
| |
| promise_test(async () => { |
| const blob = new Blob(["hello"], {type: 'text/plain'}); |
| await navigator.clipboard.write(blob); |
| }, "navigator.clipboard.write(Blob) succeeds"); |
| |
| promise_test(async t => { |
| await promise_rejects(t, new TypeError(), |
| navigator.clipboard.write()); |
| }, "navigator.clipboard.write() fails (expect Blob)"); |
| |
| promise_test(async t => { |
| await promise_rejects(t, new TypeError(), |
| navigator.clipboard.write(null)); |
| }, "navigator.clipboard.write(null) fails (expect Blob)"); |
| |
| promise_test(async t => { |
| await promise_rejects(t, new TypeError(), |
| navigator.clipboard.write("Bad string")); |
| }, "navigator.clipboard.write(DOMString) fails (expect Blob)"); |
| |
| |
| /* 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.write(Blob/image) */ |
| |
| promise_test(async () => { |
| const fetched = await fetch( |
| 'http://localhost:8001/clipboard-apis/resources/greenbox.png'); |
| const image = await fetched.blob(); |
| |
| await navigator.clipboard.write(image); |
| }, "navigator.clipboard.writeImageExperimental(Blob) succeeds"); |
| |
| promise_test(async t => { |
| await promise_rejects(t, new TypeError(), |
| navigator.clipboard.write()); |
| }, "navigator.clipboard.writeImageExperimental() fails (expect Blob)"); |
| |
| |
| /* Blob/text or Blob/image clipboard.read() */ |
| |
| promise_test(async () => { |
| const result = await navigator.clipboard.read(); |
| assert_true(result instanceof Blob); |
| assert_equals(typeof result, "object"); |
| }, "navigator.clipboard.read() succeeds"); |
| |
| |
| /* clipboard.readText() */ |
| |
| promise_test(async () => { |
| const result = await navigator.clipboard.readText(); |
| assert_equals(typeof result, "string"); |
| }, "navigator.clipboard.readText() succeeds"); |
| |
| </script> |