-
Notifications
You must be signed in to change notification settings - Fork 54
/
async-navigator-clipboard-basics.https.html
69 lines (52 loc) · 2.02 KB
/
async-navigator-clipboard-basics.https.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<meta charset="utf-8">
<title>Async Clipboard basic tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
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(function() {
var dt = new DataTransfer();
dt.items.add("Howdy", "text/plain");
return navigator.clipboard.write(dt);
}, "navigator.clipboard.write(DataTransfer) succeeds");
promise_test(function(t) {
return promise_rejects(t, new TypeError(),
navigator.clipboard.write());
}, "navigator.clipboard.write() fails (expect DataTransfer)");
promise_test(function(t) {
return promise_rejects(t, new TypeError(),
navigator.clipboard.write(null));
}, "navigator.clipboard.write(null) fails (expect DataTransfer)");
promise_test(function(t) {
return promise_rejects(t, new TypeError(),
navigator.clipboard.write("Bad string"));
}, "navigator.clipboard.write(DOMString) fails (expect DataTransfer)");
/* clipboard.writeText() */
promise_test(function() {
return navigator.clipboard.writeText("New clipboard text");
}, "navigator.clipboard.writeText(DOMString) succeeds");
promise_test(function(t) {
return promise_rejects(t, new TypeError(),
navigator.clipboard.writeText());
}, "navigator.clipboard.writeText() fails (expect DOMString)");
/* clipboard.read() */
promise_test(function() {
return navigator.clipboard.read()
.then(function(result) {
assert_true(result instanceof DataTransfer);
});
}, "navigator.clipboard.read() succeeds");
/* clipboard.readText() */
promise_test(function() {
return navigator.clipboard.readText()
.then(function(result) {
assert_equals(typeof result, "string");
});
}, "navigator.clipboard.readText() succeeds");
</script>