Bug 1109465 - Fix the interface maps of IMETextTxn and InsertTextTxn; r=smaug
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 30 Dec 2014 10:55:42 -0500
changeset 247510 82953efdb40e4e38256ae975dabce703306b35e2
parent 247509 ef7a85ec6595efcf2f74ba35ab9082ca6a57cd2e
child 247511 f46c2220f91be38dd7299474f8906cd28a15f25c
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1109465, 1056166
milestone37.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 1109465 - Fix the interface maps of IMETextTxn and InsertTextTxn; r=smaug The original change in bug 1056166 used NS_INTERFACE_MAP_ENTRY_AMBIGUOUS with the wrong order for argument names. But more importantly, we cannot use NS_INTERFACE_MAP_ENTRY_AMBIGUOUS here because the cast from the concrete class to nsISupports* will remain ambiguous even when casting first through nsITransaction, so we need to write the implementation without using any macros.
editor/libeditor/IMETextTxn.cpp
editor/libeditor/InsertTextTxn.cpp
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_bug1109465.html
--- a/editor/libeditor/IMETextTxn.cpp
+++ b/editor/libeditor/IMETextTxn.cpp
@@ -37,17 +37,19 @@ IMETextTxn::~IMETextTxn()
 {
 }
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(IMETextTxn, EditTxn,
                                    mTextNode)
 // mRangeList can't lead to cycles
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IMETextTxn)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsITransaction, IMETextTxn)
+  if (aIID.Equals(NS_GET_IID(IMETextTxn))) {
+    foundInterface = static_cast<nsITransaction*>(this);
+  } else
 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
 
 NS_IMPL_ADDREF_INHERITED(IMETextTxn, EditTxn)
 NS_IMPL_RELEASE_INHERITED(IMETextTxn, EditTxn)
 
 NS_IMETHODIMP
 IMETextTxn::DoTransaction()
 {
--- a/editor/libeditor/InsertTextTxn.cpp
+++ b/editor/libeditor/InsertTextTxn.cpp
@@ -33,17 +33,19 @@ InsertTextTxn::~InsertTextTxn()
 }
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(InsertTextTxn, EditTxn,
                                    mTextNode)
 
 NS_IMPL_ADDREF_INHERITED(InsertTextTxn, EditTxn)
 NS_IMPL_RELEASE_INHERITED(InsertTextTxn, EditTxn)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(InsertTextTxn)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsITransaction, InsertTextTxn)
+  if (aIID.Equals(NS_GET_IID(InsertTextTxn))) {
+    foundInterface = static_cast<nsITransaction*>(this);
+  } else
 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
 
 
 NS_IMETHODIMP
 InsertTextTxn::DoTransaction()
 {
   nsresult res = mTextNode->InsertData(mOffset, mStringToInsert);
   NS_ENSURE_SUCCESS(res, res);
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -149,8 +149,9 @@ skip-if = toolkit == 'android' # bug 105
 [test_dom_input_event_on_texteditor.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'
 [test_bug1068979.html]
+[test_bug1109465.html]
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_bug1109465.html
@@ -0,0 +1,69 @@
+<!DOCTYPE>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1109465
+-->
+<head>
+  <title>Test for Bug 1109465</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<div id="display">
+  <textarea></textarea>
+</div>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+</pre>
+
+<script class="testbody" type="application/javascript">
+
+/** Test for Bug 1109465 **/
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(function() {
+  var t = document.querySelector("textarea");
+  t.focus();
+
+  // Type foo\nbar and place the caret at the end of the last line
+  synthesizeKey("f", {});
+  synthesizeKey("o", {});
+  synthesizeKey("o", {});
+  synthesizeKey("VK_RETURN", {});
+  synthesizeKey("b", {});
+  synthesizeKey("a", {});
+  synthesizeKey("r", {});
+  synthesizeKey("VK_UP", {});
+  is(t.selectionStart, 3, "Correct start of selection");
+  is(t.selectionEnd, 3, "Correct end of selection");
+
+  // Compose an IME string
+  synthesizeComposition({ type: "compositionstart" });
+  var composingString = "\u306B";
+  synthesizeCompositionChange(
+    { "composition":
+      { "string": composingString,
+        "clauses":
+        [
+          { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
+        ]
+      },
+      "caret": { "start": 1, "length": 0 }
+    });
+  synthesizeComposition({ type: "compositioncommitasis" });
+  is(t.value, "foo\u306B\nbar", "Correct value after composition");
+
+  // Now undo to test that the transaction merger has correctly detected the
+  // IMETextTxn.
+  synthesizeKey("Z", {accelKey: true});
+  is(t.value, "foo\nbar", "Correct value after undo");
+
+  SimpleTest.finish();
+});
+
+</script>
+</body>
+
+</html>