diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2018-10-08 19:42:56 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-10-16 19:21:49 +0200 |
commit | c8b68f7d63df9335ab4ef90441d3d2815bb4ddd6 (patch) | |
tree | 18eb5c8c6e4ae9ad90ead4279fc4ba006f1cfcc7 /sd/qa | |
parent | 78313adecc5c9ec9ec0d54c1f4b181cd6ac53813 (diff) |
tdf#119956 unit test, LayerTabBar, adapt focus if Alt+Click
The test simulates Alt+Click and checks which tab is current.
Some methods have been exported, so that they can be used in
the test. The test classes have been changed to get an odg
document really opened in Draw.
Change-Id: I6ece8594f297c48c862693ead049e6e1f9edbc31
Reviewed-on: https://gerrit.libreoffice.org/61545
Tested-by: Jenkins
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sd/qa')
-rw-r--r-- | sd/qa/unit/data/tdf119956.odg | bin | 0 -> 11124 bytes | |||
-rw-r--r-- | sd/qa/unit/misc-tests.cxx | 92 | ||||
-rw-r--r-- | sd/qa/unit/sdmodeltestbase.hxx | 3 |
3 files changed, 83 insertions, 12 deletions
diff --git a/sd/qa/unit/data/tdf119956.odg b/sd/qa/unit/data/tdf119956.odg Binary files differnew file mode 100644 index 000000000000..eb1104035f1a --- /dev/null +++ b/sd/qa/unit/data/tdf119956.odg diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx index df038e5fde65..2bfd5789407a 100644 --- a/sd/qa/unit/misc-tests.cxx +++ b/sd/qa/unit/misc-tests.cxx @@ -20,6 +20,7 @@ #include <com/sun/star/frame/XModel2.hpp> #include <com/sun/star/awt/Gradient.hpp> +#include <com/sun/star/awt/PosSize.hpp> #include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <com/sun/star/drawing/XDrawPages.hpp> @@ -46,10 +47,17 @@ #include <controller/SlsClipboard.hxx> #include <controller/SlsPageSelector.hxx> #include <undo/undomanager.hxx> -#include <DrawViewShell.hxx> +#include <GraphicViewShell.hxx> #include <chrono> #include <sdpage.hxx> #include <comphelper/base64.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <LayerTabBar.hxx> +#include <vcl/window.hxx> +#include <vcl/event.hxx> +#include <vcl/keycodes.hxx> + + using namespace ::com::sun::star; @@ -68,6 +76,7 @@ public: void testTdf101242_settings(); void testTdf119392(); void testTdf67248(); + void testTdf119956(); CPPUNIT_TEST_SUITE(SdMiscTest); CPPUNIT_TEST(testTdf96206); @@ -81,6 +90,7 @@ public: CPPUNIT_TEST(testTdf101242_settings); CPPUNIT_TEST(testTdf119392); CPPUNIT_TEST(testTdf67248); + CPPUNIT_TEST(testTdf119956); CPPUNIT_TEST_SUITE_END(); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override @@ -118,6 +128,17 @@ sd::DrawDocShellRef SdMiscTest::Load(const OUString& rURL, sal_Int32 nFormat) uno::Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame("_blank", 0); CPPUNIT_ASSERT(xTargetFrame.is()); + // This ContainerWindow corresponds to the outermost window of a running LibreOffice. + // It needs a non-zero size and must be shown. Otherwise visible elements like the + // LayerTabBar in Draw have zero size and cannot get mouse events. + // The here used size is freely chosen. + uno::Reference<awt::XWindow> xContainerWindow = xTargetFrame->getContainerWindow(); + CPPUNIT_ASSERT(xContainerWindow.is()); + xContainerWindow->setPosSize(0, 0, 1024, 768, awt::PosSize::SIZE); + VclPtr<vcl::Window> pContainerWindow = VCLUnoHelper::GetWindow(xContainerWindow); + CPPUNIT_ASSERT(pContainerWindow); + pContainerWindow->Show(true); + // 1. Open the document sd::DrawDocShellRef xDocSh = loadURL(rURL, nFormat); CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocSh.is()); @@ -137,16 +158,27 @@ sd::DrawDocShellRef SdMiscTest::Load(const OUString& rURL, sal_Int32 nFormat) sd::ViewShell *pViewShell = xDocSh->GetViewShell(); CPPUNIT_ASSERT(pViewShell); - sd::slidesorter::SlideSorterViewShell* pSSVS = nullptr; - for (int i = 0; i < 1000; i++) + + // Draw has no slidesorter, Impress never shows a LayerTabBar + if (sd::ViewShell::ST_DRAW == pViewShell->GetShellType()) { - // Process all Tasks - slide sorter is created here - while (Scheduler::ProcessTaskScheduling()); - if ((pSSVS = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase())) != nullptr) - break; - osl::Thread::wait(std::chrono::milliseconds(100)); + sd::LayerTabBar* pLayerTabBar = static_cast<sd::GraphicViewShell*>(pViewShell)->GetLayerTabControl(); + CPPUNIT_ASSERT(pLayerTabBar); + pLayerTabBar->StateChanged(StateChangedType::InitShow); + } + else + { + sd::slidesorter::SlideSorterViewShell* pSSVS = nullptr; + for (int i = 0; i < 1000; i++) + { + // Process all Tasks - slide sorter is created here + while (Scheduler::ProcessTaskScheduling()); + if ((pSSVS = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase())) != nullptr) + break; + osl::Thread::wait(std::chrono::milliseconds(100)); + } + CPPUNIT_ASSERT(pSSVS); } - CPPUNIT_ASSERT(pSSVS); return xDocSh; } @@ -497,7 +529,7 @@ void SdMiscTest::testTdf119392() // Loads a document which has two user layers "V--" and "V-L". Inserts a new layer "-P-" between them. // Checks, that the bitfields in the saved file have the bits in the correct order. - sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf119392_InsertLayer.odg"), ODG); + sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf119392_InsertLayer.odg"), ODG); CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is()); // Insert layer "-P-", not visible, printable, not locked SdrView* pView = xDocShRef -> GetViewShell()->GetView(); @@ -542,7 +574,7 @@ void SdMiscTest::testTdf67248() // The document tdf67248.odg has been created with a German UI. It has a user layer named "Background". // On opening the user layer must still exists. The error was, that it was merged into the standard // layer "background". - sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf67248.odg"), ODG); + sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf67248.odg"), ODG); CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is()); SdrLayerAdmin& rLayerAdmin = xDocShRef->GetDoc()->GetLayerAdmin(); CPPUNIT_ASSERT_EQUAL( sal_uInt16(6), rLayerAdmin.GetLayerCount()); @@ -550,6 +582,44 @@ void SdMiscTest::testTdf67248() xDocShRef->DoClose(); } +void SdMiscTest::testTdf119956() +{ + sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf119956.odg"), ODG); + CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is()); + sd::GraphicViewShell* pGraphicViewShell = static_cast<sd::GraphicViewShell*>(xDocShRef -> GetViewShell()); + CPPUNIT_ASSERT(pGraphicViewShell); + sd::LayerTabBar* pLayerTabBar = pGraphicViewShell->GetLayerTabControl(); + CPPUNIT_ASSERT(pLayerTabBar); + + // Alt+Click sets a tab in edit mode, so that you can rename it. + // The error was, that Alt+Click on a tab, which was not the current tab, did not set the clicked tab + // as current tab. As a result, the entered text was applied to the wrong tab. + + // The test document has the layer tabs "layout", "controls", "measurelines" and "Layer4" in this order + // The "pagePos" is 0, 1, 2, 3 + // Make sure, that tab "layout" is the current tab. + MouseEvent aSyntheticMouseEvent; + if (pLayerTabBar->GetCurPagePos() != 0) + { + sal_uInt16 nIdOfTabPos0(pLayerTabBar->GetPageId(0)); + tools::Rectangle aTabPos0Rect(pLayerTabBar->GetPageRect(nIdOfTabPos0)); + aSyntheticMouseEvent = MouseEvent(aTabPos0Rect.Center(), 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, 0); + pLayerTabBar->MouseButtonDown(aSyntheticMouseEvent); + } + CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pLayerTabBar->GetCurPagePos()); + + // Alt+Click on tab "Layer4" + sal_uInt16 nIdOfTabPos3(pLayerTabBar->GetPageId(3)); + tools::Rectangle aTabPos3Rect(pLayerTabBar->GetPageRect(nIdOfTabPos3)); + aSyntheticMouseEvent = MouseEvent(aTabPos3Rect.Center(), 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, KEY_MOD2); + pLayerTabBar->MouseButtonDown(aSyntheticMouseEvent); + + // Make sure, tab 3 is current tab now. + CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pLayerTabBar->GetCurPagePos()); + + xDocShRef->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx index 089e36c6dd63..153798399cb1 100644 --- a/sd/qa/unit/sdmodeltestbase.hxx +++ b/sd/qa/unit/sdmodeltestbase.hxx @@ -20,6 +20,7 @@ #include <drawdoc.hxx> #include <DrawDocShell.hxx> +#include <GraphicDocShell.hxx> #include <unotools/tempfile.hxx> #include <unotools/ucbstreamhelper.hxx> #include <tools/color.hxx> @@ -147,7 +148,7 @@ protected: pFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); std::shared_ptr<const SfxFilter> pFilt(pFilter); - ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false, DocumentType::Draw); + ::sd::DrawDocShellRef xDocShRef = new ::sd::GraphicDocShell(SfxObjectCreateMode::EMBEDDED); SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilt, std::move(pParams)); if ( !xDocShRef->DoLoad(pSrcMed) || !xDocShRef.is() ) { |