From 64d32032ea7d710c25c5b8b91991511d517bbf8f Mon Sep 17 00:00:00 2001 From: Cristina Horotan Date: Thu, 5 Oct 2023 22:22:27 +0300 Subject: [PATCH] Backed out changeset 1e91f547f0c7 (bug 1854747) for causing bc failures at browser_save_filenames.js on a CLOSED TREE --- dom/base/nsCopySupport.cpp | 7 +- dom/events/moz.build | 1 - dom/events/test/clipboard/mochitest.toml | 7 -- dom/events/test/mochitest.toml | 6 ++ .../{clipboard => }/test_paste_image.html | 78 +++++++------------ modules/libpref/init/StaticPrefList.yaml | 6 -- .../tests/mochitest/browser_save_filenames.js | 5 +- 7 files changed, 37 insertions(+), 73 deletions(-) delete mode 100644 dom/events/test/clipboard/mochitest.toml rename dom/events/test/{clipboard => }/test_paste_image.html (73%) diff --git a/dom/base/nsCopySupport.cpp b/dom/base/nsCopySupport.cpp index 4f02de512f17..6c68baf11a4b 100644 --- a/dom/base/nsCopySupport.cpp +++ b/dom/base/nsCopySupport.cpp @@ -40,7 +40,6 @@ #include "nsContentCID.h" #ifdef XP_WIN -# include "mozilla/StaticPrefs_clipboard.h" # include "nsCExternalHandlerService.h" # include "nsEscape.h" # include "nsIMIMEInfo.h" @@ -503,10 +502,8 @@ nsresult nsCopySupport::ImageCopy(nsIImageLoadingContent* aImageElement, } #ifdef XP_WIN - if (StaticPrefs::clipboard_imageAsFile_enabled()) { - rv = AppendImagePromise(trans, imgRequest, aImageElement); - NS_ENSURE_SUCCESS(rv, rv); - } + rv = AppendImagePromise(trans, imgRequest, aImageElement); + NS_ENSURE_SUCCESS(rv, rv); #endif // copy the image data onto the transferable diff --git a/dom/events/moz.build b/dom/events/moz.build index 1238c6c35644..cdb6f960e764 100644 --- a/dom/events/moz.build +++ b/dom/events/moz.build @@ -16,7 +16,6 @@ BROWSER_CHROME_MANIFESTS += [ ] MOCHITEST_MANIFESTS += [ - "test/clipboard/mochitest.toml", "test/mochitest.toml", "test/pointerevents/mochitest.toml", ] diff --git a/dom/events/test/clipboard/mochitest.toml b/dom/events/test/clipboard/mochitest.toml deleted file mode 100644 index 7829915267bb..000000000000 --- a/dom/events/test/clipboard/mochitest.toml +++ /dev/null @@ -1,7 +0,0 @@ -[DEFAULT] - -["test_paste_image.html"] -skip-if = [ - "headless", # Bug 1405869 - "os == 'android'", # Image type isn't supported -] diff --git a/dom/events/test/mochitest.toml b/dom/events/test/mochitest.toml index c7c67e9d5594..ec0d10616aa7 100644 --- a/dom/events/test/mochitest.toml +++ b/dom/events/test/mochitest.toml @@ -483,6 +483,12 @@ support-files = ["window_empty_document.html"] ["test_passive_listeners.html"] +["test_paste_image.html"] +skip-if = [ + "headless", # Bug 1405869 + "os == 'android'", # Image type isn't supported +] + ["test_scroll_per_page.html"] support-files = ["window_empty_document.html"] skip-if = ["os == 'android'"] # fail diff --git a/dom/events/test/clipboard/test_paste_image.html b/dom/events/test/test_paste_image.html similarity index 73% rename from dom/events/test/clipboard/test_paste_image.html rename to dom/events/test/test_paste_image.html index acda7422c768..04d608646659 100644 --- a/dom/events/test/clipboard/test_paste_image.html +++ b/dom/events/test/test_paste_image.html @@ -14,9 +14,9 @@ images.push(aFile); }; - this.test = async function() { + this.test = function() { for (var i = 0; i < images.length; i++) { - await testImageSize(images[i]); + testImageSize(images[i]); } }; @@ -25,31 +25,28 @@ info("returned=" + counter + " images.length=" + images.length); if (counter == images.length) { info("test finish"); + SimpleTest.finish(); } }; - async function testImageSize(aFile) { + function testImageSize(aFile) { var source = window.URL.createObjectURL(aFile); var image = new Image(); image.src = source; var imageTester = that; - let promise = new Promise(resolve => { - image.addEventListener("load", function(e) { - is(this.width, 62, "Check generated image width"); - is(this.height, 71, "Check generated image height"); + image.onload = function() { + is(this.width, 62, "Check generated image width"); + is(this.height, 71, "Check generated image height"); - // This fails on OSX only. - if (!navigator.platform.includes("Mac")) { - testImageCanvas(image); - } + // This fails on OSX only. + if (!navigator.platform.includes("Mac")) { + testImageCanvas(image); + } - imageTester.returned(); - resolve(); - }, { once: true }); - }); + imageTester.returned(); + } document.body.appendChild(image); - await promise; }; function testImageCanvas(aImage) { @@ -83,10 +80,8 @@ documentViewer.copyImage(documentViewer.COPY_IMAGE_ALL); } - async function doTest(imageAsFileEnabled) { - await SpecialPowers.pushPrefEnv({ - set: [["clipboard.imageAsFile.enabled", imageAsFileEnabled]], - }); + function doTest() { + SimpleTest.waitForExplicitFinish(); copyImage('image'); @@ -103,30 +98,18 @@ ok(clipboard.hasDataMatchingFlavors(["image/png"], clipboard.kGlobalClipboard), "clipboard contains image"); - let promise = new Promise(resolve => { - window.addEventListener("paste", async (e) => { - isDeeply(e.clipboardData.types, - (navigator.platform.includes("Win") && imageAsFileEnabled) ? - ["application/x-moz-file", "Files"] : ["text/html", "text/plain", "Files"]); - await onPaste(e, imageAsFileEnabled); - resolve(); - }, { once: true }); - }); + window.addEventListener("paste", onPaste); var textarea = SpecialPowers.wrap(document.getElementById('textarea')); textarea.focus(); textarea.editor.paste(clipboard.kGlobalClipboard); - - await promise; - - clipboard.emptyClipboard(clipboard.kGlobalClipboard); } - async function onPaste(e, imageAsFileEnabled) { + function onPaste(e) { var imageTester = new ImageTester; - testFiles(e, imageTester, imageAsFileEnabled); + testFiles(e, imageTester); testItems(e, imageTester); - await imageTester.test(); + imageTester.test(); } function testItems(e, imageTester) { @@ -148,7 +131,7 @@ } } - function testFiles(e, imageTester, imageAsFileEnabled) { + function testFiles(e, imageTester) { var files = e.clipboardData.files; is(files, e.clipboardData.files, @@ -158,12 +141,15 @@ var file = files[i]; ok(file instanceof File, ".files should contain only File objects"); ok(file.size > 0, "This file shouldn't have size 0"); - if (navigator.platform.includes("Win") && imageAsFileEnabled) { - ok(file.name.startsWith("Untitled") && file.name.endsWith(".png"), - `Check filename, got "${file.name}"`); + if (navigator.platform.includes("Win")) { + // On Windows the pasted file is (sometimes?) produced from the Windows only + // file promise added by AppendImagePromise. + ok(file.name == "image.png" || (file.name.startsWith("Untitled") && file.name.endsWith(".png")), + `Correct filename, got "${file.name}"`); } else { - is(file.name, "image.png", "Check filename"); + is(file.name, "image.png", "Correct filename"); } + is(file.type, "image/png", "This file should be a image/png"); testSlice(file); imageTester.add(file); @@ -191,16 +177,8 @@ is(blob.type, "image/png", ".slice @type check"); } - add_task(async function test_imageAsFile_enabled() { - await doTest(true); - }); - - add_task(async function test_imageAsFile_disabled() { - await doTest(false); - }); - - +