Bug 1792387 - part 9: Make `widget/tests/test_composition_text_querycontent.xhtml` be aware of both split/join node directions r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 30 Sep 2022 22:20:23 +0000
changeset 636762 6f315dbf947e95381be2b4c478c795197d8e0470
parent 636761 acb7315965e5200e095442f887cc36ca438a9582
child 636763 f4c48015c11993989d6f1c0b608d1496a34cb5d3
push id170484
push usermasayuki@d-toybox.com
push dateFri, 30 Sep 2022 22:23:25 +0000
treeherderautoland@f4c48015c119 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1792387
milestone107.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1792387 - part 9: Make `widget/tests/test_composition_text_querycontent.xhtml` be aware of both split/join node directions r=m_kato This means that the change has a risk of compatibility with IME, but from the other point of view, we already behave differently from the other browsers in native IME API handler level too. Differential Revision: https://phabricator.services.mozilla.com/D158107
widget/tests/window_composition_text_querycontent.xhtml
--- a/widget/tests/window_composition_text_querycontent.xhtml
+++ b/widget/tests/window_composition_text_querycontent.xhtml
@@ -9789,16 +9789,20 @@ async function runIMEContentObserverTest
     checkSelectionChangeNotification(notifications[1], description, { offset: 0, text: "" });
     checkPositionChangeNotification(notifications[2], description);
     ensureToRemovePostPositionChangeNotification(description, 3);
     dumpUnexpectedNotifications(description, 3);
   }
 
   async function testWithHTMLEditor(aDescription, aElement, aDefaultParagraphSeparator)
   {
+    const isTraditionalSplitDirection =!SpecialPowers.getBoolPref(
+      "editor.join_split_direction.compatible_with_the_other_browsers"
+    );
+
     let doc = aElement.ownerDocument;
     let win = doc.defaultView;
     let sel = doc.getSelection();
     let inDesignMode = doc.designMode == "on";
     let offsetAtStart = 0;
     let offsetAtContainer = 0;
     let isDefaultParagraphSeparatorBlock = aDefaultParagraphSeparator != "br";
     doc.execCommand("defaultParagraphSeparator", false, aDefaultParagraphSeparator);
@@ -10006,67 +10010,128 @@ async function runIMEContentObserverTest
     synthesizeKey("B", {shiftKey: true}, win, callback);
     await waitNotifications;
     ensureToRemovePrecedingPositionChangeNotification();
     checkTextChangeNotification(notifications[0], description, { offset: 1 + offsetAtContainer, removedLength: 2, addedLength: 1 });
     checkSelectionChangeNotification(notifications[1], description, { offset: 2 + offsetAtContainer, text: "" });
     checkPositionChangeNotification(notifications[2], description);
     dumpUnexpectedNotifications(description, 3);
 
-    // "aB<br>[]d" or "<block>ab</block><block>[]d</block>"
+    // "aB<br>[]d" or "<block>aB</block><block>[]d</block>"
     description = aDescription + "inserting a line break after 'B' with pressing Enter";
     waitNotifications = promiseReceiveNotifications();
     synthesizeKey("KEY_Enter", {}, win, callback);
     await waitNotifications;
     ensureToRemovePrecedingPositionChangeNotification();
     if (isDefaultParagraphSeparatorBlock) {
-      // Splitting current block causes removing "<block>aB" and inserting "<block>aB</block><block>".
-      checkTextChangeNotification(notifications[0], description, { offset: 0 + offsetAtContainer - kLFLen, removedLength: getNativeText("\naB").length, addedLength: getNativeText("\naB\n").length });
+      if (isTraditionalSplitDirection) {
+        // Splitting current block causes removing "<block>aB" and inserting "<block>aB</block><block>".
+        checkTextChangeNotification(notifications[0], description, {
+          offset: offsetAtContainer - kLFLen,
+          removedLength: getNativeText("\naB").length,
+          addedLength: getNativeText("\naB\n").length,
+        });
+      } else {
+        // Splitting current block causes removing "d</block>" and inserting "</block><block>d</block>".
+        checkTextChangeNotification(notifications[0], description, {
+          offset: offsetAtContainer + "aB".length,
+          removedLength: getNativeText("d\n").length,
+          addedLength: getNativeText("\nd\n").length,
+        });
+      }
     } else {
-      // Oddly, inserting <br> causes removing "aB" and inserting "ab<br>".
-      checkTextChangeNotification(notifications[0], description, { offset: 0 + offsetAtContainer, removedLength: 2, addedLength: getNativeText("ab\n").length });
+      // eslint-disable-next-line no-lonely-if
+      if (isTraditionalSplitDirection) {
+        // Oddly, inserting <br> causes removing "aB" and inserting "ab<br>".
+        checkTextChangeNotification(notifications[0], description, {
+          offset: offsetAtContainer,
+          removedLength: 2,
+          addedLength: getNativeText("aB\n").length,
+        });
+      } else {
+        // Inserting <br> causes removing "d" and inserting "<br>d"
+        checkTextChangeNotification(notifications[0], description, {
+          offset: offsetAtContainer + "aB".length,
+          removedLength: "d".length,
+          addedLength: getNativeText("\nd").length,
+        });
+      }
     }
     checkSelectionChangeNotification(notifications[1], description, { offset: getNativeText("aB\n").length + offsetAtContainer, text: "" });
     checkPositionChangeNotification(notifications[2], description);
     dumpUnexpectedNotifications(description, 3);
 
     // "aB[]d"
     description = aDescription + "removing a line break after 'B' with pressing Backspace";
     waitNotifications = promiseReceiveNotifications();
     synthesizeKey("KEY_Backspace", {}, win, callback);
     await waitNotifications;
     ensureToRemovePrecedingPositionChangeNotification();
     if (isDefaultParagraphSeparatorBlock) {
-      // Joining two blocks causes removing both block elements and inserting new block element.
-      checkTextChangeNotification(notifications[0], description, { offset: offsetAtContainer - kLFLen, removedLength: getNativeText("\naB\nd").length, addedLength: getNativeText("\naBd").length });
+      if (isTraditionalSplitDirection) {
+          // Joining two blocks causes removing both block elements and inserting new block element.
+          checkTextChangeNotification(notifications[0], description, {
+            offset: offsetAtContainer - kLFLen,
+            removedLength: getNativeText("\naB\nd").length,
+            addedLength: getNativeText("\naBd").length,
+          });
+      } else {
+          // Joining two blocks causes removing "aB</block><block>d</block>" and inserting "aBd</block>"
+          checkTextChangeNotification(notifications[0], description, {
+            offset: offsetAtContainer,
+            removedLength: getNativeText("aB\nd\n").length,
+            addedLength: getNativeText("aBd\n").length,
+          });
+      }
       checkSelectionChangeNotification(notifications[1], description, { offset: 2 + offsetAtContainer, text: "" });
       checkPositionChangeNotification(notifications[2], description);
       dumpUnexpectedNotifications(description, 3);
     } else {
-      checkTextChangeNotification(notifications[0], description, { offset: 2 + offsetAtContainer, removedLength: kLFLen, addedLength: 0 });
+      checkTextChangeNotification(notifications[0], description, {
+        offset: offsetAtContainer + "aB".length,
+        removedLength: kLFLen,
+        addedLength: 0,
+      });
       is(notifications.length, 3, description + " should cause 3 notifications");
       is(notifications[1] && notifications[1].type, "notify-selection-change", description + " should cause selection change notification");
       is(notifications[2] && notifications[2].type, "notify-position-change", description + " should cause position change notification");
     }
 
     // "a[B]d"
     synthesizeKey("KEY_ArrowLeft", {shiftKey: true}, win, callback);
     await flushNotifications();
 
     // "a<br>[]d" or "<block>a</block><block>[]d</block>"
     description = aDescription + "replacing 'B' with a line break with pressing Enter";
     waitNotifications = promiseReceiveNotifications();
     synthesizeKey("KEY_Enter", {}, win, callback);
     await waitNotifications;
     ensureToRemovePrecedingPositionChangeNotification();
     if (isDefaultParagraphSeparatorBlock) {
-      // Splitting current block causes removing "<block>aB" and inserting "<block>aB</block><block>".
-      checkTextChangeNotification(notifications[0], description, { offset: 0 + offsetAtContainer - kLFLen, removedLength: getNativeText("\naB").length, addedLength: getNativeText("\na\n").length });
+      if (isTraditionalSplitDirection) {
+        // Splitting current block causes removing "<block>aB" and inserting "<block>aB</block><block>".
+        checkTextChangeNotification(notifications[0], description, {
+          offset: offsetAtContainer - kLFLen,
+          removedLength: getNativeText("\naB").length,
+          addedLength: getNativeText("\na\n").length,
+        });
+      } else {
+        // Splitting current block causes removing "Bd</block>" and inserting "</block><block>d</block>".
+        checkTextChangeNotification(notifications[0], description, {
+          offset: offsetAtContainer + "a".length,
+          removedLength: getNativeText("Bd\n").length,
+          addedLength: getNativeText("\nd\n").length,
+        });
+      }
     } else {
-      checkTextChangeNotification(notifications[0], description, { offset: 1 + offsetAtContainer, removedLength: 1, addedLength: kLFLen });
+      checkTextChangeNotification(notifications[0], description, {
+        offset: offsetAtContainer + "a".length,
+        removedLength: "B".length,
+        addedLength: kLFLen,
+      });
     }
     checkSelectionChangeNotification(notifications[1], description, { offset: getNativeText("a\n").length + offsetAtContainer, text: "" });
     checkPositionChangeNotification(notifications[2], description);
     dumpUnexpectedNotifications(description, 3);
 
     // "a[<br>]d" or "<block>a[</block><block>]d</block>"
     description = aDescription + "selecting '\\n' with pressing Shift+ArrowLeft";
     waitNotifications = promiseReceiveNotifications();
@@ -10078,20 +10143,37 @@ async function runIMEContentObserverTest
 
     // "a[]d"
     description = aDescription + "removing selected '\\n' with pressing Delete";
     waitNotifications = promiseReceiveNotifications();
     synthesizeKey("KEY_Delete", {}, win, callback);
     await waitNotifications;
     ensureToRemovePrecedingPositionChangeNotification();
     if (isDefaultParagraphSeparatorBlock) {
-      // Joining the blocks causes removing "<block>a</block><block>d</block>" and inserting "<block>ad</block>".
-      checkTextChangeNotification(notifications[0], description, { offset: 0 + offsetAtContainer - kLFLen, removedLength: getNativeText("\na\nd").length, addedLength: getNativeText("\nad").length });
+      if (isTraditionalSplitDirection) {
+        // Joining the blocks causes removing "<block>a</block><block>d</block>" and inserting "<block>ad</block>".
+        checkTextChangeNotification(notifications[0], description, {
+          offset: offsetAtContainer - kLFLen,
+          removedLength: getNativeText("\na\nd").length,
+          addedLength: getNativeText("\nad").length,
+        });
+      } else {
+        // Joining the blocks causes removing "a</block><block>d</block>" and inserting "<block>ad</block>".
+        checkTextChangeNotification(notifications[0], description, {
+          offset: offsetAtContainer,
+          removedLength: getNativeText("a\nd\n").length,
+          addedLength: getNativeText("ad\n").length,
+        });
+      }
     } else {
-      checkTextChangeNotification(notifications[0], description, { offset: 1 + offsetAtContainer, removedLength: kLFLen, addedLength: 0 });
+      checkTextChangeNotification(notifications[0], description, {
+        offset: offsetAtContainer + "a".length,
+        removedLength: kLFLen,
+        addedLength: 0,
+      });
     }
     checkSelectionChangeNotification(notifications[1], description, { offset: 1 + offsetAtContainer, text: "" });
     checkPositionChangeNotification(notifications[2], description);
     dumpUnexpectedNotifications(description, 3);
 
     // aElement.innerHTML = "<div>1<div>2<div>3</div>4</div>5</div>"
     description = aDescription + "inserting HTML which has nested block elements";
     waitNotifications = promiseReceiveNotifications();