Bug 1215517 part.2 Add tests for eQueryTextContent event in rich text editor r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 20 Oct 2015 14:14:17 +0900
changeset 303645 9f97448cf56a8f5fe758f9d0ab271d87fb4f3aa7
parent 303644 80d578836131322040a650a1a7672a4f84fa9a98
child 303646 4e79bfe043c8419874fff97657178408eb51ea63
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1215517
milestone44.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 1215517 part.2 Add tests for eQueryTextContent event in rich text editor r=smaug
widget/tests/window_composition_text_querycontent.xul
--- a/widget/tests/window_composition_text_querycontent.xul
+++ b/widget/tests/window_composition_text_querycontent.xul
@@ -116,50 +116,57 @@ function getHTMLEditorIMESupport(aWindow
                  QueryInterface(nsIDocShell).
                  editor;
 }
 
 const kIsWin = (navigator.platform.indexOf("Win") == 0);
 const kIsMac = (navigator.platform.indexOf("Mac") == 0);
 
 const kLFLen = kIsWin ? 2 : 1;
+const kLF = kIsWin ? "\r\n" : "\n";
 
 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;
 }
 
 function checkContent(aExpectedText, aMessage, aID)
 {
+  if (!aID) {
+    aID = "";
+  }
   var textContent = synthesizeQueryTextContent(0, 100);
   if (!checkQueryContentResult(textContent, aMessage +
                                ": synthesizeQueryTextContent " + aID)) {
     return false;
   }
   is(textContent.text, aExpectedText,
-     aMessage + ": composition string is wrong" + aID);
+     aMessage + ": composition string is wrong " + aID);
   return textContent.text == aExpectedText;
 }
 
 function checkSelection(aExpectedOffset, aExpectedText, aMessage, aID)
 {
+  if (!aID) {
+    aID = "";
+  }
   var selectedText = synthesizeQuerySelectedText();
   if (!checkQueryContentResult(selectedText, aMessage +
                                ": synthesizeQuerySelectedText " + aID)) {
     return false;
   }
   is(selectedText.offset, aExpectedOffset,
-     aMessage + ": selection offset is wrong" + aID);
+     aMessage + ": selection offset is wrong " + aID);
   is(selectedText.text, aExpectedText,
-     aMessage + ": selected text is wrong" + aID);
+     aMessage + ": selected text is wrong " + aID);
   return selectedText.offset == aExpectedOffset &&
          selectedText.text == aExpectedText;
 }
 
 function checkRect(aRect, aExpectedRect, aMessage)
 {
   is(aRect.left, aExpectedRect.left, aMessage + ": left is wrong");
   is(aRect.top, aExpectedRect.top, aMessage + " top is wrong");
@@ -2795,16 +2802,164 @@ function runSetSelectionEventTest()
   todo_is(selection.anchorOffset, contenteditable.firstChild.childNodes.length,
      "runSetSelectionEventTest #8 (kLFLen*2, 0): selection anchor offset should be the count of the <p>'s children");
   todo_is(selection.focusNode, contenteditable.firstChild,
      "runSetSelectionEventTest #8 (kLFLen*2, 0): selection focus node should be the <p> node");
   todo_is(selection.focusOffset, contenteditable.firstChild.childNodes.length,
      "runSetSelectionEventTest #8 (kLFLen*2, 0): selection focus offset should be the count of the <p>'s children");
 }
 
