Bug 1374057 - Catch more preceding position-change notifications and prevent post-test position change notifications. r=jmaher

This patch fixes failures for widget/tests/test_composition_text_querycontent.xul when it is run on ubuntu 16.04. It adds some missing handling for pre-test position change notifications and also adds some handling for after-test position change notifications.

MozReview-Commit-ID: 1t8NuxJqkOo

--HG--
extra : rebase_source : ddae0da39a087c5742e31fbae9d7930b95695f1e
This commit is contained in:
Greg Mierzwinski 2017-06-18 10:03:04 -04:00
parent df7644937e
commit add4e2d809

View File

@ -7156,6 +7156,23 @@ function* runIMEContentObserverTest()
notifications.shift();
}
// Bug 1374057 - On ubuntu 16.04 there are notify-position-change events that are
// recorded after all the other events so we remove them through this function.
function ensureToRemovePostPositionChangeNotification(aDescription, expectedCount)
{
if (!notifications.length) {
return;
}
if (notifications.length <= expectedCount) {
return;
}
if (notifications[notifications.length-1].type != "notify-position-change") {
return;
}
ok(true, "notify-position-change", aDescription + "Unnecessary notify-position-change occurred, ignoring it");
notifications.pop();
}
function getNativeText(aXPText)
{
if (kLF == "\n") {
@ -7228,9 +7245,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("a", { code: "KeyA" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 0, removedLength: 0, addedLength: 1 });
checkSelectionChangeNotification(notifications[1], description, { offset: 1, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "ab[]"
@ -7238,9 +7257,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("b", { code: "KeyB" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 1, removedLength: 0, addedLength: 1 });
checkSelectionChangeNotification(notifications[1], description, { offset: 2, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "abc[]"
@ -7248,9 +7269,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("c", { code: "KeyC" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 2, removedLength: 0, addedLength: 1 });
checkSelectionChangeNotification(notifications[1], description, { offset: 3, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "ab[c]"
@ -7258,7 +7281,9 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_ArrowLeft", { code: "ArrowLeft", shiftKey: true }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkSelectionChangeNotification(notifications[0], description, { offset: 2, text: "c", reversed: true });
ensureToRemovePostPositionChangeNotification(description, 1);
dumpUnexpectedNotifications(description, 1);
// "a[bc]"
@ -7266,7 +7291,9 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_ArrowLeft", { code: "ArrowLeft", shiftKey: true }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkSelectionChangeNotification(notifications[0], description, { offset: 1, text: "bc", reversed: true });
ensureToRemovePostPositionChangeNotification(description, 1);
dumpUnexpectedNotifications(description, 1);
// "[abc]"
@ -7274,7 +7301,9 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_ArrowLeft", { code: "ArrowLeft", shiftKey: true }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkSelectionChangeNotification(notifications[0], description, { offset: 0, text: "abc", reversed: true });
ensureToRemovePostPositionChangeNotification(description, 1);
dumpUnexpectedNotifications(description, 1);
// "[]abc"
@ -7282,7 +7311,9 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_ArrowLeft", { code: "ArrowLeft" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkSelectionChangeNotification(notifications[0], description, { offset: 0, text: "" });
ensureToRemovePostPositionChangeNotification(description, 1);
dumpUnexpectedNotifications(description, 1);
// "[a]bc"
@ -7290,7 +7321,9 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_ArrowRight", { code: "ArrowRight", shiftKey: true }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkSelectionChangeNotification(notifications[0], description, { offset: 0, text: "a" });
ensureToRemovePostPositionChangeNotification(description, 1);
dumpUnexpectedNotifications(description, 1);
// "[ab]c"
@ -7298,7 +7331,9 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_ArrowRight", { code: "ArrowRight", shiftKey: true }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkSelectionChangeNotification(notifications[0], description, { offset: 0, text: "ab" });
ensureToRemovePostPositionChangeNotification(description, 1);
dumpUnexpectedNotifications(description, 1);
// "[]c"
@ -7306,9 +7341,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_Delete", { code: "Delete" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 0, removedLength: 2, addedLength: 0 });
checkSelectionChangeNotification(notifications[1], description, { offset: 0, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "[]"
@ -7316,8 +7353,10 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_Delete", { code: "Delete" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 0, removedLength: 1, addedLength: 0 });
checkPositionChangeNotification(notifications[1], description);
ensureToRemovePostPositionChangeNotification(description, 2);
dumpUnexpectedNotifications(description, 2);
// "abc[]"
@ -7331,9 +7370,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_Backspace", { code: "Backspace" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 2, removedLength: 1, addedLength: 0 });
checkSelectionChangeNotification(notifications[1], description, { offset: 2, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "[ab]"
@ -7346,9 +7387,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_Backspace", { code: "Backspace" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 0, removedLength: 2, addedLength: 0 });
checkSelectionChangeNotification(notifications[1], description, { offset: 0, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "abcd[]"
@ -7369,9 +7412,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_Backspace", { code: "Backspace" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 1, removedLength: 2, addedLength: 0 });
checkSelectionChangeNotification(notifications[1], description, { offset: 1, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "a[bc]d"
@ -7386,9 +7431,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("B", { code: "KeyB", shiftKey: true }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 1, removedLength: 2, addedLength: 1 });
checkSelectionChangeNotification(notifications[1], description, { offset: 2, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
if (!aTestLineBreaker) {
@ -7400,9 +7447,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_Enter", { code: "Enter" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 2, removedLength: 0, addedLength: kLFLen });
checkSelectionChangeNotification(notifications[1], description, { offset: getNativeText("aB\n").length, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "aB[]d"
@ -7410,9 +7459,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_Backspace", { code: "Backspace" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 2, removedLength: kLFLen, addedLength: 0 });
checkSelectionChangeNotification(notifications[1], description, { offset: 2, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "a[B]d"
@ -7424,9 +7475,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_Enter", { code: "Enter" }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 1, removedLength: 1, addedLength: kLFLen });
checkSelectionChangeNotification(notifications[1], description, { offset: getNativeText("a\n").length, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// "a[\n]d"
@ -7434,7 +7487,9 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_ArrowLeft", { code: "ArrowLeft", shiftKey: true }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkSelectionChangeNotification(notifications[0], description, { offset: 1, text: kLF, reversed: true });
ensureToRemovePostPositionChangeNotification(description, 1);
dumpUnexpectedNotifications(description, 1);
// "a[]d"
@ -7442,9 +7497,11 @@ function* runIMEContentObserverTest()
notifications = [];
synthesizeKey("KEY_Delete", { code: "Delete", shiftKey: true }, win, callback);
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 1, removedLength: kLFLen, addedLength: 0 });
checkSelectionChangeNotification(notifications[1], description, { offset: 1, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// ab\ncd\nef\ngh\n[]
@ -7452,9 +7509,11 @@ function* runIMEContentObserverTest()
notifications = [];
aElement.value = "ab\ncd\nef\ngh\n";
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
checkTextChangeNotification(notifications[0], description, { offset: 0, removedLength: 2, addedLength: getNativeText("ab\ncd\nef\ngh\n").length });
checkSelectionChangeNotification(notifications[1], description, { offset: getNativeText("ab\ncd\nef\ngh\n").length, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
// []
@ -7462,10 +7521,12 @@ function* runIMEContentObserverTest()
notifications = [];
aElement.value = "";
yield waitUntilNotificationsReceived();
ensureToRemovePrecedingPositionChangeNotification();
// XXX Removing invisible <br> or something? The removed length is a line breaker length longer.
checkTextChangeNotification(notifications[0], description, { offset: 0, removedLength: getNativeText("ab\ncd\nef\ngh\n").length + kLFLen, addedLength: 0 });
checkSelectionChangeNotification(notifications[1], description, { offset: 0, text: "" });
checkPositionChangeNotification(notifications[2], description);
ensureToRemovePostPositionChangeNotification(description, 3);
dumpUnexpectedNotifications(description, 3);
}