From 179e1ee17e83a33acbb3283c5718e7741d9e3ce4 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Fri, 23 Jun 2017 22:36:05 +0900 Subject: [PATCH] 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 --- dom/base/nsQueryContentEventResult.cpp | 3 +- .../window_composition_text_querycontent.xul | 84 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/dom/base/nsQueryContentEventResult.cpp b/dom/base/nsQueryContentEventResult.cpp index 462cfe86a121..a246df62b75e 100644 --- a/dom/base/nsQueryContentEventResult.cpp +++ b/dom/base/nsQueryContentEventResult.cpp @@ -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; diff --git a/widget/tests/window_composition_text_querycontent.xul b/widget/tests/window_composition_text_querycontent.xul index fb84d20e8eaf..ce11e4d759d3 100644 --- a/widget/tests/window_composition_text_querycontent.xul +++ b/widget/tests/window_composition_text_querycontent.xul @@ -4508,6 +4508,89 @@ function runQueryContentEventRelativeToInsertionPoint() synthesizeComposition({ type: "compositioncommitasis" }); } +function runBug1375825Test() +{ + contenteditable.focus(); + + // #1 + contenteditable.innerHTML = "abcdefgh"; + + 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 = "abcdefgh"; + + 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();