[Clipboard API] Import web-platform-tests/clipboard-apis
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / clipboard-apis / async-navigator-clipboard-basics.https.html
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>Async Clipboard basic tests</title>
4 <script src="/resources/testharness.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <script>
7
8 test(function() {
9   assert_not_equals(navigator.clipboard, undefined);
10   assert_true(navigator.clipboard instanceof Clipboard);
11   assert_equals(navigator.clipboard, navigator.clipboard);
12 }, "navigator.clipboard exists");
13
14 /* clipboard.write() */
15
16 promise_test(function() {
17   var dt = new DataTransfer();
18   dt.items.add("Howdy", "text/plain");
19   return navigator.clipboard.write(dt);
20 }, "navigator.clipboard.write(DataTransfer) succeeds");
21
22 promise_test(function(t) {
23   return promise_rejects(t, new TypeError(),
24                          navigator.clipboard.write());
25 }, "navigator.clipboard.write() fails (expect DataTransfer)");
26
27 promise_test(function(t) {
28   return promise_rejects(t, new TypeError(),
29                          navigator.clipboard.write(null));
30 }, "navigator.clipboard.write(null) fails (expect DataTransfer)");
31
32 promise_test(function(t) {
33   return promise_rejects(t, new TypeError(),
34                          navigator.clipboard.write("Bad string"));
35 }, "navigator.clipboard.write(DOMString) fails (expect DataTransfer)");
36
37
38 /* clipboard.writeText() */
39
40 promise_test(function() {
41   return navigator.clipboard.writeText("New clipboard text");
42 }, "navigator.clipboard.writeText(DOMString) succeeds");
43
44 promise_test(function(t) {
45   return promise_rejects(t, new TypeError(),
46                          navigator.clipboard.writeText());
47 }, "navigator.clipboard.writeText() fails (expect DOMString)");
48
49
50 /* clipboard.read() */
51
52 promise_test(function() {
53   return navigator.clipboard.read()
54     .then(function(result) {
55       assert_true(result instanceof DataTransfer);
56     });
57 }, "navigator.clipboard.read() succeeds");
58
59
60 /* clipboard.readText() */
61
62 promise_test(function() {
63   return navigator.clipboard.readText()
64     .then(function(result) {
65       assert_equals(typeof result, "string");
66     });
67 }, "navigator.clipboard.readText() succeeds");
68
69 </script>