summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_bug676401.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /editor/libeditor/tests/test_bug676401.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'editor/libeditor/tests/test_bug676401.html')
-rw-r--r--editor/libeditor/tests/test_bug676401.html129
1 files changed, 129 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_bug676401.html b/editor/libeditor/tests/test_bug676401.html
new file mode 100644
index 0000000000..35653461ae
--- /dev/null
+++ b/editor/libeditor/tests/test_bug676401.html
@@ -0,0 +1,129 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=676401
+-->
+<head>
+ <title>Test for Bug 676401</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="/tests/SimpleTest/EventUtils.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=676401">Mozilla Bug 676401</a>
+<p id="display"></p>
+<div id="content">
+ <!-- we need a blockquote to test the "outdent" command -->
+ <section>
+ <blockquote> not editable </blockquote>
+ </section>
+ <section contenteditable>
+ <blockquote> editable </blockquote>
+ </section>
+</div>
+
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 676401 **/
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(runTests);
+
+var gBlock1, gBlock2;
+
+var alwaysEnabledCommands = [
+ "contentReadOnly",
+ "copy",
+ "cut",
+ "enableInlineTableEditing",
+ "enableObjectResizing",
+ "insertBrOnReturn",
+ "selectAll",
+ "styleWithCSS",
+];
+
+function ensureNobodyHasFocus() {
+ document.activeElement.blur();
+}
+
+function IsCommandEnabled(command) {
+ ensureNobodyHasFocus();
+
+ // non-editable div: should return false unless alwaysEnabled
+ window.getSelection().selectAllChildren(gBlock1);
+ is(
+ document.queryCommandEnabled(command),
+ alwaysEnabledCommands.includes(command) && document.queryCommandSupported(command),
+ "'" + command + "' should not be enabled on a non-editable block."
+ );
+
+ // editable div: should return true if it's supported
+ window.getSelection().selectAllChildren(gBlock2);
+ is(
+ document.queryCommandEnabled(command),
+ document.queryCommandSupported(command),
+ "'" + command + "' should be enabled on an editable block."
+ );
+}
+
+function runTests() {
+ var i, commands;
+ gBlock1 = document.querySelector("#content section blockquote");
+ gBlock2 = document.querySelector("#content [contenteditable] blockquote");
+
+ // common commands: test with and without "styleWithCSS"
+ commands = [
+ "bold", "italic", "underline", "strikeThrough",
+ "subscript", "superscript", "foreColor", "backColor", "hiliteColor",
+ "fontName", "fontSize",
+ "justifyLeft", "justifyCenter", "justifyRight", "justifyFull",
+ "indent", "outdent",
+ "insertOrderedList", "insertUnorderedList", "insertParagraph",
+ "heading", "formatBlock",
+ "contentReadOnly", "createLink",
+ "decreaseFontSize", "increaseFontSize",
+ "insertHTML", "insertHorizontalRule", "insertImage",
+ "removeFormat", "selectAll", "styleWithCSS",
+ ];
+ document.execCommand("styleWithCSS", false, false);
+ for (i = 0; i < commands.length; i++)
+ IsCommandEnabled(commands[i]);
+ document.execCommand("styleWithCSS", false, true);
+ for (i = 0; i < commands.length; i++)
+ IsCommandEnabled(commands[i]);
+
+ // Mozilla-specific stuff
+ commands = ["enableInlineTableEditing", "enableObjectResizing", "insertBrOnReturn"];
+ for (i = 0; i < commands.length; i++)
+ IsCommandEnabled(commands[i]);
+
+ // These are privileged, and available only to chrome.
+ ensureNobodyHasFocus();
+ window.getSelection().selectAllChildren(gBlock2);
+ commands = ["paste"];
+ for (i = 0; i < commands.length; i++) {
+ is(document.queryCommandEnabled(commands[i]), false,
+ "Command should not be enabled for non-privileged code");
+ is(SpecialPowers.wrap(document).queryCommandEnabled(commands[i]), true,
+ "Command should be enabled for privileged code");
+ is(document.execCommand(commands[i], false, false), false, "Should return false: " + commands[i]);
+ is(SpecialPowers.wrap(document).execCommand(commands[i], false, false), true, "Should return true: " + commands[i]);
+ }
+
+ // delete/undo/redo -- we have to execute this commands because:
+ // * there's nothing to undo if we haven't modified the selection first
+ // * there's nothing to redo if we haven't undone something first
+ commands = ["delete", "undo", "redo"];
+ for (i = 0; i < commands.length; i++) {
+ IsCommandEnabled(commands[i]);
+ document.execCommand(commands[i], false, false);
+ }
+
+ // done
+ SimpleTest.finish();
+}
+
+</script>
+</pre>
+</body>
+</html>