1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 /* import-globals-from clipboard_helper.js */
8 clipboardTypes.forEach(function (type) {
9 if (clipboard.isClipboardTypeSupported(type)) {
10 clipboardTypes.forEach(function (otherType) {
11 if (clipboard.isClipboardTypeSupported(otherType)) {
12 [true, false].forEach(async function (async) {
13 add_task(async function test_clipboard_pending_asyncSetData() {
15 `Test having a pending asyncSetData request on ${type} and then make a new ${
16 async ? "asyncSetData" : "setData"
17 } request on ${otherType}`
20 // Create a pending asyncSetData request
23 let priorPromise = new Promise(resolve => {
24 priorRequest = clipboard.asyncSetData(type, null, {
25 QueryInterface: SpecialPowers.ChromeUtils.generateQI([
26 "nsIAsyncSetClipboardDataCallback",
35 // Create a new request
36 let str = writeRandomStringToClipboard(
43 if (type === otherType) {
45 "The new request to the same clipboard type should cancel the prior pending request"
52 "The pending asyncSetData request should be canceled"
56 generateNewTransferable("text/plain", generateRandomString())
60 "An error should be thrown if setData is called on a canceled clipboard request"
66 "An error should be thrown if setData is called on a canceled clipboard request"
71 "The new request to the different clipboard type should not cancel the prior pending request"
73 str = generateRandomString();
75 generateNewTransferable("text/plain", str),
83 "The pending asyncSetData request should success"
88 generateNewTransferable("text/plain", generateRandomString())
92 "Calling setData multiple times should throw an error"
98 "Calling setData multiple times should throw an error"
103 // Test clipboard data.
105 getClipboardData("text/plain", type),
107 `Test clipboard data for type ${type}`
110 // Clean clipboard data.
111 cleanupAllClipboard();
117 add_task(async function test_clipboard_asyncSetData_abort() {
118 info(`Test abort asyncSetData request on ${type}`);
120 // Create a pending asyncSetData request
122 let request = clipboard.asyncSetData(type, null, rv => {
128 request.abort(Cr.NS_OK);
129 ok(false, "Throw an error when attempting to abort with NS_OK");
134 "Should throw an error when attempting to abort with NS_OK"
137 is(result, undefined, "The asyncSetData request should not be canceled");
139 // Abort with NS_ERROR_ABORT.
140 request.abort(Cr.NS_ERROR_ABORT);
144 "The asyncSetData request should be canceled"
147 request.abort(Cr.NS_ERROR_FAILURE);
148 ok(false, "Throw an error when attempting to abort again");
153 "Should throw an error when attempting to abort again"
159 "The callback should not be notified again"
164 generateNewTransferable("text/plain", generateRandomString())
168 "An error should be thrown if setData is called on a canceled clipboard request"
174 "An error should be thrown if setData is called on a canceled clipboard request"