From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../test/useractivation/file_clipboard_common.js | 505 +++++++++++++++++++++ dom/base/test/useractivation/file_empty.html | 0 .../file_iframe_check_user_activation.html | 22 + .../file_iframe_consume_user_activation.html | 15 + .../useractivation/file_iframe_user_activated.html | 14 + ...ile_useractivation_sandbox_transient_popup.html | 20 + dom/base/test/useractivation/mochitest.ini | 23 + dom/base/test/useractivation/moz.build | 9 + .../test/useractivation/test_clipboard_editor.html | 31 ++ .../useractivation/test_clipboard_noeditor.html | 29 ++ .../test_popup_blocker_async_callback.html | 83 ++++ .../test_popup_blocker_mouse_event.html | 98 ++++ .../test_popup_blocker_pointer_event.html | 122 +++++ .../test_useractivation_has_been_activated.html | 115 +++++ .../test_useractivation_key_events.html | 91 ++++ .../test_useractivation_sandbox_transient.html | 90 ++++ .../test_useractivation_scrollbar.html | 135 ++++++ .../test_useractivation_transient.html | 155 +++++++ .../test_useractivation_transient_consuming.html | 151 ++++++ 19 files changed, 1708 insertions(+) create mode 100644 dom/base/test/useractivation/file_clipboard_common.js create mode 100644 dom/base/test/useractivation/file_empty.html create mode 100644 dom/base/test/useractivation/file_iframe_check_user_activation.html create mode 100644 dom/base/test/useractivation/file_iframe_consume_user_activation.html create mode 100644 dom/base/test/useractivation/file_iframe_user_activated.html create mode 100644 dom/base/test/useractivation/file_useractivation_sandbox_transient_popup.html create mode 100644 dom/base/test/useractivation/mochitest.ini create mode 100644 dom/base/test/useractivation/moz.build create mode 100644 dom/base/test/useractivation/test_clipboard_editor.html create mode 100644 dom/base/test/useractivation/test_clipboard_noeditor.html create mode 100644 dom/base/test/useractivation/test_popup_blocker_async_callback.html create mode 100644 dom/base/test/useractivation/test_popup_blocker_mouse_event.html create mode 100644 dom/base/test/useractivation/test_popup_blocker_pointer_event.html create mode 100644 dom/base/test/useractivation/test_useractivation_has_been_activated.html create mode 100644 dom/base/test/useractivation/test_useractivation_key_events.html create mode 100644 dom/base/test/useractivation/test_useractivation_sandbox_transient.html create mode 100644 dom/base/test/useractivation/test_useractivation_scrollbar.html create mode 100644 dom/base/test/useractivation/test_useractivation_transient.html create mode 100644 dom/base/test/useractivation/test_useractivation_transient_consuming.html (limited to 'dom/base/test/useractivation') diff --git a/dom/base/test/useractivation/file_clipboard_common.js b/dom/base/test/useractivation/file_clipboard_common.js new file mode 100644 index 0000000000..fe172e52c8 --- /dev/null +++ b/dom/base/test/useractivation/file_clipboard_common.js @@ -0,0 +1,505 @@ +// This test is called from both test_clipboard_editor.html and test_clipboard_noeditor.html +// This is to test that the code works both in the presence of a contentEditable node, and in the absense of one +var WATCH_TIMEOUT = 300; + +// Some global variables to make the debug messages easier to track down +var gTestN0 = 0, + gTestN1 = 0, + gTestN2 = 0; +function testLoc() { + return " " + gTestN0 + " - " + gTestN1 + " - " + gTestN2; +} + +// Listen for cut & copy events +var gCopyCount = 0, + gCutCount = 0; +document.addEventListener("copy", function () { + gCopyCount++; +}); +document.addEventListener("cut", function () { + gCutCount++; +}); + +// Helper methods +function selectNode(aSelector, aCb) { + var dn = document.querySelector(aSelector); + var range = document.createRange(); + range.selectNodeContents(dn); + window.getSelection().removeAllRanges(); + window.getSelection().addRange(range); + if (aCb) { + aCb(); + } +} + +function selectInputNode(aSelector, aCb) { + var dn = document.querySelector(aSelector); + synthesizeMouse(dn, 10, 10, {}); + SimpleTest.executeSoon(function () { + synthesizeKey("A", { accelKey: true }); + // Clear the user activation state which is set from synthesized mouse and + // key event. + SpecialPowers.wrap(document).clearUserGestureActivation(); + SimpleTest.executeSoon(aCb); + }); +} + +// Callback functions for attaching to the button +function execCommand(aCommand, aShouldSucceed, aAsync = false) { + var cb = function (e) { + e.preventDefault(); + document.removeEventListener("keydown", cb); + + if (aAsync) { + setTimeout(() => { + is( + aShouldSucceed, + document.execCommand(aCommand), + "Keydown caused " + aCommand + " invocation" + testLoc() + ); + }, 0); + } else { + is( + aShouldSucceed, + document.execCommand(aCommand), + "Keydown caused " + aCommand + " invocation" + testLoc() + ); + } + }; + return cb; +} + +// The basic test set. Tries to cut/copy everything +function cutCopyAll( + aDoCut, + aDoCopy, + aDone, + aNegate, + aClipOverride, + aJustClipboardNegate +) { + var execCommandAlwaysSucceed = !!(aClipOverride || aJustClipboardNegate); + + function waitForClipboard(aCond, aSetup, aNext, aNegateOne) { + if (aClipOverride) { + aCond = aClipOverride; + aNegateOne = false; + } + if (aNegate || aNegateOne || aJustClipboardNegate) { + SimpleTest.waitForClipboard( + null, + aSetup, + aNext, + aNext, + "text/plain", + WATCH_TIMEOUT, + true + ); + } else { + SimpleTest.waitForClipboard(aCond, aSetup, aNext, aNext); + } + } + + function validateCutCopy(aExpectedCut, aExpectedCopy) { + if (aNegate) { + aExpectedCut = aExpectedCopy = 0; + } // When we are negating - we always expect callbacks not to be run + + is( + aExpectedCut, + gCutCount, + (aExpectedCut > 0 + ? "Expect cut callback to run" + : "Expect cut callback not to run") + testLoc() + ); + is( + aExpectedCopy, + gCopyCount, + (aExpectedCopy > 0 + ? "Expect copy callback to run" + : "Expect copy callback not to run") + testLoc() + ); + gCutCount = gCopyCount = 0; + } + + function step(n) { + function nextStep() { + step(n + 1); + } + + // Reset the user activation state before running next test. + SpecialPowers.wrap(document).clearUserGestureActivation(); + + document.querySelector("span").textContent = "span text"; + document.querySelector("input[type=text]").value = "text text"; + document.querySelector("input[type=password]").value = "password text"; + document.querySelector("textarea").value = "textarea text"; + + var contentEditableNode = document.querySelector( + "div[contentEditable=true]" + ); + if (contentEditableNode) { + contentEditableNode.textContent = "contenteditable text"; + } + + gTestN2 = n; + switch (n) { + case 0: + // copy on readonly selection + selectNode("span"); + waitForClipboard( + "span text", + function () { + aDoCopy(true); + }, + nextStep + ); + return; + + case 1: + validateCutCopy(0, 1); + + // cut on readonly selection + selectNode("span"); + + waitForClipboard( + "span text", + function () { + aDoCut(execCommandAlwaysSucceed); + }, + nextStep, + true + ); + return; + + case 2: + validateCutCopy(1, 0); + + // copy on textbox selection + selectInputNode("input[type=text]", nextStep); + return; + + case 3: + waitForClipboard( + "text text", + function () { + selectInputNode("input[type=text]", function () { + aDoCopy(true); + }); + }, + nextStep + ); + return; + + case 4: + validateCutCopy(0, 1); + + // cut on textbox selection + selectInputNode("input[type=text]", nextStep); + return; + + case 5: + waitForClipboard( + "text text", + function () { + aDoCut(true); + }, + nextStep + ); + return; + + case 6: + validateCutCopy(1, 0); + + // copy on password selection + selectInputNode("input[type=password]", nextStep); + return; + + case 7: + waitForClipboard( + null, + function () { + aDoCopy(execCommandAlwaysSucceed); + }, + nextStep, + true + ); + return; + + case 8: + validateCutCopy(0, 1); + + // cut on password selection + selectInputNode("input[type=password]", nextStep); + return; + + case 9: + waitForClipboard( + null, + function () { + aDoCut(execCommandAlwaysSucceed); + }, + nextStep, + true + ); + return; + + case 10: + validateCutCopy(1, 0); + + // copy on textarea selection + selectInputNode("textarea", nextStep); + return; + + case 11: + waitForClipboard( + "textarea text", + function () { + aDoCopy(true); + }, + nextStep + ); + return; + + case 12: + validateCutCopy(0, 1); + + // cut on password selection + selectInputNode("textarea", nextStep); + return; + + case 13: + waitForClipboard( + "textarea text", + function () { + aDoCut(true); + }, + nextStep + ); + return; + + case 14: + validateCutCopy(1, 0); + + // copy on no selection + document.querySelector("textarea").blur(); + + waitForClipboard( + null, + function () { + aDoCopy(true); + }, + nextStep, + true + ); + return; + + case 15: + validateCutCopy(0, 1); + + // cut on no selection + waitForClipboard( + null, + function () { + aDoCut(execCommandAlwaysSucceed); + }, + nextStep, + true + ); + return; + + case 16: + validateCutCopy(1, 0); + + if (!document.querySelector("div[contentEditable=true]")) { + // We're done! (no contentEditable node!) + step(-1); + return; + } + break; + + case 17: + // copy on contenteditable selection + waitForClipboard( + "contenteditable text", + function () { + selectNode("div[contentEditable=true]", function () { + aDoCopy(true); + }); + }, + nextStep + ); + return; + + case 18: + validateCutCopy(0, 1); + break; + + case 19: + // cut on contenteditable selection + waitForClipboard( + "contenteditable text", + function () { + selectNode("div[contentEditable=true]", function () { + aDoCut(true); + }); + }, + nextStep + ); + return; + + case 20: + validateCutCopy(1, 0); + break; + + default: + aDone(); + return; + } + + SimpleTest.executeSoon(function () { + step(n + 1); + }); + } + + step(0); +} + +function allMechanisms(aCb, aClipOverride, aNegateAll) { + function testStep(n) { + gTestN1 = n; + switch (n) { + /** Test for Bug 1012662 **/ + case 0: + // Keyboard issued + cutCopyAll( + function docut(aSucc) { + synthesizeKey("x", { accelKey: true }); + }, + function docopy(aSucc) { + synthesizeKey("c", { accelKey: true }); + }, + function done() { + testStep(n + 1); + }, + false, + aClipOverride, + aNegateAll + ); + return; + + case 1: + // Button issued + cutCopyAll( + function docut(aSucc) { + document.addEventListener("keydown", execCommand("cut", aSucc)); + sendString("Q"); + }, + function docopy(aSucc) { + document.addEventListener("keydown", execCommand("copy", aSucc)); + sendString("Q"); + }, + function done() { + testStep(n + 1); + }, + false, + aClipOverride, + aNegateAll + ); + return; + + case 2: + // Not triggered by user gesture + cutCopyAll( + function doCut(aSucc) { + is( + false, + document.execCommand("cut"), + "Can't directly execCommand not in a user callback" + ); + }, + function doCopy(aSucc) { + is( + false, + document.execCommand("copy"), + "Can't directly execCommand not in a user callback" + ); + }, + function done() { + testStep(n + 1); + }, + true, + aClipOverride, + aNegateAll + ); + return; + + /** Test for Bug 1597857 **/ + case 3: + // Button issued async + cutCopyAll( + function docut(aSucc) { + document.addEventListener( + "keydown", + execCommand("cut", aSucc, true) + ); + sendString("Q"); + }, + function docopy(aSucc) { + document.addEventListener( + "keydown", + execCommand("copy", aSucc, true) + ); + sendString("Q"); + }, + function done() { + testStep(n + 1); + }, + false, + aClipOverride, + aNegateAll + ); + return; + + default: + aCb(); + } + } + testStep(0); +} + +// Run the tests +SimpleTest.waitForExplicitFinish(); +SimpleTest.requestLongerTimeout(5); // On the emulator - this times out occasionally +SimpleTest.waitForFocus(function () { + function justCancel(aEvent) { + aEvent.preventDefault(); + } + + function override(aEvent) { + aEvent.clipboardData.setData("text/plain", "overridden"); + aEvent.preventDefault(); + } + + allMechanisms(function () { + gTestN0 = 1; + document.addEventListener("cut", override); + document.addEventListener("copy", override); + + allMechanisms(function () { + gTestN0 = 2; + document.removeEventListener("cut", override); + document.removeEventListener("copy", override); + document.addEventListener("cut", justCancel); + document.addEventListener("copy", justCancel); + + allMechanisms( + function () { + SimpleTest.finish(); + }, + null, + true + ); + }, "overridden"); + }); +}); diff --git a/dom/base/test/useractivation/file_empty.html b/dom/base/test/useractivation/file_empty.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/dom/base/test/useractivation/file_iframe_check_user_activation.html b/dom/base/test/useractivation/file_iframe_check_user_activation.html new file mode 100644 index 0000000000..0a3ec734a6 --- /dev/null +++ b/dom/base/test/useractivation/file_iframe_check_user_activation.html @@ -0,0 +1,22 @@ + + + + user activated iframe + + + + + diff --git a/dom/base/test/useractivation/file_iframe_consume_user_activation.html b/dom/base/test/useractivation/file_iframe_consume_user_activation.html new file mode 100644 index 0000000000..ad27453f1a --- /dev/null +++ b/dom/base/test/useractivation/file_iframe_consume_user_activation.html @@ -0,0 +1,15 @@ + + + + user activated iframe + + + + + \ No newline at end of file diff --git a/dom/base/test/useractivation/file_iframe_user_activated.html b/dom/base/test/useractivation/file_iframe_user_activated.html new file mode 100644 index 0000000000..8d188001e8 --- /dev/null +++ b/dom/base/test/useractivation/file_iframe_user_activated.html @@ -0,0 +1,14 @@ + + + + user activated iframe + + + + + \ No newline at end of file diff --git a/dom/base/test/useractivation/file_useractivation_sandbox_transient_popup.html b/dom/base/test/useractivation/file_useractivation_sandbox_transient_popup.html new file mode 100644 index 0000000000..25bc2037c3 --- /dev/null +++ b/dom/base/test/useractivation/file_useractivation_sandbox_transient_popup.html @@ -0,0 +1,20 @@ + + + + User activation popup + + + + + + diff --git a/dom/base/test/useractivation/mochitest.ini b/dom/base/test/useractivation/mochitest.ini new file mode 100644 index 0000000000..26c8594be8 --- /dev/null +++ b/dom/base/test/useractivation/mochitest.ini @@ -0,0 +1,23 @@ +[DEFAULT] +support-files = + file_empty.html + file_iframe_user_activated.html + file_iframe_check_user_activation.html + file_iframe_consume_user_activation.html + file_clipboard_common.js +prefs = + formhelper.autozoom.force-disable.test-only=true + +[test_useractivation_has_been_activated.html] +[test_useractivation_key_events.html] +[test_useractivation_transient.html] +[test_useractivation_sandbox_transient.html] +support-files = file_useractivation_sandbox_transient_popup.html +[test_useractivation_scrollbar.html] +skip-if = os == 'android' # scrollbar not showed on mobile +[test_useractivation_transient_consuming.html] +[test_clipboard_editor.html] +[test_clipboard_noeditor.html] +[test_popup_blocker_mouse_event.html] +[test_popup_blocker_pointer_event.html] +[test_popup_blocker_async_callback.html] diff --git a/dom/base/test/useractivation/moz.build b/dom/base/test/useractivation/moz.build new file mode 100644 index 0000000000..60b508c774 --- /dev/null +++ b/dom/base/test/useractivation/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +MOCHITEST_MANIFESTS += [ + "mochitest.ini", +] diff --git a/dom/base/test/useractivation/test_clipboard_editor.html b/dom/base/test/useractivation/test_clipboard_editor.html new file mode 100644 index 0000000000..691e8e4a20 --- /dev/null +++ b/dom/base/test/useractivation/test_clipboard_editor.html @@ -0,0 +1,31 @@ + + + + + Test for Clipboard + + + + + + +Mozilla Bug 1012662
+Mozilla Bug 1597857 +

