Bug 1852783 - Part 3: Add clipboard mochitest-plain tests; r=spohl

Differential Revision: https://phabricator.services.mozilla.com/D187999
This commit is contained in:
Edgar Chen 2023-09-14 09:42:52 +00:00
Родитель cd4dbf511f
Коммит 38d7173959
6 изменённых файлов: 91 добавлений и 24 удалений

Просмотреть файл

@ -3,6 +3,9 @@
"use strict";
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
const Cr = SpecialPowers.Cr;
const clipboard = SpecialPowers.Services.clipboard;
const clipboardTypes = [
clipboard.kGlobalClipboard,
@ -104,7 +107,7 @@ function getClipboardData(aFlavor, aClipboardType) {
clipboard.getData(trans, aClipboardType);
try {
var data = {};
var data = SpecialPowers.createBlankObject();
trans.getTransferData(aFlavor, data);
return data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data;
} catch (ex) {

Просмотреть файл

@ -6,7 +6,7 @@
"use strict";
function getLoadContext() {
return window.docShell.QueryInterface(Ci.nsILoadContext);
return SpecialPowers.wrap(window).docShell.QueryInterface(Ci.nsILoadContext);
}
// Get clipboard data to paste.
@ -17,7 +17,7 @@ function paste(clipboard) {
trans.init(getLoadContext());
trans.addDataFlavor("text/plain");
clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
let str = {};
let str = SpecialPowers.createBlankObject();
try {
trans.getTransferData("text/plain", str);
} catch (e) {
@ -114,7 +114,7 @@ clipboardTypes.forEach(function (clipboardType) {
// Set text/plain to empty string.
writeStringToClipboard("", "text/plain", clipboardType);
// XXX gtk doesn't support get empty text data from clipboard.
// XXX gtk doesn't support get empty text data from clipboard, bug 1852983.
if (navigator.platform.includes("Linux")) {
todo_is(
getClipboardData("text/plain", clipboardType),
@ -128,10 +128,19 @@ clipboardTypes.forEach(function (clipboardType) {
`Should get empty string on clipboard type ${clipboardType}`
);
}
ok(
clipboard.hasDataMatchingFlavors(["text/plain"], clipboardType),
`Should have text/plain flavor on clipboard ${clipboardType}`
);
// XXX android doesn't support setting empty text data to clipboard, bug 1841058.
if (navigator.userAgent.includes("Android")) {
todo_is(
clipboard.hasDataMatchingFlavors(["text/plain"], clipboardType),
true,
`Should have text/plain flavor on clipboard ${clipboardType}`
);
} else {
ok(
clipboard.hasDataMatchingFlavors(["text/plain"], clipboardType),
`Should have text/plain flavor on clipboard ${clipboardType}`
);
}
// Clear all clipboard data.
cleanupAllClipboard();

Просмотреть файл

@ -9,7 +9,7 @@ clipboardTypes.forEach(function (type) {
if (clipboard.isClipboardTypeSupported(type)) {
clipboardTypes.forEach(function (otherType) {
if (clipboard.isClipboardTypeSupported(otherType)) {
[true, false].forEach(function (async) {
[true, false].forEach(async function (async) {
add_task(async function test_clipboard_pending_asyncSetData() {
info(
`Test having a pending asyncSetData request on ${type} and then make a new ${
@ -19,13 +19,17 @@ clipboardTypes.forEach(function (type) {
// Create a pending asyncSetData request
let priorResult;
let priorRequest = clipboard.asyncSetData(type, {
QueryInterface: ChromeUtils.generateQI([
"nsIAsyncSetClipboardDataCallback",
]),
onComplete(rv) {
priorResult = rv;
},
let priorRequest;
let priorPromise = new Promise(resolve => {
priorRequest = clipboard.asyncSetData(type, {
QueryInterface: SpecialPowers.ChromeUtils.generateQI([
"nsIAsyncSetClipboardDataCallback",
]),
onComplete(rv) {
priorResult = rv;
resolve();
},
});
});
// Create a new request
@ -37,7 +41,11 @@ clipboardTypes.forEach(function (type) {
);
if (type === otherType) {
info("The new request should cancel the prior pending request");
info(
"The new request to the same clipboard type should cancel the prior pending request"
);
await priorPromise;
is(
priorResult,
Cr.NS_ERROR_ABORT,
@ -60,18 +68,21 @@ clipboardTypes.forEach(function (type) {
}
} else {
info(
"The new request should be used to cancel the prior pending request for different clipboard types"
);
is(
priorResult,
undefined,
"The pending asyncSetData request should not be canceled"
"The new request to the different clipboard type should not cancel the prior pending request"
);
str = generateRandomString();
priorRequest.setData(
generateNewTransferable("text/plain", str),
null
);
await priorPromise;
is(
priorResult,
Cr.NS_OK,
"The pending asyncSetData request should success"
);
try {
priorRequest.setData(
generateNewTransferable("text/plain", generateRandomString())
@ -109,7 +120,7 @@ clipboardTypes.forEach(function (type) {
// Create a pending asyncSetData request
let result;
let request = clipboard.asyncSetData(type, {
QueryInterface: ChromeUtils.generateQI([
QueryInterface: SpecialPowers.ChromeUtils.generateQI([
"nsIAsyncSetClipboardDataCallback",
]),
onComplete(rv) {

Просмотреть файл

@ -1,4 +1,6 @@
[DEFAULT]
support-files =
clipboard_helper.js
[test_AltGr_key_events_in_web_content_on_windows.html]
skip-if =
@ -12,6 +14,13 @@ skip-if =
android_version == '24'
(headless && os == "win")
[test_autocapitalize.html]
[test_clipboard.html]
skip-if = headless # bug 1852983
support-files =
file_test_clipboard.js
[test_clipboard_asyncSetData.html]
support-files =
file_test_clipboard_asyncSetData.js
[test_keypress_event_with_alt_on_mac.html]
skip-if = toolkit != "cocoa"
[test_mouse_event_with_control_on_mac.html]

Просмотреть файл

@ -0,0 +1,16 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=948065
-->
<head>
<title>Test for Bug 948065</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="clipboard_helper.js"></script>
</head>
<body>
<!-- Tests are in file_test_clipboard.js -->
<script src="file_test_clipboard.js"></script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1712122
-->
<head>
<title>Test for Bug 1712122</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="clipboard_helper.js"></script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<!-- Tests are in file_test_clipboard_asyncSetData.js -->
<script src="file_test_clipboard_asyncSetData.js"></script>
</body>
</html>