tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e2fbc47166f364668a5bd613e267b50de6081764
parent 458596e38ee00e8b467a4c5f4fa4954ec79a3310
Author: Edgar Chen <echen@mozilla.com>
Date:   Tue, 14 Oct 2025 07:44:05 +0000

Bug 1992067 - Move nsPlainTextSerializer gtest for <blockquote type=cite> into its own test file; r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D267173

Diffstat:
Adom/serializers/gtest/Common.h | 21+++++++++++++++++++++
Mdom/serializers/gtest/TestPlainTextSerializer.cpp | 29+----------------------------
Adom/serializers/gtest/TestPlainTextSerializerBlockQuoteCite.cpp | 33+++++++++++++++++++++++++++++++++
Mdom/serializers/gtest/moz.build | 1+
4 files changed, 56 insertions(+), 28 deletions(-)

diff --git a/dom/serializers/gtest/Common.h b/dom/serializers/gtest/Common.h @@ -0,0 +1,21 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 dom_serializers_gtest_Common_h +#define dom_serializers_gtest_Common_h + +#include "nsIParserUtils.h" +#include "nsServiceManagerUtils.h" +#include "nsString.h" + +const uint32_t kDefaultWrapColumn = 72; + +void ConvertBufToPlainText(nsString& aConBuf, int aFlag, uint32_t aWrapColumn) { + nsCOMPtr<nsIParserUtils> utils = do_GetService(NS_PARSERUTILS_CONTRACTID); + utils->ConvertToPlainText(aConBuf, aFlag, aWrapColumn, aConBuf); +} + +#endif // dom_serializers_gtest_Common_h diff --git a/dom/serializers/gtest/TestPlainTextSerializer.cpp b/dom/serializers/gtest/TestPlainTextSerializer.cpp @@ -4,6 +4,7 @@ * 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/. */ +#include "Common.h" #include "gtest/gtest.h" #include "nsCRT.h" #include "nsIDocumentEncoder.h" @@ -11,13 +12,6 @@ #include "nsServiceManagerUtils.h" #include "nsString.h" -const uint32_t kDefaultWrapColumn = 72; - -void ConvertBufToPlainText(nsString& aConBuf, int aFlag, uint32_t aWrapColumn) { - nsCOMPtr<nsIParserUtils> utils = do_GetService(NS_PARSERUTILS_CONTRACTID); - utils->ConvertToPlainText(aConBuf, aFlag, aWrapColumn, aConBuf); -} - // Test for ASCII with format=flowed; delsp=yes TEST(PlainTextSerializer, ASCIIWithFlowedDelSp) { @@ -351,24 +345,3 @@ TEST(PlainTextSerializer, OneHundredAndOneOL) expected.AppendLiteral(" 1. X" NS_LINEBREAK); ASSERT_EQ(test, expected); } - -TEST(PlainTextSerializer, BlockQuoteCite) -{ - nsAutoString test; - test.AppendLiteral(u"<blockquote type=cite>hello world</blockquote>"); - - const uint32_t wrapColumn = 10; - ConvertBufToPlainText(test, - nsIDocumentEncoder::OutputFormatted | - nsIDocumentEncoder::OutputFormatFlowed | - nsIDocumentEncoder::OutputCRLineBreak | - nsIDocumentEncoder::OutputLFLineBreak, - wrapColumn); - - constexpr auto expect = NS_LITERAL_STRING_FROM_CSTRING( - "> hello \r\n" - "> world\r\n"); - - ASSERT_TRUE(test.Equals(expect)) - << "Wrong blockquote cite to text serialization"; -} diff --git a/dom/serializers/gtest/TestPlainTextSerializerBlockQuoteCite.cpp b/dom/serializers/gtest/TestPlainTextSerializerBlockQuoteCite.cpp @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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/. */ + +#include "Common.h" +#include "gtest/gtest.h" +#include "nsCRT.h" +#include "nsIDocumentEncoder.h" +#include "nsIParserUtils.h" +#include "nsServiceManagerUtils.h" +#include "nsString.h" + +TEST(PlainTextSerializerBlockQuoteCite, BlockQuoteCite) +{ + nsAutoString test; + test.AppendLiteral(u"<blockquote type=cite>hello world</blockquote>"); + + const uint32_t wrapColumn = 10; + ConvertBufToPlainText(test, + nsIDocumentEncoder::OutputFormatted | + nsIDocumentEncoder::OutputFormatFlowed | + nsIDocumentEncoder::OutputCRLineBreak | + nsIDocumentEncoder::OutputLFLineBreak, + wrapColumn); + + constexpr auto expect = NS_LITERAL_STRING_FROM_CSTRING( + "> hello \r\n" + "> world\r\n"); + + ASSERT_EQ(test, expect) << "Wrong blockquote cite to text serialization"; +} diff --git a/dom/serializers/gtest/moz.build b/dom/serializers/gtest/moz.build @@ -6,6 +6,7 @@ UNIFIED_SOURCES += [ "TestPlainTextSerializer.cpp", + "TestPlainTextSerializerBlockQuoteCite.cpp", ] include("/ipc/chromium/chromium-config.mozbuild")