From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/base/test/gtest/TestNativeXMLHttpRequest.cpp | 58 ++++++ dom/base/test/gtest/TestParserDialogOptions.cpp | 138 ++++++++++++++ dom/base/test/gtest/TestPlainTextSerializer.cpp | 231 +++++++++++++++++++++++ dom/base/test/gtest/moz.build | 19 ++ 4 files changed, 446 insertions(+) create mode 100644 dom/base/test/gtest/TestNativeXMLHttpRequest.cpp create mode 100644 dom/base/test/gtest/TestParserDialogOptions.cpp create mode 100644 dom/base/test/gtest/TestPlainTextSerializer.cpp create mode 100644 dom/base/test/gtest/moz.build (limited to 'dom/base/test/gtest') diff --git a/dom/base/test/gtest/TestNativeXMLHttpRequest.cpp b/dom/base/test/gtest/TestNativeXMLHttpRequest.cpp new file mode 100644 index 000000000..920d80e96 --- /dev/null +++ b/dom/base/test/gtest/TestNativeXMLHttpRequest.cpp @@ -0,0 +1,58 @@ +/* -*- 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 "gtest/gtest.h" + +#include "nsContentUtils.h" +#include "nsIDOMDocument.h" +#include "nsIPrincipal.h" +#include "nsIScriptSecurityManager.h" +#include "nsIXMLHttpRequest.h" + +#define TEST_URL_PREFIX "data:text/xml," +#define TEST_URL_CONTENT "" +#define TEST_URL TEST_URL_PREFIX TEST_URL_CONTENT + +TEST(NativeXMLHttpRequest, Test) +{ + nsresult rv; + + nsCOMPtr xhr = + do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv); + ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Couldn't create nsIXMLHttpRequest instance"; + + NS_NAMED_LITERAL_CSTRING(getString, "GET"); + NS_NAMED_LITERAL_CSTRING(testURL, TEST_URL); + const nsAString& empty = EmptyString(); + + nsCOMPtr secman = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Couldn't get script security manager"; + + nsCOMPtr systemPrincipal; + rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal)); + ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Couldn't get system principal"; + + rv = xhr->Init(systemPrincipal, nullptr, nullptr, nullptr); + ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Couldn't initialize the XHR"; + + rv = xhr->Open(getString, testURL, false, empty, empty); + ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Open failed"; + + rv = xhr->Send(nullptr); + ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Send failed"; + + nsAutoString response; + rv = xhr->GetResponseText(response); + ASSERT_TRUE(NS_SUCCEEDED(rv)) << "GetResponse failed"; + ASSERT_TRUE(response.EqualsLiteral(TEST_URL_CONTENT)) << + "Response text does not match"; + + nsCOMPtr dom; + rv = xhr->GetResponseXML(getter_AddRefs(dom)); + ASSERT_TRUE(NS_SUCCEEDED(rv)) << "GetResponseXML failed"; + ASSERT_TRUE(dom) << "No DOM document constructed"; +} diff --git a/dom/base/test/gtest/TestParserDialogOptions.cpp b/dom/base/test/gtest/TestParserDialogOptions.cpp new file mode 100644 index 000000000..055f9ebfd --- /dev/null +++ b/dom/base/test/gtest/TestParserDialogOptions.cpp @@ -0,0 +1,138 @@ +/* -*- 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 "gtest/gtest.h" +#include "nsGlobalWindow.h" + +struct dialog_test { + const char* input; + const char* output; +}; + +void runTokenizeTest(dialog_test& test) +{ + NS_ConvertUTF8toUTF16 input(test.input); + + nsAString::const_iterator end; + input.EndReading(end); + + nsAString::const_iterator iter; + input.BeginReading(iter); + + nsAutoString result; + nsAutoString token; + + while (nsGlobalWindow::TokenizeDialogOptions(token, iter, end)) { + if (!result.IsEmpty()) { + result.Append(','); + } + + result.Append(token); + } + + ASSERT_STREQ(test.output, NS_ConvertUTF16toUTF8(result).get()) << "Testing " << test.input; +} + +void runTest(dialog_test& test) +{ + NS_ConvertUTF8toUTF16 input(test.input); + + nsAutoString result; + nsGlobalWindow::ConvertDialogOptions(input, result); + + ASSERT_STREQ(test.output, NS_ConvertUTF16toUTF8(result).get()) << "Testing " << test.input; +} + +TEST(GlobalWindowDialogOptions, TestDialogTokenize) +{ + dialog_test tests[] = { + /// Empty strings + { "", "" }, + { " ", "" }, + { " ", "" }, + + // 1 token + { "a", "a" }, + { " a", "a" }, + { " a ", "a" }, + { "aa", "aa" }, + { " aa", "aa" }, + { " aa ", "aa" }, + { ";", ";" }, + { ":", ":" }, + { "=", "=" }, + + // 2 tokens + { "a=", "a,=" }, + { " a= ", "a,=" }, + { " a = ", "a,=" }, + { "aa=", "aa,=" }, + { " aa= ", "aa,=" }, + { " aa = ", "aa,=" }, + { ";= ", ";,=" }, + { "==", "=,=" }, + { "::", ":,:" }, + + // 3 tokens + { "a=2", "a,=,2" }, + { "===", "=,=,=" }, + { ";:=", ";,:,=" }, + + // more + { "aaa;bbb:ccc", "aaa,;,bbb,:,ccc" }, + + // sentinel + { nullptr, nullptr } + }; + + for (uint32_t i = 0; tests[i].input; ++i) { + runTokenizeTest(tests[i]); + } +} +TEST(GlobalWindowDialogOptions, TestDialogOptions) +{ + dialog_test tests[] = { + /// Empty strings + { "", "" }, + { " ", "" }, + { " ", "" }, + + // Name without params + { "a", "" }, + { " a", "" }, + { " a ", "" }, + { "a=", "" }, + { " a= ", "" }, + { " a = ", "" }, + + // 1 unknown value + { "a=2", "" }, + { " a=2 ", "" }, + { " a = 2 ", "" }, + { "a:2", "" }, + { " a:2 ", "" }, + { " a : 2 ", "" }, + + // 1 known value, wrong value + { "center=2", "" }, + { "center:2", "" }, + + // 1 known value, good value + { "center=on", ",centerscreen=1" }, + { "center:on", ",centerscreen=1" }, + { " center : on ", ",centerscreen=1" }, + + // nonsense stuff + { " ; ", "" }, + + // sentinel + { nullptr, nullptr } + }; + + for (uint32_t i = 0; tests[i].input; ++i) { + runTest(tests[i]); + } +} diff --git a/dom/base/test/gtest/TestPlainTextSerializer.cpp b/dom/base/test/gtest/TestPlainTextSerializer.cpp new file mode 100644 index 000000000..c29340209 --- /dev/null +++ b/dom/base/test/gtest/TestPlainTextSerializer.cpp @@ -0,0 +1,231 @@ +/* -*- 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 "gtest/gtest.h" + +#include "nsServiceManagerUtils.h" +#include "nsStringGlue.h" +#include "nsIDocumentEncoder.h" +#include "nsCRT.h" +#include "nsIParserUtils.h" + +void +ConvertBufToPlainText(nsString &aConBuf, int aFlag) +{ + nsCOMPtr utils = do_GetService(NS_PARSERUTILS_CONTRACTID); + utils->ConvertToPlainText(aConBuf, aFlag, 72, aConBuf); +} + +// Test for ASCII with format=flowed; delsp=yes +TEST(PlainTextSerializer, ASCIIWithFlowedDelSp) +{ + nsString test; + nsString result; + + test.AssignLiteral("" + "Firefox Firefox Firefox Firefox " + "Firefox Firefox Firefox Firefox " + "Firefox Firefox Firefox Firefox" + ""); + + ConvertBufToPlainText(test, nsIDocumentEncoder::OutputFormatted | + nsIDocumentEncoder::OutputCRLineBreak | + nsIDocumentEncoder::OutputLFLineBreak | + nsIDocumentEncoder::OutputFormatFlowed | + nsIDocumentEncoder::OutputFormatDelSp); + + // create result case + result.AssignLiteral("Firefox Firefox Firefox Firefox " + "Firefox Firefox Firefox Firefox " + "Firefox \r\nFirefox Firefox Firefox\r\n"); + + ASSERT_TRUE(test.Equals(result)) << + "Wrong HTML to ASCII text serialization with format=flowed; delsp=yes"; +} + +// Test for CJK with format=flowed; delsp=yes +TEST(PlainTextSerializer, CJKWithFlowedDelSp) +{ + nsString test; + nsString result; + + test.AssignLiteral(""); + for (uint32_t i = 0; i < 40; i++) { + // Insert Kanji (U+5341) + test.Append(0x5341); + } + test.AppendLiteral(""); + + ConvertBufToPlainText(test, nsIDocumentEncoder::OutputFormatted | + nsIDocumentEncoder::OutputCRLineBreak | + nsIDocumentEncoder::OutputLFLineBreak | + nsIDocumentEncoder::OutputFormatFlowed | + nsIDocumentEncoder::OutputFormatDelSp); + + // create result case + for (uint32_t i = 0; i < 36; i++) { + result.Append(0x5341); + } + result.AppendLiteral(" \r\n"); + for (uint32_t i = 0; i < 4; i++) { + result.Append(0x5341); + } + result.AppendLiteral("\r\n"); + + ASSERT_TRUE(test.Equals(result)) << + "Wrong HTML to CJK text serialization with format=flowed; delsp=yes"; +} + +// Test for CJK with DisallowLineBreaking +TEST(PlainTextSerializer, CJKWithDisallowLineBreaking) +{ + nsString test; + nsString result; + + test.AssignLiteral(""); + for (uint32_t i = 0; i < 400; i++) { + // Insert Kanji (U+5341) + test.Append(0x5341); + } + test.AppendLiteral(""); + + ConvertBufToPlainText(test, nsIDocumentEncoder::OutputFormatted | + nsIDocumentEncoder::OutputCRLineBreak | + nsIDocumentEncoder::OutputLFLineBreak | + nsIDocumentEncoder::OutputFormatFlowed | + nsIDocumentEncoder::OutputDisallowLineBreaking); + + // create result case + for (uint32_t i = 0; i < 400; i++) { + result.Append(0x5341); + } + result.AppendLiteral("\r\n"); + + ASSERT_TRUE(test.Equals(result)) << + "Wrong HTML to CJK text serialization with OutputDisallowLineBreaking"; +} + +// Test for ASCII with format=flowed; and quoted lines in preformatted span. +TEST(PlainTextSerializer, PreformatFlowedQuotes) +{ + nsString test; + nsString result; + + test.AssignLiteral("" + "" + "> Firefox Firefox Firefox Firefox
" + "> Firefox Firefox Firefox Firefox
" + ">
" + ">> Firefox Firefox Firefox Firefox
" + ">> Firefox Firefox Firefox Firefox
" + "
"); + + ConvertBufToPlainText(test, nsIDocumentEncoder::OutputFormatted | + nsIDocumentEncoder::OutputCRLineBreak | + nsIDocumentEncoder::OutputLFLineBreak | + nsIDocumentEncoder::OutputFormatFlowed); + + // create result case + result.AssignLiteral("> Firefox Firefox Firefox Firefox \r\n" + "> Firefox Firefox Firefox Firefox\r\n" + ">\r\n" + ">> Firefox Firefox Firefox Firefox \r\n" + ">> Firefox Firefox Firefox Firefox\r\n"); + + ASSERT_TRUE(test.Equals(result)) << + "Wrong HTML to ASCII text serialization with format=flowed; and quoted " + "lines"; +} + +TEST(PlainTextSerializer, PrettyPrintedHtml) +{ + nsString test; + test.AppendLiteral( + "" NS_LINEBREAK + "" NS_LINEBREAK + " first
" NS_LINEBREAK + " second
" NS_LINEBREAK + "" NS_LINEBREAK ""); + + ConvertBufToPlainText(test, 0); + ASSERT_TRUE(test.EqualsLiteral("first" NS_LINEBREAK "second" NS_LINEBREAK)) << + "Wrong prettyprinted html to text serialization"; +} + +TEST(PlainTextSerializer, PreElement) +{ + nsString test; + test.AppendLiteral( + "" NS_LINEBREAK + "" NS_LINEBREAK + "
" NS_LINEBREAK
+    "  first" NS_LINEBREAK
+    "  second" NS_LINEBREAK
+    "
" NS_LINEBREAK + "" NS_LINEBREAK ""); + + ConvertBufToPlainText(test, 0); + ASSERT_TRUE(test.EqualsLiteral(" first" NS_LINEBREAK + " second" NS_LINEBREAK NS_LINEBREAK)) << + "Wrong prettyprinted html to text serialization"; +} + +TEST(PlainTextSerializer, BlockElement) +{ + nsString test; + test.AppendLiteral( + "" NS_LINEBREAK + "" NS_LINEBREAK + "
" NS_LINEBREAK + " first" NS_LINEBREAK + "
" NS_LINEBREAK + "
" NS_LINEBREAK + " second" NS_LINEBREAK + "
" NS_LINEBREAK + "" NS_LINEBREAK ""); + + ConvertBufToPlainText(test, 0); + ASSERT_TRUE(test.EqualsLiteral("first" NS_LINEBREAK "second" NS_LINEBREAK)) << + "Wrong prettyprinted html to text serialization"; +} + +TEST(PlainTextSerializer, PreWrapElementForThunderbird) +{ + // This test examines the magic pre-wrap setup that Thunderbird relies on. + nsString test; + test.AppendLiteral( + "" NS_LINEBREAK + "" NS_LINEBREAK + "
" NS_LINEBREAK
+    "  first line is too long" NS_LINEBREAK
+    "  second line is even loooonger  " NS_LINEBREAK
+    "
" NS_LINEBREAK + "" NS_LINEBREAK ""); + + ConvertBufToPlainText(test, nsIDocumentEncoder::OutputWrap); + // "\n\n first\nline is\ntoo long\n second\nline is\neven\nloooonger\n\n\n" + ASSERT_TRUE(test.EqualsLiteral(NS_LINEBREAK NS_LINEBREAK + " first" NS_LINEBREAK + "line is" NS_LINEBREAK + "too long" NS_LINEBREAK + " second" NS_LINEBREAK + "line is" NS_LINEBREAK + "even" NS_LINEBREAK + "loooonger" NS_LINEBREAK + NS_LINEBREAK NS_LINEBREAK)) << + "Wrong prettyprinted html to text serialization"; +} + +TEST(PlainTextSerializer, Simple) +{ + nsString test; + test.AppendLiteral("basespan" + "body"); + ConvertBufToPlainText(test, 0); + ASSERT_TRUE(test.EqualsLiteral("basespanbody")) << + "Wrong html to text serialization"; +} + diff --git a/dom/base/test/gtest/moz.build b/dom/base/test/gtest/moz.build new file mode 100644 index 000000000..a211184e8 --- /dev/null +++ b/dom/base/test/gtest/moz.build @@ -0,0 +1,19 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +UNIFIED_SOURCES += [ + 'TestNativeXMLHttpRequest.cpp', + 'TestParserDialogOptions.cpp', + 'TestPlainTextSerializer.cpp', +] + +LOCAL_INCLUDES += [ + '/dom/base' +] + +include('/ipc/chromium/chromium-config.mozbuild') + +FINAL_LIBRARY = 'xul-gtest' -- cgit v1.2.3