+ +
+ span text + + + +
contenteditable text
+
+ +
+
+
+ + diff --git a/dom/base/test/useractivation/test_clipboard_noeditor.html b/dom/base/test/useractivation/test_clipboard_noeditor.html new file mode 100644 index 0000000000..f7f3d6cb99 --- /dev/null +++ b/dom/base/test/useractivation/test_clipboard_noeditor.html @@ -0,0 +1,29 @@ + + + + + Test for Clipboard + + + + + + +Mozilla Bug 1012662
+Mozilla Bug 1597857 +

+ +
+ span text + + + +
+ +
+
+
+ + diff --git a/dom/base/test/useractivation/test_popup_blocker_async_callback.html b/dom/base/test/useractivation/test_popup_blocker_async_callback.html new file mode 100644 index 0000000000..dc53596531 --- /dev/null +++ b/dom/base/test/useractivation/test_popup_blocker_async_callback.html @@ -0,0 +1,83 @@ + + + + + Test for triggering popup by mouse events + + + + + +
+ + + diff --git a/dom/base/test/useractivation/test_popup_blocker_mouse_event.html b/dom/base/test/useractivation/test_popup_blocker_mouse_event.html new file mode 100644 index 0000000000..fd94150f1e --- /dev/null +++ b/dom/base/test/useractivation/test_popup_blocker_mouse_event.html @@ -0,0 +1,98 @@ + + + + + Test for triggering popup by mouse events + + + + + +
+ + + diff --git a/dom/base/test/useractivation/test_popup_blocker_pointer_event.html b/dom/base/test/useractivation/test_popup_blocker_pointer_event.html new file mode 100644 index 0000000000..8d0b2c8cd1 --- /dev/null +++ b/dom/base/test/useractivation/test_popup_blocker_pointer_event.html @@ -0,0 +1,122 @@ + + + + + Test for triggering popup by pointer events + + + + + +
+ + + diff --git a/dom/base/test/useractivation/test_useractivation_has_been_activated.html b/dom/base/test/useractivation/test_useractivation_has_been_activated.html new file mode 100644 index 0000000000..f46618915b --- /dev/null +++ b/dom/base/test/useractivation/test_useractivation_has_been_activated.html @@ -0,0 +1,115 @@ + + + + User activation test: has been user gesture activated + + + + + + + + + diff --git a/dom/base/test/useractivation/test_useractivation_key_events.html b/dom/base/test/useractivation/test_useractivation_key_events.html new file mode 100644 index 0000000000..d97906c22b --- /dev/null +++ b/dom/base/test/useractivation/test_useractivation_key_events.html @@ -0,0 +1,91 @@ + + + + User activation test: key events + + + + + + + diff --git a/dom/base/test/useractivation/test_useractivation_sandbox_transient.html b/dom/base/test/useractivation/test_useractivation_sandbox_transient.html new file mode 100644 index 0000000000..6b0fcb50f0 --- /dev/null +++ b/dom/base/test/useractivation/test_useractivation_sandbox_transient.html @@ -0,0 +1,90 @@ + + + + User activation test: transient flag + + + + + + + diff --git a/dom/base/test/useractivation/test_useractivation_scrollbar.html b/dom/base/test/useractivation/test_useractivation_scrollbar.html new file mode 100644 index 0000000000..778d6d0898 --- /dev/null +++ b/dom/base/test/useractivation/test_useractivation_scrollbar.html @@ -0,0 +1,135 @@ + + + +User activation test: consume transient flag + + + + + + +













+
+
+ + diff --git a/dom/base/test/useractivation/test_useractivation_transient.html b/dom/base/test/useractivation/test_useractivation_transient.html new file mode 100644 index 0000000000..d3148e5d1d --- /dev/null +++ b/dom/base/test/useractivation/test_useractivation_transient.html @@ -0,0 +1,155 @@ + + + + User activation test: transient flag + + + + + + + + + diff --git a/dom/base/test/useractivation/test_useractivation_transient_consuming.html b/dom/base/test/useractivation/test_useractivation_transient_consuming.html new file mode 100644 index 0000000000..4178d24477 --- /dev/null +++ b/dom/base/test/useractivation/test_useractivation_transient_consuming.html @@ -0,0 +1,151 @@ + + + + User activation test: consume transient flag + + + + + + + + + -- cgit v1.2.3