Bug 998188 part.1 Add test for this crash on debug build r=ehsan
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 26 Apr 2014 08:52:12 +0900
changeset 180701 7f9e0440e61948be00da4aea40bbeb635243feab
parent 180700 7a633ff64906ef80a8fc5716f4f29d84fc1339d2
child 180702 394ef98ad57487dc03babef3b389ea625a1f1ee4
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersehsan
bugs998188
milestone31.0a1
Bug 998188 part.1 Add test for this crash on debug build r=ehsan
dom/events/ContentEventHandler.cpp
editor/libeditor/html/tests/mochitest.ini
editor/libeditor/html/tests/test_bug998188.html
testing/mochitest/tests/SimpleTest/ChromeUtils.js
testing/mochitest/tests/SimpleTest/EventUtils.js
--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -262,17 +262,17 @@ static uint32_t CountNewlinesInNativeLen
 {
   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(
+  MOZ_ASSERT(
     (aNativeLength == UINT32_MAX || aNativeLength <= text->GetLength() * 2),
     "aNativeLength is unexpected value");
   const uint32_t xpLength = text->GetLength();
   uint32_t newlines = 0;
   for (uint32_t i = 0, nativeOffset = 0;
        i < xpLength && nativeOffset < aNativeLength;
        ++i, ++nativeOffset) {
     // For automated tests, we should abort on debug build.
--- a/editor/libeditor/html/tests/mochitest.ini
+++ b/editor/libeditor/html/tests/mochitest.ini
@@ -93,16 +93,17 @@ skip-if = toolkit == 'android' || e10s
 [test_bug790475.html]
 [test_bug796839.html]
 [test_bug832025.html]
 [test_bug857487.html]
 [test_bug966155.html]
 skip-if = os != "win"
 [test_bug966552.html]
 skip-if = os != "win"
+[test_bug998188.html]
 [test_contenteditable_focus.html]
 [test_dom_input_event_on_htmleditor.html]
 [test_keypress_untrusted_event.html]
 [test_root_element_replacement.html]
 [test_select_all_without_body.html]
 skip-if = e10s
 [test_spellcheck_pref.html]
 skip-if = toolkit == 'android'
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/html/tests/test_bug998188.html
@@ -0,0 +1,52 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=565392
+-->
+<head>
+  <title>Test for Bug 998188</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=998188">Mozilla Bug 998188</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<div id="editor" contenteditable>abc</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 998188 **/
+
+SimpleTest.waitForExplicitFinish();
+
+function runTests()
+{
+  var editor = document.getElementById("editor");
+  editor.focus();
+
+  var textNode1 = document.createTextNode("def");
+  var textNode2 = document.createTextNode("ghi");
+
+  editor.appendChild(textNode1);
+  editor.appendChild(textNode2);
+
+  window.getSelection().collapse(textNode2, 3);
+
+  for (var i = 0; i < 9; i++) {
+    var caretRect = synthesizeQueryCaretRect(i);
+    ok(caretRect.succeeded, "QueryCaretRect should succeeded (" + i + ")");
+  }
+
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForFocus(runTests);
+
+</script>
+</pre>
+</body>
+</html>
--- a/testing/mochitest/tests/SimpleTest/ChromeUtils.js
+++ b/testing/mochitest/tests/SimpleTest/ChromeUtils.js
@@ -29,35 +29,16 @@ function synthesizeQueryTextContent(aOff
   if (!utils) {
     return nullptr;
   }
   return utils.sendQueryContentEvent(utils.QUERY_TEXT_CONTENT,
                                      aOffset, aLength, 0, 0);
 }
 
 /**
- * Synthesize a query caret rect event.
- *
- * @param aOffset  The caret offset.  0 means left side of the first character
- *                 in the selection root.
- * @param aWindow  Optional (If null, current |window| will be used)
- * @return         An nsIQueryContentEventResult object.  If this failed,
- *                 the result might be null.
- */
-function synthesizeQueryCaretRect(aOffset, aWindow)
-{
-  var utils = _getDOMWindowUtils(aWindow);
-  if (!utils) {
-    return nullptr;
-  }
-  return utils.sendQueryContentEvent(utils.QUERY_CARET_RECT,
-                                     aOffset, 0, 0, 0);
-}
-
-/**
  * Synthesize a query text rect event.
  *
  * @param aOffset  The character offset.  0 means the first character in the
  *                 selection root.
  * @param aLength  The length of the text.  If the length is too long,
  *                 the extra length is ignored.
  * @param aWindow  Optional (If null, current |window| will be used)
  * @return         An nsIQueryContentEventResult object.  If this failed,
--- a/testing/mochitest/tests/SimpleTest/EventUtils.js
+++ b/testing/mochitest/tests/SimpleTest/EventUtils.js
@@ -984,16 +984,35 @@ function synthesizeQuerySelectedText(aWi
   if (!utils) {
     return null;
   }
 
   return utils.sendQueryContentEvent(utils.QUERY_SELECTED_TEXT, 0, 0, 0, 0);
 }
 
 /**
+ * Synthesize a query caret rect event.
+ *
+ * @param aOffset  The caret offset.  0 means left side of the first character
+ *                 in the selection root.
+ * @param aWindow  Optional (If null, current |window| will be used)
+ * @return         An nsIQueryContentEventResult object.  If this failed,
+ *                 the result might be null.
+ */
+function synthesizeQueryCaretRect(aOffset, aWindow)
+{
+  var utils = _getDOMWindowUtils(aWindow);
+  if (!utils) {
+    return null;
+  }
+  return utils.sendQueryContentEvent(utils.QUERY_CARET_RECT,
+                                     aOffset, 0, 0, 0);
+}
+
+/**
  * Synthesize a selection set event.
  *
  * @param aOffset  The character offset.  0 means the first character in the
  *                 selection root.
  * @param aLength  The length of the text.  If the length is too long,
  *                 the extra length is ignored.
  * @param aReverse If true, the selection is from |aOffset + aLength| to
  *                 |aOffset|.  Otherwise, from |aOffset| to |aOffset + aLength|.