+function runQueryTextContentEventTest()
+{
+  contenteditable.focus();
+
+  var result;
+
+  // #1
+  contenteditable.innerHTML = "abc<br>def";
+
+  result = synthesizeQueryTextContent(0, 6 + kLFLen);
+  is(result.text, "abc" + kLF + "def", "runQueryTextContentEventTest #1 (0, 6+kLFLen)");
+
+  result = synthesizeQueryTextContent(0, 100);
+  is(result.text, "abc" + kLF + "def", "runQueryTextContentEventTest #1 (0, 100)");
+
+  result = synthesizeQueryTextContent(2, 2 + kLFLen);
+  is(result.text, "c" + kLF + "d", "runQueryTextContentEventTest #1 (2, 2+kLFLen)");
+
+  result = synthesizeQueryTextContent(1, 2);
+  is(result.text, "bc", "runQueryTextContentEventTest #1 (1, 2)");
+
+  result = synthesizeQueryTextContent(3, kLFLen);
+  is(result.text, kLF, "runQueryTextContentEventTest #1 (3, kLFLen)");
+
+  result = synthesizeQueryTextContent(6 + kLFLen, 1);
+  is(result.text, "", "runQueryTextContentEventTest #1 (6 + kLFLen, 0)");
+
+  // #2
+  contenteditable.innerHTML = "<p>a<b>b</b>c</p><p>def</p>";
+
+  result = synthesizeQueryTextContent(0, 4);
+  is(result.text, "abcd", "runQueryTextContentEventTest #2 (0, 4)");
+
+  result = synthesizeQueryTextContent(0, 2);
+  is(result.text, "ab", "runQueryTextContentEventTest #2 (0, 2)");
+
+  result = synthesizeQueryTextContent(1, 2);
+  is(result.text, "bc", "runQueryTextContentEventTest #2 (1, 2)");
+
+  result = synthesizeQueryTextContent(2, 2);
+  is(result.text, "cd", "runQueryTextContentEventTest #2 (2, 2)");
+
+  result = synthesizeQueryTextContent(3, 1);
+  is(result.text, "d", "runQueryTextContentEventTest #2 (3, 1)");
+
+  // #3
+  contenteditable.innerHTML = "<div>abc<p>def</p></div>";
+
+  result = synthesizeQueryTextContent(1, 2);
+  is(result.text, "bc", "runQueryTextContentEventTest #3 (1, 2)");
+
+  result = synthesizeQueryTextContent(1, 3);
+  is(result.text, "bcd", "runQueryTextContentEventTest #3 (1, 3)");
+
+  result = synthesizeQueryTextContent(3, 1);
+  is(result.text, "d", "runQueryTextContentEventTest #3 (3, 1)");
+
+  result = synthesizeQueryTextContent(0, 6);
+  is(result.text, "abcdef", "runQueryTextContentEventTest #3 (0, 6)");
+
+  result = synthesizeQueryTextContent(0, 100);
+  is(result.text, "abcdef", "runQueryTextContentEventTest #3 (0, 100)");
+
+  result = synthesizeQueryTextContent(4, 2);
+  is(result.text, "ef", "runQueryTextContentEventTest #3 (4, 2)");
+
+  result = synthesizeQueryTextContent(4, 100);
+  is(result.text, "ef", "runQueryTextContentEventTest #3 (4, 100)");
+
+  result = synthesizeQueryTextContent(6, 1);
+  is(result.text, "", "runQueryTextContentEventTest #3 (6, 1)");
+
+  // #4
+  contenteditable.innerHTML = "<div><p>abc</p>def</div>";
+
+  result = synthesizeQueryTextContent(1, 2);
+  is(result.text, "bc", "runQueryTextContentEventTest #4 (1, 2)");
+
+  result = synthesizeQueryTextContent(1, 3);
+  is(result.text, "bcd", "runQueryTextContentEventTest #4 (1, 3)");
+
+  result = synthesizeQueryTextContent(3, 1);
+  is(result.text, "d", "runQueryTextContentEventTest #4 (3, 1)");
+
+  result = synthesizeQueryTextContent(0, 6);
+  is(result.text, "abcdef", "runQueryTextContentEventTest #4 (0, 6)");
+
+  result = synthesizeQueryTextContent(0, 100);
+  is(result.text, "abcdef", "runQueryTextContentEventTest #4 (0, 100)");
+
+  result = synthesizeQueryTextContent(4, 2);
+  is(result.text, "ef", "runQueryTextContentEventTest #4 (4, 2)");
+
+  result = synthesizeQueryTextContent(4, 100);
+  is(result.text, "ef", "runQueryTextContentEventTest #4 (4, 100)");
+
+  result = synthesizeQueryTextContent(6, 1);
+  is(result.text, "", "runQueryTextContentEventTest #4 (6, 1)");
+
+  // #5
+  contenteditable.innerHTML = "<br>";
+
+  result = synthesizeQueryTextContent(0, kLFLen);
+  is(result.text, kLF, "runQueryTextContentEventTest #5 (0, kLFLen)");
+
+  result = synthesizeQueryTextContent(kLFLen, 1);
+  is(result.text, "", "runQueryTextContentEventTest #5 (kLFLen, 1)");
+
+  // #6
+  contenteditable.innerHTML = "<p><br></p>";
+
+  result = synthesizeQueryTextContent(0, kLFLen);
+  is(result.text, kLF, "runQueryTextContentEventTest #6 (0, kLFLen)");
+
+  result = synthesizeQueryTextContent(kLFLen, 1);
+  is(result.text, "", "runQueryTextContentEventTest #5 (kLFLen, 1)");
+
+  // #7
+  contenteditable.innerHTML = "<br><br>";
+
+  result = synthesizeQueryTextContent(0, kLFLen);
+  is(result.text, kLF, "runQueryTextContentEventTest #7 (0, kLFLen)");
+
+  result = synthesizeQueryTextContent(0, kLFLen * 2);
+  is(result.text, kLF + kLF, "runQueryTextContentEventTest #7 (0, kLFLen*2)");
+
+  result = synthesizeQueryTextContent(kLFLen, kLFLen);
+  is(result.text, kLF, "runQueryTextContentEventTest #7 (kLFLen, kLFLen)");
+
+  result = synthesizeQueryTextContent(kLFLen * 2, 1);
+  is(result.text, "", "runQueryTextContentEventTest #7 (kLFLen*2, 1)");
+
+  // #8
+  contenteditable.innerHTML = "<p><br><br></p>";
+
+  result = synthesizeQueryTextContent(0, kLFLen);
+  is(result.text, kLF, "runQueryTextContentEventTest #8 (0, kLFLen)");
+
+  result = synthesizeQueryTextContent(0, kLFLen * 2);
+  is(result.text, kLF + kLF, "runQueryTextContentEventTest #8 (0, kLFLen*2)");
+
+  result = synthesizeQueryTextContent(kLFLen, kLFLen);
+  is(result.text, kLF, "runQueryTextContentEventTest #8 (kLFLen, kLFLen)");
+
+  result = synthesizeQueryTextContent(kLFLen * 2, 1);
+  is(result.text, "", "runQueryTextContentEventTest #8 (kLFLen*2, 1)");
+}
+
 function runCSSTransformTest()
 {
   textarea.focus();
   textarea.value = "some text";
   textarea.selectionStart = textarea.selectionEnd = textarea.value.length;
   var editorRect = synthesizeQueryEditorRect();
   if (!checkQueryContentResult(editorRect,
         "runCSSTransformTest: editorRect")) {
@@ -5089,16 +5244,17 @@ function runTest()
   runUndoRedoTest();
   runCompositionCommitAsIsTest();
   runCompositionCommitTest();
   runCompositionTest();
   runCompositionEventTest();
   runCharAtPointTest(textarea, "textarea in the document");
   runCharAtPointAtOutsideTest();
   runSetSelectionEventTest();
+  runQueryTextContentEventTest();
   runCSSTransformTest();
   runBug722639Test();
   runForceCommitTest();
   runNestedSettingValue();
   runBug811755Test();
   runIsComposingTest();
   runRedundantChangeTest();
   runNotRedundantChangeTest();