Commit 86e820d4 authored by Darwin Huang's avatar Darwin Huang Committed by Commit Bot

Async Clipboard: Update tests to use async/await syntax

Bug: 896479
Change-Id: I95b4c57b2643883f2ea7f0ebbea4f50d7bc7111a
Reviewed-on: https://chromium-review.googlesource.com/c/1371016Reviewed-by: default avatarGary Kacmarcik <garykac@chromium.org>
Commit-Queue: Darwin Huang <huangdarwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615686}
parent 5dc65dbd
......@@ -4,25 +4,20 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var test_data = "Clipboard write (dt/text) -> read (dt/text) test data";
var cb = navigator.clipboard;
var dt = new DataTransfer();
dt.items.add(test_data, "text/plain");
promise_test(async (t) => {
const input = "Clipboard write (dt/text) -> read (dt/text) test data";
const dt = new DataTransfer();
dt.items.add(input, "text/plain");
cb.write(dt).then(t.step_func(() => {
cb.read().then(t.step_func((data) => {
assert_equals(data.items.length, 1);
data.items[0].getAsString(t.step_func((s) => {
assert_equals(s, test_data);
t.done();
}));
}), function() {
t.unreached_func("clipboard.read() fail");
});
}), function() {
t.unreached_func("clipboard.write() fail");
await navigator.clipboard.write(dt);
const output = await navigator.clipboard.read();
assert_equals(output.items.length, 1);
const result_promise = new Promise(resolve => {
output.items[0].getAsString(resolve);
});
const string_output = await result_promise;
assert_equals(string_output, input);
}, "Verify write and read clipboard (DataTransfer/text)");
</script>
Note: This is a manual test because it writes/reads to the shared system
......
......@@ -4,22 +4,15 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var test_data = "Clipboard write (dt/text) -> readText test data";
var cb = navigator.clipboard;
var dt = new DataTransfer();
dt.items.add(test_data, "text/plain");
promise_test(async (t) => {
const input = "Clipboard write (dt/text) -> readText test data";
const dt = new DataTransfer();
dt.items.add(input, "text/plain");
cb.write(dt).then(t.step_func(() => {
cb.readText().then(t.step_func((data) => {
assert_equals(data, test_data);
t.done();
}), function() {
t.unreached_func("clipboard.read() fail");
});
}), function() {
t.unreached_func("clipboard.write() fail");
});
await navigator.clipboard.write(dt);
const output = await navigator.clipboard.readText();
assert_equals(output, input);
}, "Verify write and read clipboard (DataTransfer/text)");
</script>
Note: This is a manual test because it writes/reads to the shared system
......
......@@ -4,22 +4,18 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var test_data = "Clipboard writeText -> read(dt/text) test data";
var cb = navigator.clipboard;
cb.writeText(test_data).then(t.step_func(() => {
cb.read().then(t.step_func((data) => {
assert_equals(data.items.length, 1);
data.items[0].getAsString(t.step_func((s) => {
assert_equals(s, test_data);
t.done();
}));
}), function() {
t.unreached_func("clipboard.read() fail");
});
}), function() {
t.unreached_func("clipboard.writeText() fail");
promise_test(async (t) => {
const input = "Clipboard writeText -> read (dt/text) test data";
await navigator.clipboard.writeText(input);
const output = await navigator.clipboard.read();
assert_equals(output.items.length, 1);
const result_promise = new Promise(resolve => {
output.items[0].getAsString(resolve);
});
const string_output = await result_promise;
assert_equals(string_output, input);
}, "Verify write and read clipboard (DOMString)");
</script>
Note: This is a manual test because it writes/reads to the shared system
......
......@@ -4,19 +4,13 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var test_data = "Clipboard writeText -> readText test data";
var cb = navigator.clipboard;
cb.writeText(test_data).then(t.step_func(() => {
cb.readText().then(t.step_func((data) => {
assert_equals(data, test_data);
t.done();
}), function() {
t.unreached_func("clipboard.readText() fail");
});
}), function() {
t.unreached_func("clipboard.writeText() fail");
});
promise_test(async (t) => {
const input = "Clipboard writeText -> readText test data";
await navigator.clipboard.writeText(input);
const output = await navigator.clipboard.readText();
assert_equals(output, input);
}, "Verify write and read clipboard (DOMString)");
</script>
Note: This is a manual test because it writes/reads to the shared system
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment