Bug 1884020 - Make reading from clipboard cache returns same flavor order as reading from system clipboard; r=spohl

This basically makes the macOS behave the same as other platform (currently only
macOS would read data from clipboard cache). And also this would ensure behavior
doesn't change if one day we would like to enable reading-from-clipboard-cache
on other platforms as well.

Differential Revision: https://phabricator.services.mozilla.com/D203893
This commit is contained in:
Edgar Chen 2024-03-14 08:25:02 +00:00
Родитель c11cf60829
Коммит 73ebcf0f96
3 изменённых файлов: 34 добавлений и 4 удалений

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

@ -840,8 +840,8 @@ nsBaseClipboard::MaybeCreateGetRequestFromClipboardCache(
}
nsTArray<nsCString> results;
for (const auto& transferableFlavor : transferableFlavors) {
for (const auto& flavor : aFlavorList) {
for (const auto& flavor : aFlavorList) {
for (const auto& transferableFlavor : transferableFlavors) {
// XXX We need special check for image as we always put the
// image as "native" on the clipboard.
if (transferableFlavor.Equals(flavor) ||

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

@ -164,11 +164,14 @@ function getClipboardDataSnapshotSync(aClipboardType) {
);
}
function asyncGetClipboardData(aClipboardType) {
function asyncGetClipboardData(
aClipboardType,
aFormats = ["text/plain", "text/html", "image/png"]
) {
return new Promise((resolve, reject) => {
try {
clipboard.asyncGetData(
["text/plain", "text/html", "image/png"],
aFormats,
aClipboardType,
null,
SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal(),

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

@ -232,6 +232,33 @@ function runClipboardCacheTests(aIsSupportGetFromCachedTransferable) {
await testClipboardData(await asyncGetClipboardData(type), clipboardData);
});
add_task(async function test_flavorList_order() {
info(`test_flavorList_order with pref ` +
`${aIsSupportGetFromCachedTransferable ? "enabled" : "disabled"}`);
const trans = generateNewTransferable("text/plain", generateRandomString());
addStringToTransferable("text/html", `<div>${generateRandomString()}</div>`, trans);
info(`Writedata to clipboard ${type}`);
clipboard.setData(trans, null, type);
// Read with reverse order.
let flavors = trans.flavorsTransferableCanExport().reverse();
let request = await asyncGetClipboardData(type, flavors);
// XXX Not all clipboard type supports html format, e.g. kFindClipboard
// on macOS only support writing text/plain.
if (
navigator.platform.includes("Mac") &&
type == clipboard.kFindClipboard &&
!aIsSupportGetFromCachedTransferable &&
!SpecialPowers.isHeadless
) {
isDeeply(request.flavorList, ["text/plain"], "check flavor orders");
} else {
isDeeply(request.flavorList, flavors, "check flavor orders");
}
});
// Test sync set clipboard data.
testClipboardCache(type, false, aIsSupportGetFromCachedTransferable);