/* 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/. */ // Regression tests for Bug 2034094: dragging from LibreOffice Calc yields // garbled text/html and missing text/plain data on Linux/X11. #include "gtest/gtest.h" #include "mozilla/widget/nsGtkHtmlUtils.h" #include "nsString.h" #include "mozilla/Span.h" using namespace mozilla; using namespace mozilla::widget; // GetHTMLCharset unit tests TEST(GtkDragDropUtils, GetHTMLCharsetUTF8) { const char html[] = R"()" "
test"; nsCString charset; EXPECT_TRUE(GetHTMLCharset(MakeStringSpan(html), charset)); EXPECT_STREQ(charset.get(), "UTF-8"); } TEST(GtkDragDropUtils, GetHTMLCharsetISO88591) { const char html[] = R"()" "test"; nsCString charset; EXPECT_TRUE(GetHTMLCharset(MakeStringSpan(html), charset)); EXPECT_STREQ(charset.get(), "ISO-8859-1"); } TEST(GtkDragDropUtils, GetHTMLCharsetNotFound) { const char html[] = "no charset here"; nsCString charset; EXPECT_FALSE(GetHTMLCharset(MakeStringSpan(html), charset)); } // DecodeHTMLData unit tests TEST(GtkDragDropUtils, DecodeHTMLDataUTF8NonAscii) { // U+00E9 (e-acute) encoded as UTF-8: 0xC3 0xA9 const char html[] = R"()" "\xC3\xA9"; nsString decoded; EXPECT_TRUE(DecodeHTMLData(MakeStringSpan(html), decoded)); EXPECT_NE(decoded.Find(u"é"_ns), kNotFound); } TEST(GtkDragDropUtils, DecodeHTMLDataFallbackUTF8) { const char html[] = "\xC3\xA9"; nsString decoded; EXPECT_TRUE(DecodeHTMLData(MakeStringSpan(html), decoded)); EXPECT_NE(decoded.Find(u"é"_ns), kNotFound); } // Firefox prepends kHTMLMarkupPrefix when writing HTML to the clipboard or // drag source. DecodeHTMLData must strip it so it doesn't appear in the // output (Firefox-to-Firefox round-trip path). TEST(GtkDragDropUtils, DecodeHTMLDataStripsFirefoxPrefix) { nsAutoCString html; html.AppendLiteral(kHTMLMarkupPrefix); html.AppendLiteral("hello"); nsString decoded; EXPECT_TRUE( DecodeHTMLData(Span