Bug 722639 Add tests for bug 692145 r=ehsan
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 07 Feb 2012 11:32:43 +0900
changeset 86281 08b3c9d38e326f88a3df78e4f2852a89ae505cdc
parent 86280 050334f9128c16d072990c3b88cf5145dddcd0cd
child 86282 50727e830c7b60d4fc13dd22ef0631b2d3211f3d
push id22008
push userbmo@edmorley.co.uk
push dateTue, 07 Feb 2012 10:32:58 +0000
treeherdermozilla-central@2b61af9d18ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs722639, 692145
milestone13.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 722639 Add tests for bug 692145 r=ehsan
content/events/src/nsContentEventHandler.cpp
widget/tests/window_composition_text_querycontent.xul
--- 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>