Bug 998188 part.5 Fix orange and improve EventUtils.js and ChromeUtils.js r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 26 Apr 2014 08:52:13 +0900
changeset 180705 8305804b3099e068fa7f9dcf66c2836f8183c736
parent 180704 776018f74fed4a2dfd144781e62160f77e5439e2
child 180706 93b58802f74386df550295870f5be2bfc5ea51ac
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewerssmaug
bugs998188
milestone31.0a1
Bug 998188 part.5 Fix orange and improve EventUtils.js and ChromeUtils.js r=smaug
dom/tests/mochitest/chrome/queryCaretRectUnix.html
dom/tests/mochitest/chrome/queryCaretRectWin.html
testing/mochitest/tests/SimpleTest/ChromeUtils.js
testing/mochitest/tests/SimpleTest/EventUtils.js
--- a/dom/tests/mochitest/chrome/queryCaretRectUnix.html
+++ b/dom/tests/mochitest/chrome/queryCaretRectUnix.html
@@ -68,18 +68,20 @@
     if (aElement instanceof Ci.nsIDOMNSEditableElement) {
       return aElement.QueryInterface(Ci.nsIDOMNSEditableElement)
                      .editor.selection;
     }
     return null;
   }
 
   function testCaretPosition(aDomWinUtils, aOffset, aRectDims) {
-    let rect = aDomWinUtils.sendQueryContentEvent(aDomWinUtils.QUERY_CARET_RECT,
-                                                  aOffset, 0, 0, 0);
+    let rect = aDomWinUtils.sendQueryContentEvent(
+                 aDomWinUtils.QUERY_CARET_RECT,
+                 aOffset, 0, 0, 0,
+                 aDomWinUtils.QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK);
     ok(rect, "rect returned");
     ok(rect.succeeded, "call succeeded");
 
     info("left:" + rect.left + " top:" + rect.top);
 
     ok(rect.left > aRectDims.min.left, "rect.left > " + aRectDims.min.left);
     ok(rect.left < aRectDims.max.left, "rect.left < " + aRectDims.max.left);
     ok(rect.top > aRectDims.min.top, "rect.top > " + aRectDims.min.top);
--- a/dom/tests/mochitest/chrome/queryCaretRectWin.html
+++ b/dom/tests/mochitest/chrome/queryCaretRectWin.html
@@ -77,18 +77,20 @@
     if (aElement instanceof Ci.nsIDOMNSEditableElement) {
       return aElement.QueryInterface(Ci.nsIDOMNSEditableElement)
                      .editor.selection;
     }
     return null;
   }
 
   function testCaretPosition(aDomWinUtils, aOffset, aRectDims) {
-    let rect = aDomWinUtils.sendQueryContentEvent(aDomWinUtils.QUERY_CARET_RECT,
-                                                  aOffset, 0, 0, 0);
+    let rect = aDomWinUtils.sendQueryContentEvent(
+                 aDomWinUtils.QUERY_CARET_RECT,
+                 aOffset, 0, 0, 0,
+                 aDomWinUtils.QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK);
     ok(rect, "rect returned");
     ok(rect.succeeded, "call succeeded");
 
     info("left:" + rect.left + " top:" + rect.top);
 
     ok(rect.left > aRectDims.min.left, "rect.left > " + aRectDims.min.left);
     ok(rect.left < aRectDims.max.left, "rect.left < " + aRectDims.max.left);
     ok(rect.top > aRectDims.min.top, "rect.top > " + aRectDims.min.top);
--- a/testing/mochitest/tests/SimpleTest/ChromeUtils.js
+++ b/testing/mochitest/tests/SimpleTest/ChromeUtils.js
@@ -25,17 +25,18 @@ scriptLoader.loadSubScript("chrome://moc
  */
 function synthesizeQueryTextContent(aOffset, aLength, aWindow)
 {
   var utils = _getDOMWindowUtils(aWindow);
   if (!utils) {
     return nullptr;
   }
   return utils.sendQueryContentEvent(utils.QUERY_TEXT_CONTENT,
-                                     aOffset, aLength, 0, 0);
+                                     aOffset, aLength, 0, 0,
+                                     QUERY_CONTENT_FLAG_USE_NATIVE_LINE_BREAK);
 }
 
 /**
  * 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,
@@ -46,33 +47,35 @@ function synthesizeQueryTextContent(aOff
  */
 function synthesizeQueryTextRect(aOffset, aLength, aWindow)
 {
   var utils = _getDOMWindowUtils(aWindow);
   if (!utils) {
     return nullptr;
   }
   return utils.sendQueryContentEvent(utils.QUERY_TEXT_RECT,
-                                     aOffset, aLength, 0, 0);
+                                     aOffset, aLength, 0, 0,
+                                     QUERY_CONTENT_FLAG_USE_NATIVE_LINE_BREAK);
 }
 
 /**
  * Synthesize a query editor rect event.
  *
  * @param aWindow  Optional (If null, current |window| will be used)
  * @return         An nsIQueryContentEventResult object.  If this failed,
  *                 the result might be null.
  */
 function synthesizeQueryEditorRect(aWindow)
 {
   var utils = _getDOMWindowUtils(aWindow);
   if (!utils) {
     return nullptr;
   }
-  return utils.sendQueryContentEvent(utils.QUERY_EDITOR_RECT, 0, 0, 0, 0);
+  return utils.sendQueryContentEvent(utils.QUERY_EDITOR_RECT, 0, 0, 0, 0,
+                                     QUERY_CONTENT_FLAG_USE_NATIVE_LINE_BREAK);
 }
 
 /**
  * Synthesize a character at point event.
  *
  * @param aX, aY   The offset in the client area of the DOM window.
  * @param aWindow  Optional (If null, current |window| will be used)
  * @return         An nsIQueryContentEventResult object.  If this failed,
@@ -80,17 +83,18 @@ function synthesizeQueryEditorRect(aWind
  */
 function synthesizeCharAtPoint(aX, aY, aWindow)
 {
   var utils = _getDOMWindowUtils(aWindow);
   if (!utils) {
     return nullptr;
   }
   return utils.sendQueryContentEvent(utils.QUERY_CHARACTER_AT_POINT,
-                                     0, 0, aX, aY);
+                                     0, 0, aX, aY,
+                                     QUERY_CONTENT_FLAG_USE_NATIVE_LINE_BREAK);
 }
 
 /**
  * Emulate a dragstart event.
  *  element - element to fire the dragstart event on
  *  expectedDragData - the data you expect the data transfer to contain afterwards
  *                      This data is in the format:
  *                         [ [ {type: value, data: value, test: function}, ... ], ... ]
--- a/testing/mochitest/tests/SimpleTest/EventUtils.js
+++ b/testing/mochitest/tests/SimpleTest/EventUtils.js
@@ -966,31 +966,40 @@ function synthesizeText(aEvent, aWindow)
 
   if (aEvent.caret) {
     compositionString.setCaret(aEvent.caret.start, aEvent.caret.length);
   }
 
   compositionString.dispatchEvent();
 }
 
+// Must be synchronized with nsIDOMWindowUtils.
+const QUERY_CONTENT_FLAG_USE_NATIVE_LINE_BREAK          = 0x0000;
+const QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK              = 0x0001;
+
+const SELECTION_SET_FLAG_USE_NATIVE_LINE_BREAK          = 0x0000;
+const SELECTION_SET_FLAG_USE_XP_LINE_BREAK              = 0x0001;
+const SELECTION_SET_FLAG_REVERSE                        = 0x0002;
+
 /**
  * Synthesize a query selected text event.
  *
  * @param aWindow  Optional (If null, current |window| will be used)
  * @return         An nsIQueryContentEventResult object.  If this failed,
  *                 the result might be null.
  */
 function synthesizeQuerySelectedText(aWindow)
 {
   var utils = _getDOMWindowUtils(aWindow);
   if (!utils) {
     return null;
   }
 
-  return utils.sendQueryContentEvent(utils.QUERY_SELECTED_TEXT, 0, 0, 0, 0);
+  return utils.sendQueryContentEvent(utils.QUERY_SELECTED_TEXT, 0, 0, 0, 0,
+                                     QUERY_CONTENT_FLAG_USE_NATIVE_LINE_BREAK);
 }
 
 /**
  * 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)
@@ -999,17 +1008,18 @@ function synthesizeQuerySelectedText(aWi
  */
 function synthesizeQueryCaretRect(aOffset, aWindow)
 {
   var utils = _getDOMWindowUtils(aWindow);
   if (!utils) {
     return null;
   }
   return utils.sendQueryContentEvent(utils.QUERY_CARET_RECT,
-                                     aOffset, 0, 0, 0);
+                                     aOffset, 0, 0, 0,
+                                     QUERY_CONTENT_FLAG_USE_NATIVE_LINE_BREAK);
 }
 
 /**
  * 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,
@@ -1020,10 +1030,11 @@ function synthesizeQueryCaretRect(aOffse
  * @return         True, if succeeded.  Otherwise false.
  */
 function synthesizeSelectionSet(aOffset, aLength, aReverse, aWindow)
 {
   var utils = _getDOMWindowUtils(aWindow);
   if (!utils) {
     return false;
   }
-  return utils.sendSelectionSetEvent(aOffset, aLength, aReverse);
+  var flags = aReverse ? SELECTION_SET_FLAG_REVERSE : 0;
+  return utils.sendSelectionSetEvent(aOffset, aLength, flags);
 }