Bug 1485890 - Remove dumpContentTree, debugDumpContent and debugUnitTests from nsIEditor. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 29 Oct 2018 07:23:49 +0000
changeset 502510 4ad8c042d0803dc069cb33ef6c70e8fbc1e04bca
parent 502509 369be6501d4b790389c59599d1eb780aa903fbd1
child 502511 8ce35618b310a02074ed5d599f6ea19bf1c29b8d
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1485890, 1491173
milestone65.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 1485890 - Remove dumpContentTree, debugDumpContent and debugUnitTests from nsIEditor. r=masayuki Since bug 1491173 is landed, there is no users of dumpContentTree, debugDumpContent and debugUnitTests. So Let's remove these methods from nsIEditor. Differential Revision: https://phabricator.services.mozilla.com/D10029
editor/libeditor/EditorBase.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/TextEditorTest.cpp
editor/libeditor/TextEditorTest.h
editor/libeditor/moz.build
editor/nsIEditor.idl
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -2302,52 +2302,16 @@ NS_IMETHODIMP
 EditorBase::OutputToString(const nsAString& aFormatType,
                            uint32_t aFlags,
                            nsAString& aOutputString)
 {
   // these should be implemented by derived classes.
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP
-EditorBase::DumpContentTree()
-{
-#ifdef DEBUG
-  if (mRootElement) {
-    mRootElement->List(stdout);
-  }
-#endif
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-EditorBase::DebugDumpContent()
-{
-#ifdef DEBUG
-  nsCOMPtr<nsIDocument> document = GetDocument();
-  if (NS_WARN_IF(!document)) {
-    return NS_ERROR_NOT_INITIALIZED;
-  }
-  Element* body = document->GetBody();
-  if (body) {
-    body->List();
-  }
-#endif
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-EditorBase::DebugUnitTests(int32_t* outNumTests,
-                           int32_t* outNumTestsFailed)
-{
-  MOZ_ASSERT_UNREACHABLE("This should never get called. Overridden by "
-                         "subclasses");
-  return NS_OK;
-}
-
 bool
 EditorBase::ArePreservingSelection()
 {
   return !(mSavedSel.IsEmpty());
 }
 
 void
 EditorBase::PreserveSelectionAcrossActions(Selection* aSel)
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -46,17 +46,16 @@
 
 // netwerk
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 
 // Misc
 #include "mozilla/EditorUtils.h"
 #include "HTMLEditorObjectResizerUtils.h"
-#include "TextEditorTest.h"
 #include "WSRunObject.h"
 #include "nsGkAtoms.h"
 #include "nsIWidget.h"
 
 #include "nsIFrame.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/dom/Element.h"
@@ -3568,34 +3567,16 @@ HTMLEditor::ContentRemoved(nsIContent* a
 
     RefPtr<HTMLEditRules> htmlRules = mRules->AsHTMLEditRules();
     if (htmlRules) {
       htmlRules->DocumentModified();
     }
   }
 }
 
-NS_IMETHODIMP
-HTMLEditor::DebugUnitTests(int32_t* outNumTests,
-                           int32_t* outNumTestsFailed)
-{
-#ifdef DEBUG
-  NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER);
-
-  TextEditorTest *tester = new TextEditorTest();
-  NS_ENSURE_TRUE(tester, NS_ERROR_OUT_OF_MEMORY);
-
-  tester->Run(this, outNumTests, outNumTestsFailed);
-  delete tester;
-  return NS_OK;
-#else
-  return NS_ERROR_NOT_IMPLEMENTED;
-#endif
-}
-
 void
 HTMLEditor::OnStartToHandleTopLevelEditSubAction(
               EditSubAction aEditSubAction,
               nsIEditor::EDirection aDirection)
 {
   // Protect the edit rules object from dying
   RefPtr<TextEditRules> rules(mRules);
 
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -134,19 +134,16 @@ public:
   NS_IMETHOD SetFlags(uint32_t aFlags) override;
 
   NS_IMETHOD CanPaste(int32_t aSelectionType, bool* aCanPaste) override;
 
   NS_IMETHOD PasteTransferable(nsITransferable* aTransferable) override;
 
   NS_IMETHOD DeleteNode(nsINode* aNode) override;
 
-  NS_IMETHOD DebugUnitTests(int32_t* outNumTests,
-                            int32_t* outNumTestsFailed) override;
-
   virtual nsresult HandleKeyPressEvent(
                      WidgetKeyboardEvent* aKeyboardEvent) override;
   virtual nsIContent* GetFocusedContent() override;
   virtual already_AddRefed<nsIContent> GetFocusedContentForIME() override;
   virtual bool IsActiveInDOMWindow() override;
   virtual dom::EventTarget* GetDOMEventTarget() override;
   virtual Element* FindSelectionRoot(nsINode *aNode) const override;
   virtual bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent) override;
deleted file mode 100644
--- a/editor/libeditor/TextEditorTest.cpp
+++ /dev/null
@@ -1,242 +0,0 @@
-/* -*- Mode: C++ tab-width: 2 indent-tabs-mode: nil c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifdef DEBUG
-
-#include "TextEditorTest.h"
-
-#include <stdio.h>
-
-#include "nsDebug.h"
-#include "nsError.h"
-#include "nsGkAtoms.h"
-#include "nsIDocument.h"
-#include "nsIEditor.h"
-#include "nsIHTMLEditor.h"
-#include "nsINodeList.h"
-#include "nsIPlaintextEditor.h"
-#include "nsLiteralString.h"
-#include "nsReadableUtils.h"
-#include "nsString.h"
-#include "nsStringFwd.h"
-#include "mozilla/dom/Selection.h"
-
-using mozilla::dom::Selection;
-
-#define TEST_RESULT(r) { if (NS_FAILED(r)) {printf("FAILURE result=%X\n", static_cast<uint32_t>(r)); return r; } }
-#define TEST_POINTER(p) { if (!p) {printf("FAILURE null pointer\n"); return NS_ERROR_NULL_POINTER; } }
-
-TextEditorTest::TextEditorTest()
-{
-  printf("constructed a TextEditorTest\n");
-}
-
-TextEditorTest::~TextEditorTest()
-{
-  printf("destroyed a TextEditorTest\n");
-}
-
-void TextEditorTest::Run(nsIEditor *aEditor, int32_t *outNumTests, int32_t *outNumTestsFailed)
-{
-  if (!aEditor) return;
-  mTextEditor = do_QueryInterface(aEditor);
-  mEditor = aEditor;
-  RunUnitTest(outNumTests, outNumTestsFailed);
-}
-
-nsresult TextEditorTest::RunUnitTest(int32_t *outNumTests, int32_t *outNumTestsFailed)
-{
-  NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER);
-
-  *outNumTests = 0;
-  *outNumTestsFailed = 0;
-
-  nsresult rv = InitDoc();
-  TEST_RESULT(rv);
-  // shouldn't we just bail on error here?
-
-  // insert some simple text
-  rv = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
-  TEST_RESULT(rv);
-  (*outNumTests)++;
-  if (NS_FAILED(rv)) {
-    ++(*outNumTestsFailed);
-  }
-
-  // insert some more text
-  rv = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states.  I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham.  Injustice anywhere is a threat to justice everywhere"));
-  TEST_RESULT(rv);
-  (*outNumTests)++;
-  if (NS_FAILED(rv)) {
-    ++(*outNumTestsFailed);
-  }
-
-  rv = TestInsertBreak();
-  TEST_RESULT(rv);
-  (*outNumTests)++;
-  if (NS_FAILED(rv)) {
-    ++(*outNumTestsFailed);
-  }
-
-  rv = TestTextProperties();
-  TEST_RESULT(rv);
-  (*outNumTests)++;
-  if (NS_FAILED(rv)) {
-    ++(*outNumTestsFailed);
-  }
-
-  // get us back to the original document
-  rv = mEditor->Undo(12);
-  TEST_RESULT(rv);
-
-  return rv;
-}
-
-nsresult TextEditorTest::InitDoc()
-{
-  nsresult rv = mEditor->SelectAll();
-  TEST_RESULT(rv);
-  rv = mEditor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
-  TEST_RESULT(rv);
-  return rv;
-}
-
-nsresult TextEditorTest::TestInsertBreak()
-{
-  RefPtr<Selection>selection;
-  nsresult rv = mEditor->GetSelection(getter_AddRefs(selection));
-  TEST_RESULT(rv);
-  TEST_POINTER(selection.get());
-  nsCOMPtr<nsINode> anchor = selection->GetAnchorNode();
-  TEST_RESULT(rv);
-  TEST_POINTER(anchor.get());
-  selection->Collapse(anchor, 0);
-  // insert one break
-  printf("inserting a break\n");
-  rv = mTextEditor->InsertLineBreak();
-  TEST_RESULT(rv);
-  mEditor->DebugDumpContent();
-
-  // insert a second break adjacent to the first
-  printf("inserting a second break\n");
-  rv = mTextEditor->InsertLineBreak();
-  TEST_RESULT(rv);
-  mEditor->DebugDumpContent();
-
-  return rv;
-}
-
-nsresult TextEditorTest::TestTextProperties()
-{
-  nsCOMPtr<nsIDocument> doc = mEditor->AsEditorBase()->GetDocument();
-  TEST_POINTER(doc.get());
-  // XXX This is broken, text nodes are not elements.
-  nsAutoString textTag(NS_LITERAL_STRING("#text"));
-  nsCOMPtr<nsINodeList>nodeList = doc->GetElementsByTagName(textTag);
-  TEST_POINTER(nodeList.get());
-  uint32_t count = nodeList->Length();
-  NS_ASSERTION(0 != count, "there are no text nodes in the document!");
-  nsCOMPtr<nsINode>textNode = nodeList->Item(count - 1);
-  TEST_POINTER(textNode.get());
-
-  // set the whole text node to bold
-  printf("set the whole first text node to bold\n");
-  RefPtr<Selection>selection;
-  nsresult rv = mEditor->GetSelection(getter_AddRefs(selection));
-  TEST_RESULT(rv);
-  TEST_POINTER(selection.get());
-  uint32_t length = textNode->Length();
-  selection->Collapse(textNode, 0);
-  selection->Extend(textNode, length);
-
-  nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mTextEditor));
-  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
-
-  bool any = false;
-  bool all = false;
-  bool first=false;
-
-  const nsString& empty = EmptyString();
-
-  NS_NAMED_LITERAL_STRING(b, "b");
-  NS_NAMED_LITERAL_STRING(i, "i");
-  NS_NAMED_LITERAL_STRING(u, "u");
-
-  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
-  TEST_RESULT(rv);
-  NS_ASSERTION(false==first, "first should be false");
-  NS_ASSERTION(false==any, "any should be false");
-  NS_ASSERTION(false==all, "all should be false");
-  rv = htmlEditor->SetInlineProperty(b, empty, empty);
-  TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
-  TEST_RESULT(rv);
-  NS_ASSERTION(true==first, "first should be true");
-  NS_ASSERTION(true==any, "any should be true");
-  NS_ASSERTION(true==all, "all should be true");
-  mEditor->DebugDumpContent();
-
-  // remove the bold we just set
-  printf("set the whole first text node to not bold\n");
-  rv = htmlEditor->RemoveInlineProperty(b, empty);
-  TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
-  TEST_RESULT(rv);
-  NS_ASSERTION(false==first, "first should be false");
-  NS_ASSERTION(false==any, "any should be false");
-  NS_ASSERTION(false==all, "all should be false");
-  mEditor->DebugDumpContent();
-
-  // set all but the first and last character to bold
-  printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n");
-  selection->Collapse(textNode, 1);
-  selection->Extend(textNode, length-1);
-  rv = htmlEditor->SetInlineProperty(b, empty, empty);
-  TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
-  TEST_RESULT(rv);
-  NS_ASSERTION(true==first, "first should be true");
-  NS_ASSERTION(true==any, "any should be true");
-  NS_ASSERTION(true==all, "all should be true");
-  mEditor->DebugDumpContent();
-  // make all that same text italic
-  rv = htmlEditor->SetInlineProperty(i, empty, empty);
-  TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(i, empty, empty, &first, &any, &all);
-  TEST_RESULT(rv);
-  NS_ASSERTION(true==first, "first should be true");
-  NS_ASSERTION(true==any, "any should be true");
-  NS_ASSERTION(true==all, "all should be true");
-  rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
-  TEST_RESULT(rv);
-  NS_ASSERTION(true==first, "first should be true");
-  NS_ASSERTION(true==any, "any should be true");
-  NS_ASSERTION(true==all, "all should be true");
-  mEditor->DebugDumpContent();
-
-  // make all the text underlined, except for the first 2 and last 2 characters
-  nodeList = doc->GetElementsByTagName(textTag);
-  TEST_POINTER(nodeList.get());
-  count = nodeList->Length();
-  NS_ASSERTION(0!=count, "there are no text nodes in the document!");
-  textNode = nodeList->Item(count-2);
-  TEST_POINTER(textNode.get());
-  length = textNode->Length();
-  NS_ASSERTION(length==915, "wrong text node");
-  selection->Collapse(textNode, 1);
-  selection->Extend(textNode, length-2);
-  rv = htmlEditor->SetInlineProperty(u, empty, empty);
-  TEST_RESULT(rv);
-  rv = htmlEditor->GetInlineProperty(u, empty, empty, &first, &any, &all);
-  TEST_RESULT(rv);
-  NS_ASSERTION(true==first, "first should be true");
-  NS_ASSERTION(true==any, "any should be true");
-  NS_ASSERTION(true==all, "all should be true");
-  mEditor->DebugDumpContent();
-
-  return rv;
-}
-
-#endif
deleted file mode 100644
--- a/editor/libeditor/TextEditorTest.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __TextEditorTest_h__
-#define __TextEditorTest_h__
-
-#include "nscore.h"
-
-class nsIEditor;
-class nsIPlaintextEditor;
-#ifdef DEBUG
-
-#include "nsCOMPtr.h"
-
-class TextEditorTest
-{
-public:
-
-  void Run(nsIEditor *aEditor, int32_t *outNumTests, int32_t *outNumTestsFailed);
-  TextEditorTest();
-  ~TextEditorTest();
-
-protected:
-
-  /** create an empty document */
-  nsresult InitDoc();
-
-  nsresult RunUnitTest(int32_t *outNumTests, int32_t *outNumTestsFailed);
-
-  nsresult TestInsertBreak();
-
-  nsresult TestTextProperties();
-
-  nsCOMPtr<nsIPlaintextEditor> mTextEditor;
-  nsCOMPtr<nsIEditor> mEditor;
-};
-
-#endif /* DEBUG */
-
-#endif
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -66,17 +66,16 @@ UNIFIED_SOURCES += [
     'InsertTextTransaction.cpp',
     'InternetCiter.cpp',
     'JoinNodeTransaction.cpp',
     'PlaceholderTransaction.cpp',
     'SelectionState.cpp',
     'SplitNodeTransaction.cpp',
     'TextEditor.cpp',
     'TextEditorDataTransfer.cpp',
-    'TextEditorTest.cpp',
     'TextEditRules.cpp',
     'TextEditRulesBidi.cpp',
     'TextEditUtils.cpp',
     'TypeInState.cpp',
     'WSRunObject.cpp',
 ]
 
 LOCAL_INCLUDES += [
--- a/editor/nsIEditor.idl
+++ b/editor/nsIEditor.idl
@@ -466,30 +466,16 @@ interface nsIEditor  : nsISupports
   void removeEditActionListener(in nsIEditActionListener listener);
 
   /** Add a DocumentStateListener to the editors list of doc state listeners. */
   void addDocumentStateListener(in nsIDocumentStateListener listener);
 
   /** Remove a DocumentStateListener to the editors list of doc state listeners. */
   void removeDocumentStateListener(in nsIDocumentStateListener listener);
 
-
-  /* ------------ Debug methods -------------- */
-
-  /**
-   * And a debug method -- show us what the tree looks like right now
-   */
-  void dumpContentTree();
-
-  /** Dumps a text representation of the content tree to standard out */
-  void debugDumpContent() ;
-
-  /* Run unit tests. Noop in optimized builds */
-  void debugUnitTests(out long outNumTests, out long  outNumTestsFailed);
-
   /**
    * forceCompositionEnd() force the composition end
    */
   void forceCompositionEnd();
 
   /**
    * whether this editor has active IME transaction
    */