From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser_contextmenu_contenteditable.js | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js (limited to 'browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js') diff --git a/browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js b/browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js new file mode 100644 index 0000000000..ccb0be8d95 --- /dev/null +++ b/browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js @@ -0,0 +1,118 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let contextMenu; + +const example_base = + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://example.com/browser/browser/base/content/test/contextMenu/"; +const chrome_base = + "chrome://mochitests/content/browser/browser/base/content/test/contextMenu/"; + +/* import-globals-from contextmenu_common.js */ +Services.scriptloader.loadSubScript( + chrome_base + "contextmenu_common.js", + this +); + +async function openMenuAndPaste(browser, useFormatting) { + const kElementToUse = "test-contenteditable-spellcheck-false"; + let oldText = await SpecialPowers.spawn(browser, [kElementToUse], elemID => { + return content.document.getElementById(elemID).textContent; + }); + + // Open context menu and paste + await test_contextmenu( + "#" + kElementToUse, + [ + "context-undo", + null, // whether we can undo changes mid-test. + "context-redo", + false, + "---", + null, + "context-cut", + false, + "context-copy", + false, + "context-paste", + true, + "context-paste-no-formatting", + true, + "context-delete", + false, + "context-selectall", + true, + ], + { + keepMenuOpen: true, + } + ); + let popupHidden = BrowserTestUtils.waitForPopupEvent(contextMenu, "hidden"); + let menuID = "context-paste" + (useFormatting ? "" : "-no-formatting"); + contextMenu.activateItem(document.getElementById(menuID)); + await popupHidden; + await SpecialPowers.spawn( + browser, + [kElementToUse, oldText, useFormatting], + (elemID, textToReset, expectStrong) => { + let node = content.document.getElementById(elemID); + Assert.stringContains( + node.textContent, + "Bold text", + "Text should have been pasted" + ); + if (expectStrong) { + isnot( + node.querySelector("strong"), + null, + "Should be markup in the text." + ); + } else { + is( + node.querySelector("strong"), + null, + "Should be no markup in the text." + ); + } + node.textContent = textToReset; + } + ); +} + +add_task(async function test_contenteditable() { + // Put some HTML on the clipboard: + const xferable = Cc["@mozilla.org/widget/transferable;1"].createInstance( + Ci.nsITransferable + ); + xferable.init(null); + xferable.addDataFlavor("text/html"); + xferable.setTransferData( + "text/html", + PlacesUtils.toISupportsString("Bold text") + ); + xferable.addDataFlavor("text/plain"); + xferable.setTransferData( + "text/plain", + PlacesUtils.toISupportsString("Bold text") + ); + Services.clipboard.setData( + xferable, + null, + Services.clipboard.kGlobalClipboard + ); + + let url = example_base + "subtst_contextmenu.html"; + await BrowserTestUtils.withNewTab( + { + gBrowser, + url, + }, + async function (browser) { + await openMenuAndPaste(browser, false); + await openMenuAndPaste(browser, true); + } + ); +}); -- cgit v1.2.3