summaryrefslogtreecommitdiffstats
path: root/dom/base/test/gtest
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/base/test/gtest
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/base/test/gtest')
-rw-r--r--dom/base/test/gtest/TestNativeXMLHttpRequest.cpp58
-rw-r--r--dom/base/test/gtest/TestParserDialogOptions.cpp138
-rw-r--r--dom/base/test/gtest/TestPlainTextSerializer.cpp231
-rw-r--r--dom/base/test/gtest/moz.build19
4 files changed, 446 insertions, 0 deletions
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 "<foo><bar></bar></foo>"
+#define TEST_URL TEST_URL_PREFIX TEST_URL_CONTENT
+
+TEST(NativeXMLHttpRequest, Test)
+{
+ nsresult rv;
+
+ nsCOMPtr<nsIXMLHttpRequest> 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<nsIScriptSecurityManager> secman =
+ do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
+ ASSERT_TRUE(NS_SUCCEEDED(rv)) << "Couldn't get script security manager";
+
+ nsCOMPtr<nsIPrincipal> 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<nsIDOMDocument> 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<nsIParserUtils> 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("<html><body>"
+ "Firefox Firefox Firefox Firefox "
+ "Firefox Firefox Firefox Firefox "
+ "Firefox Firefox Firefox Firefox"
+ "</body></html>");
+
+ 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("<html><body>");
+ for (uint32_t i = 0; i < 40; i++) {
+ // Insert Kanji (U+5341)
+ test.Append(0x5341);
+ }
+ test.AppendLiteral("</body></html>");
+
+ 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("<html><body>");
+ for (uint32_t i = 0; i < 400; i++) {
+ // Insert Kanji (U+5341)
+ test.Append(0x5341);
+ }
+ test.AppendLiteral("</body></html>");
+
+ 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("<html><body>"
+ "<span style=\"white-space: pre-wrap;\">"
+ "&gt; Firefox Firefox Firefox Firefox <br>"
+ "&gt; Firefox Firefox Firefox Firefox<br>"
+ "&gt;<br>"
+ "&gt;&gt; Firefox Firefox Firefox Firefox <br>"
+ "&gt;&gt; Firefox Firefox Firefox Firefox<br>"
+ "</span></body></html>");
+
+ 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(
+ "<html>" NS_LINEBREAK
+ "<body>" NS_LINEBREAK
+ " first<br>" NS_LINEBREAK
+ " second<br>" NS_LINEBREAK
+ "</body>" NS_LINEBREAK "</html>");
+
+ 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(
+ "<html>" NS_LINEBREAK
+ "<body>" NS_LINEBREAK
+ "<pre>" NS_LINEBREAK
+ " first" NS_LINEBREAK
+ " second" NS_LINEBREAK
+ "</pre>" NS_LINEBREAK
+ "</body>" NS_LINEBREAK "</html>");
+
+ 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(
+ "<html>" NS_LINEBREAK
+ "<body>" NS_LINEBREAK
+ "<div>" NS_LINEBREAK
+ " first" NS_LINEBREAK
+ "</div>" NS_LINEBREAK
+ "<div>" NS_LINEBREAK
+ " second" NS_LINEBREAK
+ "</div>" NS_LINEBREAK
+ "</body>" NS_LINEBREAK "</html>");
+
+ 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(
+ "<html>" NS_LINEBREAK
+ "<body style=\"white-space: pre-wrap; width: 10ch;\">" NS_LINEBREAK
+ "<pre>" NS_LINEBREAK
+ " first line is too long" NS_LINEBREAK
+ " second line is even loooonger " NS_LINEBREAK
+ "</pre>" NS_LINEBREAK
+ "</body>" NS_LINEBREAK "</html>");
+
+ 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("<html><base>base</base><head><span>span</span></head>"
+ "<body>body</body></html>");
+ 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'