tdf#147666 sw layout: add test case

The test adds a large picture to the test document, and tests if the
document correctly moves focus to the added picture.

Change-Id: I10c6ac00510250c374391fe9a53d42b3df317bb0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158761
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sw/qa/extras/layout/data/tdf147666.odt b/sw/qa/extras/layout/data/tdf147666.odt
new file mode 100644
index 0000000..23a09b5
--- /dev/null
+++ b/sw/qa/extras/layout/data/tdf147666.odt
Binary files differ
diff --git a/sw/qa/extras/layout/data/tdf147666.png b/sw/qa/extras/layout/data/tdf147666.png
new file mode 100644
index 0000000..7e845d3
--- /dev/null
+++ b/sw/qa/extras/layout/data/tdf147666.png
Binary files differ
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index e4bfc51..8dc7b61 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -19,6 +19,7 @@
#include <editeng/unolingu.hxx>
#include <editeng/editobj.hxx>
#include <comphelper/sequence.hxx>
#include <comphelper/propertyvalue.hxx>

#include <fmtfsize.hxx>
#include <wrtsh.hxx>
@@ -2208,6 +2209,40 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf57187_Tdf158900)
}

} // end of anonymous namespace

CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf147666)
{
    createSwDoc("tdf147666.odt");

    // Move cursor into position to insert image
    dispatchCommand(mxComponent, ".uno:GoToEndOfPara", {});
    dispatchCommand(mxComponent, ".uno:GoDown", {});

    save("writer8");
    sal_Int32 nNonInsertedViewTop
        = getXPathContent(parseExport("settings.xml"),
                          "//config:config-item[@config:name='ViewTop']"_ostr)
              .toInt32();

    // Insert image below the end of the paragraph on page one
    uno::Sequence<beans::PropertyValue> aArgs = {
        comphelper::makePropertyValue("FileName", createFileURL(u"tdf147666.png")),
    };
    dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs);

    save("writer8");
    sal_Int32 nInsertedViewTop
        = getXPathContent(parseExport("settings.xml"),
                          "//config:config-item[@config:name='ViewTop']"_ostr)
              .toInt32();

    // Without the fix in place this will fail with
    // nInsertedViewTop = nNonInsertedViewTop
    // i.e. when the image is inserted, the view doesn't
    // focus to the inserted graphic
    CPPUNIT_ASSERT_LESS(nInsertedViewTop, nNonInsertedViewTop);
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */