diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-03-28 15:00:10 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-03-28 17:55:17 +0200 |
commit | 6a189b2ac72d5fb83199bdb09e41f7d088440cc9 (patch) | |
tree | 980a682eb9435c5573d794dac97ea6a1451f4c6f /sw/qa/extras/uiwriter | |
parent | e74578ed67d42036646fb575a3c3d5d50147abc0 (diff) |
tdf#108122 HTML export: fix lost images on copy
As in the copy part of copy&paste. The problem was that the document has
an empty base URL during copy, and this was images were not exported at
all.
An alternative fix would be to use embedded images, but sadly Word's
HTML import doesn't understand that markup, so use tempfiles instead.
Change-Id: Iab8c555ac244d943c4958f24f8ac61cba4ec3aba
Reviewed-on: https://gerrit.libreoffice.org/52003
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sw/qa/extras/uiwriter')
-rw-r--r-- | sw/qa/extras/uiwriter/data/image.odt | bin | 0 -> 9569 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 35 |
2 files changed, 34 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/data/image.odt b/sw/qa/extras/uiwriter/data/image.odt Binary files differnew file mode 100644 index 000000000000..195f8836cfad --- /dev/null +++ b/sw/qa/extras/uiwriter/data/image.odt diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 5b97e54f6867..42bdf476b551 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -115,12 +115,15 @@ #include <sfx2/watermarkitem.hxx> #include <sfx2/fcontnr.hxx> #include <sfx2/docfile.hxx> +#include <svtools/htmlout.hxx> +#include <test/htmltesttools.hxx> #include <fmthdft.hxx> #include <iodetect.hxx> +#include <wrthtml.hxx> static char const DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data/"; -class SwUiWriterTest : public SwModelTestBase +class SwUiWriterTest : public SwModelTestBase, public HtmlTestTools { public: @@ -310,6 +313,7 @@ public: void testTdf115132(); void testXDrawPagesSupplier(); void testTdf116403(); + void testHtmlCopyImages(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -496,6 +500,7 @@ public: CPPUNIT_TEST(testTdf115132); CPPUNIT_TEST(testXDrawPagesSupplier); CPPUNIT_TEST(testTdf116403); + CPPUNIT_TEST(testHtmlCopyImages); CPPUNIT_TEST_SUITE_END(); private: @@ -6098,6 +6103,34 @@ void SwUiWriterTest::testTdf116403() static_cast<sal_Int32>(17000 - 2 * 500 - 2 * 1), aTabs[0].Position); } +void SwUiWriterTest::testHtmlCopyImages() +{ + // Load a document with an image. + SwDoc* pDoc = createDoc("image.odt"); + + // Trigger the copy part of HTML copy&paste. + WriterRef xWrt; + xWrt = new SwHTMLWriter( /*rBaseURL=*/OUString() ); + CPPUNIT_ASSERT(xWrt.is()); + + xWrt->bWriteClipboardDoc = true; + xWrt->bWriteOnlyFirstTable = false; + xWrt->SetShowProgress(false); + { + SvFileStream aStream(maTempFile.GetURL(), StreamMode::WRITE|StreamMode::TRUNC); + SwWriter aWrt(aStream, *pDoc); + aWrt.Write(xWrt); + } + htmlDocPtr pHtmlDoc = parseHtml(maTempFile); + CPPUNIT_ASSERT(pHtmlDoc); + + // This failed, image was lost during HTML copy. + OUString aImage = getXPath(pHtmlDoc, "/html/body/p/img", "src"); + // Also make sure that the image is not embedded (e.g. Word doesn't handle + // embedded images). + CPPUNIT_ASSERT(aImage.startsWith("file:///")); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); |