summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_bug795785.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_bug795785.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_bug795785.html')
-rw-r--r--editor/libeditor/tests/test_bug795785.html139
1 files changed, 139 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_bug795785.html b/editor/libeditor/tests/test_bug795785.html
new file mode 100644
index 0000000000..3e56207b63
--- /dev/null
+++ b/editor/libeditor/tests/test_bug795785.html
@@ -0,0 +1,139 @@
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=795785
+-->
+<head>
+ <title>Test for Bug 795785</title>
+ <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="/tests/SimpleTest/EventUtils.js"></script>
+ <script src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.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=795785">Mozilla Bug 795785</a>
+<div id="display">
+ <textarea style="overflow: hidden; height: 3em; width: 5em; word-wrap: normal;"></textarea>
+ <div contenteditable style="overflow: hidden; height: 3em; width: 5em;"></div>
+</div>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+
+<script>
+"use strict";
+
+function waitForScroll() {
+ return waitToClearOutAnyPotentialScrolls(window);
+}
+
+async function synthesizeKeyInEachEventLoop(aKey, aEvent, aCount) {
+ for (let i = 0; i < aCount; i++) {
+ synthesizeKey(aKey, aEvent);
+ await new Promise(resolve => SimpleTest.executeSoon(resolve));
+ }
+}
+
+async function sendStringOneByOne(aString) {
+ for (const ch of aString) {
+ sendString(ch);
+ await new Promise(resolve => SimpleTest.executeSoon(resolve));
+ }
+}
+
+async function doKeyEventTest(aSelector) {
+ const element = document.querySelector(aSelector);
+ if (element.value !== undefined) {
+ element.value = "";
+ } else {
+ element.innerHTML = "";
+ }
+ element.focus();
+ element.scrollTop = 0;
+ await waitForScroll();
+ is(element.scrollTop, 0, `${aSelector}.scrollTop should be 0`);
+ await synthesizeKeyInEachEventLoop("KEY_Enter", {shiftKey: true}, 6);
+ await waitForScroll();
+ isnot(element.scrollTop, 0, `${aSelector} should be scrolled by inserting line breaks`);
+ const oldScrollTop = element.scrollTop;
+ await synthesizeKeyInEachEventLoop("KEY_ArrowUp", {}, 5);
+ await waitForScroll();
+ isnot(element.scrollTop, oldScrollTop, `${aSelector} should be scrolled by up key events`);
+ await synthesizeKeyInEachEventLoop("KEY_ArrowDown", {}, 5);
+ await waitForScroll();
+ is(element.scrollTop, oldScrollTop, `${aSelector} should be scrolled by down key events`);
+ const longWord = "aaaaaaaaaaaaaaaaaaaa";
+ await sendStringOneByOne(longWord);
+ await waitForScroll();
+ isnot(element.scrollLeft, 0, `${aSelector} should be scrolled by typing long word`);
+ const oldScrollLeft = element.scrollLeft;
+ await synthesizeKeyInEachEventLoop("KEY_ArrowLeft", {}, longWord.length);
+ await waitForScroll();
+ isnot(element.scrollLeft, oldScrollLeft, `${aSelector} should be scrolled by left key events`);
+ await synthesizeKeyInEachEventLoop("KEY_ArrowRight", {}, longWord.length);
+ await waitForScroll();
+ is(element.scrollLeft, oldScrollLeft, `${aSelector} should be scrolled by right key events`);
+}
+
+async function doCompositionTest(aSelector) {
+ const element = document.querySelector(aSelector);
+ if (element.value !== undefined) {
+ element.value = "";
+ } else {
+ element.innerHTML = "";
+ }
+ element.focus();
+ element.scrollTop = 0;
+ await waitForScroll();
+ is(element.scrollTop, 0, `${aSelector}.scrollTop should be 0`);
+ const longCompositionString =
+ "Web \u958b\u767a\u8005\u306e\u7686\u3055\u3093\u306f\u3001" +
+ "Firefox \u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b HTML5" +
+ " \u3084 CSS \u306e\u65b0\u6a5f\u80fd\u3092\u6d3b\u7528\u3059" +
+ "\u308b\u3053\u3068\u3067\u3001\u9b45\u529b\u3042\u308b Web " +
+ "\u30b5\u30a4\u30c8\u3084\u9769\u65b0\u7684\u306a Web \u30a2" +
+ "\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u3088\u308a" +
+ "\u77ed\u6642\u9593\u3067\u7c21\u5358\u306b\u4f5c\u6210\u3067" +
+ "\u304d\u307e\u3059\u3002";
+ synthesizeCompositionChange(
+ {
+ composition: {
+ string: longCompositionString,
+ clauses: [
+ {
+ length: longCompositionString.length,
+ attr: COMPOSITION_ATTR_RAW_CLAUSE,
+ },
+ ],
+ },
+ caret: {
+ start: longCompositionString.length,
+ length: 0,
+ },
+ }
+ );
+ await waitForScroll();
+ isnot(element.scrollTop, 0, `${aSelector} should be scrolled by composition`);
+ synthesizeComposition({ type: "compositioncommit", data: "" });
+ await waitForScroll();
+ is(
+ element.scrollTop,
+ 0,
+ `${aSelector} should be scrolled back to the top by canceling composition`
+ );
+}
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(async () => {
+ await doKeyEventTest("textarea");
+ await doKeyEventTest("div[contenteditable]");
+ await doCompositionTest("textarea");
+ await doCompositionTest("div[contenteditable]");
+ SimpleTest.finish();
+});
+</script>
+</body>
+
+</html>