--- a/content/events/src/nsContentEventHandler.cpp
+++ b/content/events/src/nsContentEventHandler.cpp
@@ -210,18 +210,20 @@ static void AppendSubString(nsAString& a
static PRUint32 CountNewlinesInXPLength(nsIContent* aContent,
PRUint32 aXPLength)
{
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
"aContent is not a text node!");
const nsTextFragment* text = aContent->GetText();
if (!text)
return 0;
- NS_ASSERTION(aXPLength == PR_UINT32_MAX || aXPLength <= text->GetLength(),
- "text offset is out-of-bounds");
+ // For automated tests, we should abort on debug build.
+ NS_ABORT_IF_FALSE(
+ (aXPLength == PR_UINT32_MAX || aXPLength <= text->GetLength()),
+ "aXPLength is out-of-bounds");
const PRUint32 length = NS_MIN(aXPLength, text->GetLength());
PRUint32 newlines = 0;
for (PRUint32 i = 0; i < length; ++i) {
if (text->CharAt(i) == '\n') {
++newlines;
}
}
return newlines;
@@ -231,21 +233,27 @@ static PRUint32 CountNewlinesInNativeLen
PRUint32 aNativeLength)
{
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
"aContent is not a text node!");
const nsTextFragment* text = aContent->GetText();
if (!text) {
return 0;
}
+ // For automated tests, we should abort on debug build.
+ NS_ABORT_IF_FALSE(
+ (aNativeLength == PR_UINT32_MAX || aNativeLength <= text->GetLength() * 2),
+ "aNativeLength is unexpected value");
const PRUint32 xpLength = text->GetLength();
PRUint32 newlines = 0;
for (PRUint32 i = 0, nativeOffset = 0;
i < xpLength && nativeOffset < aNativeLength;
++i, ++nativeOffset) {
+ // For automated tests, we should abort on debug build.
+ NS_ABORT_IF_FALSE(i < text->GetLength(), "i is out-of-bounds");
if (text->CharAt(i) == '\n') {
++newlines;
++nativeOffset;
}
}
return newlines;
}
#endif
--- a/widget/tests/window_composition_text_querycontent.xul
+++ b/widget/tests/window_composition_text_querycontent.xul
@@ -75,16 +75,18 @@ var iframe = document.getElementById("if
var input = document.getElementById("input");
var textareaInFrame;
const nsIDOMWindowUtils = Components.interfaces.nsIDOMWindowUtils;
const kIsWin = (navigator.platform.indexOf("Win") == 0);
const kIsMac = (navigator.platform.indexOf("Mac") == 0);
+const kLFLen = kIsWin ? 2 : 1;
+
function checkQueryContentResult(aResult, aMessage)
{
ok(aResult, aMessage + ": the result is null");
if (!aResult) {
return false;
}
ok(aResult.succeeded, aMessage + ": the query content failed");
return aResult.succeeded;
@@ -1814,18 +1816,16 @@ function runCompositionEventTest()
function runCharAtPointTest(aFocusedEditor, aTargetName)
{
aFocusedEditor.value = "This is a test of the\nContent Events";
// 012345678901234567890 12345678901234
// 0 1 2 3
aFocusedEditor.focus();
- const kLFLen = kIsWin ? 2 : 1;
-
const kNone = -1;
const kTestingOffset = [ 0, 10, 20, 21 + kLFLen, 34 + kLFLen];
const kLeftSideOffset = [ kNone, 9, 19, kNone, 33 + kLFLen];
const kRightSideOffset = [ 1, 11, kNone, 22 + kLFLen, kNone];
var editorRect = synthesizeQueryEditorRect();
if (!checkQueryContentResult(editorRect,
"runCharAtPointTest (" + aTargetName + "): editorRect")) {
@@ -1919,16 +1919,59 @@ function runCharAtPointAtOutsideTest()
editorRect.top - 10);
if (checkQueryContentResult(charAtPt,
"runCharAtPointAtOutsideTest: charAtPt")) {
ok(charAtPt.notFound,
"runCharAtPointAtOutsideTest: charAtPt is found on outside of editor");
}
}
+function runBug722639Test()
+{
+ textarea.focus();
+ textarea.value = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
+ textarea.value += textarea.value;
+ textarea.value += textarea.value; // 80 characters
+
+ var firstLine = synthesizeQueryTextRect(0, 1);
+ if (!checkQueryContentResult(firstLine,
+ "runBug722639Test: firstLine")) {
+ return;
+ }
+ var secondLine = synthesizeQueryTextRect(kLFLen, 1);
+ if (!checkQueryContentResult(secondLine,
+ "runBug722639Test: secondLine")) {
+ return;
+ }
+ var lineHeight = secondLine.top - firstLine.top;
+ ok(lineHeight > 0,
+ "runBug722639Test: lineHeight must be positive");
+ is(secondLine.left, firstLine.left,
+ "runBug722639Test: the left value must be always same value");
+ var previousTop = secondLine.top;
+ for (var i = 2; i < textarea.value.length; i++) {
+ var currentLine = synthesizeQueryTextRect(kLFLen * i, 1);
+ if (!checkQueryContentResult(currentLine,
+ "runBug722639Test: " + i + "th currentLine")) {
+ return;
+ }
+ // NOTE: the top position may be 1px larger or smaller than other lines
+ // due to sub pixel positioning.
+ if (Math.abs(currentLine.top - (previousTop + lineHeight)) <= 1) {
+ ok(true, "runBug722639Test: " + i + "th line's top is expected");
+ } else {
+ is(currentLine.top, previousTop + lineHeight,
+ "runBug722639Test: " + i + "th line's top is unexpected");
+ }
+ is(currentLine.left, firstLine.left,
+ "runBug722639Test: " + i + "th line's left is unexpected");
+ previousTop = currentLine.top;
+ }
+}
+
function runTestOnAnotherContext(aPanelOrFrame, aFocusedEditor, aTestName)
{
aFocusedEditor.value = "";
var editorRect = synthesizeQueryEditorRect();
if (!checkQueryContentResult(editorRect, aTestName + ": editorRect")) {
return;
}
@@ -2403,16 +2446,17 @@ function runMaxLengthTest()
function runTest()
{
runUndoRedoTest();
runCompositionTest();
runCompositionEventTest();
runCharAtPointTest(textarea, "textarea in the document");
runCharAtPointAtOutsideTest();
+ runBug722639Test();
runFrameTest();
runPanelTest();
runMaxLengthTest();
}
]]>
</script>