Bug 1375825 - part1: Create test for querying text rect in a non-editable element in a contenteditable element r=smaug

This patch adds some automated tests for reproducing bug 1375825 and makes nsQuetyContentEventResult::GetText() work with eQueryTextRect event because ContentEventHandler sets it to the text which was used for computing the rect.

MozReview-Commit-ID: Gk8IV2Vln6V

--HG--
extra : rebase_source : 2d7127c09713358cf9a69fbbc180c325981794b2
This commit is contained in:
Masayuki Nakano 2017-06-23 22:36:05 +09:00
parent 5949e620e5
commit 179e1ee17e
2 changed files with 86 additions and 1 deletions

View File

@ -162,7 +162,8 @@ nsQueryContentEventResult::GetText(nsAString &aText)
{
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(mEventMessage == eQuerySelectedText ||
mEventMessage == eQueryTextContent,
mEventMessage == eQueryTextContent ||
mEventMessage == eQueryTextRect,
NS_ERROR_NOT_AVAILABLE);
aText = mString;
return NS_OK;

View File

@ -4508,6 +4508,89 @@ function runQueryContentEventRelativeToInsertionPoint()
synthesizeComposition({ type: "compositioncommitasis" });
}
function runBug1375825Test()
{
contenteditable.focus();
// #1
contenteditable.innerHTML = "abc<span contenteditable=\"false\">defgh</span>";
var ret = synthesizeQueryTextRect(2, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #1 (2, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "c", "runBug1375825Test #1 (2, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'c'");
ret = synthesizeQueryTextRect(3, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #1 (3, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "d", "runBug1375825Test #1 (3, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'd'");
ret = synthesizeQueryTextRect(4, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #1 (4, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "e", "runBug1375825Test #1 (4, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'e'");
ret = synthesizeQueryTextRect(5, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #1 (5, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "f", "runBug1375825Test #1 (5, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'f'");
ret = synthesizeQueryTextRect(6, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #1 (6, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "g", "runBug1375825Test #1 (6, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'g'");
ret = synthesizeQueryTextRect(7, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #1 (7, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "h", "runBug1375825Test #1 (7, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'h'");
// #2
contenteditable.innerHTML = "abc<span style=\"-moz-user-select: all;\">defgh</span>";
ret = synthesizeQueryTextRect(2, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #2 (2, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "c", "runBug1375825Test #2 (2, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'c'");
ret = synthesizeQueryTextRect(3, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #2 (3, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "d", "runBug1375825Test #2 (3, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'd'");
ret = synthesizeQueryTextRect(4, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #2 (4, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "e", "runBug1375825Test #2 (4, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'e'");
ret = synthesizeQueryTextRect(5, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #2 (5, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "f", "runBug1375825Test #2 (5, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'f'");
ret = synthesizeQueryTextRect(6, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #2 (6, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "g", "runBug1375825Test #2 (6, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'g'");
ret = synthesizeQueryTextRect(7, 1);
if (!checkQueryContentResult(ret, "runBug1375825Test #2 (7, 1), \"" + contenteditable.innerHTML + "\"")) {
return;
}
is(ret.text, "h", "runBug1375825Test #2 (7, 1), \"" + contenteditable.innerHTML + "\": should have queried a rect for 'h'");
}
function runCSSTransformTest()
{
textarea.focus();
@ -8042,6 +8125,7 @@ function* testBody()
yield* runIMEContentObserverTest();
runCSSTransformTest();
runBug722639Test();
runBug1375825Test();
runForceCommitTest();
runNestedSettingValue();
runBug811755Test();