diff --git a/widget/nsBaseClipboard.cpp b/widget/nsBaseClipboard.cpp index 4fdc1a2cd857..333d154e70b6 100644 --- a/widget/nsBaseClipboard.cpp +++ b/widget/nsBaseClipboard.cpp @@ -840,8 +840,8 @@ nsBaseClipboard::MaybeCreateGetRequestFromClipboardCache( } nsTArray 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) || diff --git a/widget/tests/clipboard_helper.js b/widget/tests/clipboard_helper.js index 0ba2f351825f..76ed2aeb378a 100644 --- a/widget/tests/clipboard_helper.js +++ b/widget/tests/clipboard_helper.js @@ -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(), diff --git a/widget/tests/test_clipboard_cache_chrome.html b/widget/tests/test_clipboard_cache_chrome.html index e08024ab0347..81d7a652b68d 100644 --- a/widget/tests/test_clipboard_cache_chrome.html +++ b/widget/tests/test_clipboard_cache_chrome.html @@ -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", `
${generateRandomString()}
`, 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);