diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /editor/libeditor/tests/test_join_split_node_direction_change_command.html | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | editor/libeditor/tests/test_join_split_node_direction_change_command.html | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_join_split_node_direction_change_command.html b/editor/libeditor/tests/test_join_split_node_direction_change_command.html new file mode 100644 index 0000000000..79faab4806 --- /dev/null +++ b/editor/libeditor/tests/test_join_split_node_direction_change_command.html @@ -0,0 +1,197 @@ +<!doctype html> +<html> +<head> +<meta charset="utf-8"> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<link rel="stylesheet" href="/tests/SimpleTest/test.css"/> +<script> +"use strict"; + +SimpleTest.waitForExplicitFinish(); +SimpleTest.waitForFocus(async () => { + let iframe = document.querySelector("iframe"); + async function resetIframe() { + iframe?.remove(); + iframe = document.createElement("iframe"); + document.body.appendChild(iframe); + iframe.srcdoc = "<body></body>"; + if (iframe.contentDocument?.readyState != "complete") { + await new Promise(resolve => iframe.addEventListener("load", resolve, {once: true})); + } + iframe.contentWindow.focus(); + } + + await resetIframe(); + await SpecialPowers.pushPrefEnv({ + set: [["editor.join_split_direction.compatible_with_the_other_browsers", false]], + }); + (function test_command_when_legacy_behavior_is_enabled_by_default() { + iframe.contentDocument.body.innerHTML = "<div contenteditable><br></div>"; + ok( + iframe.contentDocument.queryCommandSupported("enableCompatibleJoinSplitDirection"), + "test_command_when_legacy_behavior_is_enabled_by_default: command should be supported" + ); + ok( + iframe.contentDocument.queryCommandEnabled("enableCompatibleJoinSplitDirection"), + "test_command_when_legacy_behavior_is_enabled_by_default: command should be enabled" + ); + ok( + !iframe.contentDocument.queryCommandState("enableCompatibleJoinSplitDirection"), + "test_command_when_legacy_behavior_is_enabled_by_default: command state should be false" + ); + is( + iframe.contentDocument.queryCommandValue("enableCompatibleJoinSplitDirection"), + "", + "test_command_when_legacy_behavior_is_enabled_by_default: command value should be empty string" + ); + ok( + iframe.contentDocument.execCommand("enableCompatibleJoinSplitDirection", false, "true"), + "test_command_when_legacy_behavior_is_enabled_by_default: command to enable it should return true" + ); + })(); + + (function test_command_when_enabling_new_behavior_when_legacy_one_is_enabled_by_default() { + ok( + iframe.contentDocument.queryCommandSupported("enableCompatibleJoinSplitDirection"), + "test_command_when_enabling_new_behavior_when_legacy_one_is_enabled_by_default: command should be supported" + ); + ok( + iframe.contentDocument.queryCommandEnabled("enableCompatibleJoinSplitDirection"), + "test_command_when_enabling_new_behavior_when_legacy_one_is_enabled_by_default: command should be enabled" + ); + ok( + iframe.contentDocument.queryCommandState("enableCompatibleJoinSplitDirection"), + "test_command_when_enabling_new_behavior_when_legacy_one_is_enabled_by_default: command state should be true" + ); + is( + iframe.contentDocument.queryCommandValue("enableCompatibleJoinSplitDirection"), + "", + "test_command_when_enabling_new_behavior_when_legacy_one_is_enabled_by_default: command value should be empty string" + ); + + ok( + iframe.contentDocument.execCommand("enableCompatibleJoinSplitDirection", false, "false"), + "test_command_when_enabling_new_behavior_when_legacy_one_is_enabled_by_default: command to disable it should return true" + ); + })(); + + (function test_command_when_disabling_new_behavior_when_the_legacy_one_is_enabled_by_default() { + ok( + iframe.contentDocument.queryCommandSupported("enableCompatibleJoinSplitDirection"), + "test_command_when_disabling_new_behavior_when_the_legacy_one_is_enabled_by_default: command should be supported" + ); + ok( + iframe.contentDocument.queryCommandEnabled("enableCompatibleJoinSplitDirection"), + "test_command_when_disabling_new_behavior_when_the_legacy_one_is_enabled_by_default: command should be enabled" + ); + ok( + !iframe.contentDocument.queryCommandState("enableCompatibleJoinSplitDirection"), + "test_command_when_disabling_new_behavior_when_the_legacy_one_is_enabled_by_default: command state should be false" + ); + is( + iframe.contentDocument.queryCommandValue("enableCompatibleJoinSplitDirection"), + "", + "test_command_when_disabling_new_behavior_when_the_legacy_one_is_enabled_by_default: command value should be empty string" + ); + })(); + + await resetIframe(); + await SpecialPowers.pushPrefEnv({ + set: [["editor.join_split_direction.compatible_with_the_other_browsers", true]], + }); + (function test_command_when_new_behavior_is_enabled_by_default() { + iframe.contentDocument.body.innerHTML = "<div contenteditable><br></div>"; + ok( + iframe.contentDocument.queryCommandSupported("enableCompatibleJoinSplitDirection"), + "test_command_when_new_behavior_is_enabled_by_default: command should be supported" + ); + ok( + iframe.contentDocument.queryCommandEnabled("enableCompatibleJoinSplitDirection"), + "test_command_when_new_behavior_is_enabled_by_default: command should be enabled" + ); + ok( + iframe.contentDocument.queryCommandState("enableCompatibleJoinSplitDirection"), + "test_command_when_new_behavior_is_enabled_by_default: command state should be true" + ); + is( + iframe.contentDocument.queryCommandValue("enableCompatibleJoinSplitDirection"), + "", + "test_command_when_new_behavior_is_enabled_by_default: command value should be empty string" + ); + ok( + !iframe.contentDocument.execCommand("enableCompatibleJoinSplitDirection", false, "false"), + "test_command_when_new_behavior_is_enabled_by_default: command to disable it should return false" + ); + ok( + iframe.contentDocument.queryCommandState("enableCompatibleJoinSplitDirection"), + "test_command_when_new_behavior_is_enabled_by_default: command state should be true even after executing the command to disable it" + ); + })(); + + await resetIframe(); + await SpecialPowers.pushPrefEnv({ + set: [["editor.join_split_direction.compatible_with_the_other_browsers", false]], + }); + (function test_command_disabled_after_joining_nodes() { + iframe.contentDocument.body.innerHTML = "<div contenteditable><p>abc</p><p>def</p></div>"; + iframe.contentWindow.getSelection().collapse(iframe.contentDocument.querySelector("p + p").firstChild, 0); + iframe.contentDocument.execCommand("delete"); + ok( + !iframe.contentDocument.execCommand("enableCompatibleJoinSplitDirection", false, "true"), + "test_command_disabled_after_joining_nodes: command should return false" + ); + ok( + !iframe.contentDocument.queryCommandEnabled("enableCompatibleJoinSplitDirection"), + "test_command_when_new_behavior_is_enabled_by_default: command should be disabled" + ); + ok( + !iframe.contentDocument.queryCommandState("enableCompatibleJoinSplitDirection"), + "test_command_when_new_behavior_is_enabled_by_default: command state should be false" + ); + })(); + + await resetIframe(); + await SpecialPowers.pushPrefEnv({ + set: [["editor.join_split_direction.compatible_with_the_other_browsers", false]], + }); + (function test_command_disabled_after_splitting_node() { + iframe.contentDocument.body.innerHTML = "<div contenteditable><p>abcdef</p></div>"; + iframe.contentWindow.getSelection().collapse(iframe.contentDocument.querySelector("p").firstChild, "abc".length); + iframe.contentDocument.execCommand("insertParagraph"); + ok( + !iframe.contentDocument.execCommand("enableCompatibleJoinSplitDirection", false, "true"), + "test_command_disabled_after_splitting_node: command should return false" + ); + ok( + !iframe.contentDocument.queryCommandEnabled("enableCompatibleJoinSplitDirection"), + "test_command_disabled_after_splitting_node: command should be disabled" + ); + ok( + !iframe.contentDocument.queryCommandState("enableCompatibleJoinSplitDirection"), + "test_command_disabled_after_splitting_node: command state should be false" + ); + })(); + + await resetIframe(); + await SpecialPowers.pushPrefEnv({ + set: [["editor.join_split_direction.compatible_with_the_other_browsers", false]], + }); + (function test_split_direction_after_enabling_new_direction() { + iframe.contentDocument.body.innerHTML = "<div contenteditable><p>abc</p><p>def</p></div>"; + const rightP = iframe.contentDocument.querySelector("p + p"); + iframe.contentWindow.getSelection().collapse(rightP.firstChild, 0); + iframe.contentDocument.execCommand("delete"); + iframe.contentDocument.execCommand("enableCompatibleJoinSplitDirection", false, "true"); + is( + iframe.contentDocument.querySelector("p"), + rightP, + "test_split_direction_after_enabling_new_direction: left paragraph should be deleted and right paragraph should be alive" + ); + })(); + + SimpleTest.finish(); +}); +</script> +</head> +<body></body> +</html> |